mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
app_update: Fix case when elf file SHA256 should be printed by panic handler while cache is disabled
Closes: IDF-1342
This commit is contained in:
parent
a30557ca31
commit
fc03161f70
@ -36,4 +36,14 @@ menu "Application manager"
|
|||||||
help
|
help
|
||||||
Project version
|
Project version
|
||||||
|
|
||||||
|
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"
|
endmenu # "Application manager"
|
||||||
|
@ -72,13 +72,35 @@ static inline char IRAM_ATTR to_hex_digit(unsigned val)
|
|||||||
return (val < 10) ? ('0' + val) : ('a' + val - 10);
|
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)
|
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));
|
static char s_app_elf_sha256[CONFIG_APP_RETRIEVE_LEN_ELF_SHA / 2];
|
||||||
const uint8_t* src = esp_app_desc.app_elf_sha256;
|
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) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
dst[2*i] = to_hex_digit(src[i] >> 4);
|
dst[2*i] = to_hex_digit(s_app_elf_sha256[i] >> 4);
|
||||||
dst[2*i + 1] = to_hex_digit(src[i] & 0xf);
|
dst[2*i + 1] = to_hex_digit(s_app_elf_sha256[i] & 0xf);
|
||||||
}
|
}
|
||||||
dst[2*n] = 0;
|
dst[2*n] = 0;
|
||||||
return 2*n + 1;
|
return 2*n + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user