Attached a patch series with an implementation.
I added the ability to concatenate multiple scripts/snippets for the
final boot script. The new overlay handling snippet is supposed to be
used with this. But the feature itself also allows nice cleanups,
demonstrated on odroid-u3 and beaglebone (and there're quite some more
cleanups possible).
To test this, you need:
- u-boot with CONFIG_OF_LIBFDT_OVERLAY
- base dtb with symbols (-@)
- your own overlays, again with symbols, in /boot/dtbs/overlays
With e.g. foo.dtb and bar.dtb in /boot/dtbs/overlays you can then set
either set $fk_overlays on the u-boot prompt or OVERLAYS in
/etc/defaults/flash-kernel to "foo bar".
Testing on beaglebone looks promising so far ;)
>From efaadbd96967674f2fb82eb530dd447a6b5c65ba Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 09:23:37 +0100
Subject: [PATCH 01/10] bootscr.uboot-generic: quote bootargs
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
bootscript/all/bootscr.uboot-generic | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bootscript/all/bootscr.uboot-generic b/bootscript/all/bootscr.uboot-generic
index db4066a..bcf6e96 100644
--- a/bootscript/all/bootscr.uboot-generic
+++ b/bootscript/all/bootscr.uboot-generic
@@ -25,7 +25,7 @@ if test -n "${console}"; then
setenv bootargs "${bootargs} console=${console}"
fi
-setenv bootargs @@LINUX_KERNEL_CMDLINE_DEFAULTS@@ ${bootargs} @@LINUX_KERNEL_CMDLINE@@
+setenv bootargs "@@LINUX_KERNEL_CMDLINE_DEFAULTS@@ ${bootargs} @@LINUX_KERNEL_CMDLINE@@"
@@UBOOT_ENV_EXTRA@@
if test -z "${fk_kvers}"; then
--
2.15.1
>From 8f3c0450c778901ba93a8dd8a918820f92d662d5 Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 08:16:26 +0100
Subject: [PATCH 02/10] Allow compiling scripts from $tmpdir
Append a suffix to the temporary file to ensure source != target
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
functions | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/functions b/functions
index b2ae5be..ad53277 100644
--- a/functions
+++ b/functions
@@ -456,7 +456,7 @@ mkimage_script() {
local sdata="$3"
local script="$4"
- local tdata="$tmpdir/$(basename $sdata)"
+ local tdata="$tmpdir/$(basename $sdata).out"
local ubootenv="$(mktemp --tmpdir=$tmpdir)"
gen_ubootenv > $ubootenv
--
2.15.1
>From 8dd287741e23ea06c6a8e480ab1f24689d36bf9b Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 08:18:12 +0100
Subject: [PATCH 03/10] Add support for multiple scripts sources
Allow multiple entries in 'U-Boot-Script-Name' and concatenate them
as the final boot script.
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
functions | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/functions b/functions
index ad53277..885413e 100644
--- a/functions
+++ b/functions
@@ -948,7 +948,11 @@ case "$method" in
fi
if [ -n "$boot_script_path" ]; then
boot_script_path="$boot_mnt_dir/$boot_script_path"
- boot_script="$BOOTSCRIPTS_DIR/$usname"
+ boot_script="$tmpdir/bootscript"
+ for script in $usname ; do
+ echo "\n#\n# flash-kernel: $script\n#\n" >> "$boot_script"
+ cat "$BOOTSCRIPTS_DIR/$script" >> "$boot_script"
+ done
mkimage_script "$usaddr" "boot script" "$boot_script" \
"$tmpdir/boot.scr"
boot_script="$tmpdir/boot.scr"
--
2.15.1
>From 132dfdeb0e9a5a396ee543ee1386cb750929846f Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 09:12:28 +0100
Subject: [PATCH 04/10] odroid-u3: clean up boot script
bootscr.odroid first sets some compatibility variables and then contains
a full copy of bootscr.uboot-generic.
Get rid of the copy and use the multiple scripts feature instead. This
results in the very same boot script.
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
bootscript/armhf/bootscr.odroid | 63 -----------------------------------------
db/all.db | 2 +-
2 files changed, 1 insertion(+), 64 deletions(-)
diff --git a/bootscript/armhf/bootscr.odroid b/bootscript/armhf/bootscr.odroid
index b66aafc..7a46f6c 100644
--- a/bootscript/armhf/bootscr.odroid
+++ b/bootscript/armhf/bootscr.odroid
@@ -18,66 +18,3 @@ fi
if test -z "${ramdisk_addr_r}" ; then
setenv ramdisk_addr_r ${initrdaddr}
fi
-
-# Bootscript using the new unified bootcmd handling
-# introduced with u-boot v2014.10, and patched into
-# the debian odroid target since 2016.03+dfsg1-5.
-#
-# Expects to be called with the following environment variables set:
-#
-# devtype e.g. mmc/scsi etc
-# devnum The device number of the given type
-# bootpart The partition containing the boot files
-# distro_bootpart The partition containing the boot files
-# (introduced in u-boot mainline 2016.01)
-# prefix Prefix within the boot partiion to the boot files
-# kernel_addr_r Address to load the kernel to
-# fdt_addr_r Address to load the FDT to
-# ramdisk_addr_r Address to load the initrd to.
-#
-# The uboot must support the bootz and generic filesystem load commands.
-
-# Workaround lack of baudrate included with console on various iMX
-# systems (e.g. wandboard, cubox-i, hummingboard)
-if test "${console}" = "ttymxc0" && test -n "${baudrate}"; then
- setenv console "${console},${baudrate}"
-fi
-
-if test -n "${console}"; then
- setenv bootargs "${bootargs} console=${console}"
-fi
-
-setenv bootargs @@LINUX_KERNEL_CMDLINE_DEFAULTS@@ ${bootargs} @@LINUX_KERNEL_CMDLINE@@
-@@UBOOT_ENV_EXTRA@@
-
-if test -z "${fk_kvers}"; then
- setenv fk_kvers '@@KERNEL_VERSION@@'
-fi
-
-# These two blocks should be the same apart from the use of
-# ${fk_kvers} in the first, the syntax supported by u-boot does not
-# lend itself to removing this duplication.
-
-if test -n "${fdtfile}"; then
- setenv fdtpath dtbs/${fk_kvers}/${fdtfile}
-else
- setenv fdtpath dtb-${fk_kvers}
-fi
-
-if test -z "${distro_bootpart}"; then
- setenv partition ${bootpart}
-else
- setenv partition ${distro_bootpart}
-fi
-
-load ${devtype} ${devnum}:${partition} ${kernel_addr_r} ${prefix}vmlinuz-${fk_kvers} \
-&& load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${prefix}${fdtpath} \
-&& load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${prefix}initrd.img-${fk_kvers} \
-&& echo "Booting Debian ${fk_kvers} from ${devtype} ${devnum}:${partition}..." \
-&& bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
-
-load ${devtype} ${devnum}:${partition} ${kernel_addr_r} ${prefix}vmlinuz \
-&& load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${prefix}dtb \
-&& load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${prefix}initrd.img \
-&& echo "Booting Debian from ${devtype} ${devnum}:${partition}..." \
-&& bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
diff --git a/db/all.db b/db/all.db
index 44ad116..d7520a3 100644
--- a/db/all.db
+++ b/db/all.db
@@ -489,7 +489,7 @@ Machine: Hardkernel ODROID-U3 board based on Exynos4412
Kernel-Flavors: armmp armmp-lpae
DTB-Id: exynos4412-odroidu3.dtb
Boot-Script-Path: /boot/boot.scr
-U-Boot-Script-Name: bootscr.odroid
+U-Boot-Script-Name: bootscr.odroid bootscr.uboot-generic
Required-Packages: u-boot-tools
Machine: Hardkernel Odroid XU4
--
2.15.1
>From b29052bfe4deaf359635347e1e0fc559059067e9 Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 09:25:26 +0100
Subject: [PATCH 05/10] bootscr.uboot-generic: support multiple prefixes to
load from
Allow custom boot scripts to set $fk_image_locations as a list of
directories to load boot files from.
If unset, $prefix will be the used - which is sufficient for all recent
u-boot versions.
This allows the clean up of various custom boot scripts. Code borrowed
form the sunxi script.
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
bootscript/all/bootscr.uboot-generic | 38 +++++++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 11 deletions(-)
diff --git a/bootscript/all/bootscr.uboot-generic b/bootscript/all/bootscr.uboot-generic
index bcf6e96..509efe7 100644
--- a/bootscript/all/bootscr.uboot-generic
+++ b/bootscript/all/bootscr.uboot-generic
@@ -48,14 +48,30 @@ else
setenv partition ${distro_bootpart}
fi
-load ${devtype} ${devnum}:${partition} ${kernel_addr_r} ${prefix}vmlinuz-${fk_kvers} \
-&& load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${prefix}${fdtpath} \
-&& load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${prefix}initrd.img-${fk_kvers} \
-&& echo "Booting Debian ${fk_kvers} from ${devtype} ${devnum}:${partition}..." \
-&& bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
-
-load ${devtype} ${devnum}:${partition} ${kernel_addr_r} ${prefix}vmlinuz \
-&& load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${prefix}dtb \
-&& load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${prefix}initrd.img \
-&& echo "Booting Debian from ${devtype} ${devnum}:${partition}..." \
-&& bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
+if test -z "${fk_image_locations}"; then
+ setenv fk_image_locations ${prefix}
+fi
+
+for pathprefix in ${fk_image_locations}
+do
+ if test -e ${devtype} ${devnum}:${partition} ${pathprefix}vmlinuz-${fk_kvers}
+ then
+ load ${devtype} ${devnum}:${partition} ${kernel_addr_r} ${pathprefix}vmlinuz-${fk_kvers} \
+ && load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${pathprefix}${fdtpath} \
+ && load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${pathprefix}initrd.img-${fk_kvers} \
+ && echo "Booting Debian ${fk_kvers} from ${devtype} ${devnum}:${partition}..." \
+ && bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
+ fi
+done
+
+for pathprefix in ${fk_image_locations}
+do
+ if test -e ${devtype} ${devnum}:${partition} ${pathprefix}vmlinuz
+ then
+ load ${devtype} ${devnum}:${partition} ${kernel_addr_r} ${pathprefix}vmlinuz \
+ && load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${pathprefix}dtb \
+ && load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${pathprefix}initrd.img \
+ && echo "Booting Debian from ${devtype} ${devnum}:${partition}..." \
+ && bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
+ fi
+done
--
2.15.1
>From 4a52b89ec529c4422acd8f4a3efab59a841a1280 Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 09:36:04 +0100
Subject: [PATCH 06/10] beaglebone: clean up boot script
Use $fk_image_locations and distro compatible variable names, get rid
of the duplicated code from bootscr.uboot-generic, and use that script
additionally instead.
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
bootscript/armhf/bootscr.beaglebone | 49 +++++--------------------------------
db/all.db | 4 +--
2 files changed, 8 insertions(+), 45 deletions(-)
diff --git a/bootscript/armhf/bootscr.beaglebone b/bootscript/armhf/bootscr.beaglebone
index edc1cd0..f04532d 100644
--- a/bootscript/armhf/bootscr.beaglebone
+++ b/bootscript/armhf/bootscr.beaglebone
@@ -10,51 +10,14 @@ then
exit
fi
-if test "${devtype}" = ""
-then
- setenv device mmc
-else
- # use device provided by distro_bootcmd
- setenv device "${devtype}"
-fi
-
-if test "${devnum}" = ""
-then
- setenv partition ${bootpart}
-elif test "${distro_bootpart}" = ""
-then
- # use partition provided by bootpart
- setenv partition ${devnum}:${bootpart}
-else
- # use partition provided by distro_bootpart
- setenv partition ${devnum}:${distro_bootpart}
+if test -z "${devtype}"; then
+ setenv devtype "mmc"
fi
-setenv bootargs @@LINUX_KERNEL_CMDLINE_DEFAULTS@@ ${bootargs} @@LINUX_KERNEL_CMDLINE@@
-
-if test "${prefix}" = ""
-then
- setenv image_locations '/boot/ /'
-else
- # use prefix provided by distro_bootcmd
- setenv image_locations "${prefix}"
+if test -z "${devnum}"; then
+ setenv devnum ${bootpart}
fi
-if test -z "${fk_kvers}"; then
- setenv fk_kvers '@@KERNEL_VERSION@@'
+if test -z "${prefix}"; then
+ setenv fk_image_locations '/boot/ /'
fi
-
-if test -n "${fdtfile}"; then
- setenv fdtpath dtbs/${fk_kvers}/${fdtfile}
-else
- setenv fdtpath dtb-${fk_kvers}
-fi
-
-for pathprefix in ${image_locations}
-do
- load ${device} ${partition} ${loadaddr} ${pathprefix}vmlinuz-${fk_kvers} \
- && load ${device} ${partition} ${fdtaddr} ${pathprefix}${fdtpath} \
- && load ${device} ${partition} ${rdaddr} ${pathprefix}initrd.img-${fk_kvers} \
- && echo "Booting Debian ${fk_kvers} from ${device} ${partition}..." \
- && bootz ${loadaddr} ${rdaddr}:${filesize} ${fdtaddr}
-done
diff --git a/db/all.db b/db/all.db
index d7520a3..838578f 100644
--- a/db/all.db
+++ b/db/all.db
@@ -1445,14 +1445,14 @@ Machine: TI AM335x BeagleBone Black
Kernel-Flavors: armmp
DTB-Id: am335x-boneblack.dtb
Boot-Script-Path: /boot/boot.scr
-U-Boot-Script-Name: bootscr.beaglebone
+U-Boot-Script-Name: bootscr.beaglebone bootscr.uboot-generic
Required-Packages: u-boot-tools
Machine: TI AM335x BeagleBone Green
Kernel-Flavors: armmp
DTB-Id: am335x-bonegreen.dtb
Boot-Script-Path: /boot/boot.scr
-U-Boot-Script-Name: bootscr.beaglebone
+U-Boot-Script-Name: bootscr.beaglebone bootscr.uboot-generic
Required-Packages: u-boot-tools
Machine: TI AM5728 BeagleBoard-X15
--
2.15.1
>From 58061b1bb9ce02324561dda0762a62d98f1c1577 Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 19:32:04 +0100
Subject: [PATCH 07/10] Introduce user variable OVERLAYS
A user can set OVERLAYS in /etc/defaults/flash-kernel, which can contain
a list of overlays to apply on top the dtb.
Fix some whitespace errors in similar functions while here.
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
functions | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/functions b/functions
index 885413e..f09aa8f 100644
--- a/functions
+++ b/functions
@@ -417,13 +417,17 @@ flash_initrd() {
}
get_kernel_cmdline() {
- . /etc/default/flash-kernel
+ . /etc/default/flash-kernel
echo "$LINUX_KERNEL_CMDLINE"
}
get_kernel_cmdline_defaults() {
- . /etc/default/flash-kernel
+ . /etc/default/flash-kernel
echo "$LINUX_KERNEL_CMDLINE_DEFAULTS"
}
+get_overlays() {
+ . /etc/default/flash-kernel
+ echo "$OVERLAYS"
+}
mkimage_kernel() {
local kaddr="$1"
@@ -465,6 +469,7 @@ mkimage_script() {
sed -e "s/@@KERNEL_VERSION@@/$kvers/g" \
-e "s!@@LINUX_KERNEL_CMDLINE@@!$(get_kernel_cmdline)!g" \
-e "s!@@LINUX_KERNEL_CMDLINE_DEFAULTS@@!$(get_kernel_cmdline_defaults)!g" \
+ -e "s!@@OVERLAYS@@!$(get_overlays)!g" \
-e "/@@UBOOT_ENV_EXTRA@@/{
s/@@UBOOT_ENV_EXTRA@@//g
r $ubootenv
--
2.15.1
>From 5c9883b455c93053b260ce73ccf4f5ca80e54cdf Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 20:08:21 +0100
Subject: [PATCH 08/10] Add a hook to bootscr.uboot-generic for post fdt
loading tasks
The optional hook $fk_fdt_cmd gets run after loading a ftd.
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
bootscript/all/bootscr.uboot-generic | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/bootscript/all/bootscr.uboot-generic b/bootscript/all/bootscr.uboot-generic
index 509efe7..6d40779 100644
--- a/bootscript/all/bootscr.uboot-generic
+++ b/bootscript/all/bootscr.uboot-generic
@@ -52,13 +52,17 @@ if test -z "${fk_image_locations}"; then
setenv fk_image_locations ${prefix}
fi
+if test -z "${fk_fdt_cmd}"; then
+ setenv fk_fdt_cmd true
+fi
+
for pathprefix in ${fk_image_locations}
do
if test -e ${devtype} ${devnum}:${partition} ${pathprefix}vmlinuz-${fk_kvers}
then
load ${devtype} ${devnum}:${partition} ${kernel_addr_r} ${pathprefix}vmlinuz-${fk_kvers} \
&& load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${pathprefix}${fdtpath} \
- && load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${pathprefix}initrd.img-${fk_kvers} \
+ && run fk_fdt_cmd && load ${devtype} ${devnum}:${partition} ${ramdisk_addr_r} ${pathprefix}initrd.img-${fk_kvers} \
&& echo "Booting Debian ${fk_kvers} from ${devtype} ${devnum}:${partition}..." \
&& bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
fi
--
2.15.1
>From 02cdcab0d99ec8bc16e90ca5fd757fe81b6b32e6 Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 11:42:19 +0100
Subject: [PATCH 09/10] Introduce fdt overlay support
Add a new 'fdt-overlays' script snippet to handle overlays.
This script utilizes the new bootscr.uboot-generic hook to load all
requested overlays. Per default this is the list specified with OVERLAYS
in /etc/defaults/flash-kernel, but can be overwritten using $fk_overlays.
Overlay support needs to be enabled specifically for each machine entry.
If an overlay fails to load, the untouched dtb is restored - meaning
that all overlays need to be valid (since they can depend on each other).
Overlays need to be placed in /boot/dtbs/overlays.
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
bootscript/all/fdt-overlays | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 bootscript/all/fdt-overlays
diff --git a/bootscript/all/fdt-overlays b/bootscript/all/fdt-overlays
new file mode 100644
index 0000000..407d4be
--- /dev/null
+++ b/bootscript/all/fdt-overlays
@@ -0,0 +1,12 @@
+if test -z "${fk_overlays}"; then
+ setenv fk_overlays "@@OVERLAYS@@"
+fi
+
+if test -z "${ftdo_addr_r}"; then
+ setenv ftdo_addr_r ${ramdisk_addr_r}
+fi
+
+setenv load_overlay_cmd 'echo loading overlay ${overlay}; load ${devtype} ${devnum}:${partition} ${ftdo_addr_r} ${pathprefix}dtbs/overlays/${overlay}.dtb && fdt apply ${ftdo_addr_r}'
+setenv load_overlays_cmd 'fdt addr ${fdt_addr_r} && fdt resize 8192 && for overlay in ${fk_overlays}; do run load_overlay_cmd; done'
+setenv restore_fdt_cmd 'echo "error loading overlays, using untouched dtb" && load ${devtype} ${devnum}:${partition} ${fdt_addr_r} ${pathprefix}${fdtpath}'
+setenv fk_fdt_cmd 'if test -n "${fk_overlays}"; then run load_overlays_cmd || run restore_fdt_cmd; else true; fi'
--
2.15.1
>From 01b8e063c51720e1c0bcf2cd7095973cef5fdc9e Mon Sep 17 00:00:00 2001
From: Andre Heider <a.hei...@gmail.com>
Date: Tue, 12 Dec 2017 20:24:04 +0100
Subject: [PATCH 10/10] beaglebone: enable fdt overlay support
Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
db/all.db | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/db/all.db b/db/all.db
index 838578f..d972efb 100644
--- a/db/all.db
+++ b/db/all.db
@@ -1445,14 +1445,14 @@ Machine: TI AM335x BeagleBone Black
Kernel-Flavors: armmp
DTB-Id: am335x-boneblack.dtb
Boot-Script-Path: /boot/boot.scr
-U-Boot-Script-Name: bootscr.beaglebone bootscr.uboot-generic
+U-Boot-Script-Name: bootscr.beaglebone fdt-overlays bootscr.uboot-generic
Required-Packages: u-boot-tools
Machine: TI AM335x BeagleBone Green
Kernel-Flavors: armmp
DTB-Id: am335x-bonegreen.dtb
Boot-Script-Path: /boot/boot.scr
-U-Boot-Script-Name: bootscr.beaglebone bootscr.uboot-generic
+U-Boot-Script-Name: bootscr.beaglebone fdt-overlays bootscr.uboot-generic
Required-Packages: u-boot-tools
Machine: TI AM5728 BeagleBoard-X15
--
2.15.1