ubuntu-rockchip icon indicating copy to clipboard operation
ubuntu-rockchip copied to clipboard

Feature Request: Support for u-boot-update sort by date (rather than release number)

Open ewaldc opened this issue 5 months ago • 0 comments

Feature Description

When building custom kernels with tag names, e.g. vmlinuz-6.1.0-1025+test-rockchip, they end up coming after the default (source) kernel (vmlinuz-6.1.0-1025-rockchip) in the u-boot menu.

The request is to have the ability to sort the kernels by (modification) date rather than by name/release.

Proposed solution: Add parameter U_BOOT_SORT to /etc/default/u-boot, for example

## /etc/default/u-boot - configuration file for u-boot-update(8)
#U_BOOT_SORT="date"
#U_BOOT_UPDATE="true"

#U_BOOT_ALTERNATIVES="default recovery"
#U_BOOT_DEFAULT="l0"
#U_BOOT_PROMPT="1"
#U_BOOT_ENTRIES="all"
#U_BOOT_MENU_LABEL="Debian GNU/Linux"
#U_BOOT_PARAMETERS="ro earlycon"
#U_BOOT_ROOT=""
#U_BOOT_TIMEOUT="50"
#U_BOOT_FDT=""
#U_BOOT_FDT_DIR="/lib/firmware/"
#U_BOOT_FDT_OVERLAYS=""
#U_BOOT_FDT_OVERLAYS_DIR="/lib/firmware/"
#U_BOOT_SYNC_DTBS="false"

In /usr/sbin/u-boot-update, change

# Find linux versions
if [ -n "${U_BOOT_SORT}" ] && [ "${U_BOOT_SORT}" = "date" ]; then
        _KERNELS=$(cd /boot; ls -t vmlinu[xz]-*)
else
        _KERNELS=$(linux-version list --paths | linux-version sort --reverse | sed -e 's,.*/boot/,,g')
fi

When U_BOOT_SORT is commented out (the default), than the current behavior is maintained (sort by release number). This change was validated with the current v2.3.2 release running kernel version 1025.

Note: While update-initramfs -u should update the newest kernel according to its manual page, it sadly picks the kernel with the "highest" version number instead. Consequently it will also select the wrong version when launched as update-initramfs -u. Strange behavior IMHO, it would be more logical to take either the newest kernel (by date), or the current running kernel (per 'uname -r'). Anyhow, it will thus be required to explicitely call update-initramfs -u -k <kernel version> to regenerate the ramdisk. For installing (custom) kernels this is of no concern, only when updating/changing a kernel module.

Happy to contribute via push request, if you believe this is a useful enhancement. In the meantime, I attached a patch file for your convenience. Install e.g. with patch -b -p0 --directory=/ --forward -i $PWD/u-boot-update.patch -r - u-boot-update.patch.zip

ewaldc avatar Sep 15 '24 11:09 ewaldc