diff mbox series

[v2,1/3] package/uboot-tools: migrate BR2_TARGET_UBOOT_ENVIMAGE from U-Boot pkg

Message ID 20200924192912.51913-2-matthew.weber@rockwellcollins.com
State Accepted
Headers show
Series Support uboot file creation w/o uboot | expand

Commit Message

Matt Weber Sept. 24, 2020, 7:29 p.m. UTC
Migrating the support for this feature to uboot-tools to gain the
ability to build env files when BR2_TARGET_UBOOT isn't selected.

Note: This patch creates a circular dependency with uboot until the
similar migration patch is merged for uboot scripts

Cc: Arnout Vandecappelle <arnout@mind.be>
Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
---
Changes 1 -> 2
[Arnout
 - Config legacy entries for strings and cleaned up bool entries to
   have all the selects required
 - Did some renaming in the makefile
 - Used env files directly
 - Added build check that env file existed when !uboot but env img
   creation is enabled
 - Added Note in this commit message about the circular dependency
 - Fixed dependency on uboot to be a host dependency
---
 Config.in.legacy                   | 42 ++++++++++++++++++++++
 boot/uboot/Config.in               | 43 -----------------------
 boot/uboot/uboot.mk                | 25 -------------
 package/uboot-tools/Config.in.host | 56 ++++++++++++++++++++++++++++--
 package/uboot-tools/uboot-tools.mk | 36 +++++++++++++++++++
 5 files changed, 132 insertions(+), 70 deletions(-)

Comments

Arnout Vandecappelle Oct. 6, 2020, 8:14 p.m. UTC | #1
Hi Matt,

On 24/09/2020 21:29, Matt Weber wrote:
> Migrating the support for this feature to uboot-tools to gain the
> ability to build env files when BR2_TARGET_UBOOT isn't selected.
> 
> Note: This patch creates a circular dependency with uboot until the
> similar migration patch is merged for uboot scripts
> 
> Cc: Arnout Vandecappelle <arnout@mind.be>
> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>

[snip]
> +config BR2_TARGET_UBOOT_ENVIMAGE
> +	bool "u-boot env generation was moved"
> +	select BR2_LEGACY
> +	select BR2_PACKAGE_HOST_UBOOT_TOOLS
> +	select BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
> +	help
> +	  Migrated U-Boot env generation to uboot-tools
> +
> +config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
> +	string "The uboot env image source string has been renamed"
> +	help
> +	  Migrated U-Boot env generation to uboot-tools.
> +	  New option is named BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE
> +
> +config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE_WRAP
> +	bool
> +	default y if BR2_TARGET_UBOOT_ENVIMAGE_SOURCE != ""
> +	select BR2_LEGACY

 I believe we can simplify this to:

config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
	string "The uboot env image source string has been renamed"
	depends on BR2_TARGET_UBOOT_ENVIMAGE
	help
	  Migrated U-Boot env generation to uboot-tools.
	  New option is named BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE

 There is no need to select BR2_LEGACY explicitly, since the top-level option
already selects it. Thanks to the "depends on", it is sufficient to remove the
top-level option and save the .config to start using the new options and get rid
of the legacy ones.

> +
> +# Note: BR2_TARGET_UBOOT_ENVIMAGE_SOURCE is still referenced from package/uboot-tools/Config.in
> +
> +config BR2_TARGET_UBOOT_ENVIMAGE_SIZE
> +	string "The uboot env image size string has been renamed"
> +	help
> +	  Migrated U-Boot env generation to uboot-tools.
> +	  New option is named BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE
> +
> +config BR2_TARGET_UBOOT_ENVIMAGE_SIZE_WRAP
> +	bool
> +	default y if BR2_TARGET_UBOOT_ENVIMAGE_SIZE != ""
> +	select BR2_LEGACY

 Same here.

> +
> +# Note: BR2_TARGET_UBOOT_ENVIMAGE_SIZE is still referenced from package/uboot-tools/Config.in
> +
> +config BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT
> +	bool "u-boot env generation was moved"
> +	select BR2_LEGACY
> +	select BR2_PACKAGE_HOST_UBOOT_TOOLS
> +	select BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_REDUNDANT
> +	help
> +	  Migrated U-Boot env generation to uboot-tools

 And this one isn't necessary at all, the top-level one is sufficient. At least
I think so, please double-check :-)


