Initial public release of the 2024A software.

This commit is contained in:
Joe Kearney 2025-01-25 14:04:42 -06:00
parent 7b9ad3edfd
commit 303e9e1dad
361 changed files with 60083 additions and 2 deletions

View file

@ -0,0 +1,108 @@
# Link Time Optimization(LTO)
Link time optimization(LTO) improves the optimization effect of GCC, such as reducing binary size, increasing performance, and so on. For more details please refer to related [GCC documents](https://gcc.gnu.org/onlinedocs/gccint/LTO.html).
## Use
To use this feature, you need to include the required CMake file in your project's CMakeLists.txt after `project(XXXX)`.
```cmake
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(XXXX)
include(gcc)
```
The LTO feature is disabled by default. To use it, you should enable the option `CU_GCC_LTO_ENABLE` in menuconfig. Then specify target components or dependencies to be optimized by LTO after `include(gcc)` as follows:
```cmake
include(gcc)
cu_gcc_lto_set(COMPONENTS component_a component_b
DEPENDS dependence_a dependence_b)
cu_gcc_string_1byte_align(COMPONENTS component_c component_d
DEPENDS dependence_c dependence_d)
```
Based on your requirement, set compiling optimization level in the option `COMPILER_OPTIMIZATION`.
* Note
```
1. Reducing firmware size may decrease performance
2. Increasing performance may increase firmware size
3. Enable LTO cause compiling time cost increases a lot
4. Enable LTO may increase task stack cost
5. Enable string 1-byte align may decrease string process speed
```
## Limitation
At the linking stage, the LTO generates new function indexes instead of the file path as follows:
- LTO
```txt
.text 0x00000000420016f4 0x6 /tmp/ccdjwYMH.ltrans51.ltrans.o
0x00000000420016f4 app_main
```
- Without LTO
```txt
.text.app_main 0x00000000420016f4 0x6 esp-idf/main/libmain.a(app_main.c.obj)
0x00000000420016f4 app_main
```
So tools used to relink functions between flash and IRAM can't affect these optimized components and dependencies again. It is recommended that users had better optimize application components and dependencies than kernel and hardware driver ones.
## Example
The example applies LTO in `light` of `esp-matter` because its application code is much larger. Add LTO configuration into project script `CMakeLists.txt` as follows:
```cmake
project(light)
include(gcc)
# Add
set(app_lto_components main chip esp_matter)
# Add
set(idf_lto_components lwip wpa_supplicant nvs_flash)
# Add
set(lto_depends mbedcrypto)
# Add
cu_gcc_lto_set(COMPONENTS ${app_lto_components} ${idf_lto_components}
DEPENDS ${lto_depends})
```
Configure `ESP32-C2` as the target platform, enable `CU_GCC_LTO_ENABLE` and `CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE`, set `COMPILER_OPTIMIZATION` to be `-Os`.
Increase the `main` task stack size to `5120` by option `ESP_MAIN_TASK_STACK_SIZE`.
Compile the project, and then you can see the firmware size decrease a lot:
Option | Firmware size | Stask cost
|:-:|:-:|:-:|
-Os | 1,113,376 | 2508
-Os + LTO | 1,020,640 | 4204
Then add `cu_gcc_string_1byte_align` after `cu_gcc_lto_set`:
```cmake
# Add
cu_gcc_lto_set(COMPONENTS ${app_lto_components} ${idf_lto_components}
DEPENDS ${lto_depends})
cu_gcc_string_1byte_align(COMPONENTS ${app_lto_components} ${idf_lto_components}
DEPENDS ${lto_depends})
```
Build the project and the firmware size is:
Option | Firmware size |
|:-:|:-:|
-Os + LTO | 1,020,640 |
-Os + LTO + string 1-byte align | 1,018,340 |

View file

@ -0,0 +1,41 @@
# Gen Compressed OTA
When using the compressed OTA, we need to generate the compressed app firmware. This document mainly describes how to generate the compressed app firmware.
For more information about compressed OTA, refer to [bootloader_support_plus](https://github.com/espressif/esp-iot-solution/tree/master/components/bootloader_support_plus).
## Use
In order to use this feature, you need to include the needed CMake file in your project's CMakeLists.txt after `project(XXXX)`.
```cmake
project(XXXX)
include(gen_compressed_ota)
```
Generate the compressed app firmware in an ESP-IDF "project" directory by running:
```plaintext
idf.py gen_compressed_ota
```
This command will compile your project first, then it will generate the compressed app firmware. For example, run the command under the project `simple_ota_examples` folder. If there are no errors, the `custom_ota_binaries` folder will be created and contains the following files:
```plaintext
simple_ota.bin.xz
simple_ota.bin.xz.packed
```
The file named `simple_ota.bin.xz.packed` is the actual compressed app binary file to be transferred.
In addition, if [secure boot](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/security/secure-boot-v2.html) is enabled, the command will generate the signed compressed app binary file:
```plaintext
simple_ota.bin.xz.packed.signed
```
you can also use the script [gen_custom_ota.py](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/scripts/gen_custom_ota.py) to compress the specified app:
```plaintext
python3 gen_custom_ota.py -i simple_ota.bin
```

View file

@ -0,0 +1,66 @@
# Relinker
In ESP-IDF, some functions are put in SRAM when link stage, the reason is that some functions are critical, we need to put them in SRAM to speed up the program, or the functions will be executed when the cache is disabled. But actually, some functions can be put into Flash, here, we provide a script to let the user set the functions which are located in SRAM by default to put them into Flash, in order to save more SRAM which can be used as heap region later. This happens in the linker stage, so we call it as relinker.
## Use
In order to use this feature, you need to include the needed CMake file in your project's CMakeLists.txt after `project(XXXX)`.
```cmake
project(XXXX)
include(relinker)
```
The relinker feature is disabled by default, in order to use it, you need to enable the option `CU_RELINKER_ENABLE` in menuconfig.
Here are the default configuration files in the folder `cmake_utilities/scripts/relinker/examples/esp32c2`, it's just used as a reference. If you would like to use your own configuration files, please enable option `CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES` and set the path of your configuration files as following, this path is evaluated relative to the project root directory:
```
[*] Enable customized relinker configuration files
(path of your configuration files) Customized relinker configuration files path
```
> Note: Currently only esp32c2 is supported.
## Configuration Files
You can refer to the files in the directory of `cmake_utilities/scripts/relinker/examples/esp32c2`:
- library.csv
- object.csv
- function.csv
For example, if you want to link function `__getreent` from SRAM to Flash, firstly you should add it to `function.csv` file as following:
```
libfreertos.a,tasks.c.obj,__getreent,
```
This means function `__getreent` is in object file `tasks.c.obj`, and object file `tasks.c.obj` is in library `libfreertos.a`.
If function `__getreent` depends on the option `FREERTOS_PLACE_FUNCTIONS_INTO_FLASH` in menuconfig, then it should be:
```
libfreertos.a,tasks.c.obj,__getreent,CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH
```
This means when only `FREERTOS_PLACE_FUNCTIONS_INTO_FLASH` is enabled in menuconfig, function `__getreent` will be linked from SRAM to Flash.
Next step you should add the path of the object file to `object.csv`:
```
libfreertos.a,tasks.c.obj,esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj
```
This means the object file `tasks.c.obj` is in library `libfreertos.a` and its location is `esp-idf/freertos/CMakeFiles/__idf_freertos.dir/FreeRTOS-Kernel/tasks.c.obj` relative to directory of `build`.
Next step you should add path of library to `library.csv`:
```
libfreertos.a,./esp-idf/freertos/libfreertos.a
```
This means library `libfreertos.a`'s location is `./esp-idf/freertos/libfreertos.a` relative to `build`.
If above related data has exists in corresponding files, please don't add this repeatedly.