Umstrukuriert/windows-app hinzugefügt
This commit is contained in:
@@ -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 |
|
||||
@@ -0,0 +1,51 @@
|
||||
# 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 -hv v3 -i simple_ota.bin --add_app_header
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
1. Command tool [gen_custom_ota.py](https://github.com/espressif/esp-iot-solution/tree/master/tools/cmake_utilities/scripts/gen_custom_ota.py) can also be used to generate the compressed firmware required by [esp bootloader plus](https://github.com/espressif/esp-bootloader-plus):
|
||||
|
||||
```plaintext
|
||||
python3 gen_custom_ota.py -i simple_ota.bin
|
||||
```
|
||||
|
||||
Use `python3 gen_custom_ota.py -h` to see a summary of all available command line options.
|
||||
@@ -0,0 +1,102 @@
|
||||
# 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.
|
||||
|
||||
Some SoCs(ESP32-C2 and ESP32-C3) support hardware auto flash-suspend, meaning when reading, writing, or erasing the flash stage, the CPU hardware can switch to run code laying in the flash automatically without any software assist, so that we can link more functions from IRAM to flash.
|
||||
|
||||
## 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/flash_suspend/XXX (XXX=esp32c2, esp32c3...)` for specific SoC platform when flash_suspend and relinker feature are enabled, please note that the configuration files may be slightly different for different ESP-IDF versions, 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
|
||||
```
|
||||
|
||||
If you would like to save more RAM, you can try flash-suspend feature, enable options as following:
|
||||
|
||||
```
|
||||
Component config --->
|
||||
SPI Flash driver --->
|
||||
[ ] Use esp_flash implementation in ROM
|
||||
[*] Auto suspend long erase/write operations (READ DOCS FIRST)
|
||||
|
||||
CMake Utilities --->
|
||||
[*] Enable relinker
|
||||
[*] Link specific functions to IRAM regardless of ESP-IDF's behavior
|
||||
```
|
||||
|
||||
> Note: Currently supported platform: esp32c2 and esp32c3.
|
||||
> Note: Before enable flash-suspend, please check if ESP-IDF supports this flash's flash-suspend feature.
|
||||
|
||||
## Configuration Files
|
||||
|
||||
You can refer to the files in the directory of `cmake_utilities/scripts/relinker/examples/$ACTION/XXX ($ACTION=iram_strip, flash_suspend) (XXX=esp32c2, esp32c3...)`:
|
||||
|
||||
- library.csv
|
||||
- object.csv
|
||||
- function.csv
|
||||
|
||||
1. iram_strip
|
||||
|
||||
For `example/iram_strip`, it includes the functions which you want to relink into Flash after enable the option `CU_RELINKER_ENABLE` and disable the option `CU_RELINKER_LINK_SPECIFIC_FUNCTIONS_TO_IRAM` in menuconfig. 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,
|
||||
```
|
||||
|
||||
2. flash_suspend
|
||||
|
||||
For `example/flash_suspend`, it includes the functions which you want to relink into SRAM after enable the options: `SPI_FLASH_AUTO_SUSPEND`, `CU_RELINKER_ENABLE`, `CU_RELINKER_LINK_SPECIFIC_FUNCTIONS_TO_IRAM` in menuconfig. If you want to link function `__getreent` into SRAM no matter its original locations, 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.
|
||||
|
||||
## Test Results Reference
|
||||
|
||||
| Chip | example | | SRAM used (Bytes) | |
|
||||
| -------- | --------------- | ----------------- | ----------------- | --------------------------------- |
|
||||
| | | Default options | Enable relinker | Enable relinker and flash-suspend |
|
||||
| ESP32-C2 | power_save | 101408 | 91728 | 51360 |
|
||||
| ESP32-C3 | power_save | 118728 | 99864 | 58312 |
|
||||
|
||||
All of the above examples are compiled on ESP-IDF Tag/v5.3.2 and version v1.1.0 of `cmake_utilities` component, you can view the memory type usage summary by using `idf.py size`, the above data is for reference only.
|
||||
Reference in New Issue
Block a user