[snip]

> +ifeq ($(BR2_TARGET_UBOOT),y)
> +define HOST_UBOOT_TOOLS_GENERATE_ENV_DEFAULTS
> +	CROSS_COMPILE="$(TARGET_CROSS)" \
> +		$(UBOOT_SRCDIR)/scripts/get_default_envs.sh \
> +		$(UBOOT_SRCDIR) \
> +		>$(@D)/boot-env-defaults.txt
> +endef
> +HOST_UBOOT_TOOLS_DEPENDENCIES += uboot

 I believe this dependency is only needed if
BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE is set and
BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE is empty, no?

 Of course the dependency doesn't really *hurt*, but it's nicer to avoid
unneeded dependencies IMHO.

> +endif
> +
> +ifneq ($(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE),)
> +UBOOT_TOOLS_GENERATE_ENV_FILE = $(call qstrip,$(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE))
> +define HOST_UBOOT_TOOLS_GENERATE_ENV_IMAGE
> +	$(HOST_DIR)/bin/mkenvimage -s $(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE) \
> +		$(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_REDUNDANT),-r) \
> +		$(if $(filter "BIG",$(BR2_ENDIAN)),-b) \
> +		-o $(BINARIES_DIR)/uboot-env.bin \
> +		$(if $(UBOOT_TOOLS_GENERATE_ENV_FILE), \
> +		$(UBOOT_TOOLS_GENERATE_ENV_FILE), \
> +		$(@D)/boot-env-defaults.txt)
> +endef
> +
> +ifeq ($(BR_BUILDING),y)
> +ifeq ($(call qstrip,$(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE)),)
> +$(error Please provide U-Boot environment size (BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE setting))
> +endif
> +ifeq ($(BR2_TARGET_UBOOT),)
> +ifeq ($(call qstrip,$(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE),)
> +$(error Please provide U-Boot environment file BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE setting))
> +endif
> +endif #BR2_TARGET_UBOOT
> +endif #BR_BUILDING
> +endif #BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
> +
>  define HOST_UBOOT_TOOLS_INSTALL_CMDS
>  	$(INSTALL) -m 0755 -D $(@D)/tools/mkimage $(HOST_DIR)/bin/mkimage
>  	$(INSTALL) -m 0755 -D $(@D)/tools/mkenvimage $(HOST_DIR)/bin/mkenvimage
>  	$(INSTALL) -m 0755 -D $(@D)/tools/dumpimage $(HOST_DIR)/bin/dumpimage
> +	$(HOST_UBOOT_TOOLS_GENERATE_ENV_DEFAULTS)

 This will *always* build boot-env-defaults.txt when uboot is selected, even if
we're not building an environment image. That's not good IMHO.

 Regards,
 Arnout

> +	$(HOST_UBOOT_TOOLS_GENERATE_ENV_IMAGE)
>  endef
>  
>  $(eval $(generic-package))
>
Arnout Vandecappelle Oct. 6, 2020, 9:36 p.m. UTC | #2
On 24/09/2020 21:29, Matt Weber wrote:
> Note: This patch creates a circular dependency with uboot until the
> similar migration patch is merged for uboot scripts

 Actually, there is still a circular dependency after this series: uboot ->
arm-trusted-firmware -> host-uboot-tools -> uboot.

 However, this would only be the case if both
BR2_TARGET_ARM_TRUSTED_FIRMWARE_BL31_UBOOT and BR2_TARGET_UBOOT_NEEDS_ATF_BL31
are selected. This is possible, but in practice not useful AFAIU.

 Anyway, to reduce the chance even further I've added the uboot dependency only
if _ENVIMAGE_SOURCE is empty.

 Regards,
 Arnout
Arnout Vandecappelle Oct. 6, 2020, 9:39 p.m. UTC | #3
On 24/09/2020 21:29, Matt Weber wrote:
> Migrating the support for this feature to uboot-tools to gain the
> ability to build env files when BR2_TARGET_UBOOT isn't selected.
> 
> Note: This patch creates a circular dependency with uboot until the
> similar migration patch is merged for uboot scripts
> 
> Cc: Arnout Vandecappelle <arnout@mind.be>
> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>

 Series applied with the changes as explained in my reply to patch 1, and a few
