All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts
@ 2017-06-21 21:41 Thomas Petazzoni
  2017-06-21 21:41 ` [Buildroot] [PATCH 2/2] configs/cubieboard2_defconfig: use U-Boot boot script generation logic Thomas Petazzoni
  2017-06-22 11:06 ` [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts Peter Korsgaard
  0 siblings, 2 replies; 8+ messages in thread
From: Thomas Petazzoni @ 2017-06-21 21:41 UTC (permalink / raw)
  To: buildroot

More and more of our defconfigs need to generate a U-Boot boot
script. It's a simple call to mkimage, but we already have 12
instances of this logic in board/, and there are patch series waiting
in patchwork adding 3 more boards that need this.

So let's add an option in the U-Boot package to generate such a boot
script image easily.

Note that we assume a single script needs to be generated, and the
output file name is boot.scr. The only platform for which it seems to
not be the case are the Boundary Devices platforms: they generate two
boot scripts, 6x_bootscript and 6x_upgrade, but they are anyway
installed inside TARGET_DIR, not BINARIES_DIR.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
We could have chosen to create a helper script that can be used as a
post-build or post-image script, ala
support/scripts/genimage.sh. However, I find rather messy how we are
passing arguments to such scripts: we have a single
BR2_ROOTFS_POST_SCRIPT_ARGS, passed to all scripts. Proposals such as
https://patchwork.ozlabs.org/patch/777463/ with:

  BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/bananapi/bananapi-m64/genimage.cfg board/bananapi/bananapi-m64/boot.cmd"

where support/scripts/genimage.sh parses the first two arguments, and
the post-build script generating the U-Boot boot script parses the
last argument, look really really ugly to me.

Retrospectively, I believe the choice of adding such a helper script
for genimage was wrong. Having a proper option would be much
cleaner/nicer IMO.
---
 boot/uboot/Config.in | 16 ++++++++++++++++
 boot/uboot/uboot.mk  | 13 +++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
index 547822d..52f3a32 100644
--- a/boot/uboot/Config.in
+++ b/boot/uboot/Config.in
@@ -407,6 +407,22 @@ config BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT
 
 endif # BR2_TARGET_UBOOT_ENVIMAGE
 
+config BR2_TARGET_UBOOT_BOOT_SCRIPT
+	bool "Generate a U-Boot boot script"
+	help
+	  Generate a U-Boot boot script, given a file listing U-Boot
+	  commands to be executed at boot time. The generated boot
+	  script will be called 'boot.scr'.
+
+if BR2_TARGET_UBOOT_BOOT_SCRIPT
+
+config BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE
+	string "U-Boot boot script source"
+	help
+	  Source file to generate the U-Boot boot script.
+
+endif
+
 if BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG
 
 config BR2_TARGET_UBOOT_CUSTOM_DTS_PATH
diff --git a/boot/uboot/uboot.mk b/boot/uboot/uboot.mk
index 904d45a..0f423a8 100644
--- a/boot/uboot/uboot.mk
+++ b/boot/uboot/uboot.mk
@@ -235,6 +235,10 @@ define UBOOT_INSTALL_IMAGES_CMDS
 			$(if $(BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT),-r) \
 			$(if $(filter BIG,$(BR2_ENDIAN)),-b) \
 			-o $(BINARIES_DIR)/uboot-env.bin -)
+	$(if $(BR2_TARGET_UBOOT_BOOT_SCRIPT),
+		$(HOST_DIR)/usr/bin/mkimage -C none -A $(MKIMAGE_ARCH) -T script \
+			-d $(call qstrip,$(BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE)) \
+			$(BINARIES_DIR)/boot.scr)
 endef
 
 define UBOOT_INSTALL_OMAP_IFT_IMAGE
