Skip to contentSkip to conversation

*** boot: Add Kconfig options for script-based boot parameters ***

PATCH In review Wadim Egorov 2 participants 9 messages May 8, 2025 – May 9, 2025 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

cover *** boot: Add Kconfig options for script-based boot parameters ***

This series introduces new Kconfig options to configure default environment variables used in script-based boot scenarios. Specifically, it allows setting the following standard boot environment variables:

- boot_script_dhcp via BOOTSCRIPT_DHCP
- script_offset_f and script_size_f via USE_SPI_FLASH_SCRIPT and related options

These changes make it possible to define standard boot environment variables directly via Kconfig, allowing higher-level build systems like Yocto to set them at build time. This avoids the need for post-build environment patches or runtime overrides, improving reproducibility and simplifying integration in automated firmware build workflows.

Wadim Egorov (2):
boot: Add BOOTSCRIPT_DHCP Kconfig option for boot_script_dhcp env
mtd: bootdev: Add Kconfig option for defining script parameters

 boot/Kconfig            | 18 ++++++++++++++++++
 drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
 include/env_default.h   |  7 +++++++
 3 files changed, 51 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 boot: Add BOOTSCRIPT_DHCP Kconfig option for boot_script_dhcp env

Introduce a new Kconfig option BOOTSCRIPT_DHCP to allow setting a value for boot_script_dhcp in the default environment.

---
 boot/Kconfig          | 18 ++++++++++++++++++
 include/env_default.h |  3 +++
 2 files changed, 21 insertions(+)
boot/Kconfig +18 -0
index fb37d912bc9..ed34eff5b7a 100644
@@ -875,6 +875,24 @@ config BOOTMETH_SCRIPT
 	  This provides a way to try out standard boot on an existing boot flow.
 	  It is not enabled by default to save space.
 
+config USE_BOOTSCRIPT_DHCP
+	bool "Enable default DHCP boot script filename"
+	depends on BOOTMETH_SCRIPT
+	help
+	  Enable this option if you want to set a default value for the
+	  'boot_script_dhcp' environment variable, which is used to fetch a
+	  boot script via TFTP over the network.
+
+	  If unsure, say N.
+
+config BOOTSCRIPT_DHCP
+	string "Default boot script filename (boot_script_dhcp)"
+	depends on USE_BOOTSCRIPT_DHCP
+	help
+	  This option sets the default value for the 'boot_script_dhcp' environment
+	  variable, which is used to fetch a boot script over the network via TFTP.
+	  The script must reside in the top-level directory of the TFTP server.
+
 config UPL
 	bool "upl - Universal Payload Specification"
 	imply CMD_UPL
