soc: nxp: Centralize flexspi related configuration

Currently this code related to how to configure the
flash size and address when using flexspi to XIP is copy
pasted in all sort of places and ways all over the tree,
let's clean this up and have single point of control over
this configuration.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2024-08-12 14:15:19 -05:00 committed by Alberto Escolar
commit a097cdc4fe
19 changed files with 63 additions and 218 deletions

View file

@ -0,0 +1,41 @@
# Copyright 2024 NXP
# SPDX-License-Identifier: Apache-2.0
DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_FLEXSPI := nxp,imx-flexspi
DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
DT_FLASH_PARENT_IS_FLEXSPI := $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI))
DT_FLASH_HAS_SIZE_PROP := $(dt_node_has_prop,$(DT_CHOSEN_FLASH_NODE),size)
config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) \
if $(DT_FLASH_PARENT_IS_FLEXSPI)
default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))
config FLASH_SIZE
default $(dt_node_int_prop_int,$(DT_CHOSEN_FLASH_NODE),size,Kb) \
if $(DT_FLASH_HAS_SIZE_PROP)
default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_FLASH),0,K)
config FLASH_MCUX_FLEXSPI_XIP
bool
default $(DT_FLASH_PARENT_IS_FLEXSPI)
select XIP
help
Allows REfor the soc to safely initialize the clocks for the
FlexSpi when planning to execute code in FlexSpi Memory.
config CODE_DATA_RELOCATION_SRAM
default y if FLASH_MCUX_FLEXSPI_XIP && MEMC_MCUX_FLEXSPI
config FLASH_MCUX_FLEXSPI_XIP_MEM
string
prompt "Flexspi drivers memory location"
default "RAM"
depends on MEMC_MCUX_FLEXSPI && FLASH_MCUX_FLEXSPI_XIP
help
Select the location to run the FlexSPI drivers when using
the flash API.

View file

@ -10,47 +10,7 @@ if SOC_FAMILY_NXP_IMXRT
# can override the defaults given here
rsource "*/Kconfig"
# Used for default value in FLASH_MCUX_FLEXSPI_XIP
DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_FLEXSPI := nxp,imx-flexspi
# Macros to shorten Kconfig definitions
DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
config FLASH_MCUX_FLEXSPI_XIP
bool "MCUX FlexSPI flash access with xip"
default $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI))
select XIP
help
Allows for the soc to safely initialize the clocks for the
FlexSpi when planning to execute code in FlexSpi Memory.
if FLASH_MCUX_FLEXSPI_XIP && MEMC_MCUX_FLEXSPI
choice FLASH_MCUX_FLEXSPI_XIP_MEM_TARGET
prompt "FlexSPI drivers relocation target"
default FLASH_MCUX_FLEXSPI_XIP_MEM_SRAM if SOC_MIMXRT1189_CM33 # RT118X_CM33 core lacks ITCM
default FLASH_MCUX_FLEXSPI_XIP_MEM_ITCM
help
Select the location to run the FlexSPI drivers when using
the flash API.
config FLASH_MCUX_FLEXSPI_XIP_MEM_ITCM
bool "ITCM"
select CODE_DATA_RELOCATION
config FLASH_MCUX_FLEXSPI_XIP_MEM_SRAM
bool "RAM"
select CODE_DATA_RELOCATION_SRAM
endchoice
config FLASH_MCUX_FLEXSPI_XIP_MEM
string
default "ITCM" if FLASH_MCUX_FLEXSPI_XIP_MEM_ITCM
default "RAM" if FLASH_MCUX_FLEXSPI_XIP_MEM_SRAM
endif # FLASH_MCUX_FLEXSPI_XIP && MEMC_MCUX_FLEXSPI
rsource "../common/Kconfig.flexspi_xip"
# Note- When SECOND_CORE_MCUX is set, the dependencies for this Kconfig
# should be set elsewhere, since the determination of which SOC core

View file

