zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
9.91k stars 6.1k forks source link

Add Support for XIP from FlexSPI on MCXN947 #72905

Open mmahadevan108 opened 3 weeks ago

mmahadevan108 commented 3 weeks ago

This PR requires a bootloader like MCUboot to be programmed to internal flash which will load and execute the Zephyr application from QSPI. PR: https://github.com/mcu-tools/mcuboot/pull/1961 to update MCUboot for this QSPI variant

zephyrbot commented 3 weeks ago

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_nxp https://github.com/zephyrproject-rtos/hal_nxp/commit/5e84f1d2173e3c5057725d76f9dad6bfabad0b5f https://github.com/zephyrproject-rtos/hal_nxp/pull/390 zephyrproject-rtos/hal_nxp#390/files

Note: This message is automatically posted and updated by the Manifest GitHub Action.

hakehuang commented 3 weeks ago

it does not work on my board, see below steps:

  1. build mcuboot
    west build -s boot/zephyr -b frdm_mcxn947/mcxn947/cpu0/qspi
  2. flash the bootload
    west flash --runner=linkserver -- "--probe="2FFNMNKFWMLA0""
ubuntu@ubuntu-OptiPlex-7040:~/nxp/frdm_mcxn947/bootloader/mcuboot$ west flash --runner=linkserver -- "--probe="2FFNMNKFWMLA0""
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner linkserver
-- runners.linkserver: LinkServer: /usr/local/LinkServer/LinkServer, version v1.5.30
INFO: Exact match for MCXN947:FRDM-MCXN947 found
INFO: Selected device MCXN947:FRDM-MCXN947
INFO: Getting available probes
INFO: Selecting probe by serial substring
INFO: Selected probe #1 2FFNMNKFWMLA0 (MCU-LINK on-board (r0C7) CMSIS-DAP V3.140)
INFO: MCU-Link firmware update CHECK: local firmware [3.140] is the same with the version running on the selected probe ([2FFNMNKFWMLA0] [MCU-LINK on-board (r0C7) CMSIS-DAP V3.140])

reset the boards, no console output

  1. build hello world
west build -b frdm_mcxn947/mcxn947/cpu0/qspi samples/hello_world/ -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"bootloader/mcuboot/root-rsa-2048.pem\" -DCONFIG_BOOTLOADER_MCUBOOT=y -p always

and flash again

reset board still no output

PetervdPerk-NXP commented 3 weeks ago

Can we also add support to link code directly to the XIP region? Right now there's only the onboard FLASH region

[135/135] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       28292 B         2 MB      1.35%
             RAM:        4248 B       320 KB      1.30%
           SRAM1:          0 GB        96 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%

Ideally you want be able to use both

[135/135] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           ONBOARD_FLASH:       28292 B         2 MB      1.35%
           EXTERNAL_FLASH:       28292 B         8 MB      1.35%
             RAM:        4248 B       320 KB      1.30%
           SRAM1:          0 GB        96 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
dleach02 commented 2 weeks ago

@mmahadevan108 https://github.com/mcu-tools/mcuboot/pull/1961 merged but I guess now we need to ensure that the Zephyr version of mcuboot is updated for this PR to work? Should we do that in this PR as well (coordinating with @d3zd3z)

Also, I rebased your branch to address the merge conflict

hakehuang commented 1 week ago

@mmahadevan108 , I switch to the mcuboot commit that has your commit

commit 45d379e715d82ae71ce2bb42882769a4cf4428e4 (HEAD -> main, origin/main)
Author: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
Date:   Thu Apr 25 09:42:12 2024 -0500

    zephyr: boards: Add files needed for NXP FRDM MCXN947 QSPI variant

    1. set BOOT_MAX_IMG_SECTORS value for frmd_mcxn947_qspi. W25Q64 flash on the board
       is very large (8MB), so we must increase the number of max sectors when
       targeting this board with MCUboot.
    2. Set the zephyr,flash chosen node to point to internal flash as this board
       supports booting from internal flash only.

    Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>

with below command line with this zephyr PR source I get

west build -s boot/zephyr -b frdm_mcxn947/mcxn947/cpu0/qspi
In file included from /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include/bootutil/bootutil.h:33,
                 from /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/bootutil_misc.c:36:
/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include/bootutil/bootutil_public.h:89:1: error: static assertion failed: "Unsupported value for MCUBOOT_BOOT_MAX_ALIGN for SWAP upgrade modes"
   89 | _Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 32,
      | ^~~~~~~~~~~~~~
