Hi Vagrant,Thanks for the review. I'm attaching a v2 which should address your comments:
* all patches moving code from one file to another now copy it verbatim so it can be easily compared with the origin * actual code changes are in separate patches (actually that only applies to factoring the has_separate_boot() function) * whitespace/name fixups are now a separate (optional) patch
Le 15/01/2024 à 00:29, Vagrant Cascadian a écrit :
In order to maintain the current behaviour, this feature is disabled by default and must be enabled by setting the `U_BOOT_SYNC_DTBS` configuration variable to `true`.Mixed feelings on weather it should be guarded in the long-term, but that makes sense at least at when first introducing this...
Yes, I'd prefer it to be enabled by default TBH, but I assume there will be users out there not comfortable which such a big behavior change overnight.
diff --git a/default b/default index 2e29c83..21801b4 100644 --- a/default +++ b/default @@ -13,4 +13,4 @@ #U_BOOT_FDT_DIR="/usr/lib/linux-image-" #U_BOOT_FDT_OVERLAYS="" #U_BOOT_FDT_OVERLAYS_DIR="/boot/dtbo/" - +#U_BOOT_SYNC_DTBS="false"I almost wish to kill off /etc/default/u-boot entirely... all of the defaults are commented out and could instead be shipped in /usr/share/u-boot-menu/conf.d/default.conf rather than embedded in the u-boot-update script (or the new read-config snippet).
Dropping /etc/default/u-boot makes sense to me, although I'd rather keep the default values in the script rather than in a config file:
* the variables are all described in the man page along with their default values, so there's no need to further document them * dropping the defaults from the script itself will make it harder to detect when they have been overridden (unless we compare them with hardcoded default values, which isn't much better IMHO)
... and the configuration has U_BOOT_SYNC_DTBS=true (described later)? E.g. it does not detect a /boot partition unless U_BOOT_SYNC_DTBS=true?
That's a fair point, as my previous implementation didn't take that into account: the default FDT_DIR would change no matter the value of SYNC_DTBS, which could be surprising/disappointing to users (and not in line with my justification above for guarding this feature).
I changed that in v2 and reworked the man page so SYNC_DTBS is described before FDT_DIR.
Regards, Arnaud
From c873741f89d46041991dc3609893be31233b6e99 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris <arnaud.ferra...@collabora.com> Date: Mon, 12 Dec 2022 13:57:47 +0100 Subject: [PATCH 1/4] u-boot-update: split config file reading to a separate script The logic of reading the configuration file and determining whether `/boot` is on a separate partition can be useful to other scripts, such as the kernel postinst/postrm ones. This commit moves this code to a separate, source-able script to make it more easily reusable. --- debian/u-boot-menu.install | 1 + read-config | 70 ++++++++++++++++++++++++++++++++++++++ u-boot-update | 70 +------------------------------------- 3 files changed, 72 insertions(+), 69 deletions(-) create mode 100644 read-config diff --git a/debian/u-boot-menu.install b/debian/u-boot-menu.install index 1f801fe..695129f 100644 --- a/debian/u-boot-menu.install +++ b/debian/u-boot-menu.install @@ -1,3 +1,4 @@ +read-config usr/share/u-boot-menu u-boot-update usr/sbin zz-u-boot-menu etc/kernel/postinst.d zz-u-boot-menu etc/kernel/postrm.d diff --git a/read-config b/read-config new file mode 100644 index 0000000..9c4a884 --- /dev/null +++ b/read-config @@ -0,0 +1,70 @@ +#!/bin/sh + +# Reading the default file +if [ -e /etc/default/u-boot ] +then + . /etc/default/u-boot +fi + +# Reading config file fragments if they exist +for file in /usr/share/u-boot-menu/conf.d/*.conf /etc/u-boot-menu/conf.d/*.conf +do + if [ -e "${file}" ] + then + . "${file}" + fi +done + +# Reading the os-release file +if [ -e /etc/os-release ] +then + . /etc/os-release +elif [ -e /usr/lib/os-release ] +then + . /usr/lib/os-release +fi + + +U_BOOT_UPDATE="${U_BOOT_UPDATE:-true}" + +if [ "${U_BOOT_UPDATE}" != "true" ] +then + echo "P: u-boot-update is disabled in /etc/default/u-boot." + + exit 0 +fi + +# Find boot directory as seen in u-boot, and path prefix while in linux +if [ "$(stat --printf %d /)" = "$(stat --printf %d /boot)" ] +then + # / and /boot are on the same filesystem + _BOOT_DIRECTORY="/boot" + _BOOT_PATH="" +else + # / and /boot are not on the same filesystem + _BOOT_DIRECTORY="" + _BOOT_PATH="/boot" +fi + +# Setting defaults if /etc/default/u-boot is missing + +U_BOOT_ALTERNATIVES="${U_BOOT_ALTERNATIVES:-default recovery}" +U_BOOT_DEFAULT="${U_BOOT_DEFAULT:-l0}" +U_BOOT_PROMPT="${U_BOOT_PROMPT:-1}" +U_BOOT_ENTRIES="${U_BOOT_ENTRIES:-all}" +U_BOOT_TIMEOUT="${U_BOOT_TIMEOUT:-50}" +U_BOOT_MENU_LABEL="${U_BOOT_MENU_LABEL:-${PRETTY_NAME:-Debian GNU/Linux kernel}}" +U_BOOT_FDT_DIR="${U_BOOT_FDT_DIR:-/usr/lib/linux-image-}" +U_BOOT_FDT_OVERLAYS="${U_BOOT_FDT_OVERLAYS:-}" +U_BOOT_FDT_OVERLAYS_DIR="${U_BOOT_FDT_OVERLAYS_DIR:-/boot/dtbo}" +U_BOOT_INITRD="${U_BOOT_INITRD:-initrd.img}" + +if [ -z "${U_BOOT_PARAMETERS}" ] && [ -f /etc/kernel/cmdline ] +then + U_BOOT_PARAMETERS="$(cat /etc/kernel/cmdline | sed -e 's/root=[^[:space:]]*//' -e 's/^[[:space:]]*//')" + if [ -z "${U_BOOT_ROOT}" ] + then + U_BOOT_ROOT="$(cat /etc/kernel/cmdline | sed -re 's/.*(root=[^[:space:]]*).*/\1/')" + fi +fi +U_BOOT_PARAMETERS="${U_BOOT_PARAMETERS:-ro quiet}" diff --git a/u-boot-update b/u-boot-update index 828e355..6b20e7f 100755 --- a/u-boot-update +++ b/u-boot-update @@ -43,39 +43,7 @@ fi # Redirect stdout to stderr due Debconf usage exec 1>&2 -# Reading the default file -if [ -e /etc/default/u-boot ] -then - . /etc/default/u-boot -fi - -# Reading config file fragments if they exist -for file in /usr/share/u-boot-menu/conf.d/*.conf /etc/u-boot-menu/conf.d/*.conf -do - if [ -e "${file}" ] - then - . "${file}" - fi -done - -# Reading the os-release file -if [ -e /etc/os-release ] -then - . /etc/os-release -elif [ -e /usr/lib/os-release ] -then - . /usr/lib/os-release -fi - - -U_BOOT_UPDATE="${U_BOOT_UPDATE:-true}" - -if [ "${U_BOOT_UPDATE}" != "true" ] -then - echo "P: u-boot-update is disabled in /etc/default/u-boot." - - exit 0 -fi +. /usr/share/u-boot-menu/read-config # Checking extlinux directory printf '%s' "P: Checking for EXTLINUX directory..." @@ -92,29 +60,6 @@ else echo " found." fi -# Setting defaults if /etc/default/u-boot is missing - -U_BOOT_ALTERNATIVES="${U_BOOT_ALTERNATIVES:-default recovery}" -U_BOOT_DEFAULT="${U_BOOT_DEFAULT:-l0}" -U_BOOT_PROMPT="${U_BOOT_PROMPT:-1}" -U_BOOT_ENTRIES="${U_BOOT_ENTRIES:-all}" -U_BOOT_TIMEOUT="${U_BOOT_TIMEOUT:-50}" -U_BOOT_MENU_LABEL="${U_BOOT_MENU_LABEL:-${PRETTY_NAME:-Debian GNU/Linux kernel}}" -U_BOOT_FDT_DIR="${U_BOOT_FDT_DIR:-/usr/lib/linux-image-}" -U_BOOT_FDT_OVERLAYS="${U_BOOT_FDT_OVERLAYS:-}" -U_BOOT_FDT_OVERLAYS_DIR="${U_BOOT_FDT_OVERLAYS_DIR:-/boot/dtbo}" -U_BOOT_INITRD="${U_BOOT_INITRD:-initrd.img}" - -if [ -z "${U_BOOT_PARAMETERS}" ] && [ -f /etc/kernel/cmdline ] -then - U_BOOT_PARAMETERS="$(cat /etc/kernel/cmdline | sed -e 's/root=[^[:space:]]*//' -e 's/^[[:space:]]*//')" - if [ -z "${U_BOOT_ROOT}" ] - then - U_BOOT_ROOT="$(cat /etc/kernel/cmdline | sed -re 's/.*(root=[^[:space:]]*).*/\1/')" - fi -fi -U_BOOT_PARAMETERS="${U_BOOT_PARAMETERS:-ro quiet}" - # Find parameter for root from fstab if [ -z "${U_BOOT_ROOT}" ] then @@ -170,19 +115,6 @@ timeout ${U_BOOT_TIMEOUT} # Find linux versions _KERNELS=$(linux-version list --paths | linux-version sort --reverse | sed -e 's,.*/boot/,,g') -# Find boot directory as seen in u-boot, and path prefix while in linux -if [ "$(stat --printf %d /)" = "$(stat --printf %d /boot)" ] -then - # / and /boot are on the same filesystem - _BOOT_DIRECTORY="/boot" - _BOOT_PATH="" -else - # / and /boot are not on the same filesystem - _BOOT_DIRECTORY="" - _BOOT_PATH="/boot" -fi - - for _KERNEL in ${_KERNELS} do # Strip kernel prefix to derive version. -- 2.43.0
From 6cf3e54484a684b3a414bc3e6b294ee0791b0c49 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris <arnaud.ferra...@collabora.com> Date: Mon, 15 Jan 2024 11:18:08 +0100 Subject: [PATCH 2/4] read-config: make /boot partition check a function A simple check is used to find out whether `/boot` and the root filesystem are on the same partition or not. Factoring it as a function will make it usable in more scripts with a clearer meaning than esoteric variables comparisons. --- read-config | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/read-config b/read-config index 9c4a884..621d384 100644 --- a/read-config +++ b/read-config @@ -1,5 +1,9 @@ #!/bin/sh +has_separate_boot() { + [ "$(stat --printf %d /)" != "$(stat --printf %d /boot)" ] +} + # Reading the default file if [ -e /etc/default/u-boot ] then @@ -35,15 +39,15 @@ then fi # Find boot directory as seen in u-boot, and path prefix while in linux -if [ "$(stat --printf %d /)" = "$(stat --printf %d /boot)" ] +if has_separate_boot then - # / and /boot are on the same filesystem - _BOOT_DIRECTORY="/boot" - _BOOT_PATH="" -else # / and /boot are not on the same filesystem _BOOT_DIRECTORY="" _BOOT_PATH="/boot" +else + # / and /boot are on the same filesystem + _BOOT_DIRECTORY="/boot" + _BOOT_PATH="" fi # Setting defaults if /etc/default/u-boot is missing -- 2.43.0
From fdb399aa04afa12e42fe9c6c985a199a76dbef03 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris <arnaud.ferra...@collabora.com> Date: Mon, 12 Dec 2022 14:14:27 +0100 Subject: [PATCH 3/4] Allow to automatically sync DTBs when /boot is on a separate partition Having `/boot` on a separate partition is a very common use-case, requiring device tree binary files to be copied over to this partition as `u-boot` won't be searching other partitions for those. Up until now, users had to manually copy (and potentially edit) the provided `zz-sync-dtb` example script if their system was using a separate `/boot` partition, which isn't practical. This patch implements a way to automate this synchronization process in such cases, and remove the synchronized files when the corresponding kernel is removed as well. In order to maintain the current behaviour, this feature is disabled by default and must be enabled by setting the `U_BOOT_SYNC_DTBS` configuration variable to `true`. --- debian/control | 2 ++ debian/u-boot-menu.examples | 1 - debian/u-boot-menu.install | 4 ++-- default | 2 +- postinst/zz-u-boot-menu | 29 +++++++++++++++++++++++++++++ postrm/zz-u-boot-menu | 33 +++++++++++++++++++++++++++++++++ read-config | 10 ++++++++-- u-boot-update.8 | 16 +++++++++++++++- zz-sync-dtb | 36 ------------------------------------ zz-u-boot-menu | 10 ---------- 10 files changed, 90 insertions(+), 53 deletions(-) delete mode 100644 debian/u-boot-menu.examples create mode 100755 postinst/zz-u-boot-menu create mode 100755 postrm/zz-u-boot-menu delete mode 100755 zz-sync-dtb delete mode 100755 zz-u-boot-menu diff --git a/debian/control b/debian/control index d558f5b..7f7140c 100644 --- a/debian/control +++ b/debian/control @@ -15,6 +15,8 @@ Package: u-boot-menu Depends: linux-base, ${misc:Depends}, +Recommends: + rsync, Suggests: flash-kernel, Architecture: all diff --git a/debian/u-boot-menu.examples b/debian/u-boot-menu.examples deleted file mode 100644 index 343ab28..0000000 --- a/debian/u-boot-menu.examples +++ /dev/null @@ -1 +0,0 @@ -zz-sync-dtb diff --git a/debian/u-boot-menu.install b/debian/u-boot-menu.install index 695129f..03ede4c 100644 --- a/debian/u-boot-menu.install +++ b/debian/u-boot-menu.install @@ -1,4 +1,4 @@ read-config usr/share/u-boot-menu u-boot-update usr/sbin -zz-u-boot-menu etc/kernel/postinst.d -zz-u-boot-menu etc/kernel/postrm.d +postinst/zz-u-boot-menu etc/kernel/postinst.d +postrm/zz-u-boot-menu etc/kernel/postrm.d diff --git a/default b/default index d1bacb5..002e532 100644 --- a/default +++ b/default @@ -14,4 +14,4 @@ #U_BOOT_FDT_DIR="/usr/lib/linux-image-" #U_BOOT_FDT_OVERLAYS="" #U_BOOT_FDT_OVERLAYS_DIR="/boot/dtbo/" - +#U_BOOT_SYNC_DTBS="false" diff --git a/postinst/zz-u-boot-menu b/postinst/zz-u-boot-menu new file mode 100755 index 0000000..e2fe60f --- /dev/null +++ b/postinst/zz-u-boot-menu @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e + +. /usr/share/u-boot-menu/read-config + +version="$1" +srcdir="/usr/lib/linux-image-${version}" +destdir="${_BOOT_PATH}${_BOOT_DIRECTORY}${U_BOOT_FDT_DIR}${version}" + +# Sync DTBs if /boot is on a different partition than / +if has_separate_boot && [ "${U_BOOT_SYNC_DTBS}" = "true" ] && command -v rsync >/dev/null 2>&1 +then + if [ -d "${srcdir}" ] + then + echo "I: u-boot-menu: syncing ${srcdir} to ${destdir}" + mkdir -p "${destdir}" + rsync -a "${srcdir}/" "${destdir}/" + else + echo >&2 "W: u-boot-menu: ${srcdir} NOT PRESENT" + fi +fi + +# Exit if extlinux was removed (!= purged) +if [ -x /usr/sbin/u-boot-update ] +then + # Update extlinux configuration + u-boot-update +fi diff --git a/postrm/zz-u-boot-menu b/postrm/zz-u-boot-menu new file mode 100755 index 0000000..f34b4a5 --- /dev/null +++ b/postrm/zz-u-boot-menu @@ -0,0 +1,33 @@ +#!/bin/sh + +set -e + +. /usr/share/u-boot-menu/read-config + +version="$1" +kernel="$2" + +if [ -e "${kernel}" ] +then + # Kernel still exists, meaning it's being upgraded, not + # uninstalled; quit as we have nothing to do in such cases + exit 0 +fi + +dtbdir="${_BOOT_PATH}${_BOOT_DIRECTORY}${U_BOOT_FDT_DIR}${version}" + +# DTBs are synced if /boot is on a different partition than / +# Ensure there's no leftover when removing a kernel +if has_separate_boot && [ "${U_BOOT_SYNC_DTBS}" = "true" ] && [ -d "${dtbdir}" ] +then + # Kernel has been removed, delete DTBs + echo "I: u-boot-menu: removing ${dtbdir}" + rm -rf "${dtbdir}" +fi + +# Exit if extlinux was removed (!= purged) +if [ -x /usr/sbin/u-boot-update ] +then + # Update extlinux configuration + u-boot-update +fi diff --git a/read-config b/read-config index 621d384..d25edcc 100644 --- a/read-config +++ b/read-config @@ -30,6 +30,7 @@ fi U_BOOT_UPDATE="${U_BOOT_UPDATE:-true}" +U_BOOT_SYNC_DTBS="${U_BOOT_SYNC_DTBS:-false}" if [ "${U_BOOT_UPDATE}" != "true" ] then @@ -41,13 +42,18 @@ fi # Find boot directory as seen in u-boot, and path prefix while in linux if has_separate_boot then - # / and /boot are not on the same filesystem + # / and /boot are on different filesystems _BOOT_DIRECTORY="" _BOOT_PATH="/boot" + if [ "${U_BOOT_SYNC_DTBS}" = "true" ] + then + _FDT_DIR="/dtb-" + fi else # / and /boot are on the same filesystem _BOOT_DIRECTORY="/boot" _BOOT_PATH="" + _FDT_DIR="/usr/lib/linux-image-" fi # Setting defaults if /etc/default/u-boot is missing @@ -58,7 +64,7 @@ U_BOOT_PROMPT="${U_BOOT_PROMPT:-1}" U_BOOT_ENTRIES="${U_BOOT_ENTRIES:-all}" U_BOOT_TIMEOUT="${U_BOOT_TIMEOUT:-50}" U_BOOT_MENU_LABEL="${U_BOOT_MENU_LABEL:-${PRETTY_NAME:-Debian GNU/Linux kernel}}" -U_BOOT_FDT_DIR="${U_BOOT_FDT_DIR:-/usr/lib/linux-image-}" +U_BOOT_FDT_DIR="${U_BOOT_FDT_DIR:-${_FDT_DIR}}" U_BOOT_FDT_OVERLAYS="${U_BOOT_FDT_OVERLAYS:-}" U_BOOT_FDT_OVERLAYS_DIR="${U_BOOT_FDT_OVERLAYS_DIR:-/boot/dtbo}" U_BOOT_INITRD="${U_BOOT_INITRD:-initrd.img}" diff --git a/u-boot-update.8 b/u-boot-update.8 index 12852ee..13e1d51 100644 --- a/u-boot-update.8 +++ b/u-boot-update.8 @@ -108,10 +108,18 @@ Values are in decisecond greater than 0 0 specifies to wait forever. The default is 50. +.IP "U_BOOT_SYNC_DTBS=""\fBtrue\fR|false""" 4 +This variable specifies if u\-boot\-update should automatically +attempt to copy device tree binaries to /boot in case it is on a +different partition than /. +Values are either 'true' or 'false', default is 'false'. + .IP "U_BOOT_FDT_DIR=""\fB/usr/lib/linux-image-\fR""" 4 This variable specifies the unversioned stem of paths where U\-BOOT should look for the flattened device tree binaries. -Default is '/usr/lib/linux-image-'. +Default is '/usr/lib/linux-image-'. When U_BOOT_SYNC_DTBS is true +and u\-boot\-update detects /boot is on a separate partition, the +default value is then '/dtb-'. .IP "U_BOOT_FDT=""device-tree.dtb""" 4 This variable specifies filename or trailing part of path @@ -137,6 +145,12 @@ then that is set as option 'initrd', otherwise option 'initrd' is not set. Default is 'initrd.img'. +.IP "U_BOOT_SYNC_DTBS=""\fBtrue\fR|false""" 4 +This variable specifies if u\-boot\-update should automatically +attempt to copy device tree binaries to /boot in case it is on a +different partition than /. +Values are either 'true' or 'false', default is 'false'. + .SH FILES /etc/default/u-boot /usr/share/u-boot-menu/conf.d/ diff --git a/zz-sync-dtb b/zz-sync-dtb deleted file mode 100755 index 7eee5eb..0000000 --- a/zz-sync-dtb +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -## Copyright 2019-2020 Vagrant Cascadian <vagr...@debian.org> - -## This program comes with ABSOLUTELY NO WARRANTY; for details see -## COPYING. This is free software, and you are welcome to -## redistribute it under the terms of the GNU GPL, version 2 or any -## later version; see COPYING for details. - -# sync .dtb files into /boot to simplify installations on systems with -# a split /boot partition. To use, install this file into -# /etc/kernel/postinst.d/zz-sync-dtb and mark it as executable. - -set -e - -version="$1" - -command -v rsync >/dev/null 2>&1 || exit 0 - -# passing the kernel version is required -if [ -z "${version}" ]; then - echo >&2 "W: sync-dtb: ${DPKG_MAINTSCRIPT_PACKAGE:-kernel package} did not pass a version number" - exit 2 -fi - -dtbdir="/usr/lib/linux-image-${version}" - - - -if [ -d "${dtbdir}" ]; then - echo >&2 "W: sync-dtb: syncing ${dtbdir}" - mkdir -p "/boot/${dtbdir}" - rsync -a "${dtbdir}/." "/boot/${dtbdir}/." -else - echo >&2 "W: sync-dtb: ${dtbdir} NOT PRESENT" -fi diff --git a/zz-u-boot-menu b/zz-u-boot-menu deleted file mode 100755 index ce3d184..0000000 --- a/zz-u-boot-menu +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -set -e - -# Exit if extlinux was removed (!= purged) -if [ -x /usr/sbin/u-boot-update ] -then - # Update extlinux configuration - u-boot-update -fi -- 2.43.0
From c469de8887b7258c320a85353b56a3a1f1c81db9 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris <arnaud.ferra...@collabora.com> Date: Mon, 15 Jan 2024 11:34:21 +0100 Subject: [PATCH 4/4] Minor fixes and whitespace fixups --- debian/u-boot-menu.install | 6 +++--- postinst/zz-u-boot-menu | 2 +- postrm/zz-u-boot-menu | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/debian/u-boot-menu.install b/debian/u-boot-menu.install index 03ede4c..9aa984c 100644 --- a/debian/u-boot-menu.install +++ b/debian/u-boot-menu.install @@ -1,4 +1,4 @@ -read-config usr/share/u-boot-menu -u-boot-update usr/sbin -postinst/zz-u-boot-menu etc/kernel/postinst.d +read-config usr/share/u-boot-menu +u-boot-update usr/sbin +postinst/zz-u-boot-menu etc/kernel/postinst.d postrm/zz-u-boot-menu etc/kernel/postrm.d diff --git a/postinst/zz-u-boot-menu b/postinst/zz-u-boot-menu index e2fe60f..eea64e3 100755 --- a/postinst/zz-u-boot-menu +++ b/postinst/zz-u-boot-menu @@ -21,7 +21,7 @@ then fi fi -# Exit if extlinux was removed (!= purged) +# Exit if u-boot-menu was removed (!= purged) if [ -x /usr/sbin/u-boot-update ] then # Update extlinux configuration diff --git a/postrm/zz-u-boot-menu b/postrm/zz-u-boot-menu index f34b4a5..5410c2d 100755 --- a/postrm/zz-u-boot-menu +++ b/postrm/zz-u-boot-menu @@ -25,7 +25,7 @@ then rm -rf "${dtbdir}" fi -# Exit if extlinux was removed (!= purged) +# Exit if u-boot-menu was removed (!= purged) if [ -x /usr/sbin/u-boot-update ] then # Update extlinux configuration -- 2.43.0
OpenPGP_0xD3EBB5966BB99196.asc
Description: OpenPGP public key
OpenPGP_signature.asc
Description: OpenPGP digital signature