• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

bootloader_components/my_boot_hooks/11-Mar-2024-2916

main/11-Mar-2024-207

CMakeLists.txtD11-Mar-2024364 97

MakefileD11-Mar-2024188 102

README.mdD11-Mar-20242.1 KiB5844

example_test.pyD11-Mar-2024614 1910

README.md

1# Bootloader hooks
2
3(See the README.md file in the upper level for more information about bootloader examples.)
4
5The purpose of this example is to show how to add hooks to the 2nd stage bootloader.
6
7## Usage of this example:
8
9Simply compile it:
10```
11idf.py build
12```
13
14Then flash it and open the monitor with the following command:
15```
16idf.py flash monitor
17```
18
19If everything went well, the bootloader output should be as followed:
20```
21I (24) HOOK: This hook is called BEFORE bootloader initialization
22I (37) boot: [...]
23[...]
24I (60) HOOK: This hook is called AFTER bootloader initialization
25```
26
27And finally the application will start and show the message:
28```
29User application is loaded and running.
30```
31
32## Organisation of this example
33
34This project contains an application, in the `main` directory that represents a user program.
35It also contains a `bootloader_components` that, as it name states, contains a component compiled and linked with the bootloader.
36
37Below is a short explanation of files in the project folder.
38
39```
40├── CMakeLists.txt
41├── main
42│   ├── CMakeLists.txt
43│   └── main.c                 User application
44├── bootloader_components
45│   └── my_boot_hooks
46│       ├── CMakeLists.txt
47│       └── hooks.c            Implementation of the hooks to execute on boot
48└── README.md                  This is the file you are currently reading
49```
50Bootloader hooks are **not** supported in legacy `make` build system. They are only supported with `CMake` build system.
51
52## Note about including weak symbols
53
54The components in ESP-IDF are compiled as static libraries. Moreover, the bootloaders' hooks are declared as `weak`. Thus, when
55defining hooks for the bootloader, we **must** tell the compiler to always include our library (`my_boot_hooks`) in the link process.
56To achieve this, we need to define an extra symbol: `bootloader_hooks_include`. In our case, this symbol is a function defined in
57`bootloader_components/my_boot_hooks/hooks.c`. This will make the linker include all the symbols contained in that file.
58