additional changes. Please have a got with current master to check if I broke
anything.

 Regards,
 Arnout
Matt Weber Oct. 7, 2020, 12:44 p.m. UTC | #4
Arnout,


On Tue, Oct 6, 2020 at 4:42 PM Arnout Vandecappelle <arnout@mind.be> wrote:
>
>
>
> On 24/09/2020 21:29, Matt Weber wrote:
> > Migrating the support for this feature to uboot-tools to gain the
> > ability to build env files when BR2_TARGET_UBOOT isn't selected.
> >
> > Note: This patch creates a circular dependency with uboot until the
> > similar migration patch is merged for uboot scripts
> >
> > Cc: Arnout Vandecappelle <arnout@mind.be>
> > Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
>
>  Series applied with the changes as explained in my reply to patch 1, and a few
> additional changes. Please have a got with current master to check if I broke
> anything.
>

Changes looked good, however I forgot to also include a fixup for all
the defconfigs using the feature.  I'll get a patch ready this morning
and sent out.

configs/at91sam9x5ek_mmc_dev_defconfig:99:BR2_TARGET_UBOOT_ENVIMAGE_SOURCE="board/atmel/at91sam9x5ek_mmc/uboot-env.txt"
configs/socrates_cyclone5_defconfig:27:BR2_TARGET_UBOOT_ENVIMAGE_SOURCE="board/altera/socrates_cyclone5/boot-env.txt"
configs/at91sam9x5ek_mmc_defconfig:39:BR2_TARGET_UBOOT_ENVIMAGE_SOURCE="board/atmel/at91sam9x5ek_mmc/uboot-env.txt"
configs/ci20_defconfig:32:BR2_TARGET_UBOOT_ENVIMAGE_SOURCE="board/ci20/uboot-env.txt"
configs/snps_archs38_hsdk_defconfig:39:BR2_TARGET_UBOOT_ENVIMAGE_SOURCE="board/synopsys/hsdk/uboot.env.txt"

configs/nanopi_m1_defconfig:36:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/friendlyarm/nanopi-m1/boot.cmd"
configs/orangepi_pc_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-pc/boot.cmd"
configs/orangepi_pc_plus_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-pc-plus/boot.cmd"
configs/pine64_sopine_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/pine64/sopine/boot.cmd"
configs/nanopi_m1_plus_defconfig:36:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/friendlyarm/nanopi-m1-plus/boot.cmd"
configs/olimex_a10_olinuxino_lime_defconfig:44:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/olimex/a10_olinuxino/boot.cmd"
configs/orangepi_zero_plus2_defconfig:31:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-zero-plus2/boot.cmd"
configs/orangepi_zero_defconfig:32:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-zero/boot.cmd"
configs/orangepi_lite_defconfig:32:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-lite/boot.cmd"
configs/orangepi_prime_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-prime/boot.cmd"
configs/orangepi_r1_defconfig:29:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-r1/boot.cmd"
configs/nitrogen6x_defconfig:32:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/boundarydevices/common/boot.cmd"
configs/orangepi_one_defconfig:27:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-one/boot.cmd"
configs/nitrogen7_defconfig:31:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/boundarydevices/common/boot.cmd"
configs/orangepi_plus_defconfig:36:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-plus/boot.cmd"
configs/friendlyarm_nanopi_a64_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/friendlyarm/nanopi-a64/boot.cmd"
configs/nanopi_r1_defconfig:40:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/friendlyarm/nanopi-r1/boot.cmd"
configs/bananapi_m2_ultra_defconfig:26:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/bananapi/bananapi-m2-ultra/boot.cmd"
configs/olimex_a20_olinuxino_lime2_defconfig:55:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/olimex/a20_olinuxino/boot.cmd"
configs/nitrogen6sx_defconfig:32:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/boundarydevices/common/boot.cmd"
configs/odroidc2_defconfig:29:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/hardkernel/odroidc2/boot.cmd"
configs/bananapi_m2_zero_defconfig:27:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/bananapi/bananapi-m2-zero/boot.cmd"
configs/friendlyarm_nanopi_neo2_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/friendlyarm/nanopi-neo2/boot.cmd"
configs/licheepi_zero_defconfig:46:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/licheepi/boot.cmd"
configs/olimex_a64_olinuxino_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/olimex/a64-olinuxino/boot.cmd"
configs/olimex_a20_olinuxino_lime_defconfig:55:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/olimex/a20_olinuxino/boot.cmd"
configs/bananapi_m2_plus_defconfig:26:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/sinovoip/m2-plus/boot.cmd"
configs/orangepi_pc2_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-pc2/boot.cmd"
configs/olimex_a20_olinuxino_micro_defconfig:42:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/olimex/a20_olinuxino/boot.cmd"
configs/bananapi_m64_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/bananapi/bananapi-m64/boot.cmd"
configs/pine64_defconfig:30:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/pine64/pine64/boot.cmd"
configs/olimex_a33_olinuxino_defconfig:26:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/olimex/a33_olinuxino/boot.cmd"
configs/bananapi_m1_defconfig:25:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/bananapi/bananapi-m1/boot.cmd"
configs/orangepi_win_defconfig:29:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/orangepi/orangepi-win/boot.cmd"
configs/cubieboard2_defconfig:28:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/cubietech/cubieboard2/boot.cmd"
configs/nanopi_neo_defconfig:34:BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/friendlyarm/nanopi-neo/boot.cmd"


