From eac0c36e04c82b61bc367d49f20a689f612c8bab Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 16 Nov 2019 01:03:25 +0100 Subject: [PATCH 1/4] kconfig: Make FLASH_LOAD_OFFSET/SIZE non-configurable when DT is used Having FLASH_LOAD_OFFSET and FLASH_LOAD_SIZE always configurable froze their values at 0 when BOOTLOADER_MCUBOOT was enabled in menuconfig, when instead the values from /chosen/zephyr,code-partition in devicetree should be used. BOOTLOADER_MCUBOOT selects USE_CODE_PARTITION, which is a flag to use the devicetree information. To fix it, only make FLASH_LOAD_OFFSET and FLASH_LOAD_SIZE configurable when USE_CODE_PARTITION is disabled. It looks like no configuration files set them at the moment. See the added documentation in https://github.com/zephyrproject-rtos/zephyr/pull/20722 for an explanation of why this happens. This bit novalisek in https://github.com/zephyrproject-rtos/zephyr/issues/20673. Fixes: #20673 Signed-off-by: Ulf Magnusson --- Kconfig.zephyr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 4ca994a6c9011..7a92c144aa4a8 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -95,7 +95,8 @@ config USE_CODE_PARTITION DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition config FLASH_LOAD_OFFSET - hex "Kernel load offset" + # Only user-configurable when USE_CODE_PARTITION is disabled + hex "Kernel load offset" if !USE_CODE_PARTITION default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION default 0 depends on HAS_FLASH_LOAD_OFFSET @@ -108,7 +109,8 @@ config FLASH_LOAD_OFFSET If unsure, leave at the default value 0. config FLASH_LOAD_SIZE - hex "Kernel load size" + # Only user-configurable when USE_CODE_PARTITION is disabled + hex "Kernel load size" if !USE_CODE_PARTITION default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION default 0 depends on HAS_FLASH_LOAD_OFFSET From 33bb397a3af674be86ccdbed6ff1d0e1ea38846f Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 16 Nov 2019 01:16:57 +0100 Subject: [PATCH 2/4] kconfig: Improve USE_CODE_PARTITION prompt and help string The prompt and help string for USE_CODE_PARTITION were too terse and didn't make it clear that it's related to devicetree, which confused me. Spell things out in more detail. Unless the meaning of a symbol is completely obvious from context, aim for at least a few sentences of help text. Think about what would be confusing for someone coming at it without much context. Signed-off-by: Ulf Magnusson --- Kconfig.zephyr | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 7a92c144aa4a8..63cd4d063102d 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -86,10 +86,13 @@ config HAS_FLASH_LOAD_OFFSET and FLASH_LOAD_SIZE. config USE_CODE_PARTITION - bool "link into code-partition" + bool "Link application into /chosen/zephyr,code-partition from devicetree" depends on HAS_FLASH_LOAD_OFFSET help - When selected application will be linked into chosen code-partition. + When enabled, the application will be linked into the flash partition + selected by the zephyr,code-partition property in /chosen in devicetree. + When this is disabled, the flash load offset and size can be set manually + below. # Workaround for not being able to have commas in macro arguments DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition From 5f7373b776e511897d3d920f0baeebb189e513e3 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 16 Nov 2019 01:22:16 +0100 Subject: [PATCH 3/4] kconfig: Rename USE_CODE_PARTITION to USE_DT_CODE_PARTITION USE_CODE_PARTITION is a bit vague as a symbol name ("use code partition how?"). Rename it to USE_DT_CODE_PARTITION to make it clearer that it's about devicetree. This would break any third-party configuration files that set it, but it'll generate an error since kconfig.py promotes warnings to errors, so it's probably not a big deal. Signed-off-by: Ulf Magnusson --- Kconfig.zephyr | 16 ++++++++-------- boards/arm/nrf52840_pca10059/Kconfig.defconfig | 6 +++--- soc/riscv/openisa_rv32m1/linker.ld | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 63cd4d063102d..a0fead75e93b4 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -85,7 +85,7 @@ config HAS_FLASH_LOAD_OFFSET This option is selected by targets having a FLASH_LOAD_OFFSET and FLASH_LOAD_SIZE. -config USE_CODE_PARTITION +config USE_DT_CODE_PARTITION bool "Link application into /chosen/zephyr,code-partition from devicetree" depends on HAS_FLASH_LOAD_OFFSET help @@ -98,9 +98,9 @@ config USE_CODE_PARTITION DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition config FLASH_LOAD_OFFSET - # Only user-configurable when USE_CODE_PARTITION is disabled - hex "Kernel load offset" if !USE_CODE_PARTITION - default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION + # Only user-configurable when USE_DT_CODE_PARTITION is disabled + hex "Kernel load offset" if !USE_DT_CODE_PARTITION + default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_DT_CODE_PARTITION default 0 depends on HAS_FLASH_LOAD_OFFSET help @@ -112,9 +112,9 @@ config FLASH_LOAD_OFFSET If unsure, leave at the default value 0. config FLASH_LOAD_SIZE - # Only user-configurable when USE_CODE_PARTITION is disabled - hex "Kernel load size" if !USE_CODE_PARTITION - default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_CODE_PARTITION + # Only user-configurable when USE_DT_CODE_PARTITION is disabled + hex "Kernel load size" if !USE_DT_CODE_PARTITION + default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_DT_CODE_PARTITION default 0 depends on HAS_FLASH_LOAD_OFFSET help @@ -356,7 +356,7 @@ config BOOTLOADER_SRAM_SIZE config BOOTLOADER_MCUBOOT bool "MCUboot bootloader support" - select USE_CODE_PARTITION + select USE_DT_CODE_PARTITION help This option signifies that the target uses MCUboot as a bootloader, or in other words that the image is to be chain-loaded by MCUboot. diff --git a/boards/arm/nrf52840_pca10059/Kconfig.defconfig b/boards/arm/nrf52840_pca10059/Kconfig.defconfig index bd2dd768e62d2..f82a146019218 100644 --- a/boards/arm/nrf52840_pca10059/Kconfig.defconfig +++ b/boards/arm/nrf52840_pca10059/Kconfig.defconfig @@ -9,7 +9,7 @@ if BOARD_NRF52840_PCA10059 config BOARD default "nrf52840_pca10059" -if BOARD_HAS_NRF5_BOOTLOADER && !USE_CODE_PARTITION +if BOARD_HAS_NRF5_BOOTLOADER && !USE_DT_CODE_PARTITION # To let the nRF5 bootloader load an application, the application # must be linked after Nordic MBR, that is factory-programmed on the board. @@ -18,14 +18,14 @@ if BOARD_HAS_NRF5_BOOTLOADER && !USE_CODE_PARTITION # DTS file, so we manually override FLASH_LOAD_OFFEST to link the application # correctly, after Nordic MBR. -# When building MCUBoot, MCUBoot itself will select USE_CODE_PARTITION +# When building MCUBoot, MCUBoot itself will select USE_DT_CODE_PARTITION # which will make it link into the correct partition specified in DTS file, # so no override is necessary. config FLASH_LOAD_OFFSET default 0x1000 -endif # BOARD_HAS_NRF5_BOOTLOADER && !USE_CODE_PARTITION +endif # BOARD_HAS_NRF5_BOOTLOADER && !USE_DT_CODE_PARTITION if ADC diff --git a/soc/riscv/openisa_rv32m1/linker.ld b/soc/riscv/openisa_rv32m1/linker.ld index 7fe1ae9a6fd4f..b441b899470ce 100644 --- a/soc/riscv/openisa_rv32m1/linker.ld +++ b/soc/riscv/openisa_rv32m1/linker.ld @@ -28,7 +28,7 @@ #define VECTOR_SIZE CONFIG_RISCV_RV32M1_VECTOR_SIZE -#ifdef CONFIG_USE_CODE_PARTITION +#ifdef CONFIG_USE_DT_CODE_PARTITION #ifdef CONFIG_BOOTLOADER_MCUBOOT From 8a498bbc8460c9379cbf986da01880979e9b3a8d Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 16 Nov 2019 01:33:09 +0100 Subject: [PATCH 4/4] kconfig: Factor out HAS_FLASH_LOAD_OFFSET dependency Use a top-level 'if' instead of three separate 'depends on'. They're exactly equivalent (top-level 'if's are just a shorthand for adding 'depends on' to each item within the 'if'). Signed-off-by: Ulf Magnusson --- Kconfig.zephyr | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index a0fead75e93b4..d878031bed8be 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -85,9 +85,10 @@ config HAS_FLASH_LOAD_OFFSET This option is selected by targets having a FLASH_LOAD_OFFSET and FLASH_LOAD_SIZE. +if HAS_FLASH_LOAD_OFFSET + config USE_DT_CODE_PARTITION bool "Link application into /chosen/zephyr,code-partition from devicetree" - depends on HAS_FLASH_LOAD_OFFSET help When enabled, the application will be linked into the flash partition selected by the zephyr,code-partition property in /chosen in devicetree. @@ -102,7 +103,6 @@ config FLASH_LOAD_OFFSET hex "Kernel load offset" if !USE_DT_CODE_PARTITION default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_DT_CODE_PARTITION default 0 - depends on HAS_FLASH_LOAD_OFFSET help This option specifies the byte offset from the beginning of flash that the kernel should be loaded into. Changing this value from zero will @@ -116,7 +116,6 @@ config FLASH_LOAD_SIZE hex "Kernel load size" if !USE_DT_CODE_PARTITION default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_CODE_PARTITION)) if USE_DT_CODE_PARTITION default 0 - depends on HAS_FLASH_LOAD_OFFSET help If non-zero, this option specifies the size, in bytes, of the flash area that the Zephyr image will be allowed to occupy. If zero, the @@ -125,6 +124,8 @@ config FLASH_LOAD_SIZE If unsure, leave at the default value 0. +endif # HAS_FLASH_LOAD_OFFSET + config TEXT_SECTION_OFFSET hex prompt "TEXT section offset" if !BOOTLOADER_MCUBOOT