@ -107,29 +107,22 @@ config TEST_EXTRA_STACK_SIZE
default 1024
endif # MBEDTLS
if CPU_CORTEX_M7
# defaults specific for the M7 core
# Enable cache management features when using M7 core, since these parts
# have L1 instruction and data caches that should be enabled at boot
config CACHE_MANAGEMENT
default y if CPU_CORTEX_M7
default y
config FLASH_MCUX_FLEXSPI_XIP_MEM
default "ITCM"
config CODE_DATA_RELOCATION_SRAM
default n
endif # CPU_CORTEX_M7
endif # SOC_SERIES_IMXRT10XX || SOC_SERIES_IMXRT11XX || SOC_SERIES_IMXRT118X
# Logic to set flash size for all IMXRT parts
DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_FLEXSPI := nxp,imx-flexspi
DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
DT_FLASH_PARENT_IS_FLEXSPI := $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI))
DT_FLASH_HAS_SIZE_PROP := $(dt_node_has_prop,$(DT_CHOSEN_FLASH_NODE),size)
config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) \
if $(DT_FLASH_PARENT_IS_FLEXSPI)
config FLASH_SIZE
default $(dt_node_int_prop_int,$(DT_CHOSEN_FLASH_NODE),size,Kb) \
if $(DT_FLASH_HAS_SIZE_PROP)
endif # SOC_FAMILY_NXP_IMXRT

View file

@ -18,7 +18,7 @@ endif()
if(CONFIG_MEMC_MCUX_FLEXSPI)
zephyr_sources(flexspi.c)
if(CONFIG_FLASH_MCUX_FLEXSPI_XIP)
zephyr_code_relocate(FILES flexspi.c LOCATION ITCM_TEXT)
zephyr_code_relocate(FILES flexspi.c LOCATION ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT)
endif()
endif()

View file

@ -33,4 +33,5 @@ config NXP_IMXRT_BOOT_HEADER
depends on !(CPU_CORTEX_M4 || BOOTLOADER_MCUBOOT)
endif
endif

View file

@ -14,10 +14,6 @@ config NUM_IRQS
config ZTEST_NO_YIELD
default y if (PM && ZTEST)
# Code relocation is needed for flash clock setup
config CODE_DATA_RELOCATION_SRAM
default y
#
# MBEDTLS is larger but much faster than TinyCrypt so choose wisely
#

View file

@ -10,10 +10,9 @@ zephyr_compile_definitions_ifdef(CONFIG_USB_DEVICE_DRIVER USB_STACK_USE_DEDICATE
zephyr_include_directories(.)
zephyr_sources(
soc.c
flash_clock_setup.c
)
zephyr_sources(soc.c)
zephyr_sources_ifdef(CONFIG_FLASH_MCUX_FLEXSPI_XIP flash_clock_setup.c)
zephyr_sources_ifdef(CONFIG_PM power.c)

View file

@ -6,7 +6,6 @@ config SOC_MIMXRT685S_CM33
select CPU_CORTEX_M33
select CPU_CORTEX_M_HAS_DWT
select CLOCK_CONTROL
select CODE_DATA_RELOCATION_SRAM if FLASH_MCUX_FLEXSPI_XIP
select PLATFORM_SPECIFIC_INIT
select HAS_PM
select CPU_HAS_ARM_SAU

View file

@ -35,33 +35,6 @@ FLEXSPI_BASE := $(dt_node_reg_addr_hex,/soc/spi@134000,1)
config BUILD_OUTPUT_ADJUST_LMA
default "$(FLEXSPI_BASE) - $(FLASH_BASE)" if NXP_IMX_RT_ROM_RAMLOADER
# The base address is determined from the zephyr,flash node with the following
# precedence:
# FlexSPI base address (if flash node is on a FlexSPI bus)
# node reg property (used for memory regions such as SRAM)
# Workaround for not being able to have commas in macro arguments
DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_FLEXSPI := nxp,imx-flexspi
# Macros to shorten Kconfig definitions
DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) \
if $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI))
default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))
# The RT6xx has no internal flash. If the flash node has a size property,
# use that over the reg property. This is used for the external flash
# present on the board. Otherwise, fallback to the reg property
config FLASH_SIZE
default $(dt_node_int_prop_int,$(DT_CHOSEN_FLASH_NODE),size,Kb) \
if $(dt_node_has_prop,$(DT_CHOSEN_FLASH_NODE),size)
default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_FLASH),0,K)
#
# MBEDTLS is larger but much faster than TinyCrypt so choose wisely
#

View file