@@ -298,6 +302,15 @@ 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)),)
+$(error Please define a source file for Uboot boot script (BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE setting))
+endif
+endif
+UBOOT_DEPENDENCIES += host-uboot-tools
+endif
+
 ifeq ($(BR2_TARGET_UBOOT)$(BR_BUILDING),yy)
 
 #
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Buildroot] [PATCH 2/2] configs/cubieboard2_defconfig: use U-Boot boot script generation logic
  2017-06-21 21:41 [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts Thomas Petazzoni
@ 2017-06-21 21:41 ` Thomas Petazzoni
  2017-06-22 11:06   ` Peter Korsgaard
  2017-06-22 11:06 ` [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts Peter Korsgaard
  1 sibling, 1 reply; 8+ messages in thread
From: Thomas Petazzoni @ 2017-06-21 21:41 UTC (permalink / raw)
  To: buildroot

Instead of a custom post-build script, use the boot script generation
logic of the U-Boot package.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
This is just one example on one specific platform of what it looks
like. If we agree on the feature, my intent is to rework all the
existing boards that generate such a boot script.
---
 board/cubietech/cubieboard2/post-build.sh | 11 -----------
 configs/cubieboard2_defconfig             |  4 ++--
 2 files changed, 2 insertions(+), 13 deletions(-)
 delete mode 100755 board/cubietech/cubieboard2/post-build.sh

diff --git a/board/cubietech/cubieboard2/post-build.sh b/board/cubietech/cubieboard2/post-build.sh
deleted file mode 100755
index 465d493..0000000
--- a/board/cubietech/cubieboard2/post-build.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-# post-build.sh for Cubieboard2
-# 2013, Carlo Caione <carlo.caione@gmail.com>
-
-BOARD_DIR="$(dirname $0)"
-MKIMAGE=$HOST_DIR/usr/bin/mkimage
-BOOT_CMD=$BOARD_DIR/boot.cmd
-BOOT_CMD_H=$BINARIES_DIR/boot.scr
-
-# U-Boot script
-$MKIMAGE -C none -A arm -T script -d $BOOT_CMD $BOOT_CMD_H
diff --git a/configs/cubieboard2_defconfig b/configs/cubieboard2_defconfig
index 353aaa5..a0d2399 100644
--- a/configs/cubieboard2_defconfig
+++ b/configs/cubieboard2_defconfig
@@ -6,7 +6,6 @@ BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_6=y
 BR2_TARGET_GENERIC_HOSTNAME="Cubieboard2"
 BR2_TARGET_GENERIC_ISSUE="Welcome to Cubieboard2!"
 BR2_TARGET_GENERIC_GETTY_PORT="ttyS0"
-BR2_ROOTFS_POST_BUILD_SCRIPT="board/cubietech/cubieboard2/post-build.sh"
 BR2_ROOTFS_POST_IMAGE_SCRIPT="board/cubietech/cubieboard2/post-image.sh"
 BR2_LINUX_KERNEL=y
 BR2_LINUX_KERNEL_CUSTOM_VERSION=y
@@ -24,7 +23,8 @@ BR2_TARGET_UBOOT_BOARD_DEFCONFIG="Cubieboard2"
 BR2_TARGET_UBOOT_NEEDS_DTC=y
 BR2_TARGET_UBOOT_SPL=y
 BR2_TARGET_UBOOT_SPL_NAME="u-boot-sunxi-with-spl.bin"
+BR2_TARGET_UBOOT_BOOT_SCRIPT=y
+BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="board/cubietech/cubieboard2/boot.cmd"
 BR2_PACKAGE_HOST_DOSFSTOOLS=y
 BR2_PACKAGE_HOST_GENIMAGE=y
 BR2_PACKAGE_HOST_MTOOLS=y
-BR2_PACKAGE_HOST_UBOOT_TOOLS=y
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts
  2017-06-21 21:41 [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts Thomas Petazzoni
  2017-06-21 21:41 ` [Buildroot] [PATCH 2/2] configs/cubieboard2_defconfig: use U-Boot boot script generation logic Thomas Petazzoni
@ 2017-06-22 11:06 ` Peter Korsgaard
  2017-06-22 11:31   ` Thomas Petazzoni
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Korsgaard @ 2017-06-22 11:06 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@free-electrons.com> writes:

 > More and more of our defconfigs need to generate a U-Boot boot
 > script. It's a simple call to mkimage, but we already have 12
 > instances of this logic in board/, and there are patch series waiting
 > in patchwork adding 3 more boards that need this.

 > So let's add an option in the U-Boot package to generate such a boot
 > script image easily.

 > Note that we assume a single script needs to be generated, and the
 > output file name is boot.scr. The only platform for which it seems to
 > not be the case are the Boundary Devices platforms: they generate two
 > boot scripts, 6x_bootscript and 6x_upgrade, but they are anyway
 > installed inside TARGET_DIR, not BINARIES_DIR.

 > Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

Makes sense to me. Committed, thanks.

> ---
 > We could have chosen to create a helper script that can be used as a
 > post-build or post-image script, ala
 > support/scripts/genimage.sh. However, I find rather messy how we are
 > passing arguments to such scripts: we have a single
 > BR2_ROOTFS_POST_SCRIPT_ARGS, passed to all scripts. Proposals such as
 > https://patchwork.ozlabs.org/patch/777463/ with:

 >   BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/bananapi/bananapi-m64/genimage.cfg board/bananapi/bananapi-m64/boot.cmd"

 > where support/scripts/genimage.sh parses the first two arguments, and
 > the post-build script generating the U-Boot boot script parses the
 > last argument, look really really ugly to me.

 > Retrospectively, I believe the choice of adding such a helper script
 > for genimage was wrong. Having a proper option would be much
 > cleaner/nicer IMO.

Yes, agreed. My idea was also to add a kconfig option for it. This could
also have sub options like "support creating fat partitions" that would
pull in the needed host packages.

The reason we went with the script solution was afaik that some projects
might want to extra processing before or after creating the image, so it
wasn't clear if it should run before or after the post-image scripts.

You can argue though that for such "special" situations you should just
manually call genimage from the post-image script instead though.

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Buildroot] [PATCH 2/2] configs/cubieboard2_defconfig: use U-Boot boot script generation logic
  2017-06-21 21:41 ` [Buildroot] [PATCH 2/2] configs/cubieboard2_defconfig: use U-Boot boot script generation logic Thomas Petazzoni
@ 2017-06-22 11:06   ` Peter Korsgaard
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Korsgaard @ 2017-06-22 11:06 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@free-electrons.com> writes:

 > Instead of a custom post-build script, use the boot script generation
 > logic of the U-Boot package.

