Skip to content

Commit

Permalink
refactor(esp_app_format): Move esp_app_format-related init steps into…
Browse files Browse the repository at this point in the history
… the component
  • Loading branch information
laukik-hase committed Feb 12, 2024
1 parent 4b5b064 commit 5430e2f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 38 deletions.
45 changes: 43 additions & 2 deletions components/esp_app_format/esp_app_desc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -10,6 +10,12 @@
#include "esp_app_desc.h"
#include "sdkconfig.h"

#include "hal/efuse_hal.h"
#include "esp_log.h"
#include "esp_private/startup_internal.h"

static const char *TAG = "app_init";

// Application version info
const __attribute__((weak)) __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
.magic_word = ESP_APP_DESC_MAGIC_WORD,
Expand Down Expand Up @@ -62,7 +68,7 @@ char app_elf_sha256_str[CONFIG_APP_RETRIEVE_LEN_ELF_SHA + 1] = { 0 };
* For this reason we do a reading of esp_app_desc.app_elf_sha256 and convert to string while start up in esp_system_init_app_elf_sha256()
* and keep it in the static app_elf_sha256_str variable.
*/
__attribute__((constructor)) void esp_app_format_init_elf_sha256(void)
static void esp_app_format_init_elf_sha256(void)
{
if (*((int *)&app_elf_sha256_str) != 0) {
// app_elf_sha256_str is already set
Expand Down Expand Up @@ -94,3 +100,38 @@ int esp_app_get_elf_sha256(char* dst, size_t size)
dst[n - 1] = 0;
return n;
}

ESP_SYSTEM_INIT_FN(init_show_app_info, CORE, BIT(0), 20)
{
// Load the current ELF SHA256
esp_app_format_init_elf_sha256();

// Display information about the current running image.
if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {
ESP_EARLY_LOGI(TAG, "Application information:");
#ifndef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
ESP_EARLY_LOGI(TAG, "Project name: %s", esp_app_desc.project_name);
#endif
#ifndef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
ESP_EARLY_LOGI(TAG, "App version: %s", esp_app_desc.version);
#endif
#ifdef CONFIG_BOOTLOADER_APP_SECURE_VERSION
ESP_EARLY_LOGI(TAG, "Secure version: %d", esp_app_desc.secure_version);
#endif
#ifdef CONFIG_APP_COMPILE_TIME_DATE
ESP_EARLY_LOGI(TAG, "Compile time: %s %s", esp_app_desc.date, esp_app_desc.time);
#endif
char buf[17];
esp_app_get_elf_sha256(buf, sizeof(buf));
ESP_EARLY_LOGI(TAG, "ELF file SHA256: %s...", buf);
ESP_EARLY_LOGI(TAG, "ESP-IDF: %s", esp_app_desc.idf_ver);

// TODO: To be moved to the eFuse initialization routine
ESP_EARLY_LOGI(TAG, "Min chip rev: v%d.%d", CONFIG_ESP_REV_MIN_FULL / 100, CONFIG_ESP_REV_MIN_FULL % 100);
ESP_EARLY_LOGI(TAG, "Max chip rev: v%d.%d %s", CONFIG_ESP_REV_MAX_FULL / 100, CONFIG_ESP_REV_MAX_FULL % 100,
efuse_hal_get_disable_wafer_version_major() ? "(constraint ignored)" : "");
unsigned revision = efuse_hal_chip_revision();
ESP_EARLY_LOGI(TAG, "Chip rev: v%d.%d", revision / 100, revision % 100);
}
return ESP_OK;
}
35 changes: 0 additions & 35 deletions components/esp_system/startup_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#endif

#if __has_include("esp_app_desc.h")
#define WITH_APP_IMAGE_INFO
#include "esp_app_desc.h"
#endif

Expand Down Expand Up @@ -77,40 +76,6 @@ ESP_SYSTEM_INIT_FN(init_show_cpu_freq, CORE, BIT(0), 10)
return ESP_OK;
}

#ifdef WITH_APP_IMAGE_INFO
ESP_SYSTEM_INIT_FN(init_show_app_info, CORE, BIT(0), 20)
{
// Display information about the current running image.
if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {
const esp_app_desc_t *app_desc = esp_app_get_description();
ESP_EARLY_LOGI(TAG, "Application information:");
#ifndef CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR
ESP_EARLY_LOGI(TAG, "Project name: %s", app_desc->project_name);
#endif
#ifndef CONFIG_APP_EXCLUDE_PROJECT_VER_VAR
ESP_EARLY_LOGI(TAG, "App version: %s", app_desc->version);
#endif
#ifdef CONFIG_BOOTLOADER_APP_SECURE_VERSION
ESP_EARLY_LOGI(TAG, "Secure version: %d", app_desc->secure_version);
#endif
#ifdef CONFIG_APP_COMPILE_TIME_DATE
ESP_EARLY_LOGI(TAG, "Compile time: %s %s", app_desc->date, app_desc->time);
#endif
char buf[17];
esp_app_get_elf_sha256(buf, sizeof(buf));
ESP_EARLY_LOGI(TAG, "ELF file SHA256: %s...", buf);
ESP_EARLY_LOGI(TAG, "ESP-IDF: %s", app_desc->idf_ver);

ESP_EARLY_LOGI(TAG, "Min chip rev: v%d.%d", CONFIG_ESP_REV_MIN_FULL / 100, CONFIG_ESP_REV_MIN_FULL % 100);
ESP_EARLY_LOGI(TAG, "Max chip rev: v%d.%d %s", CONFIG_ESP_REV_MAX_FULL / 100, CONFIG_ESP_REV_MAX_FULL % 100,
efuse_hal_get_disable_wafer_version_major() ? "(constraint ignored)" : "");
unsigned revision = efuse_hal_chip_revision();
ESP_EARLY_LOGI(TAG, "Chip rev: v%d.%d", revision / 100, revision % 100);
}
return ESP_OK;
}
#endif // WITH_APP_IMAGE_INFO

ESP_SYSTEM_INIT_FN(init_heap, CORE, BIT(0), 100)
{
heap_caps_init();
Expand Down
2 changes: 1 addition & 1 deletion components/esp_system/system_init_fn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# Log some information about the system
CORE: 10: init_show_cpu_freq in components/esp_system/startup_funcs.c on BIT(0)
CORE: 20: init_show_app_info in components/esp_system/startup_funcs.c on BIT(0)
CORE: 20: init_show_app_info in components/esp_app_format/esp_app_desc.c on BIT(0)

# Initialize heap allocator. WARNING: This *needs* to happen *after* the app cpu has booted.
# If the heap allocator is initialized first, it will put free memory linked list items into
Expand Down

0 comments on commit 5430e2f

Please sign in to comment.