Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions boards/nxp/mr_canhubk3/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@

endif # NETWORKING

if BOOTLOADER_MCUBOOT

# S32K3 places the vector table at +0x400
# This makes the bootloader and the sign tool compatible with that.
config ROM_START_OFFSET
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be done at the soc level, similar to

default 0x400 if BOOTLOADER_MCUBOOT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I just kept it with board's defconfig since I was just able to validate it CANHUBK3 board yet.

hex

Check warning on line 41 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:41 please, no spaces at the start of a line

Check warning on line 41 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:41 please, no spaces at the start of a line

Check warning on line 41 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:41 please, no spaces at the start of a line

Check warning on line 41 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:41 please, no spaces at the start of a line
default 0x400

Check warning on line 42 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:42 please, no spaces at the start of a line

Check warning on line 42 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:42 please, no spaces at the start of a line

Check warning on line 42 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:42 please, no spaces at the start of a line

Check warning on line 42 in boards/nxp/mr_canhubk3/Kconfig.defconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

boards/nxp/mr_canhubk3/Kconfig.defconfig:42 please, no spaces at the start of a line

endif

endif # BOARD_MR_CANHUBK3
75 changes: 75 additions & 0 deletions boards/nxp/mr_canhubk3/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,81 @@ For example, to erase and verify flash content:

west flash -r trace32 --startup-args elfFile=build/zephyr/zephyr.elf loadTo=flash eraseFlash=yes verifyFlash=yes

MCUboot chain-loading
=====================

This board supports booting Zephyr applications via :ref:`mcuboot`.

.. important::

On S32K3 the vector table is larger than 512 bytes, so MCUboot images
**must be signed with a 1 KiB (0x400) header**. You do **not** need to
change :kconfig:option:`CONFIG_ROM_START_OFFSET` in your app (the
S32K3 linker naturally aligns the vector table to 0x400 when needed),
but you **do** need to sign the image with ``--header-size 0x400``.
Copy link
Contributor

@JarmouniA JarmouniA Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should look at sysbuild & MCUboot CMake in Zephyr, they already handle many things added in the PR such as this

--version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --header-size ${CONFIG_ROM_START_OFFSET}

Copy link
Contributor Author

@sumitbatra-nxp sumitbatra-nxp Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JarmouniA ..
Agreed that S32K3 linker does take care of the right alignment of the vector table
but if I don't change CONFIG_ROM_START_OFFSET explicitly, then MCUboot looks out for the vector table at default 0x200 offset.
With the commands that I have mentioned in the PR description, if I don't change CONFIG_ROM_START_OFFSET to 0x400 then MCUboot cannot jump to the right Zephyr image in slot0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have not configured things right if that is the case, this is all handled and works fine on other devices (also as said, use sysbuild, none of this manual signing stuff, in which case you don't need to document anything here because it should just work like it does for other boards)


Build and flash MCUboot
-----------------------

Use the provided overlays to place MCUboot and the application slots in
internal flash (PFLASH):

.. code-block:: console

west build -b mr_canhubk3 -d build/mcuboot bootloader/mcuboot/boot/zephyr \
-DEXTRA_DTC_OVERLAY_FILE="boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay;boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

west flash -d build/mcuboot -r jlink

Build the application for MCUboot
---------------------------------

Use the application overlay so the app links to the primary slot:

.. code-block:: console

west build -b mr_canhubk3 -d build/flash_shell samples/drivers/flash_shell \
-DEXTRA_DTC_OVERLAY_FILE="boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay;boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay" \
-DOVERLAY_CONFIG=samples/drivers/flash_shell/overlay-mcuboot.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


Sign the image with a 1 KiB header
----------------------------------

Either pass the extra header size when signing:

.. code-block:: console

west sign -d build/flash_shell -t imgtool -- \
--key bootloader/mcuboot/root-rsa-2048.pem \
--header-size 0x400

or bake it into the build with:

.. code-block:: console

-DMCUBOOT_EXTRA_IMGTOOL_ARGS="--header-size 0x400"

Flash the signed application
----------------------------

.. code-block:: console

west flash -d build/flash_shell -r jlink -f build/flash_shell/zephyr/zephyr.signed.hex

After reset you should see MCUboot logs followed by the application banner
(e.g. the Flash Shell prompt).

Troubleshooting
---------------

* If MCUboot prints *“Image in the primary slot is not valid”* or gets stuck
after *“Jumping to the first image slot”*, the image was likely signed with
a 512-byte header. Re-sign with ``--header-size 0x400`` and re-flash.

* Do **not** add an IVT to MCUboot-chainloaded applications. The SoC support
emits the IVT for standalone/XIP images or for MCUboot itself; it is
automatically omitted for apps built with :kconfig:option:`CONFIG_BOOTLOADER_MCUBOOT`.

Debugging
=========

Expand Down
2 changes: 2 additions & 0 deletions boards/nxp/mr_canhubk3/mr_canhubk3.dts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@
};

