Skip to content

Commit

Permalink
app_update: Fix case when elf file SHA256 should be printed by panic …
Browse files Browse the repository at this point in the history
…handler while cache is disabled

Closes: IDF-1342
  • Loading branch information
KonstantinKondrashov committed Apr 15, 2020
1 parent 2ebad46 commit 2705b76
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
10 changes: 10 additions & 0 deletions components/app_update/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ menu "Application manager"
The PROJECT_NAME variable from the build system will not affect the firmware image.
This value will not be contained in the esp_app_desc structure.

config APP_RETRIEVE_LEN_ELF_SHA
int "The length of APP ELF SHA is stored in RAM(chars)"
default 16
range 8 64
help
At startup, the app will read this many hex characters from the embedded APP ELF SHA-256 hash value
and store it in static RAM. This ensures the app ELF SHA-256 value is always available
if it needs to be printed by the panic handler code.
Changing this value will change the size of a static buffer, in bytes.

endmenu # "Application manager"
30 changes: 26 additions & 4 deletions components/app_update/esp_app_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,35 @@ static inline char IRAM_ATTR to_hex_digit(unsigned val)
return (val < 10) ? ('0' + val) : ('a' + val - 10);
}

__attribute__((constructor)) void esp_ota_init_app_elf_sha256(void)
{
esp_ota_get_app_elf_sha256(NULL, 0);
}

/* The esp_app_desc.app_elf_sha256 should be possible to print in panic handler during cache is disabled.
* But because the cache is disabled the reading esp_app_desc.app_elf_sha256 is not right and
* can lead to a complete lock-up of the CPU.
* For this reason we do a reading of esp_app_desc.app_elf_sha256 while start up in esp_ota_init_app_elf_sha256()
* and keep it in the static s_app_elf_sha256 value.
*/
int IRAM_ATTR esp_ota_get_app_elf_sha256(char* dst, size_t size)
{
size_t n = MIN((size - 1) / 2, sizeof(esp_app_desc.app_elf_sha256));
const uint8_t* src = esp_app_desc.app_elf_sha256;
static char s_app_elf_sha256[CONFIG_APP_RETRIEVE_LEN_ELF_SHA / 2];
static bool first_call = true;
if (first_call) {
first_call = false;
const uint8_t* src = esp_app_desc.app_elf_sha256;
for (size_t i = 0; i < sizeof(s_app_elf_sha256); ++i) {
s_app_elf_sha256[i] = src[i];
}
}
if (dst == NULL || size == 0) {
return 0;
}
size_t n = MIN((size - 1) / 2, sizeof(s_app_elf_sha256));
for (size_t i = 0; i < n; ++i) {
dst[2*i] = to_hex_digit(src[i] >> 4);
dst[2*i + 1] = to_hex_digit(src[i] & 0xf);
dst[2*i] = to_hex_digit(s_app_elf_sha256[i] >> 4);
dst[2*i + 1] = to_hex_digit(s_app_elf_sha256[i] & 0xf);
}
dst[2*n] = 0;
return 2*n + 1;
Expand Down

0 comments on commit 2705b76

Please sign in to comment.