Regards,
Matt
Matt Weber Oct. 7, 2020, 1:21 p.m. UTC | #5
Arnout,

On Wed, Oct 7, 2020 at 7:44 AM Matthew Weber
<matthew.weber@rockwellcollins.com> wrote:
>
> Arnout,
>
>
> On Tue, Oct 6, 2020 at 4:42 PM Arnout Vandecappelle <arnout@mind.be> wrote:
> >
> >
> >
> > On 24/09/2020 21:29, Matt Weber wrote:
> > > Migrating the support for this feature to uboot-tools to gain the
> > > ability to build env files when BR2_TARGET_UBOOT isn't selected.
> > >
> > > Note: This patch creates a circular dependency with uboot until the
> > > similar migration patch is merged for uboot scripts
> > >
> > > Cc: Arnout Vandecappelle <arnout@mind.be>
> > > Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
> >
> >  Series applied with the changes as explained in my reply to patch 1, and a few
> > additional changes. Please have a got with current master to check if I broke
> > anything.
> >
>
> Changes looked good, however I forgot to also include a fixup for all
> the defconfigs using the feature.  I'll get a patch ready this morning
> and sent out.
>

Here's the bugfix.  My bad on this one.

http://patchwork.ozlabs.org/project/buildroot/list/?series=206474

Best Regards,
Matt
Arnout Vandecappelle Oct. 7, 2020, 7:02 p.m. UTC | #6
On 07/10/2020 15:21, Matthew Weber wrote:
> Arnout,
> 
> On Wed, Oct 7, 2020 at 7:44 AM Matthew Weber
> <matthew.weber@rockwellcollins.com> wrote:
>>
>> Arnout,
>>
>>
>> On Tue, Oct 6, 2020 at 4:42 PM Arnout Vandecappelle <arnout@mind.be> wrote:
>>>
>>>
>>>
>>> On 24/09/2020 21:29, Matt Weber wrote:
>>>> Migrating the support for this feature to uboot-tools to gain the
>>>> ability to build env files when BR2_TARGET_UBOOT isn't selected.
>>>>
>>>> Note: This patch creates a circular dependency with uboot until the
>>>> similar migration patch is merged for uboot scripts
>>>>
>>>> Cc: Arnout Vandecappelle <arnout@mind.be>
>>>> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
>>>
>>>  Series applied with the changes as explained in my reply to patch 1, and a few
>>> additional changes. Please have a got with current master to check if I broke
>>> anything.
>>>
>>
>> Changes looked good, however I forgot to also include a fixup for all
>> the defconfigs using the feature.  I'll get a patch ready this morning
>> and sent out.
>>
> 
> Here's the bugfix.  My bad on this one.

 My bad for not noticing when applying :-)