Committed, thanks.

 > Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
 > ---
 > This is just one example on one specific platform of what it looks
 > like. If we agree on the feature, my intent is to rework all the
 > existing boards that generate such a boot script.

Great, thanks!

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts
  2017-06-22 11:06 ` [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts Peter Korsgaard
@ 2017-06-22 11:31   ` Thomas Petazzoni
  2017-06-22 14:18     ` Peter Korsgaard
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Petazzoni @ 2017-06-22 11:31 UTC (permalink / raw)
  To: buildroot

Hello,

On Thu, 22 Jun 2017 13:06:02 +0200, Peter Korsgaard wrote:

>  > More and more of our defconfigs need to generate a U-Boot boot
>  > script. It's a simple call to mkimage, but we already have 12
>  > instances of this logic in board/, and there are patch series waiting
>  > in patchwork adding 3 more boards that need this.  
> 
>  > So let's add an option in the U-Boot package to generate such a boot
>  > script image easily.  
> 
>  > Note that we assume a single script needs to be generated, and the
>  > output file name is boot.scr. The only platform for which it seems to
>  > not be the case are the Boundary Devices platforms: they generate two
>  > boot scripts, 6x_bootscript and 6x_upgrade, but they are anyway
>  > installed inside TARGET_DIR, not BINARIES_DIR.  
> 
>  > Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>  
> 
> Makes sense to me. Committed, thanks.

Wow, that was fast. I was wondering if we should extend it to multiple
boot scripts, but then the syntax would be a bit horrible:

BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="script1src:script1dest script2src:script2dest"

We could still keep the compatibility by having:

BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="script1src"

just generate script1src and install it as boot.scr.

Or maybe it's something we can take care of later?

>  > Retrospectively, I believe the choice of adding such a helper script
>  > for genimage was wrong. Having a proper option would be much
>  > cleaner/nicer IMO.  
> 
> Yes, agreed. My idea was also to add a kconfig option for it. This could
> also have sub options like "support creating fat partitions" that would
> pull in the needed host packages.

Also my thinking.

> The reason we went with the script solution was afaik that some projects
> might want to extra processing before or after creating the image, so it
> wasn't clear if it should run before or after the post-image scripts.
> 
> You can argue though that for such "special" situations you should just
> manually call genimage from the post-image script instead though.

Absolutely. I don't think we should try in those options to cover *all*
cases, only the most common ones. As long as the more special cases can
be covered by custom logic in post-build/post-image scripts, we're good
IMO.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts
  2017-06-22 11:31   ` Thomas Petazzoni
