diff --git a/components/bootloader_support/src/bootloader_common.c b/components/bootloader_support/src/bootloader_common.c index 641d07b3c3..09de9c246a 100644 --- a/components/bootloader_support/src/bootloader_common.c +++ b/components/bootloader_support/src/bootloader_common.c @@ -217,65 +217,3 @@ RESET_REASON bootloader_common_get_reset_reason(int cpu_no) { return rtc_get_reset_reason(cpu_no); } - -#if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC ) - -rtc_retain_mem_t *const rtc_retain_mem = (rtc_retain_mem_t *)(SOC_RTC_DRAM_HIGH - sizeof(rtc_retain_mem_t)); - -static bool check_rtc_retain_mem(void) -{ - return esp_rom_crc32_le(UINT32_MAX, (uint8_t*)rtc_retain_mem, sizeof(rtc_retain_mem_t) - sizeof(rtc_retain_mem->crc)) == rtc_retain_mem->crc && rtc_retain_mem->crc != UINT32_MAX; -} - -static void update_rtc_retain_mem_crc(void) -{ - rtc_retain_mem->crc = esp_rom_crc32_le(UINT32_MAX, (uint8_t*)rtc_retain_mem, sizeof(rtc_retain_mem_t) - sizeof(rtc_retain_mem->crc)); -} - -void bootloader_common_reset_rtc_retain_mem(void) -{ - memset(rtc_retain_mem, 0, sizeof(rtc_retain_mem_t)); -} - -uint16_t bootloader_common_get_rtc_retain_mem_reboot_counter(void) -{ - if (check_rtc_retain_mem()) { - return rtc_retain_mem->reboot_counter; - } - return 0; -} - -esp_partition_pos_t* bootloader_common_get_rtc_retain_mem_partition(void) -{ - if (check_rtc_retain_mem()) { - return &rtc_retain_mem->partition; - } - return NULL; -} - -void bootloader_common_update_rtc_retain_mem(esp_partition_pos_t* partition, bool reboot_counter) -{ - if (reboot_counter) { - if (!check_rtc_retain_mem()) { - bootloader_common_reset_rtc_retain_mem(); - } - if (++rtc_retain_mem->reboot_counter == 0) { - // do not allow to overflow. Stop it. - --rtc_retain_mem->reboot_counter; - } - - } - - if (partition != NULL) { - rtc_retain_mem->partition.offset = partition->offset; - rtc_retain_mem->partition.size = partition->size; - } - - update_rtc_retain_mem_crc(); -} - -rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void) -{ - return rtc_retain_mem; -} -#endif diff --git a/components/bootloader_support/src/bootloader_common_loader.c b/components/bootloader_support/src/bootloader_common_loader.c index ea5f406895..f0c65fadca 100644 --- a/components/bootloader_support/src/bootloader_common_loader.c +++ b/components/bootloader_support/src/bootloader_common_loader.c @@ -97,3 +97,65 @@ int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata, return active_otadata; } + +#if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC ) + +rtc_retain_mem_t *const rtc_retain_mem = (rtc_retain_mem_t *)(SOC_RTC_DRAM_HIGH - sizeof(rtc_retain_mem_t)); + +static bool check_rtc_retain_mem(void) +{ + return esp_rom_crc32_le(UINT32_MAX, (uint8_t*)rtc_retain_mem, sizeof(rtc_retain_mem_t) - sizeof(rtc_retain_mem->crc)) == rtc_retain_mem->crc && rtc_retain_mem->crc != UINT32_MAX; +} + +static void update_rtc_retain_mem_crc(void) +{ + rtc_retain_mem->crc = esp_rom_crc32_le(UINT32_MAX, (uint8_t*)rtc_retain_mem, sizeof(rtc_retain_mem_t) - sizeof(rtc_retain_mem->crc)); +} + +void bootloader_common_reset_rtc_retain_mem(void) +{ + memset(rtc_retain_mem, 0, sizeof(rtc_retain_mem_t)); +} + +uint16_t bootloader_common_get_rtc_retain_mem_reboot_counter(void) +{ + if (check_rtc_retain_mem()) { + return rtc_retain_mem->reboot_counter; + } + return 0; +} + +esp_partition_pos_t* bootloader_common_get_rtc_retain_mem_partition(void) +{ + if (check_rtc_retain_mem()) { + return &rtc_retain_mem->partition; + } + return NULL; +} + +void bootloader_common_update_rtc_retain_mem(esp_partition_pos_t* partition, bool reboot_counter) +{ + if (reboot_counter) { + if (!check_rtc_retain_mem()) { + bootloader_common_reset_rtc_retain_mem(); + } + if (++rtc_retain_mem->reboot_counter == 0) { + // do not allow to overflow. Stop it. + --rtc_retain_mem->reboot_counter; + } + + } + + if (partition != NULL) { + rtc_retain_mem->partition.offset = partition->offset; + rtc_retain_mem->partition.size = partition->size; + } + + update_rtc_retain_mem_crc(); +} + +rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void) +{ + return rtc_retain_mem; +} +#endif // defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC ) diff --git a/examples/storage/parttool/example_test.py b/examples/storage/parttool/example_test.py index f8e258879f..8493ecab2f 100644 --- a/examples/storage/parttool/example_test.py +++ b/examples/storage/parttool/example_test.py @@ -28,7 +28,7 @@ def test_examples_parttool(env, extra_data): binary_path = flash_file[1] break - subprocess.check_call([sys.executable, script_path, "--binary", binary_path]) + subprocess.check_call([sys.executable, script_path, "--binary", binary_path, "--port", dut.port]) if __name__ == '__main__': diff --git a/tools/test_apps/system/bootloader_sections/sdkconfig.ci.rtc_retain b/tools/test_apps/system/bootloader_sections/sdkconfig.ci.rtc_retain new file mode 100644 index 0000000000..3ba7ab36b7 --- /dev/null +++ b/tools/test_apps/system/bootloader_sections/sdkconfig.ci.rtc_retain @@ -0,0 +1 @@ +CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y