From dbe4d156feb59c15661d656cbaf8a7f53550db81 Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Wed, 27 Dec 2023 14:30:13 +0800 Subject: [PATCH] fix(bootloader): add legacy retained memory CRC calculation * Closes https://github.com/espressif/esp-idf/issues/12849 In former versions of ESP-IDF, the user custom memory data in the retained memory was taken into account during the CRC calculation. This was changed in a later commit, the custom memory was ignored, therefore this can seen as a breaking change. This commit gives the possibility to choose between the former (legacy) or new way of calculating the CRC. --- components/bootloader/Kconfig.projbuild | 15 +++++++++++++++ .../src/bootloader_common_loader.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/bootloader/Kconfig.projbuild b/components/bootloader/Kconfig.projbuild index 895085d383..e6081adca5 100644 --- a/components/bootloader/Kconfig.projbuild +++ b/components/bootloader/Kconfig.projbuild @@ -383,6 +383,21 @@ menu "Bootloader config" (The application and bootoloader must be compiled with the same option). The RTC FAST memory has access only through PRO_CPU. + config BOOTLOADER_CUSTOM_RESERVE_RTC_IN_CRC + bool "Include custom memory in the CRC calculation" + depends on BOOTLOADER_CUSTOM_RESERVE_RTC + default n + help + This option allows the customer to use the legacy bootloader behavior when the + RTC FAST memory CRC calculation takes place. When this option is enabled, the + allocated user custom data will be taken into account in the CRC calculcation. + This means that any change to the custom data would need a CRC update to prevent + the bootloader from marking this data as corrupted. + If this option is disabled, the custom data will not be taken into account when + calculating the RTC FAST memory CRC. The user custom data can be changed freely, + without the need to update the CRC. + THIS OPTION MUST BE THE SAME FOR BOTH THE BOOTLOADER AND THE APPLICATION BUILDS. + config BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE hex "Size in bytes for custom purposes" default 0 diff --git a/components/bootloader_support/src/bootloader_common_loader.c b/components/bootloader_support/src/bootloader_common_loader.c index e958cc462b..2ef556f27a 100644 --- a/components/bootloader_support/src/bootloader_common_loader.c +++ b/components/bootloader_support/src/bootloader_common_loader.c @@ -168,7 +168,7 @@ SOC_RESERVE_MEMORY_REGION(RTC_RETAIN_MEM_ADDR, RTC_RETAIN_MEM_ADDR + sizeof(rtc_ #endif static uint32_t rtc_retain_mem_size(void) { -#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC +#if CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC && !CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_IN_CRC /* A custom memory has been reserved by the user, do not consider this memory into CRC calculation as it may change without * the have the user updating the CRC. Return the offset of the custom field, which is equivalent to size of the structure * minus the size of everything after (including) `custom` */