&flash0 {
status = "disabled";

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
Expand Down
8 changes: 8 additions & 0 deletions boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in dts of an MCUboot board variant.
An example 69edf96

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/ {

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay:1 File has no SPDX-License-Identifier header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay:1 File has no SPDX-License-Identifier header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_app.overlay:1 File has no SPDX-License-Identifier header, consider adding one.
chosen {
/* App links to primary slot when booted by MCUboot */
zephyr,code-partition = &slot0_partition;
/* Ensure we are using internal flash as the main flash */
zephyr,flash = &flash0;
};
};
8 changes: 8 additions & 0 deletions boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/ {

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay:1 File has no SPDX-License-Identifier header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay:1 File has no SPDX-License-Identifier header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_boot.overlay:1 File has no SPDX-License-Identifier header, consider adding one.
chosen {
/* Bootloader image is linked to its own partition */
zephyr,code-partition = &mcuboot;
/* Ensure we are using internal flash as the main flash */
zephyr,flash = &flash0;
};
};
44 changes: 44 additions & 0 deletions boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
&flash0 {

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay:1 File has no SPDX-License-Identifier header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay:1 File has no SPDX-License-Identifier header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

boards/nxp/mr_canhubk3/mr_canhubk3_mcuboot_layout.overlay:1 File has no SPDX-License-Identifier header, consider adding one.
/* Replace any board-default partitions with the MCUboot layout */
/delete-node/ partitions;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

ivt_header: partition@0 {
label = "ivt-header";
reg = <0x00000000 0x00000100>;
};

/* pad up to the 8 KiB sector boundary at 0x2000 */
ivt_pad: partition@100 {
label = "ivt_pad";
reg = <0x00000100 0x00001F00>;
};

/* MCUboot @ 0x2000 (128 KiB here; adjust if you use 64 KiB) */
mcuboot: partition@2000 {
label = "mcuboot";
reg = <0x00002000 0x00020000>;
};

/* Primary image (slot 0) */
slot0_partition: partition@22000 {
label = "image-0";
reg = <0x00022000 0x001C0000>;
};

/* Secondary image (slot 1) — start right after slot0 ends */
slot1_partition: partition@1E2000 {
label = "image-1";
reg = <0x001E2000 0x001C0000>;
};

/* Scratch (swap) area */
scratch_partition: partition@3A2000 {
label = "image-scratch";
reg = <0x003A2000 0x00040000>;
};
};
};
1 change: 1 addition & 0 deletions boards/nxp/mr_canhubk3/overlay-mcuboot-1kheader.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed, Zephyr MCUboot CMake takes care of this.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS="--header-size 0x400"
10 changes: 10 additions & 0 deletions drivers/flash/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ if(CONFIG_FLASH_NXP_S32_QSPI_NOR OR CONFIG_FLASH_NXP_S32_QSPI_HYPERFLASH)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers/memc)
endif()

zephyr_library_sources_ifdef(CONFIG_FLASH_MCUX_C40_API flash_mcux_c40.c)
# Run the driver from RAM or another relocation source when relocation is enabled
if(CONFIG_FLASH_MCUX_C40_API AND CONFIG_CODE_DATA_RELOCATION)
zephyr_code_relocate(FILES ${CMAKE_CURRENT_LIST_DIR}/flash_mcux_c40.c LOCATION RAM)
if(DEFINED ZEPHYR_HAL_NXP_MODULE_DIR)
# Relocating HAL driver from Zephyr keeping HAL RTOS-agnostic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake indent is 2 spaces

zephyr_code_relocate(FILES ${ZEPHYR_HAL_NXP_MODULE_DIR}/mcux/mcux-sdk-ng/drivers/flash_c40/fsl_c40_flash.c LOCATION RAM)
endif()
endif()

if(CONFIG_SOC_FLASH_RENESAS_RA_HP)
zephyr_library_sources(soc_flash_renesas_ra_hp.c)
zephyr_library_sources_ifdef(CONFIG_FLASH_EX_OP_ENABLED soc_flash_renesas_ra_hp_ex_op.c)
Expand Down
29 changes: 29 additions & 0 deletions drivers/flash/Kconfig.mcux
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,32 @@ choice FLASH_LOG_LEVEL_CHOICE
endchoice

endif # DT_HAS_NXP_IMX_FLEXSPI_ENABLED

# MCUX C40 internal flash API shim (S32K3x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# MCUX C40 internal flash API shim (S32K3x)
# MCUX C40 internal flash driver (S32K3x)

config FLASH_MCUX_C40_API
def_bool y
depends on SOC_SERIES_S32K3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant with DT_HAS_NXP_S32K3X_C40_FLASH_ENABLED

depends on DT_HAS_NXP_S32K3X_C40_FLASH_ENABLED
select FLASH_HAS_DRIVER_ENABLED
select FLASH_HAS_EXPLICIT_ERASE
select FLASH_HAS_PAGE_LAYOUT
# C40 uses controller commands, not CPU stores to flash
# so we are not relaxing MPU for ROM writes.
# Relocate driver/HAL when XIP so erase/program run from SRAM:
imply CODE_DATA_RELOCATION if XIP
imply CODE_DATA_RELOCATION_SRAM if XIP
help
Enable the MCUX C40 internal flash API shim used on NXP S32K3x
(e.g. S32K344). Provides Zephyr flash driver glue for &flash0 using
the MCUX C40 HAL. Needed for FLASH_MAP/MCUboot on internal flash
Comment on lines +136 to +138
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Enable the MCUX C40 internal flash API shim used on NXP S32K3x
(e.g. S32K344). Provides Zephyr flash driver glue for &flash0 using
the MCUX C40 HAL. Needed for FLASH_MAP/MCUboot on internal flash
Enable the MCUX C40 internal flash driver used on NXP S32K3x
(e.g. S32K344). Provides Zephyr flash API using MCUX C40 HAL.


# NXP MCUX C40 internal flash: optional protection pass at init
config FLASH_MCUX_C40_APPLY_PROTECTION
bool "Apply default protection windows (IVT/MCUboot) at init"
depends on FLASH_MCUX_C40_API
default y if XIP
help
When enabled, the driver locks/unlocks protection for well-known
regions derived from devicetree (e.g. ivt_header, ivt_pad, mcuboot)
during driver init. Useful on XIP systems to keep IVT/bootloader
areas read-only. Disable if your bootloader/policy manages this.
Loading
Loading