forked from espressif/esp-idf
feat(bootloader): add the possibility to specify extra components directories
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# For more information about build system see
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
set(BOOTLOADER_EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/extra_bootloader_components/")
|
||||
|
||||
project(main)
|
||||
56
examples/custom_bootloader/bootloader_extra_dir/README.md
Normal file
56
examples/custom_bootloader/bootloader_extra_dir/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
# Bootloader extra component
|
||||
|
||||
(See the README.md file in the upper level for more information about bootloader examples.)
|
||||
|
||||
The purpose of this example is to show how to add a custom directory that contains a component to the bootloader build.
|
||||
|
||||
Registering extra components for the bootloader can be done thanks to the CMake variable `BOOTLOADER_EXTRA_COMPONENT_DIRS`. It works the same way as the application's `EXTRA_COMPONENT_DIRS`, it can either refer to a directory that contains several components, either refer to a single component.
|
||||
|
||||
## Usage of this example:
|
||||
|
||||
Simply compile it:
|
||||
```
|
||||
idf.py build
|
||||
```
|
||||
|
||||
Then flash it and open the monitor with the following command:
|
||||
```
|
||||
idf.py flash monitor
|
||||
```
|
||||
|
||||
If everything went well, the bootloader should output the following message:
|
||||
```
|
||||
I (60) EXTRA: This function is called from an extra component
|
||||
```
|
||||
|
||||
And finally the application will start and show the message:
|
||||
```
|
||||
User application is loaded and running.
|
||||
```
|
||||
|
||||
## Organization of this example
|
||||
|
||||
This project contains an application, in the `main` directory that represents an application. It also contains a `bootloader_components` that contains a component compiled and linked with the bootloader. This `bootloader_components` can contain several components, each of them would be in a different directory.
|
||||
|
||||
The directory `extra_bootloader_components/extra_component/` contains a component that is meant to be included in the bootloader build. To do so, the variable `BOOTLOADER_EXTRA_COMPONENT_DIRS` is set from the `CMakeLists.txt` file.
|
||||
|
||||
Below is a short explanation of files in the project folder.
|
||||
|
||||
```
|
||||
├── CMakeLists.txt Defines the `BOOTLOADER_EXTRA_COMPONENT_DIRS` variable
|
||||
├── main
|
||||
│ ├── CMakeLists.txt
|
||||
│ └── main.c User application
|
||||
├── bootloader_components
|
||||
│ └── my_boot_hooks
|
||||
│ ├── CMakeLists.txt
|
||||
│ └── hooks.c Implementation of the hooks to execute on boot
|
||||
├── extra_bootloader_components
|
||||
│ └── extra_component
|
||||
│ ├── CMakeLists.txt
|
||||
│ └── extra_component.c Implementation of the extra component
|
||||
└── README.md This is the file you are currently reading
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
idf_component_register(SRCS "hooks.c"
|
||||
REQUIRES extra_component)
|
||||
|
||||
# We need to force GCC to integrate this static library into the
|
||||
# bootloader link. Indeed, by default, as the hooks in the bootloader are weak,
|
||||
# the linker would just ignore the symbols in the extra. (i.e. not strictly
|
||||
# required)
|
||||
# To do so, we need to define the symbol (function) `bootloader_hooks_include`
|
||||
# within hooks.c source file.
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
extern void bootloader_extra_dir_function(void);
|
||||
|
||||
/* Function used to tell the linker to include this file
|
||||
* with all its symbols.
|
||||
*/
|
||||
void bootloader_hooks_include(void){
|
||||
}
|
||||
|
||||
void bootloader_after_init(void) {
|
||||
bootloader_extra_dir_function();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
idf_component_register(SRCS "extra_component.c")
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "esp_log.h"
|
||||
|
||||
void bootloader_extra_dir_function(void)
|
||||
{
|
||||
ESP_LOGI("EXTRA", "This function is called from an extra component");
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "bootloader_hooks_example_main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
printf("User application is loaded and running.\n");
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.generic
|
||||
def test_custom_bootloader_extra_component(dut: Dut) -> None:
|
||||
dut.expect_exact('This function is called from an extra component')
|
||||
Reference in New Issue
Block a user