[55/287] Building C object CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/swap_scratch.c.obj
FAILED: CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/swap_scratch.c.obj
ccache /home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DCPU_MCXN947VDF_cm33_core0 -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DLPFLEXCOMM_INIT_NOT_USED_IN_DRIVER=1 -DMBEDTLS_CONFIG_FILE=\"mcuboot-mbedtls-cfg.h\" -DNDEBUG -D__PROGRAM_START -D__ZEPHYR__=1 -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/zephyr/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/zephyr/targets -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/build/zephyr/include/generated/zephyr -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/build/zephyr/include/generated -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/soc/nxp/mcx -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/soc/nxp/mcx/mcxnx4x/. -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/cmsis/CMSIS/Core/Include -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/cmsis/. -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/devices/MCXN947 -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/devices/MCXN947/drivers -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/common -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/ostimer -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/lpflexcomm -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/lpflexcomm/lpuart -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/flexspi -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/mcx_spc -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/cache/cache64 -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/mcx_romapi -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/mcx_romapi/flash -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/port -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/hal_nxp/. -I/home/ubuntu/nxp/frdm_mcxn947/modules/crypto/mbedtls/include -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/mbedtls/configs -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/mbedtls/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/zephyr/.. -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/zephyr/../include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/zephyr/../../zephyr/include -isystem /home/ubuntu/nxp/frdm_mcxn947/zephyr/lib/libc/minimal/include -isystem /home/ubuntu/nxp/frdm_mcxn947/zephyr/lib/libc/common/include -isystem /home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem /home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -fno-strict-aliasing -Os -imacros /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/build/zephyr/include/generated/zephyr/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=/home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/arm-zephyr-eabi -imacros /home/ubuntu/nxp/frdm_mcxn947/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/zephyr=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/ubuntu/nxp/frdm_mcxn947/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/ubuntu/nxp/frdm_mcxn947=WEST_TOPDIR -ffunction-sections -fdata-sections -mcmse -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/swap_scratch.c.obj -MF CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/swap_scratch.c.obj.d -o CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/swap_scratch.c.obj -c /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/swap_scratch.c
In file included from /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include/bootutil/bootutil.h:33,
                 from /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/swap_scratch.c:24:
/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include/bootutil/bootutil_public.h:89:1: error: static assertion failed: "Unsupported value for MCUBOOT_BOOT_MAX_ALIGN for SWAP upgrade modes"
   89 | _Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 32,
      | ^~~~~~~~~~~~~~
[56/287] Building C object CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/loader.c.obj
FAILED: CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/loader.c.obj
ccache /home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DCPU_MCXN947VDF_cm33_core0 -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DLPFLEXCOMM_INIT_NOT_USED_IN_DRIVER=1 -DMBEDTLS_CONFIG_FILE=\"mcuboot-mbedtls-cfg.h\" -DNDEBUG -D__PROGRAM_START -D__ZEPHYR__=1 -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/zephyr/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/zephyr/targets -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/build/zephyr/include/generated/zephyr -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/build/zephyr/include/generated -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/soc/nxp/mcx -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/soc/nxp/mcx/mcxnx4x/. -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/cmsis/CMSIS/Core/Include -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/cmsis/. -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/devices/MCXN947 -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/devices/MCXN947/drivers -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/common -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/ostimer -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/lpflexcomm -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/lpflexcomm/lpuart -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/flexspi -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/mcx_spc -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/cache/cache64 -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/mcx_romapi -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/mcx_romapi/flash -I/home/ubuntu/nxp/frdm_mcxn947/modules/hal/nxp/mcux/mcux-sdk/drivers/port -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/hal_nxp/. -I/home/ubuntu/nxp/frdm_mcxn947/modules/crypto/mbedtls/include -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/mbedtls/configs -I/home/ubuntu/nxp/frdm_mcxn947/zephyr/modules/mbedtls/include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/zephyr/.. -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/zephyr/../include -I/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/zephyr/../../zephyr/include -isystem /home/ubuntu/nxp/frdm_mcxn947/zephyr/lib/libc/minimal/include -isystem /home/ubuntu/nxp/frdm_mcxn947/zephyr/lib/libc/common/include -isystem /home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem /home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -fno-strict-aliasing -Os -imacros /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/build/zephyr/include/generated/zephyr/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=/home/ubuntu/zephyr-sdk-0.16.4/arm-zephyr-eabi/arm-zephyr-eabi -imacros /home/ubuntu/nxp/frdm_mcxn947/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/zephyr=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/ubuntu/nxp/frdm_mcxn947/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/ubuntu/nxp/frdm_mcxn947=WEST_TOPDIR -ffunction-sections -fdata-sections -mcmse -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/loader.c.obj -MF CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/loader.c.obj.d -o CMakeFiles/app.dir/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/loader.c.obj -c /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/loader.c
In file included from /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include/bootutil/bootutil.h:33,
                 from /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/src/loader.c:39:
/home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/boot/bootutil/include/bootutil/bootutil_public.h:89:1: error: static assertion failed: "Unsupported value for MCUBOOT_BOOT_MAX_ALIGN for SWAP upgrade modes"
   89 | _Static_assert(MCUBOOT_BOOT_MAX_ALIGN >= 8 && MCUBOOT_BOOT_MAX_ALIGN <= 32,
      | ^~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/ubuntu/nxp/frdm_mcxn947/bootloader/mcuboot/build
dleach02 commented 2 days ago

@mmahadevan108, need a rebase