mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-05 04:15:21 +02:00
esp_bootloader_format: Adds bootloader description structure to read bootloader version from app
Closes https://github.com/espressif/esp-idf/issues/8800 Closes https://github.com/espressif/esp-idf/issues/9132
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
|
||||
|
||||
components/esp_bootloader_format/test_apps:
|
||||
disable:
|
||||
- if: IDF_TARGET != "esp32"
|
||||
reason: It is enough to test it only for one target
|
||||
@@ -0,0 +1,11 @@
|
||||
idf_component_register(SRCS "esp_bootloader_desc.c"
|
||||
INCLUDE_DIRS "include")
|
||||
|
||||
if(BOOTLOADER_BUILD)
|
||||
# esp_bootloader_desc structure is added as an undefined symbol because otherwise the
|
||||
# linker will ignore this structure as it has no other files depending on it.
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_bootloader_desc")
|
||||
|
||||
idf_build_get_property(project_name PROJECT_NAME)
|
||||
message(STATUS "Bootloader project name: \"${project_name}\" version: ${CONFIG_BOOTLOADER_PROJECT_VER}")
|
||||
endif()
|
||||
@@ -0,0 +1,21 @@
|
||||
menu "Bootloader manager"
|
||||
|
||||
config BOOTLOADER_COMPILE_TIME_DATE
|
||||
bool "Use time/date stamp for bootloader"
|
||||
default y
|
||||
depends on !APP_REPRODUCIBLE_BUILD
|
||||
help
|
||||
If set, then the bootloader will be built with the current time/date stamp.
|
||||
It is stored in the bootloader description
|
||||
structure. If not set, time/date stamp will be excluded from bootloader image.
|
||||
This can be useful for getting the
|
||||
same binary image files made from the same source, but at different times.
|
||||
|
||||
config BOOTLOADER_PROJECT_VER
|
||||
int "Project version"
|
||||
default 1
|
||||
range 0 4294967295
|
||||
help
|
||||
Project version. It is placed in "version" field of the esp_bootloader_desc structure.
|
||||
The type of this field is "uint32_t".
|
||||
endmenu # "Bootloader manager"
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <sys/param.h>
|
||||
#include "esp_bootloader_desc.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
|
||||
// Bootloader version info
|
||||
const __attribute__((weak)) __attribute__((section(".data_bootloader_desc"))) esp_bootloader_desc_t esp_bootloader_desc = {
|
||||
.magic_byte = ESP_BOOTLOADER_DESC_MAGIC_BYTE,
|
||||
.reserved = { 0 },
|
||||
.version = CONFIG_BOOTLOADER_PROJECT_VER,
|
||||
.idf_ver = IDF_VER,
|
||||
#ifdef CONFIG_BOOTLOADER_COMPILE_TIME_DATE
|
||||
.date_time = __DATE__ " " __TIME__,
|
||||
#else
|
||||
.date_time = "",
|
||||
#endif
|
||||
.reserved2 = { 0 },
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(IDF_VER) <= sizeof(esp_bootloader_desc.idf_ver), "IDF_VER is longer than idf_ver field in structure");
|
||||
|
||||
const esp_bootloader_desc_t *esp_bootloader_get_description(void)
|
||||
{
|
||||
return &esp_bootloader_desc;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_assert.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define ESP_BOOTLOADER_DESC_MAGIC_BYTE (80) /*!< The magic byte for the esp_bootloader_desc structure that is in DRAM. */
|
||||
|
||||
/**
|
||||
* @brief Bootloader description structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t magic_byte; /*!< Magic byte ESP_BOOTLOADER_DESC_MAGIC_BYTE */
|
||||
uint8_t reserved[3]; /*!< reserved for IDF */
|
||||
uint32_t version; /*!< Bootloader version */
|
||||
char idf_ver[32]; /*!< Version IDF */
|
||||
char date_time[24]; /*!< Compile date and time*/
|
||||
uint8_t reserved2[16]; /*!< reserved for IDF */
|
||||
} esp_bootloader_desc_t;
|
||||
|
||||
/** @cond */
|
||||
ESP_STATIC_ASSERT(sizeof(esp_bootloader_desc_t) == 80, "esp_bootloader_desc_t should be 80 bytes");
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @brief Return esp_bootloader_desc structure.
|
||||
*
|
||||
* Intended for use by the bootloader.
|
||||
* @return Pointer to esp_bootloader_desc structure.
|
||||
*/
|
||||
const esp_bootloader_desc_t *esp_bootloader_get_description(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
# This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
|
||||
set(COMPONENTS main)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(esp_bootloader_format_test)
|
||||
@@ -0,0 +1,2 @@
|
||||
| Supported Targets | ESP32 |
|
||||
| ----------------- | ----- |
|
||||
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRCS "test_bootloader_desc.c"
|
||||
PRIV_INCLUDE_DIRS .
|
||||
PRIV_REQUIRES esp_bootloader_format app_update unity)
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_ota_ops.h"
|
||||
#include "esp_bootloader_desc.h"
|
||||
#include "unity.h"
|
||||
#include "unity_fixture.h"
|
||||
#include "unity_internals.h"
|
||||
|
||||
TEST_GROUP(esp_bootloader_format);
|
||||
|
||||
TEST_SETUP(esp_bootloader_format)
|
||||
{
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(esp_bootloader_format)
|
||||
{
|
||||
}
|
||||
|
||||
TEST(esp_bootloader_format, esp_ota_get_bootloader_description)
|
||||
{
|
||||
esp_bootloader_desc_t desc;
|
||||
printf("\n");
|
||||
TEST_ESP_OK(esp_ota_get_bootloader_description(NULL, &desc));
|
||||
TEST_ASSERT_EQUAL(desc.magic_byte, ESP_BOOTLOADER_DESC_MAGIC_BYTE);
|
||||
TEST_ASSERT_EQUAL(desc.version, CONFIG_BOOTLOADER_PROJECT_VER);
|
||||
printf("\tESP-IDF version from 2nd stage bootloader: %s\n", desc.idf_ver);
|
||||
printf("\tESP-IDF version from app: %s\n", IDF_VER);
|
||||
TEST_ASSERT_EQUAL(0, memcmp(desc.idf_ver, IDF_VER, sizeof(IDF_VER)));
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(esp_bootloader_format)
|
||||
{
|
||||
RUN_TEST_CASE(esp_bootloader_format, esp_ota_get_bootloader_description)
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
UNITY_MAIN(esp_bootloader_format);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.generic
|
||||
def test_esp_bootloader_format(dut: Dut) -> None:
|
||||
dut.expect_unity_test_output()
|
||||
@@ -0,0 +1,10 @@
|
||||
# General options for additional checks
|
||||
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
|
||||
CONFIG_COMPILER_WARN_WRITE_STRINGS=y
|
||||
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
|
||||
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
|
||||
CONFIG_COMPILER_STACK_CHECK=y
|
||||
|
||||
# Enable Unity fixture support
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
||||
Reference in New Issue
Block a user