Source: u-boot-menu Version: 4.2.0 Severity: wishlist Tags: patch X-Debbugs-Cc: aferra...@debian.org
Dear Maintainer, It is common practice for /boot to be on a separate partition, requiring DTBs to be synced to this partition for u-boot to be able to access them. This used to be done manually, or required additional scripts to be installed by the user for automatic processing. As I think it would be useful for u-boot- menu to automatically perform such synchronization, I have implemented such a feature and attached the corresponding patches. Please note this feature is currently guarded by a new config option, as I expect users might get surprised and/or unexpected results by a sudden behaviour change that important. Comments and suggestions are obviously welcome. Thanks, Arnaud -- System Information: Debian Release: bookworm/sid APT prefers testing APT policy: (500, 'testing'), (200, 'unstable') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 6.0.0-5-amd64 (SMP w/8 CPU threads; PREEMPT) Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE not set Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled
>From 01aa1671b9893e2ec72ceb6eb1a716de6bb53d57 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/2] 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..c9d7ce5 --- /dev/null +++ b/read-config @@ -0,0 +1,70 @@ +# -*- shell-script -*- + +has_separate_boot() { + [ "$(stat --printf %d /)" != "$(stat --printf %d /boot)" ] +} + +# 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 + +U_BOOT_UPDATE="${U_BOOT_UPDATE:-true}" +if [ "${U_BOOT_UPDATE}" != "true" ] +then + echo "P: u-boot-update is disabled in configuration." + + exit 0 +fi + +# 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 + +# Find boot directory as seen in u-boot, and path prefix while in linux +if has_separate_boot +then + # / and /boot are on different filesystems + _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 +U_BOOT_ALTERNATIVES="${U_BOOT_ALTERNATIVES:-default recovery}" +U_BOOT_DEFAULT="${U_BOOT_DEFAULT:-l0}" +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 b7bfbb0..effd304 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,28 +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_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 @@ -169,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. @@ -288,4 +221,3 @@ done _NUMBER="" Update "${_U_BOOT_DIRECTORY}/extlinux.conf" "${_CONFIG}" - -- 2.35.1
>From 6efd5ba1523bdc1a8966caf5756d50bfd3218a30 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 2/2] 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 | 8 ++++---- default | 2 +- postinst/zz-u-boot-menu | 29 +++++++++++++++++++++++++++++ postrm/zz-u-boot-menu | 33 +++++++++++++++++++++++++++++++++ read-config | 5 ++++- u-boot-update.8 | 9 ++++++++- zz-sync-dtb | 36 ------------------------------------ zz-u-boot-menu | 10 ---------- 10 files changed, 81 insertions(+), 54 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 9b988e2..10fd73e 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, Breaks: 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..4816e32 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 +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/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" diff --git a/postinst/zz-u-boot-menu b/postinst/zz-u-boot-menu new file mode 100755 index 0000000..eea64e3 --- /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 u-boot-menu 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..5410c2d --- /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 u-boot-menu 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 c9d7ce5..2cdfb1f 100644 --- a/read-config +++ b/read-config @@ -42,10 +42,12 @@ then # / and /boot are on different filesystems _BOOT_DIRECTORY="" _BOOT_PATH="/boot" + _FDT_DIR="/dtb-" 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 @@ -54,10 +56,11 @@ U_BOOT_DEFAULT="${U_BOOT_DEFAULT:-l0}" 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}" +U_BOOT_SYNC_DTBS="${U_BOOT_SYNC_DTBS:-false}" if [ -z "${U_BOOT_PARAMETERS}" ] && [ -f /etc/kernel/cmdline ] then diff --git a/u-boot-update.8 b/u-boot-update.8 index 12852ee..3f47c1b 100644 --- a/u-boot-update.8 +++ b/u-boot-update.8 @@ -111,7 +111,8 @@ The default is 50. .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-', or '/dtb-' when u\-boot\-update +detects /boot is on a separate partition. .IP "U_BOOT_FDT=""device-tree.dtb""" 4 This variable specifies filename or trailing part of path @@ -137,6 +138,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.35.1