2021-05-10 01:48:25 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2018-10-05 12:29:07 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
2019-01-09 12:06:01 +00:00
|
|
|
#include <sys/param.h>
|
2018-10-05 12:29:07 +00:00
|
|
|
#include "esp_ota_ops.h"
|
2019-01-09 12:06:01 +00:00
|
|
|
#include "esp_attr.h"
|
2018-10-05 12:29:07 +00:00
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
// Application version info
|
|
|
|
const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
|
|
|
.magic_word = ESP_APP_DESC_MAGIC_WORD,
|
2018-12-13 07:45:27 +00:00
|
|
|
#ifdef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
|
|
|
|
.version = "",
|
|
|
|
#else
|
2018-10-05 12:29:07 +00:00
|
|
|
.version = PROJECT_VER,
|
2018-12-13 07:45:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
|
|
|
|
.project_name = "",
|
|
|
|
#else
|
2018-10-05 12:29:07 +00:00
|
|
|
.project_name = PROJECT_NAME,
|
2018-12-13 07:45:27 +00:00
|
|
|
#endif
|
2018-10-05 12:29:07 +00:00
|
|
|
.idf_ver = IDF_VER,
|
|
|
|
|
2019-05-09 12:10:35 +00:00
|
|
|
#ifdef CONFIG_BOOTLOADER_APP_SECURE_VERSION
|
|
|
|
.secure_version = CONFIG_BOOTLOADER_APP_SECURE_VERSION,
|
2018-10-05 12:29:07 +00:00
|
|
|
#else
|
|
|
|
.secure_version = 0,
|
|
|
|
#endif
|
|
|
|
|
2021-10-09 07:42:14 +00:00
|
|
|
#if defined(CONFIG_APP_COMPILE_TIME_DATE) && !defined(CONFIG_APP_REPRODUCIBLE_BUILD)
|
2018-10-05 12:29:07 +00:00
|
|
|
.time = __TIME__,
|
|
|
|
.date = __DATE__,
|
|
|
|
#else
|
|
|
|
.time = "",
|
|
|
|
.date = "",
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-12-13 07:45:27 +00:00
|
|
|
#ifndef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
|
2018-10-05 12:29:07 +00:00
|
|
|
_Static_assert(sizeof(PROJECT_VER) <= sizeof(esp_app_desc.version), "PROJECT_VER is longer than version field in structure");
|
2018-12-13 07:45:27 +00:00
|
|
|
#endif
|
2018-10-05 12:29:07 +00:00
|
|
|
_Static_assert(sizeof(IDF_VER) <= sizeof(esp_app_desc.idf_ver), "IDF_VER is longer than idf_ver field in structure");
|
2018-12-13 07:45:27 +00:00
|
|
|
#ifndef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
|
2018-10-05 12:29:07 +00:00
|
|
|
_Static_assert(sizeof(PROJECT_NAME) <= sizeof(esp_app_desc.project_name), "PROJECT_NAME is longer than project_name field in structure");
|
2018-12-13 07:45:27 +00:00
|
|
|
#endif
|
2018-10-05 12:29:07 +00:00
|
|
|
|
|
|
|
const esp_app_desc_t *esp_ota_get_app_description(void)
|
|
|
|
{
|
|
|
|
return &esp_app_desc;
|
|
|
|
}
|
2019-01-09 12:06:01 +00:00
|
|
|
|
|
|
|
/* The following two functions may be called from the panic handler
|
|
|
|
* or core dump, hence IRAM_ATTR.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline char IRAM_ATTR to_hex_digit(unsigned val)
|
|
|
|
{
|
|
|
|
return (val < 10) ? ('0' + val) : ('a' + val - 10);
|
|
|
|
}
|
|
|
|
|
2020-02-07 10:57:55 +00:00
|
|
|
__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.
|
2020-11-10 07:40:01 +00:00
|
|
|
* For this reason we do a reading of esp_app_desc.app_elf_sha256 while start up in esp_ota_init_app_elf_sha256()
|
2020-02-07 10:57:55 +00:00
|
|
|
* and keep it in the static s_app_elf_sha256 value.
|
|
|
|
*/
|
2019-01-09 12:06:01 +00:00
|
|
|
int IRAM_ATTR esp_ota_get_app_elf_sha256(char* dst, size_t size)
|
|
|
|
{
|
2020-02-07 10:57:55 +00:00
|
|
|
static char s_app_elf_sha256[CONFIG_APP_RETRIEVE_LEN_ELF_SHA / 2];
|
|
|
|
static bool first_call = true;
|
|
|
|
if (first_call) {
|
|
|
|
first_call = false;
|
2021-01-13 00:01:52 +00:00
|
|
|
// At -O2 optimization level, GCC optimizes out the copying of the first byte of the app_elf_sha256,
|
|
|
|
// because it is zero at compile time, and only modified afterwards by esptool.
|
|
|
|
// Casting to volatile disables the optimization.
|
|
|
|
const volatile uint8_t* src = (const volatile uint8_t*)esp_app_desc.app_elf_sha256;
|
2020-02-07 10:57:55 +00:00
|
|
|
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));
|
2019-01-09 12:06:01 +00:00
|
|
|
for (size_t i = 0; i < n; ++i) {
|
2020-02-07 10:57:55 +00:00
|
|
|
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);
|
2019-01-09 12:06:01 +00:00
|
|
|
}
|
|
|
|
dst[2*n] = 0;
|
|
|
|
return 2*n + 1;
|
|
|
|
}
|