> http://patchwork.ozlabs.org/project/buildroot/list/?series=206474

 Thanks for the fix! I'll apply right away.

 Regards,
 Arnout
diff mbox series

Patch

diff --git a/Config.in.legacy b/Config.in.legacy
index ae583b912f..213984ac9c 100644
--- a/Config.in.legacy
+++ b/Config.in.legacy
@@ -146,6 +146,48 @@  endif
 
 comment "Legacy options removed in 2020.11"
 
+config BR2_TARGET_UBOOT_ENVIMAGE
+	bool "u-boot env generation was moved"
+	select BR2_LEGACY
+	select BR2_PACKAGE_HOST_UBOOT_TOOLS
+	select BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+	help
+	  Migrated U-Boot env generation to uboot-tools
+
+config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
+	string "The uboot env image source string has been renamed"
+	help
+	  Migrated U-Boot env generation to uboot-tools.
+	  New option is named BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE
+
+config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE_WRAP
+	bool
+	default y if BR2_TARGET_UBOOT_ENVIMAGE_SOURCE != ""
+	select BR2_LEGACY
+
+# Note: BR2_TARGET_UBOOT_ENVIMAGE_SOURCE is still referenced from package/uboot-tools/Config.in
+
+config BR2_TARGET_UBOOT_ENVIMAGE_SIZE
+	string "The uboot env image size string has been renamed"
+	help
+	  Migrated U-Boot env generation to uboot-tools.
+	  New option is named BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE
+
+config BR2_TARGET_UBOOT_ENVIMAGE_SIZE_WRAP
+	bool
+	default y if BR2_TARGET_UBOOT_ENVIMAGE_SIZE != ""
+	select BR2_LEGACY
+
+# Note: BR2_TARGET_UBOOT_ENVIMAGE_SIZE is still referenced from package/uboot-tools/Config.in
+
+config BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT
+	bool "u-boot env generation was moved"
+	select BR2_LEGACY
+	select BR2_PACKAGE_HOST_UBOOT_TOOLS
+	select BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_REDUNDANT
+	help
+	  Migrated U-Boot env generation to uboot-tools
+
 config BR2_PACKAGE_GQVIEW
 	bool "gqview package was removed"
 	select BR2_LEGACY
diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
index a87a642581..668806dc50 100644
--- a/boot/uboot/Config.in
+++ b/boot/uboot/Config.in
@@ -533,49 +533,6 @@  config BR2_TARGET_UBOOT_ALTERA_SOCFPGA_IMAGE_CRC
 	  In either case the resulting file will be given a .crc
 	  extension.
 
-menuconfig BR2_TARGET_UBOOT_ENVIMAGE
-	bool "Environment image"
-	help
-	  Generate a valid binary environment image from a text file
-	  describing the key=value pairs of the environment.
-
-	  The environment image will be called uboot-env.bin.
-
-if BR2_TARGET_UBOOT_ENVIMAGE
-
-config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
-	string "Source files for environment"
-	help
-	  Text files describing the environment. Files should have
-	  lines of the form var=value, one per line. Blank lines and
-	  lines starting with a # are ignored.
-
-	  Multiple source files are concatenated in the order listed.
-
-	  Leave empty to generate image from compiled-in env.
-
-config BR2_TARGET_UBOOT_ENVIMAGE_SIZE
-	string "Size of environment"
-	help
-	  Size of envronment, can be prefixed with 0x for hexadecimal
-	  values.
-
-config BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT
-	bool "Environment has two copies"
-	help
-	  Some platforms define in their U-Boot configuration that the
-	  U-Boot environment should be duplicated in two locations (for
-	  extra safety). Check your U-Boot configuration for the
-	  CONFIG_ENV_ADDR_REDUND and CONFIG_ENV_SIZE_REDUND settings to
-	  see if this is the case for your platform.
-
-	  If it is the case, then you should enable this option to
-	  ensure that the U-Boot environment image generated by
-	  Buildroot is compatible with the "redundant environment"
-	  mechanism of U-Boot.
-
-endif # BR2_TARGET_UBOOT_ENVIMAGE
-
 config BR2_TARGET_UBOOT_BOOT_SCRIPT
 	bool "Generate a U-Boot boot script"
 	help
