Skip to content

Conversation

fsammoura1980
Copy link
Contributor

Move the logic for determining flash base address and size from the RISC-V common linker script to Kconfig.

The new Kconfig options CONFIG_FLASH_BASE_ADDRESS and CONFIG_FLASH_SIZE are now the source of truth for the linker script. These options are given default values derived from the devicetree, supporting both "soc-nv-flash" and "jedec,spi-nor" flash types.

SoC-specific defaults for litex_vexriscv with JEDEC SPI NOR flash have also been added.

This change simplifies the linker script and consolidates the flash geometry configuration within the Kconfig system.

DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))

config FLASH_SIZE
default $(dt_node_reg_size_int,$(DT_CHOSEN_FLASH_PARENT),9,K) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),$(DT_COMPAT_JEDEC_SPI_NOR)))
Copy link
Member

Choose a reason for hiding this comment

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

even tho this soc is the only in tree usage of it, we don't want to break behavior for out of tree boards and socs, therefore this should also be part of the Kconfig of riscv.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe update ‎arch/riscv/Kconfig like:

 DT_CHOSEN_Z_FLASH := zephyr,flash
 DT_COMPAT_JEDEC_SPI_NOR := jedec,spi-nor
+DT_COMPAT_LITEX_SPI_LITESPI := litex,spi-litespi
 DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
 DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
 
 config FLASH_SIZE
        default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_FLASH),0,K) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),soc-nv-flash))
+       default $(dt_node_reg_size_int,$(DT_CHOSEN_FLASH_PARENT),9,K) if (XIP && $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_LITEX_SPI_LITESPI)))
        default $(dt_node_reg_size_int,$(DT_CHOSEN_FLASH_PARENT),1,K) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),$(DT_COMPAT_JEDEC_SPI_NOR)))
 
 config FLASH_BASE_ADDRESS
        default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH)) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),soc-nv-flash))
+       default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),9) if (XIP && $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_LITEX_SPI_LITESPI)))
        default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),$(DT_COMPAT_JEDEC_SPI_NOR)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified per the recommendation.

Copy link
Member

@fkokosinski fkokosinski Oct 10, 2025

Choose a reason for hiding this comment

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

Isn't this already handled by both of these symbols' default values when used in conjunction with zephyr,flash (with XIP being y-selected) in the chosen node?

Move the logic for determining flash base address and size from
the RISC-V common linker script to Kconfig.

The new Kconfig options CONFIG_FLASH_BASE_ADDRESS and CONFIG_FLASH_SIZE
are now the source of truth for the linker script. These options are
given default values derived from the devicetree, supporting both
"soc-nv-flash", "jedec,spi-nor", and "litex,spi-litespi" flash types.

This change simplifies the linker script and consolidates the flash
geometry configuration within the Kconfig system.

Signed-off-by: Firas Sammoura <[email protected]>
Copy link

sonarqubecloud bot commented Oct 9, 2025

#endif

#endif /* DT_NODE_HAS_COMPAT_STATUS */
#endif /* ROM_SIZE*/
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this comment is wrong?

Suggested change
#endif /* ROM_SIZE*/
#endif /* CONFIG_XIP */

Comment on lines +536 to +543
default $(dt_chosen_reg_size_int,$(DT_CHOSEN_Z_FLASH),0,K) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),soc-nv-flash))
default $(dt_node_reg_size_int,$(DT_CHOSEN_FLASH_PARENT),9,K) if (XIP && $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_LITEX_SPI_LITESPI)))
default $(dt_node_reg_size_int,$(DT_CHOSEN_FLASH_PARENT),1,K) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),$(DT_COMPAT_JEDEC_SPI_NOR)))

config FLASH_BASE_ADDRESS
default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH)) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),soc-nv-flash))
default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),9) if (XIP && $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_LITEX_SPI_LITESPI)))
default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) if (XIP && $(dt_chosen_has_compat,$(DT_CHOSEN_Z_FLASH),$(DT_COMPAT_JEDEC_SPI_NOR)))
Copy link
Member

Choose a reason for hiding this comment

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

the reg-name ("flash_mmap") has to be checked. The position is completely irrelevant.
in Litex this changed already a few times and it also depends on the configuration.
Also that prop might not be used drom the litex litespi driver in tree, but out of tree users could have also used it for others.

Copy link
Member

Choose a reason for hiding this comment

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

was added here: #73482 for more context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants