Skip to content

Commit 0d40dff

Browse files
drivers: flash: Add MCUX C40 flash controller driver
Add flash controller driver for the on-chip C40 flash controller The driver is backed by the MCUX C40 HAL and implements read/erase/program, page layout, and an optional protection policy that can lock well-known regions (IVT/MCUboot) derived from devicetree. Key details: - Selects FLASH_HAS_DRIVER_ENABLED / FLASH_HAS_EXPLICIT_ERASE / FLASH_HAS_PAGE_LAYOUT. - Runs erase/program from SRAM when XIP by relocating both the shim and the MCUX HAL source if CODE_DATA_RELOCATION_SRAM=y. - Optional protection pass at init (FLASH_MCUX_C40_APPLY_PROTECTION), which aligns windows to sector boundaries and applies lock/unlock using the HAL. This is useful on XIP systems to keep IVT/bootloader ranges read-only; can be disabled if a bootloader or security policy manages protection instead. Files: - drivers/flash/flash_mcux_c40.c (new) - drivers/flash/CMakeLists.txt (+zephyr_code_relocate when needed, Compliance fixes) - drivers/flash/Kconfig.mcux (enable flash driver, reloc & protection) - modules/hal_nxp/mcux/mcux-sdk-ng/drivers/drivers.cmake Signed-off-by: Sumit Batra <sumit.batra@nxp.com>
1 parent f3eae4a commit 0d40dff

File tree

4 files changed

+430
-0
lines changed

4 files changed

+430
-0
lines changed

drivers/flash/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ if(CONFIG_FLASH_NXP_S32_QSPI_NOR OR CONFIG_FLASH_NXP_S32_QSPI_HYPERFLASH)
184184
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers/memc)
185185
endif()
186186

187+
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_MCUX_C40 flash_mcux_c40.c)
188+
189+
if(CONFIG_SOC_FLASH_MCUX_C40 AND CONFIG_CODE_DATA_RELOCATION)
190+
# Relocate the Zephyr driver to RAM when relocation is enabled
191+
zephyr_code_relocate(FILES ${CMAKE_CURRENT_LIST_DIR}/flash_mcux_c40.c LOCATION RAM)
192+
if(DEFINED ZEPHYR_HAL_NXP_MODULE_DIR)
193+
# Relocate the HAL driver to RAM
194+
zephyr_code_relocate(FILES ${ZEPHYR_HAL_NXP_MODULE_DIR}/mcux/mcux-sdk-ng/drivers/flash_c40/fsl_c40_flash.c LOCATION RAM)
195+
endif()
196+
endif()
197+
187198
if(CONFIG_SOC_FLASH_RENESAS_RA_HP)
188199
zephyr_library_sources(soc_flash_renesas_ra_hp.c)
189200
zephyr_library_sources_ifdef(CONFIG_FLASH_EX_OP_ENABLED soc_flash_renesas_ra_hp_ex_op.c)

drivers/flash/Kconfig.mcux

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,31 @@ config FLASH_MCUX_XSPI
130130
select FLASH_HAS_EXPLICIT_ERASE
131131
help
132132
Enable the mcux xspi flash driver.
133+
134+
# MCUX C40 internal flash driver
135+
config SOC_FLASH_MCUX_C40
136+
bool "MCUX C40 flash driver"
137+
default y
138+
depends on DT_HAS_NXP_C40_FLASH_CONTROLLER_ENABLED
139+
depends on DT_HAS_NXP_C40_FLASH_ENABLED
140+
select FLASH_HAS_DRIVER_ENABLED
141+
select FLASH_HAS_EXPLICIT_ERASE
142+
select FLASH_HAS_PAGE_LAYOUT
143+
# C40 uses controller commands, not CPU stores to flash
144+
# so we are not relaxing MPU for ROM writes.
145+
# Relocate driver/HAL when XIP so erase/program run from SRAM:
146+
imply CODE_DATA_RELOCATION if XIP
147+
imply CODE_DATA_RELOCATION_SRAM if XIP
148+
help
149+
Enable the NXP MCUX C40 internal flash driver
150+
Provides Zephyr flash driver using MCUX C40 HAL.
151+
152+
config SOC_FLASH_MCUX_C40_APPLY_PROTECTION
153+
bool "Apply default protection windows (IVT/MCUboot) at init"
154+
depends on SOC_FLASH_MCUX_C40
155+
default y if XIP
156+
help
157+
When enabled, the driver locks/unlocks protection for well-known
158+
regions derived from devicetree (e.g. ivt_header, ivt_pad, mcuboot)
159+
during driver init. Useful on XIP systems to keep IVT/bootloader
160+
areas read-only. Disable if your bootloader/policy manages this.

0 commit comments

Comments
 (0)