include/env_default.h +3 -0
index 60c39f9853f..c72cf123004 100644
@@ -124,6 +124,9 @@ const char default_environment[] = {
 #ifdef CONFIG_MTDPARTS_DEFAULT
 	"mtdparts="	CONFIG_MTDPARTS_DEFAULT		"\0"
 #endif
+#ifdef CONFIG_BOOTSCRIPT_DHCP
+	"boot_script_dhcp="	CONFIG_BOOTSCRIPT_DHCP	"\0"
+#endif
 #ifdef CONFIG_EXTRA_ENV_TEXT
 	/* This is created in the Makefile */
 	CONFIG_EXTRA_ENV_TEXT
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 mtd: bootdev: Add Kconfig option for defining script parameters

In reply to Wadim Egorov

Introduce USE_SPI_FLASH_SCRIPT Kconfig option to enable setting default environment values for loading boot scripts from SPI flash. When enabled, SPI_FLASH_SCRIPT_OFFSET and SPI_FLASH_SCRIPT_SIZE define the default script_offset_f and script_size_f variables.

---
 drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
 include/env_default.h   |  4 ++++
 2 files changed, 30 insertions(+)
drivers/mtd/spi/Kconfig +26 -0
index ca60a425ba3..fc154ec89d7 100644
@@ -89,6 +89,32 @@ config BOOTDEV_SPI_FLASH
 
 	  If unsure, say N
 
+config USE_SPI_FLASH_SCRIPT
+	bool "Enable default SPI flash script parameters"
+	depends on BOOTDEV_SPI_FLASH
+	help
+	  Enable this option to provide default values for SPI flash script loading.
+	  These values will be assigned to the 'script_offset_f' and 'script_size_f'
+	  environment variables at boot time if not already defined in the environment.
+
+	  If unsure, say N.
+
+config SPI_FLASH_SCRIPT_OFFSET
+	hex "Offset for SPI flash script (script_offset_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_offset_f' environment
+	  variable. It specifies the offset (in bytes) in SPI flash from which
+	  the boot script should be loaded.
+
+config SPI_FLASH_SCRIPT_SIZE
+	hex "Size of SPI flash script (script_size_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_size_f' environment
+	  variable. It specifies the number of bytes to read from SPI flash to
+	  load the boot script.
+
 config SPI_FLASH_SFDP_SUPPORT
 	bool "SFDP table parsing support for SPI NOR flashes"
 	depends on !SPI_FLASH_BAR
include/env_default.h +4 -0
index c72cf123004..9f2f222519d 100644
@@ -127,6 +127,10 @@ const char default_environment[] = {
 #ifdef CONFIG_BOOTSCRIPT_DHCP
 	"boot_script_dhcp="	CONFIG_BOOTSCRIPT_DHCP	"\0"
 #endif
+#ifdef USE_SPI_FLASH_SCRIPT
+	"script_offset_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_OFFSET)"\0"
+	"script_size_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_SIZE)"\0"
+#endif
 #ifdef CONFIG_EXTRA_ENV_TEXT
 	/* This is created in the Makefile */
 	CONFIG_EXTRA_ENV_TEXT
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/2] mtd: bootdev: Add Kconfig option for defining script parameters

Quoted 53 lines · Wadim Egorov

Introduce USE_SPI_FLASH_SCRIPT Kconfig option to enable setting default environment values for loading boot scripts from SPI flash. When enabled, SPI_FLASH_SCRIPT_OFFSET and SPI_FLASH_SCRIPT_SIZE define the default script_offset_f and script_size_f variables.

---
 drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
 include/env_default.h   |  4 ++++
 2 files changed, 30 insertions(+)
drivers/mtd/spi/Kconfig +26 -0
index ca60a425ba3..fc154ec89d7 100644
@@ -89,6 +89,32 @@ config BOOTDEV_SPI_FLASH
 
 	  If unsure, say N
 
+config USE_SPI_FLASH_SCRIPT
+	bool "Enable default SPI flash script parameters"
+	depends on BOOTDEV_SPI_FLASH
+	help
+	  Enable this option to provide default values for SPI flash script loading.
+	  These values will be assigned to the 'script_offset_f' and 'script_size_f'
+	  environment variables at boot time if not already defined in the environment.
+
+	  If unsure, say N.
+
+config SPI_FLASH_SCRIPT_OFFSET
+	hex "Offset for SPI flash script (script_offset_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_offset_f' environment
+	  variable. It specifies the offset (in bytes) in SPI flash from which
+	  the boot script should be loaded.
+
+config SPI_FLASH_SCRIPT_SIZE
+	hex "Size of SPI flash script (script_size_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_size_f' environment
+	  variable. It specifies the number of bytes to read from SPI flash to
+	  load the boot script.
+
 config SPI_FLASH_SFDP_SUPPORT
 	bool "SFDP table parsing support for SPI NOR flashes"
 	depends on !SPI_FLASH_BAR
include/env_default.h +0 -0
index c72cf123004..9f2f222519d 100644

include/env_default.h const char default_environment[] = { · line 133

Quoted 7 lines
include/env_default.h +4 -0
@@ -127,6 +127,10 @@ const char default_environment[] = {
 #ifdef CONFIG_BOOTSCRIPT_DHCP
 	"boot_script_dhcp="	CONFIG_BOOTSCRIPT_DHCP	"\0"
 #endif
+#ifdef USE_SPI_FLASH_SCRIPT
+	"script_offset_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_OFFSET)"\0"
+	"script_size_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_SIZE)"\0"
+#endif

This should be CONFIG_... yes? Did that just get missed in uplifting this from, I assume, an internal tree?

Signature · 1 line
Tom
#4 lore raw

Re: [PATCH 2/2] mtd: bootdev: Add Kconfig option for defining script parameters

Am 08.05.25 um 18:27 schrieb Tom Rini:

Quoted 56 lines · Wadim Egorov
Quoted 55 lines

Introduce USE_SPI_FLASH_SCRIPT Kconfig option to enable setting default environment values for loading boot scripts from SPI flash. When enabled, SPI_FLASH_SCRIPT_OFFSET and SPI_FLASH_SCRIPT_SIZE define the default script_offset_f and script_size_f variables.

---
  drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
  include/env_default.h   |  4 ++++
  2 files changed, 30 insertions(+)
drivers/mtd/spi/Kconfig +26 -0
index ca60a425ba3..fc154ec89d7 100644
@@ -89,6 +89,32 @@ config BOOTDEV_SPI_FLASH
 
  	  If unsure, say N
 
+config USE_SPI_FLASH_SCRIPT
+	bool "Enable default SPI flash script parameters"
+	depends on BOOTDEV_SPI_FLASH
+	help
+	  Enable this option to provide default values for SPI flash script loading.
+	  These values will be assigned to the 'script_offset_f' and 'script_size_f'
+	  environment variables at boot time if not already defined in the environment.
+
+	  If unsure, say N.
+
+config SPI_FLASH_SCRIPT_OFFSET
+	hex "Offset for SPI flash script (script_offset_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_offset_f' environment
+	  variable. It specifies the offset (in bytes) in SPI flash from which
+	  the boot script should be loaded.
+
+config SPI_FLASH_SCRIPT_SIZE
+	hex "Size of SPI flash script (script_size_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_size_f' environment
+	  variable. It specifies the number of bytes to read from SPI flash to
+	  load the boot script.
+
  config SPI_FLASH_SFDP_SUPPORT
  	bool "SFDP table parsing support for SPI NOR flashes"
  	depends on !SPI_FLASH_BAR
include/env_default.h +0 -0
index c72cf123004..9f2f222519d 100644
@@ -127,6 +127,10 @@ const char default_environment[] = {
  #ifdef CONFIG_BOOTSCRIPT_DHCP
  	"boot_script_dhcp="	CONFIG_BOOTSCRIPT_DHCP	"\0"
Quoted 9 lines

include/env_default.h const char default_environment[] = { · line 133

Quoted 5 lines
include/env_default.h +4 -0
  #endif
+#ifdef USE_SPI_FLASH_SCRIPT
+	"script_offset_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_OFFSET)"\0"
+	"script_size_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_SIZE)"\0"
+#endif

This should be CONFIG_... yes? Did that just get missed in uplifting this from, I assume, an internal tree?

I will double check, test and resend a v2.

But is the general idea for defaulting standard boot environment variables in env_default.h okay?

Regards,
Wadim

#5 lore raw

Re: [PATCH 2/2] mtd: bootdev: Add Kconfig option for defining script parameters

Quoted 65 lines · Wadim Egorov

Am 08.05.25 um 18:27 schrieb Tom Rini:

Quoted 54 lines · Wadim Egorov
Quoted 53 lines

Introduce USE_SPI_FLASH_SCRIPT Kconfig option to enable setting default environment values for loading boot scripts from SPI flash. When enabled, SPI_FLASH_SCRIPT_OFFSET and SPI_FLASH_SCRIPT_SIZE define the default script_offset_f and script_size_f variables.

---
  drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
  include/env_default.h   |  4 ++++
  2 files changed, 30 insertions(+)
drivers/mtd/spi/Kconfig +26 -0
index ca60a425ba3..fc154ec89d7 100644
@@ -89,6 +89,32 @@ config BOOTDEV_SPI_FLASH
  	  If unsure, say N
+config USE_SPI_FLASH_SCRIPT
+	bool "Enable default SPI flash script parameters"
+	depends on BOOTDEV_SPI_FLASH
+	help
+	  Enable this option to provide default values for SPI flash script loading.
+	  These values will be assigned to the 'script_offset_f' and 'script_size_f'
+	  environment variables at boot time if not already defined in the environment.
+
+	  If unsure, say N.
+
+config SPI_FLASH_SCRIPT_OFFSET
+	hex "Offset for SPI flash script (script_offset_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_offset_f' environment
+	  variable. It specifies the offset (in bytes) in SPI flash from which
+	  the boot script should be loaded.
+
+config SPI_FLASH_SCRIPT_SIZE
+	hex "Size of SPI flash script (script_size_f)"
+	depends on USE_SPI_FLASH_SCRIPT
+	help
+	  This option sets the default value for the 'script_size_f' environment
+	  variable. It specifies the number of bytes to read from SPI flash to
+	  load the boot script.
+
  config SPI_FLASH_SFDP_SUPPORT
  	bool "SFDP table parsing support for SPI NOR flashes"
  	depends on !SPI_FLASH_BAR
include/env_default.h +0 -0
index c72cf123004..9f2f222519d 100644
@@ -127,6 +127,10 @@ const char default_environment[] = {
  #ifdef CONFIG_BOOTSCRIPT_DHCP
  	"boot_script_dhcp="	CONFIG_BOOTSCRIPT_DHCP	"\0"
Quoted 9 lines

include/env_default.h const char default_environment[] = { · line 133

Quoted 5 lines
include/env_default.h +4 -0
  #endif
+#ifdef USE_SPI_FLASH_SCRIPT
+	"script_offset_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_OFFSET)"\0"
+	"script_size_f="	__stringify(CONFIG_SPI_FLASH_SCRIPT_SIZE)"\0"
+#endif

This should be CONFIG_... yes? Did that just get missed in uplifting this from, I assume, an internal tree?

Quoted 4 lines

I will double check, test and resend a v2.

But is the general idea for defaulting standard boot environment variables in env_default.h okay?

That I am still thinking on. But I did want to be sure you're testing the whole path out elsewhere and this was just a typo :)

Signature · 1 line
Tom
#6 lore raw
In reply to Wadim Egorov

Am 08.05.25 um 16:16 schrieb Wadim Egorov:

Quoted 14 lines

This series introduces new Kconfig options to configure default environment variables used in script-based boot scenarios. Specifically, it allows setting the following standard boot environment variables:

- boot_script_dhcp via BOOTSCRIPT_DHCP
- script_offset_f and script_size_f via USE_SPI_FLASH_SCRIPT and related options

These changes make it possible to define standard boot environment variables directly via Kconfig, allowing higher-level build systems like Yocto to set them at build time. This avoids the need for post-build environment patches or runtime overrides, improving reproducibility and simplifying integration in automated firmware build workflows.

Quoted 9 lines

Wadim Egorov (2):
boot: Add BOOTSCRIPT_DHCP Kconfig option for boot_script_dhcp env
mtd: bootdev: Add Kconfig option for defining script parameters

  boot/Kconfig            | 18 ++++++++++++++++++
  drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
  include/env_default.h   |  7 +++++++
  3 files changed, 51 insertions(+)

Sorry for sending this twice, first time included a mailing list which should not be in the CC list.

#7 lore raw
In reply to Wadim Egorov
Quoted 14 lines · Wadim Egorov

This series introduces new Kconfig options to configure default environment variables used in script-based boot scenarios. Specifically, it allows setting the following standard boot environment variables:

- boot_script_dhcp via BOOTSCRIPT_DHCP
- script_offset_f and script_size_f via USE_SPI_FLASH_SCRIPT and related options

These changes make it possible to define standard boot environment variables directly via Kconfig, allowing higher-level build systems like Yocto to set them at build time. This avoids the need for post-build environment patches or runtime overrides, improving reproducibility and simplifying integration in automated firmware build workflows.

Quoted 8 lines

Wadim Egorov (2):
boot: Add BOOTSCRIPT_DHCP Kconfig option for boot_script_dhcp env
mtd: bootdev: Add Kconfig option for defining script parameters

 boot/Kconfig            | 18 ++++++++++++++++++
 drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
 include/env_default.h   |  7 +++++++
 3 files changed, 51 insertions(+)

It would be nice to see what the Yocto side of this looks like for example. My first thought is about if this is really easier / better to maintain than dropping in a new env file? Thanks.

Signature · 1 line
Tom
#8 lore raw
Quoted 20 lines · Tom Rini
Quoted 18 lines · Wadim Egorov

This series introduces new Kconfig options to configure default environment variables used in script-based boot scenarios. Specifically, it allows setting the following standard boot environment variables:

- boot_script_dhcp via BOOTSCRIPT_DHCP
- script_offset_f and script_size_f via USE_SPI_FLASH_SCRIPT and related options

These changes make it possible to define standard boot environment variables directly via Kconfig, allowing higher-level build systems like Yocto to set them at build time. This avoids the need for post-build environment patches or runtime overrides, improving reproducibility and simplifying integration in automated firmware build workflows.

Wadim Egorov (2):
boot: Add BOOTSCRIPT_DHCP Kconfig option for boot_script_dhcp env
mtd: bootdev: Add Kconfig option for defining script parameters

Quoted 9 lines
Quoted 4 lines
  boot/Kconfig            | 18 ++++++++++++++++++
  drivers/mtd/spi/Kconfig | 26 ++++++++++++++++++++++++++
  include/env_default.h   |  7 +++++++
  3 files changed, 51 insertions(+)

It would be nice to see what the Yocto side of this looks like for example. My first thought is about if this is really easier / better to maintain than dropping in a new env file? Thanks.

We use config fragments in Yocto (based on merge_config.sh) to enable or disable u-boot features in different builds.
Because users may require different SPI flash memory layouts, they can override variables like script_offset_f in their own layer instead of appending an extra patch for this job.