|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| esp32/ | | 03-Aug-2024 | - | 2,298 | 2,228 |
| esp32c2/ | | 03-Aug-2024 | - | 3,009 | 2,883 |
| esp32c3/ | | 03-Aug-2024 | - | 2,557 | 2,431 |
| esp32c6/ | | 03-Aug-2024 | - | 2,114 | 1,974 |
| esp32h2/ | | 03-Aug-2024 | - | 1,090 | 982 |
| esp32s2/ | | 03-Aug-2024 | - | 1,280 | 1,215 |
| esp32s3/ | | 03-Aug-2024 | - | 2,785 | 2,655 |
| include/ | | 03-Aug-2024 | - | 32,998 | 10,781 |
| linux/ | | 03-Aug-2024 | - | 818 | 660 |
| patches/ | | 03-Aug-2024 | - | 2,396 | 1,698 |
| test_apps/ | | 03-Aug-2024 | - | 534 | 424 |
| .build-test-rules.yml | D | 03-Aug-2024 | 371 | 13 | 9 |
| CMakeLists.txt | D | 03-Aug-2024 | 9.6 KiB | 283 | 225 |
| Kconfig.projbuild | D | 03-Aug-2024 | 1.4 KiB | 38 | 33 |
| README.md | D | 03-Aug-2024 | 4.2 KiB | 76 | 64 |
| linker.lf | D | 03-Aug-2024 | 405 | 13 | 12 |
README.md
1# `esp_rom` Component
2
3## Function Description
4
5`esp_rom` component contains each chip's ROM functions, which are used in the ROM bootloader, 2nd bootloader, esp_tool flash stub and some driver code (e.g. GPIO matrix). ROM functions as not treated as public APIs, attentions are required when you use ROM functions:
6
71. ROM functions are **not** thread-safe in RTOS, extra locks are needed to be around the ROM functions.
82. Names/signatures/behaviors of ROM function may be different between chips.
93. ROM functions are not guaranteed to exist across all chips.
10
11When using ROM functions in esp-idf, the including convention is `<target>/rom/<header_file>.h`. This can prevent you from using a nonexistent ROM function for a specific `<target>`. Thus ROM functions are recommended for use in a target-specific source file. For example, `bootloader_esp32.c` can include `esp32/rom/<header_file>.h` without any violations. However, this is not the case when it comes to a common source file that also wants to use some of the ROM functions. The include list would be quite extensive:
12
13```c
14#if CONFIG_IDF_TARGET_ESP32
15#include "esp32/rom/uart.h"
16#elif CONFIG_IDF_TARGET_ESP32C3
17#include "esp32c3/rom/uart.h"
18#elif CONFIG_IDF_TARGET_ESP32S3
19#include "esp32s3/rom/uart.h"
20...
21```
22
23So, we added a wrapper for those commonly used ROM functions. They're declared in `esp_rom/include/esp_rom_xxx.h`. Unlike the original ROM functions, these extracted ones are expected to exist across all chips. If some of them are missed in the new chips, we will implement them again in `esp_rom/patches`. These ROM APIs are always prefixed with the name `esp_rom` (e.g. `esp_rom_printf`), so that it's obvious to know whether a function is linked to ROM.
24
25Most of the time, the ROM wrapper APIs are just alias to the original ROM functions by linker script `esp_rom/<target>/ld/<target>.rom.api.ld`. For example, `esp_rom_printf` is alias to `ets_printf` in the following way:
26
27```
28PROVIDE ( esp_rom_printf = ets_printf );
29```
30
31If some original ROM functions have changed the behavior or have bugs, we should override them in the wrapper layer. A common example is the `esp_rom_install_uart_printf()`, on ESP32 and ESP32S2, it's just alias to `ets_install_uart_printf`, but on other chips, it's re-implemented in the `esp_rom/patches/esp_rom_uart.c`. To some extent, the ROM wrapper layer works like an anti-corrosion layer between esp-rom project and esp-idf project.
32
33As ROM functions are unique to each target, features are as well. For example, ESP32 has the `tjpgd` library built into the ROM, but ESP32S2 hasn't. We have a header file `esp_rom/<target>/esp_rom_caps.h` declaring the features that are supported by each target. Based on the macros defined there, we can decide whether a function should be patched or whether a feature should be re-implemented.
34
35## Directory Structure
36
37```
38.
39├── CMakeLists.txt
40├── <target/chip_name>
41│ ├── esp_rom_caps.h
42│ └── ld
43│ ├── <target>.rom.api.ld
44│ ├── <target>.rom.ld
45│ ├── <target>.rom.libgcc.ld
46│ ├── <target>.rom.newlib.ld
47│ ├── <target>.rom.newlib-nano.ld
48│ ├── <target>.rom.version.ld
49│ └── ... // other ROM linker scripts, added when bring up new chip
50├── include
51│ ├── <target/chip_name>
52│ │ └── rom
53│ │ ├── cache.h
54│ │ ├── efuse.h
55│ │ ├── esp_flash.h
56│ │ ├── ets_sys.h
57│ │ ├── gpio.h
58│ │ ├── uart.h
59│ │ └── ... // other original ROM header files, added when bring up new chip
60│ ├── esp_rom_gpio.h
61│ ├── esp_rom_md5.h
62│ ├── esp_rom_sys.h
63│ ├── esp_rom_uart.h
64│ └── ... // other ROM wrapper api files
65├── Kconfig.projbuild
66├── linker.lf
67├── patches
68│ ├── esp_rom_sys.c
69│ ├── esp_rom_uart.c
70│ └── ... // other patched source files
71├── README.md
72└── test
73 ├── CMakeLists.txt
74 ├── test_miniz.c
75 └── ... // other ROM function unit tests
76```