diff --git a/zephcore/boards/example_board/README.md b/zephcore/boards/example_board/README.md index 28cacbc..cb97721 100644 --- a/zephcore/boards/example_board/README.md +++ b/zephcore/boards/example_board/README.md @@ -27,7 +27,7 @@ SWD flash: `west flash` (requires J-Link, pyocd, or nrfjprog connected). | Board | Build string | Flash | |----------------------|-----------------------------------------------------------|-----------------| | XIAO ESP32-C3 | `west build -b xiao_esp32c3 zephcore` | `west flash` | -| XIAO ESP32-C6 | `west build -b xiao_esp32c6 zephcore` | `west flash` | +| XIAO ESP32-C6 | `west build -b xiao_esp32c6/esp32c6/hpcore zephcore` | `west flash` | | LilyGo TLoRa C6 | `west build -b lilygo_tlora_c6/esp32c6/hpcore zephcore` | `west flash` | | XIAO ESP32-S3 | `west build -b xiao_esp32s3/esp32s3/procpu zephcore` | `west flash` | | Station G2 | `west build -b station_g2/esp32s3/procpu zephcore` | `west flash` | diff --git a/zephcore/boards/supported_boards.md b/zephcore/boards/supported_boards.md index dd1fa99..5ab08ca 100644 --- a/zephcore/boards/supported_boards.md +++ b/zephcore/boards/supported_boards.md @@ -21,7 +21,7 @@ promicro_lr2021 ``` xiao_esp32c3 -xiao_esp32c6 +xiao_esp32c6/esp32c6/hpcore xiao_esp32s3/esp32s3/procpu lilygo_tlora_c6/esp32c6/hpcore station_g2/esp32s3/procpu diff --git a/zephcore/sysbuild/CMakeLists.txt b/zephcore/sysbuild/CMakeLists.txt index fd45423..96678a4 100644 --- a/zephcore/sysbuild/CMakeLists.txt +++ b/zephcore/sysbuild/CMakeLists.txt @@ -2,5 +2,52 @@ # so the BOARD_ROOT set there never fires. Set it here, before find_package(Sysbuild). set(BOARD_ROOT "${APP_DIR}" CACHE STRING "" FORCE) +# Auto-propagate flash size from board.conf to MCUboot. +# +# MCUboot is built as a separate image and does NOT inherit the app's board.conf +# or esp32_common.conf. Boards with non-default flash sizes set +# CONFIG_ESPTOOLPY_FLASHSIZE_MB=y in their board.conf, but without this +# block MCUboot builds with whatever its defconfig/Kconfig default is. +# A mismatch between MCUboot's image header flash size and the actual hardware +# causes the ROM bootloader to misconfigure the SPI flash controller, making +# MCUboot hang at "spi_flash: detected chip:". +# +# We set mcuboot_EXTRA_CONF_FILE BEFORE find_package(Sysbuild) so it takes +# priority — sysbuild_extensions.cmake uses CACHE INTERNAL (no FORCE) which +# only writes if the variable is not already set. +# +# Static conf files (mcuboot_flashsize_*.conf) are used instead of generating +# a temp file to avoid Windows line-ending issues with cmake file(WRITE). +string(REPLACE "/" ";" _board_parts "${BOARD}") +list(GET _board_parts 0 _board_base) + +file(GLOB_RECURSE _board_conf_candidates + "${APP_DIR}/boards/*/${_board_base}/board.conf") +if(NOT _board_conf_candidates AND + EXISTS "${APP_DIR}/boards/${_board_base}/board.conf") + set(_board_conf_candidates "${APP_DIR}/boards/${_board_base}/board.conf") +endif() + +if(_board_conf_candidates) + list(GET _board_conf_candidates 0 _board_conf) + file(READ "${_board_conf}" _board_conf_content) + + set(_flashsize_fragment "") + foreach(_size 16MB 8MB 32MB 64MB 128MB) + if(_board_conf_content MATCHES "CONFIG_ESPTOOLPY_FLASHSIZE_${_size}=y") + string(TOLOWER "${_size}" _size_lower) + set(_flashsize_fragment + "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot_flashsize_${_size_lower}.conf") + break() + endif() + endforeach() + + if(_flashsize_fragment AND EXISTS "${_flashsize_fragment}") + set(mcuboot_EXTRA_CONF_FILE + "${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf;${_flashsize_fragment}" + CACHE INTERNAL "MCUboot conf: global + flash size auto-propagated from board.conf") + endif() +endif() + find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(sysbuild LANGUAGES) diff --git a/zephcore/sysbuild/mcuboot.conf b/zephcore/sysbuild/mcuboot.conf index b1ed31d..db1ab4c 100644 --- a/zephcore/sysbuild/mcuboot.conf +++ b/zephcore/sysbuild/mcuboot.conf @@ -28,5 +28,11 @@ CONFIG_SPI=n # unavailable in MCUboot's minimal kernel. CONFIG_POWER_DOMAIN=n +# Flash size baseline — Kconfig default is 2MB, but all zephcore boards use at +# least 4MB. Boards with larger flash (8MB, 16MB) override this via the +# auto-propagation logic in sysbuild/CMakeLists.txt which appends +# mcuboot_flashsize_mb.conf when the app's board.conf sets a larger size. +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y + # ESP32 HAL's mcuboot_config.h is patched (patches/modules/hal/espressif/...) # to respect Zephyr Kconfig: mbedTLS detection, AUTO sector count, slot0 validation. diff --git a/zephcore/sysbuild/mcuboot_flashsize_16mb.conf b/zephcore/sysbuild/mcuboot_flashsize_16mb.conf new file mode 100644 index 0000000..dc395a7 --- /dev/null +++ b/zephcore/sysbuild/mcuboot_flashsize_16mb.conf @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y diff --git a/zephcore/sysbuild/mcuboot_flashsize_8mb.conf b/zephcore/sysbuild/mcuboot_flashsize_8mb.conf new file mode 100644 index 0000000..88b7b69 --- /dev/null +++ b/zephcore/sysbuild/mcuboot_flashsize_8mb.conf @@ -0,0 +1 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y