|
|
@@ -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;
|