diff --git a/boot/uboot/uboot.mk b/boot/uboot/uboot.mk
index 1831466780..9dbd06b64b 100644
--- a/boot/uboot/uboot.mk
+++ b/boot/uboot/uboot.mk
@@ -312,21 +312,6 @@  define UBOOT_BUILD_OMAP_IFT
 		-c $(call qstrip,$(BR2_TARGET_UBOOT_OMAP_IFT_CONFIG))
 endef
 
-ifneq ($(BR2_TARGET_UBOOT_ENVIMAGE),)
-UBOOT_GENERATE_ENV_FILE = $(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SOURCE))
-define UBOOT_GENERATE_ENV_IMAGE
-	$(if $(UBOOT_GENERATE_ENV_FILE), \
-		cat $(UBOOT_GENERATE_ENV_FILE), \
-		CROSS_COMPILE="$(TARGET_CROSS)" $(@D)/scripts/get_default_envs.sh $(@D)) \
-		>$(@D)/buildroot-env.txt
-	$(HOST_DIR)/bin/mkenvimage -s $(BR2_TARGET_UBOOT_ENVIMAGE_SIZE) \
-		$(if $(BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT),-r) \
-		$(if $(filter "BIG",$(BR2_ENDIAN)),-b) \
-		-o $(BINARIES_DIR)/uboot-env.bin \
-		$(@D)/buildroot-env.txt
-endef
-endif
-
 define UBOOT_INSTALL_IMAGES_CMDS
 	$(foreach f,$(UBOOT_BINS), \
 			cp -dpf $(@D)/$(f) $(BINARIES_DIR)/
@@ -338,7 +323,6 @@  define UBOOT_INSTALL_IMAGES_CMDS
 			cp -dpf $(@D)/$(f) $(BINARIES_DIR)/
 		)
 	)
-	$(UBOOT_GENERATE_ENV_IMAGE)
 	$(if $(BR2_TARGET_UBOOT_BOOT_SCRIPT),
 		$(MKIMAGE) -C none -A $(MKIMAGE_ARCH) -T script \
 			-d $(call qstrip,$(BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE)) \
@@ -443,15 +427,6 @@  define UBOOT_KCONFIG_FIXUP_CMDS
 	$(UBOOT_ZYNQMP_KCONFIG_PSU_INIT)
 endef
 
-ifeq ($(BR2_TARGET_UBOOT_ENVIMAGE),y)
-ifeq ($(BR_BUILDING),y)
-ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SIZE)),)
-$(error Please provide U-Boot environment size (BR2_TARGET_UBOOT_ENVIMAGE_SIZE setting))
-endif
-endif
-UBOOT_DEPENDENCIES += host-uboot-tools
-endif
-
 ifeq ($(BR2_TARGET_UBOOT_BOOT_SCRIPT),y)
 ifeq ($(BR_BUILDING),y)
 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE)),)
diff --git a/package/uboot-tools/Config.in.host b/package/uboot-tools/Config.in.host
index 52a4c2ec30..a10835c589 100644
--- a/package/uboot-tools/Config.in.host
+++ b/package/uboot-tools/Config.in.host
@@ -37,6 +37,58 @@  config BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT
 	  public key is stored in a non-volatile place, any image can
 	  be verified in this way.
 
-endif
+endif # BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SUPPORT
 
