-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/esp32: add periph_flashpage support #19079
Conversation
6c0d578
to
4f0a28a
Compare
19077: cpu/esp32: configurable linker scripts r=benpicco a=gschorcht ### Contribution description This PR provides configurable linker scripts for ESP32x SoCs. Using the vendor `memory.ld.in` file and a `sections.ld.in` file instead of the static versions of these files, from which the actual used `memory.ld` and `sections.ld` are generated using the C preprocessor, allows to use the configuration in `sdkconfig.h` as well as Kconfig to define a custom memory layout. For example, it is no longer necessary to maintain different `memory.ld` files for the ESP32 BLE module, since the memory layout is now defined from the values of the configuration. Note for the review: The `memory.ld.in` files are now simply copies of the manufacturer's `memory.ld.in` files. However, it is not possible to use the vendor's `memory.ld.in` files directly, because they have to be extended further on, e.g. for the `periph_flashpage` implementation. This PR is prerequisite for the `periph_flashpage` support in PR #19079. ### Testing procedure Green CI. ### Issues/PRs references Prerequisite for PR #19079 Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
19078: cpu/esp32: define FLASHFILE_POS r=benpicco a=gschorcht ### Contribution description Instead of using a fixed position of the image file in the flash, the variable `FLASHFILE_POS` is used which allows to override the default position of the image in the flash at 0x10000. This PR is a prerequisite for the `periph_flashpage` implementation PR #19079. ### Testing procedure Flashing a ESP32x SoC should work with `FLASHFILE_POS=0x20000`, for example: ``` USEMODULE=esp_log_startup FLASHFILE_POS=0x20000 BOARD=esp32-wroom-32 make -j8 -C tests/shell flash ``` The bootloader output should give `00020000` as offset for the `factory` partition ``` I (75) boot: Partition Table: I (78) boot: ## Label Usage Type ST Offset Length I (84) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (91) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (97) boot: 2 factory factory app 00 00 00020000 000199b0 I (104) boot: End of partition table ``` and ``` I (125) esp_image: segment 0: paddr=00020020 vaddr=3f400020 size=02140h ( 8512) map ``` during the load of the image. ### Issues/PRs references Prerequisite for PR #19079 Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
4f0a28a
to
88ba041
Compare
Please note: There is an open problem with the ESP32-S2 implementation. The flashpage access requires any kind of additional mapping between the DCache (Data Bus Cache) and the MMU pages for ESP32-S2. Unfortunatly, til now this works only with ICache (Instruction Bus Cache) but not with DCache, no idea why yet. The problem of ICache is that it only allows word access. |
88ba041
to
65633a2
Compare
|
Replaces the custom `memdump` implementation with `od_hex_dump`, which provides a more common and especially more compact print format.
65633a2
to
c21eb6b
Compare
bors try |
tryBuild succeeded: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also works on ESP32-C3 and ESP32-S3
btw, what's needed for riotboot
support?
bors merge
bors merge |
I was already thinking about that. There will be no chance to replace the ESP-IDF bootloader by a bare metal implementation since the bootloader preconfigures a lot of the SoC. My approach would be to implement |
That's already how riotboot works anyway.
That would make changes to the CPU startup routines impossible. Is it a problem to call the CPU init twice? |
I see, I didn't check it yet.
I'm afraid that doing the complete SoC initialization a second time won't really work. We will have to give it a try. I have actually had it on my to-do list for quite some time. |
Well for the most simple It just checks the riotboot header of the two slots to decide where to jump, so you don't need to initialize any peripherals, the boot config should be sufficient for that. |
Build succeeded: |
@benpicco Thankd for reviewing and merging. |
I will take a look into |
Contribution description
This PR provides the
periph_flashpage
support for ESP32x SoCs.For byte-aligned read access to constant data in the flash, the MMU of all ESP32x SoCs allows to map a certain number of 64 kByte pages of the flash into the data address space of the CPU. This address space is called DROM. Normally the whole DROM address space is assigned to the section
.rodata
. The default flash layout used by all ESP32x SoCs is:0x0000
or0x1000
0x8000
0x9000
nvs
parition with WiFi data0xf000
phy_init
partition with RF data0x10000
factory
partition with the app imageThe factory partition consists of a number of 64 kByte pages for the sections
.text
,.rodata
,.bss
and others. The.text
androdata
sections are page-aligned and are simply mapped into the instruction address space (IROM) and the data address space (DROM), respectively. All other sections are loaded into RAM.If the
periph_flashpage
module is used, theperiph_flashpage
driver.rodata
section in DROM address space byCONFIG_ESP_FLASHPAGE_CAPACITY
,.flashpage.writable
of sizeCONFIG_ESP_FLASHPAGE_CAPACITY
at the end of DROM address space that is mapped into data address space of the CPU,CONFIG_ESP_FLASHPAGE_CAPACITY
starting from0x10000
in front of the image partitionfactory
andfactory
byCONFIG_ESP_FLASHPAGE_CAPACITY
to address0x10000 + CONFIG_ESP_FLASHPAGE_CAPACITY
.The new flash layout is then:
0x0000
or0x1000
0x8000
0x9000
nvs
parition with WiFi data0xf000
phy_init
partition with RF data0x10000
0x10000 + CONFIG_ESP_FLASHPAGE_CAPACITY
factory
partition with the app imageThis guarantees that the flash pages are not overwritten if a new app image with changed size is flashed.
CONFIG_ESP_FLASHPAGE_CAPACITY
has to be a multiple of 64 kBytes.The PR includes PR #19077 and PR #19078 for the moment to be compilable.Testing procedure
The following tests should pass.
Issues/PRs references
Depends on PR #19077
Depends on PR #19078