@ -49,29 +49,6 @@ config MCUX_CORE_SUFFIX
default "_cm33_core1" if SOC_MCXN947_CPU1
endif
DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_FLEXSPI := nxp,imx-flexspi
DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
DT_FLASH_PARENT_IS_FLEXSPI := $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI))
DT_FLASH_HAS_SIZE_PROP := $(dt_node_has_prop,$(DT_CHOSEN_FLASH_NODE),size)
config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) \
if $(DT_FLASH_PARENT_IS_FLEXSPI)
config FLASH_SIZE
default $(dt_node_int_prop_int,$(DT_CHOSEN_FLASH_NODE),size,Kb) \
if $(DT_FLASH_HAS_SIZE_PROP)
config FLASH_MCUX_FLEXSPI_XIP
bool
default $(DT_FLASH_PARENT_IS_FLEXSPI)
select XIP
help
Allows for the soc to safely initialize the clocks for the
FlexSpi when planning to execute code in FlexSpi Memory.
rsource "../../common/Kconfig.flexspi_xip"
endif # SOC_SERIES_MCXN

View file

@ -3,18 +3,6 @@
if SOC_SERIES_MCXN
if FLASH_MCUX_FLEXSPI_XIP
# Code relocation is needed when FLASH_MCUX_FLEXSPI_XIP is enabled
config CODE_DATA_RELOCATION_SRAM
default y
config FLASH_MCUX_FLEXSPI_XIP_MEM
string
default "RAM"
endif # FLASH_MCUX_FLEXSPI_XIP
config MFD
default y if DT_HAS_NXP_LP_FLEXCOMM_ENABLED

View file

@ -60,20 +60,7 @@ config IMAGE_VECTOR_TABLE_OFFSET
endif # NXP_RW6XX_BOOT_HEADER
# Used for default value in FLASH_MCUX_FLEXSPI_XIP
DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_FLEXSPI := nxp,imx-flexspi
# Macros to shorten Kconfig definitions
DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
config FLASH_MCUX_FLEXSPI_XIP
bool "MCUX FlexSPI flash access with xip"
default $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI))
select XIP
help
Allows for the soc to safely initialize the clocks for the
FlexSpi when planning to execute code in FlexSpi Memory.
rsource "../common/Kconfig.flexspi_xip"
config NXP_RW_ROM_RAMLOADER
depends on !FLASH_MCUX_FLEXSPI_XIP
@ -85,9 +72,4 @@ config NXP_RW_ROM_RAMLOADER
FlexSPI boot device into RAM region. The image will be loaded
from FLEXSPI into the region specified by `zephyr,flash` node.
config FLASH_MCUX_FLEXSPI_XIP_MEM
string
default "RAM"
depends on MEMC_MCUX_FLEXSPI
endif # SOC_SERIES_RW6XX

View file

@ -28,30 +28,9 @@ endif # CORTEX_M_SYSTICK
# FlexSPI base address (if flash node is on a FlexSPI bus)
# node reg property (used for memory regions such as SRAM)
# Workaround for not being able to have commas in macro arguments
DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_FLEXSPI := nxp,imx-flexspi
# Macros to shorten Kconfig definitions
DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
config FLASH_BASE_ADDRESS
default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) \
if $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_FLEXSPI))
default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))
# The RW6xx has no internal flash. If the flash node has a size property,
# use that over the reg property. This is used for the external flash
# present on the board. Otherwise, fallback to the reg property
config FLASH_SIZE
default $(dt_node_int_prop_int,$(DT_CHOSEN_FLASH_NODE),size,Kb) \
if $(dt_node_has_prop,$(DT_CHOSEN_FLASH_NODE),size)
default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_FLASH),0,K)
if NXP_RW_ROM_RAMLOADER
DT_CHOSEN_Z_FLASH := zephyr,flash
FLASH_BASE := $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))
FLEXSPI_BASE := $(dt_node_reg_addr_hex,/soc/spi@134000,1)
config BUILD_OUTPUT_ADJUST_LMA
@ -59,14 +38,6 @@ config BUILD_OUTPUT_ADJUST_LMA
endif # NXP_RW_ROM_RAMLOADER
if FLASH_MCUX_FLEXSPI_XIP
# Code relocation is needed when MEMC driver is enabled
config CODE_DATA_RELOCATION_SRAM
default y if MEMC
endif # FLASH_MCUX_FLEXSPI_XIP
choice USB_MCUX_CONTROLLER_TYPE
default USB_DC_NXP_EHCI
endchoice