maxikrie opened a new pull request, #21132:
URL: https://github.com/apache/nuttx/pull/21132
## Summary
#18828 added CMake files for the Xtensa ESP32 chips and boards, but
`esp32s3-devkit:nsh` (and the ESP32 and ESP32-S2 boards) did not build with
CMake on master:
1. The toolchain prefix gets a double dash: `CMAKE_ASM_COMPILER:
xtensa-esp32s3-elf--gcc ... not found`.
2. Nothing clones esp-hal-3rdparty or includes the `hal_*.cmake` files for
Xtensa: `soc/soc.h: No such file or directory`.
3. The source lists were partial (e.g. no `esp32_serial.c` for the ESP32),
the board lists named a removed `esp32s3_appinit.c`, the boards' linker scripts
were not passed, and each board added `../common` a second time.
4. The image step never found `esptool.py` (esptool 4.x), the flash step
used esptool 5 commands, and it flashed the ESP32 and ESP32-S2 images to 0x0
instead of 0x1000.
This PR translates the Make files (`Make.defs`, `hal.mk`, `Wireless.mk`, the
boards' `scripts/Make.defs` and `src/Make.defs`) into the CMake files, so a
CMake build compiles the same sources with the same flags, and builds
`nuttx.bin`.
Only simple boot is supported (the default of all but 9 of the 298 configs);
MCUboot, the legacy app format and the ULP RISC-V coprocessor stop at configure
time with a message to use Make.
## Impact
CMake builds of `esp32s3-devkit`, `esp32-devkitc` and `esp32s2-saola-1` work
(other ESP32 boards have no CMake files yet). Make builds are unchanged. The
esptool fix also applies to the RISC-V Espressif chips.
## Testing
CMake builds (Debian 12, esp-14.2.0 toolchain, esptool 4.11), all with
`nuttx.bin`:
- esp32s3-devkit: nsh, smp, tickless, gpio, spi, i2c, psram_quad,
psram_octal, usb_device, usbnsh, ble, wifi, blewifi, sta_softap, timer, ostest,
pwm, rmt, spiflash, twai, adc, romfs, txtable, crypto, mbedtls, cxx, efuse,
sdmmc, pm
- esp32-devkitc: nsh, wifi, espnow, ble, smp, psram, spiflash, twai, ostest,
crypto, dac, pm
- esp32s2-saola-1: nsh, wifi, spiflash, i2c, ostest, temperature_sensor
`esp32-devkitc:wifi_smp` fails in nuttx-apps:
`examples/webserver/CMakeLists.txt` registers the app without its sources
(`webserver_main` undefined), a separate fix.
Compared with the Make build of the same config (`nm`, `size -A`):
| config | symbols | .text |
|---|---|---|
| esp32s3-devkit:nsh | same | same |
| esp32-devkitc:nsh | same | same |
| esp32s2-saola-1:nsh | same | -64 B |
| esp32s3-devkit:wifi | same | +800 B |
Every symbol is in the same output section in both builds (IRAM, DRAM, flash
text, flash rodata; checked for all four), except `romfs_img_len` (const in the
CMake ROMFS: flash rodata instead of DRAM). The S3 `nuttx.bin` images have the
same segments at the same load addresses.
The remaining size differences are the version string, the /etc ROMFS (see
below) and call relaxation: `-mlongcalls` calls are relaxed at link time
depending on the distance, which depends on the link order; the objects
themselves are the same size. The Xtensa CMake build also passes
`-mtext-section-literals` to all files (Make: only to modules and ELF
programs); left as it is.
After the rebase onto master 93c7e875a4, rebuilt with CMake:
esp32s3-devkit:nsh, esp32s3-devkit:wifi, esp32-devkitc:nsh, esp32s2-saola-1:nsh.
Flash target (no board, port missing): ESP32/ESP32-S2 write at 0x1000,
ESP32-S3 at 0x0, with esptool 4.11; esptool 5.1 takes the same commands.
Reconfiguring a build directory after removing the wireless submodules: they
are fetched again and the wifi build links.
Hardware: ESP32-S3 (custom board, chip rev v0.2), `esp32s3-devkit:usbnsh`
built with CMake on master 5055d980da, flashed with `cmake --build <dir> -t
flash` at 0x0: ROM loads it, `nsh>` on the CDC-ACM console. The ROM prints
"SHA-256 comparison failed ... Attempting to boot anyway", as for a
Make-built simple-boot image (no hash appended). `esp32s3-devkit:wifi`, same
way, console on UART0: `wlan0` up, `wapi scan wlan0` lists the nearby
networks.
Found on the way, not in this PR: nuttx-apps `examples/webserver` has no
CMake sources (and needs its `httpd_fsdata.c` generation); CMake ROMFS images
contain the preprocessor's `.d` files (`/etc/init.d/rcS.d`, ...), for every
board (cmake/nuttx_toolchain.cmake writes the depfile next to the preprocessed
file since 0afb8c7ad5).
## Logs
<details><summary>master: CMake configure fails</summary>
```
CMake Error at CMakeLists.txt:524 (project):
The CMAKE_ASM_COMPILER:
xtensa-esp32s3-elf--gcc
is not a full path and was not found in the PATH.
```
</details>
<details><summary>this PR: esp32s3-devkit:nsh, end of the build</summary>
```
$ cmake -B build -GNinja -DBOARD_CONFIG=esp32s3-devkit:nsh && cmake --build
build
...
esptool v5.6.0
Creating ESP32-S3 image...
Image has only RAM segments visible. ROM segments are hidden and SHA256
digest is not appended.
Merged 1 ELF section.
Successfully created ESP32-S3 image.
-- Generated: nuttx.bin
$ xtensa-esp32s3-elf-size build/nuttx
text data bss dec hex filename
140998 22664 223044 386706 5e692 build/nuttx
```
</details>
<details><summary>this PR: esp32s3-devkit:usbnsh on hardware</summary>
```
$ ESPTOOL_PORT=/dev/ttyUSB1 cmake --build build -t flash
UART0 (ESP-Prog, /dev/ttyUSB1):
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0xb (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fc8e800,len:0x1670
load:0x40374000,len:0x8238
load:0x50000000,len:0x24
SHA-256 comparison failed:
Calculated: 8bf7fcb488b5465fc82cf5d9334b73f57f82c4d9d66bc8fa7e80112a2fdfe888
Expected: 00000000f0660000000000000000000000000000000000000000000000000000
Attempting to boot anyway...
entry 0x40374ba4
Native USB, CDC-ACM console (/dev/ttyACM0):
nsh>
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]