@ 2017-06-22 14:18     ` Peter Korsgaard
  2017-06-22 14:44       ` Thomas Petazzoni
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Korsgaard @ 2017-06-22 14:18 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@free-electrons.com> writes:

Hi,

 >> Makes sense to me. Committed, thanks.

 > Wow, that was fast. I was wondering if we should extend it to multiple
 > boot scripts, but then the syntax would be a bit horrible:

 > BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="script1src:script1dest script2src:script2dest"

 > We could still keep the compatibility by having:

 > BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="script1src"

 > just generate script1src and install it as boot.scr.

 > Or maybe it's something we can take care of later?

Or alternatively use destfile = srcfile with extension replaced by .bin


 >> > Retrospectively, I believe the choice of adding such a helper script
 >> > for genimage was wrong. Having a proper option would be much
 >> > cleaner/nicer IMO.  
 >> 
 >> Yes, agreed. My idea was also to add a kconfig option for it. This could
 >> also have sub options like "support creating fat partitions" that would
 >> pull in the needed host packages.

 > Also my thinking.

 >> The reason we went with the script solution was afaik that some projects
 >> might want to extra processing before or after creating the image, so it
 >> wasn't clear if it should run before or after the post-image scripts.
 >> 
 >> You can argue though that for such "special" situations you should just
 >> manually call genimage from the post-image script instead though.

 > Absolutely. I don't think we should try in those options to cover *all*
 > cases, only the most common ones. As long as the more special cases can
 > be covered by custom logic in post-build/post-image scripts, we're good
 > IMO.

Agreed!

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts
  2017-06-22 14:18     ` Peter Korsgaard
@ 2017-06-22 14:44       ` Thomas Petazzoni
  2017-06-22 16:00         ` Peter Korsgaard
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Petazzoni @ 2017-06-22 14:44 UTC (permalink / raw)
  To: buildroot

Hello,

On Thu, 22 Jun 2017 16:18:03 +0200, Peter Korsgaard wrote:

>  > BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="script1src:script1dest script2src:script2dest"  
> 
>  > We could still keep the compatibility by having:  
> 
>  > BR2_TARGET_UBOOT_BOOT_SCRIPT_SOURCE="script1src"  
> 
>  > just generate script1src and install it as boot.scr.  
> 
>  > Or maybe it's something we can take care of later?  
> 
> Or alternatively use destfile = srcfile with extension replaced by .bin

Doesn't really match the default case where the boot script is expected
by U-Boot to be called boot.scr.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts
  2017-06-22 14:44       ` Thomas Petazzoni
@ 2017-06-22 16:00         ` Peter Korsgaard
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Korsgaard @ 2017-06-22 16:00 UTC (permalink / raw)
  To: buildroot

>>>>> "Thomas" == Thomas Petazzoni <thomas.petazzoni@free-electrons.com> writes:

Hi,

 >> > Or maybe it's something we can take care of later?  
 >> 
 >> Or alternatively use destfile = srcfile with extension replaced by .bin

 > Doesn't really match the default case where the boot script is expected
 > by U-Boot to be called boot.scr.

Sorry, I naturally meant that the extension should be .scr, not .bin.

-- 
Bye, Peter Korsgaard

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-06-22 16:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-21 21:41 [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts Thomas Petazzoni
2017-06-21 21:41 ` [Buildroot] [PATCH 2/2] configs/cubieboard2_defconfig: use U-Boot boot script generation logic Thomas Petazzoni
2017-06-22 11:06   ` Peter Korsgaard
2017-06-22 11:06 ` [Buildroot] [PATCH 1/2] uboot: add support for generating U-Boot boot scripts Peter Korsgaard
2017-06-22 11:31   ` Thomas Petazzoni
2017-06-22 14:18     ` Peter Korsgaard
2017-06-22 14:44       ` Thomas Petazzoni
2017-06-22 16:00         ` Peter Korsgaard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.