Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bootloader] Implement bootloader reset reasons #2773

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bootloader/src/rtl872x/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void HAL_Delay_Microseconds(uint32_t uSec) {
}

void HAL_Core_System_Reset_Ex(int reason, uint32_t data, void *reserved) {
HAL_Core_Write_Backup_Register(BKP_DR_02, reason);
HAL_Core_Write_Backup_Register(BKP_DR_03, data);
HAL_Core_System_Reset();
}

Expand Down
3 changes: 1 addition & 2 deletions platform/MCU/rtl872x/src/hw_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ void Finish_Update()

// USB_Cable_Config(DISABLE);

// FIXME: reset reason?
HAL_Core_System_Reset_Ex(0, 0, NULL);
HAL_Core_System_Reset_Ex(RESET_REASON_UPDATE, 0, NULL);
}

__attribute__((section(".retained_system_flags"))) platform_system_flags_t system_flags;
Expand Down
50 changes: 22 additions & 28 deletions system/src/system_cloud_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,23 @@ bool publishSafeModeEventIfNeeded() {
return true; // ok
}

void publishResetReasonIfNeeded() {
uint8_t flag = 0;
if (system_get_flag(SYSTEM_FLAG_PUBLISH_RESET_INFO, &flag, nullptr) == 0 && flag)
{
system_set_flag(SYSTEM_FLAG_PUBLISH_RESET_INFO, 0, nullptr); // Publish the reset info only once
int reason = RESET_REASON_NONE;
uint32_t data = 0;
if (HAL_Core_Get_Last_Reset_Info(&reason, &data, nullptr) == 0 && reason != RESET_REASON_NONE)
{
char buf[64];
formatResetReasonEventData(reason, data, buf, sizeof(buf));
LOG(INFO,"Send spark/device/last_reset event");
publishEvent("spark/device/last_reset", buf);
}
}
}

void handleServerMovedRequest(const char* reqData, size_t reqSize, ServerMovedResponseCallback respCallback, void* ctx) {
clear_system_error_message();
#if PLATFORM_ID != PLATFORM_GCC && PLATFORM_ID != PLATFORM_NEWHAL
Expand Down Expand Up @@ -1260,45 +1277,22 @@ int Spark_Handshake(bool presence_announce)
publishEvent("spark/device/claim/code", buf);
}

// open up for possibility of retrieving multiple ID datums
if (!HAL_Get_Device_Identifier(NULL, buf, sizeof(buf), 0, NULL) && *buf) {
LOG(INFO,"Send spark/device/ident/0 event");
publishEvent("spark/device/ident/0", buf);
}

publishSafeModeEventIfNeeded();

uint8_t flag = 0;
if (system_get_flag(SYSTEM_FLAG_PUBLISH_RESET_INFO, &flag, nullptr) == 0 && flag)
{
system_set_flag(SYSTEM_FLAG_PUBLISH_RESET_INFO, 0, nullptr); // Publish the reset info only once
int reason = RESET_REASON_NONE;
uint32_t data = 0;
if (HAL_Core_Get_Last_Reset_Info(&reason, &data, nullptr) == 0 && reason != RESET_REASON_NONE)
{
char buf[64];
formatResetReasonEventData(reason, data, buf, sizeof(buf));
LOG(INFO,"Send spark/device/last_reset event");
publishEvent("spark/device/last_reset", buf);
}
}

Send_Firmware_Update_Flags();

if (presence_announce) {
Multicast_Presence_Announcement();
}
spark_protocol_send_time_request(sp);
} else {
LOG(INFO,"cloud connected from existing session.");

publishSafeModeEventIfNeeded();
Send_Firmware_Update_Flags();

if (!hal_rtc_time_is_valid(nullptr) && spark_sync_time_last(nullptr, nullptr) == 0) {
spark_protocol_send_time_request(sp);
}
}

publishSafeModeEventIfNeeded();
publishResetReasonIfNeeded();
Send_Firmware_Update_Flags();

if (system_mode() != AUTOMATIC || APPLICATION_SETUP_DONE) {
err = sendApplicationDescription();
if (err != 0) {
Expand Down
3 changes: 2 additions & 1 deletion user/tests/wiring/watchdog/watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ test(WATCHDOG_00_setup_disconnect_power_off_ncp) {
Cellular.off();
waitFor(Cellular.isOff, 120000);
assertTrue(Cellular.isOff());
#elif Wiring_WiFi
#endif
#if Wiring_WiFi
scott-brust marked this conversation as resolved.
Show resolved Hide resolved
WiFi.disconnect();
waitForNot(WiFi.ready, 60000);
WiFi.off();
Expand Down