-endif
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+	bool "Environment image"
+	help
+	  Generate a valid binary environment image from a text file
+	  describing the key=value pairs of the environment.
+
+	  This option can be useful to build enviornment configurations
+	  as part of a Linux / rootfs only defconfig instead of using
+	  post scripts. This supports a hardware use case of a single
+	  bootloader only defconfig but multiple Linux / rootfs
+	  defconfigs with different boot environments.
+
+	  The environment image will be called uboot-env.bin.
+
+if BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE
+	string "Source files for environment"
+	default BR2_TARGET_UBOOT_ENVIMAGE_SOURCE if BR2_TARGET_UBOOT_ENVIMAGE_SOURCE != "" # legacy
+	help
+	  Text files describing the environment. Files should have
+	  lines of the form var=value, one per line. Blank lines and
+	  lines starting with a # are ignored.
+
+	  Multiple source files are concatenated in the order listed.
+
+	  Leave empty to generate image from compiled-in env if a U-boot
+	  target build is configured (BR2_TARGET_UBOOT)
+
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE
+	string "Size of environment"
+	default BR2_TARGET_UBOOT_ENVIMAGE_SIZE if BR2_TARGET_UBOOT_ENVIMAGE_SIZE != "" # legacy
+	help
+	  Size of envronment, can be prefixed with 0x for hexadecimal
+	  values.
+
+config BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_REDUNDANT
+	bool "Environment has two copies"
+	help
+	  Some platforms define in their U-Boot configuration that the
+	  U-Boot environment should be duplicated in two locations (for
+	  extra safety). Check your U-Boot configuration for the
+	  CONFIG_ENV_ADDR_REDUND and CONFIG_ENV_SIZE_REDUND settings to
+	  see if this is the case for your platform.
+
+	  If it is the case, then you should enable this option to
+	  ensure that the U-Boot environment image generated by
+	  Buildroot is compatible with the "redundant environment"
+	  mechanism of U-Boot.
+
+endif # BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+
+endif # BR2_PACKAGE_HOST_UBOOT_TOOLS
diff --git a/package/uboot-tools/uboot-tools.mk b/package/uboot-tools/uboot-tools.mk
index a06c25998f..0cb58ef70b 100644
--- a/package/uboot-tools/uboot-tools.mk
+++ b/package/uboot-tools/uboot-tools.mk
@@ -110,10 +110,46 @@  define HOST_UBOOT_TOOLS_BUILD_CMDS
 	$(BR2_MAKE1) -C $(@D) $(HOST_UBOOT_TOOLS_MAKE_OPTS) tools-only
 endef
 
+ifeq ($(BR2_TARGET_UBOOT),y)
+define HOST_UBOOT_TOOLS_GENERATE_ENV_DEFAULTS
+	CROSS_COMPILE="$(TARGET_CROSS)" \
+		$(UBOOT_SRCDIR)/scripts/get_default_envs.sh \
+		$(UBOOT_SRCDIR) \
+		>$(@D)/boot-env-defaults.txt
+endef
+HOST_UBOOT_TOOLS_DEPENDENCIES += uboot
+endif
+
+ifneq ($(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE),)
+UBOOT_TOOLS_GENERATE_ENV_FILE = $(call qstrip,$(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE))
+define HOST_UBOOT_TOOLS_GENERATE_ENV_IMAGE
+	$(HOST_DIR)/bin/mkenvimage -s $(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE) \
+		$(if $(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_REDUNDANT),-r) \
+		$(if $(filter "BIG",$(BR2_ENDIAN)),-b) \
+		-o $(BINARIES_DIR)/uboot-env.bin \
+		$(if $(UBOOT_TOOLS_GENERATE_ENV_FILE), \
+		$(UBOOT_TOOLS_GENERATE_ENV_FILE), \
+		$(@D)/boot-env-defaults.txt)
+endef
+
+ifeq ($(BR_BUILDING),y)
+ifeq ($(call qstrip,$(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE)),)
+$(error Please provide U-Boot environment size (BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SIZE setting))
+endif
+ifeq ($(BR2_TARGET_UBOOT),)
+ifeq ($(call qstrip,$(BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE),)
+$(error Please provide U-Boot environment file BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE_SOURCE setting))
+endif
+endif #BR2_TARGET_UBOOT
+endif #BR_BUILDING
+endif #BR2_PACKAGE_HOST_UBOOT_TOOLS_ENVIMAGE
+
 define HOST_UBOOT_TOOLS_INSTALL_CMDS
 	$(INSTALL) -m 0755 -D $(@D)/tools/mkimage $(HOST_DIR)/bin/mkimage
 	$(INSTALL) -m 0755 -D $(@D)/tools/mkenvimage $(HOST_DIR)/bin/mkenvimage
 	$(INSTALL) -m 0755 -D $(@D)/tools/dumpimage $(HOST_DIR)/bin/dumpimage
+	$(HOST_UBOOT_TOOLS_GENERATE_ENV_DEFAULTS)
+	$(HOST_UBOOT_TOOLS_GENERATE_ENV_IMAGE)
 endef
 
 $(eval $(generic-package))