# Install method "extlinux" (Orange Pi Zero), sourced by install-kernel.sh: # unpack the tarball into the target root and (re)generate # /boot/extlinux/extlinux.conf for mainline U-Boot. Nothing else in the root # filesystem is touched: no initramfs, no Armbian boot.scr/armbianEnv.txt # changes (they stay as they are, unused by our U-Boot, which tries # extlinux.conf first). # Every kernel under /boot// gets a menu entry, highest version first # (sort -V on the release name, not file dates); the highest is the default. # An older one can be picked on the serial console if a new one fails. # Settings (boards/.sh / environment): PARTUUID, BOOT_DTB, BOOT_OVERLAYS, # KERNEL_CONSOLE, KERNEL_CMDLINE_EXTRA. # Provided by install-kernel.sh: TARGET, TARBALL, RELEASE, ROOT or HOST, trun, # tput_file. # Root partition by PARTUUID: no initramfs, so root=UUID= cannot work. # PARTUUID=... in the environment overrides the detection. partuuid="${PARTUUID:-}" if [ -n "${ROOT:-}" ]; then if [ -z "$partuuid" ]; then [ "$(findmnt -no TARGET --target "$ROOT")" = "$ROOT" ] || die "$ROOT is not a mount point; mount the card's root partition there (or set PARTUUID)" partuuid="$(blkid -s PARTUUID -o value "$(findmnt -no SOURCE --target "$ROOT")" || true)" fi fstype="$(findmnt -no FSTYPE --target "$ROOT" || true)" else [ -n "$partuuid" ] || partuuid="$(trun 'blkid -s PARTUUID -o value "$(findmnt -no SOURCE /)"' || true)" fstype="$(trun 'findmnt -no FSTYPE /' || true)" fi [ -n "$partuuid" ] || die "could not find the PARTUUID of the root partition" case "$fstype" in ext[234]|btrfs|f2fs|xfs) ;; *) fstype=ext4 ;; esac info "root: PARTUUID=$partuuid ($fstype)" # Writing below follows the target's own symlinks (tar # --keep-directory-symlink, cp, mv). A relative link such as Debian's # lib -> usr/lib stays inside the target, but an absolute one (or ../..) # would resolve on this PC and write into its own /usr/lib or /boot. if [ -n "${ROOT:-}" ]; then for p in boot boot/$BOOT_SUBDIR "boot/$BOOT_SUBDIR/$RELEASE" boot/extlinux \ boot/extlinux/extlinux.conf boot/extlinux/extlinux.conf.bak \ boot/extlinux/extlinux.conf.new lib lib/modules "lib/modules/$RELEASE"; do r="$(realpath -m -- "$ROOT/$p")" case "$r" in "$ROOT"/*) ;; *) die "/$p on the target resolves to $r, outside $ROOT (absolute symlink?); not writing there" ;; esac done for p in "boot/$BOOT_SUBDIR/$RELEASE" "lib/modules/$RELEASE"; do [ -d "$ROOT/$p" ] || continue r="$(find "$ROOT/$p" -type l -lname '/*' -print -quit)" [ -z "$r" ] || die "absolute symlink $r in the target; not extracting over it" done fi # Armbian packages that can undo this setup on an apt upgrade. Warnings only. check_target_packages() { local st unheld st="$(trun 'cat var/lib/dpkg/status 2>/dev/null' | awk 'BEGIN { RS = ""; FS = "\n" } { p = s = "" for (i = 1; i <= NF; i++) { if ($i ~ /^Package: /) p = substr($i, 10) else if ($i ~ /^Status: /) s = substr($i, 9) } if (s ~ / installed$/) print p, s }' || true)" [ -n "$st" ] || return 0 unheld="$(awk '$1 ~ /^linux-(image|dtb|u-boot)-/ && $2 != "hold" { print $1 }' <<<"$st" | tr '\n' ' ')" [ -z "$unheld" ] || echo "WARNING: not on hold: ${unheld% }; an upgrade may rewrite Armbian's boot files or the bootloader. On the target: apt-mark hold ${unheld% }" >&2 ! grep -q '^u-boot-menu ' <<<"$st" || echo "WARNING: u-boot-menu is installed; it rewrites /boot/extlinux/extlinux.conf on kernel changes. Remove it." >&2 trun 'test -e lib/firmware/xr819/fw_xr819.bin' || echo "WARNING: /lib/firmware/xr819/ is missing (package armbian-firmware); the XR819 Wi-Fi will not work" >&2 local alg alg="$(trun 'cat etc/default/armbian-zram-config 2>/dev/null' | sed -n "s/^[[:space:]]*SWAP_ALGORITHM=[\"']*\([a-z0-9-]*\).*/\1/p" | tail -1 || true)" case "$alg" in ""|lz4|zstd|lzo|lzo-rle) ;; *) echo "WARNING: armbian-zram-config uses SWAP_ALGORITHM=$alg, which files/opi0/kernel.config does not enable" >&2 ;; esac } check_target_packages info "installing $RELEASE to $TARGET" # --keep-directory-symlink: /lib is a symlink to usr/lib on merged-/usr systems case "$TARGET" in ssh:*) ssh "$HOST" "tar --keep-directory-symlink --no-same-owner -xzf - -C /" < "$TARBALL" ;; *) tar --keep-directory-symlink -xzf "$TARBALL" -C "$ROOT" ;; esac # Releases on the target, highest version first (by name, not by date). releases="$(trun "ls -1 boot/$BOOT_SUBDIR 2>/dev/null" | sort -rV)" [ -n "$releases" ] || die "no kernels in /boot/$BOOT_SUBDIR on the target" # The last console= becomes /dev/console (emergency shell, init output). Keep # the serial console there even if KERNEL_CONSOLE is overridden in a different # order; the relative order of everything else is kept. console_args() { local a serial="" rest="" for a in $KERNEL_CONSOLE; do case "$a" in console=ttyS*) serial="${serial:+$serial }$a" ;; *) rest="${rest:+$rest }$a" ;; esac done echo "$rest${rest:+${serial:+ }}$serial" } cmdline_console="$(console_args)" case "$cmdline_console" in *console=ttyS*) ;; *) echo "WARNING: no console=ttyS* in KERNEL_CONSOLE; no serial emergency console" >&2 ;; esac gen_extlinux() { local r ov echo "# Generated by install-kernel.sh ($BOARD_NAME) - rerun it to update." echo "# Booted by mainline U-Boot; no initramfs." echo "menu title $BOOT_MENU_TITLE" echo "timeout 20" echo "default $(head -1 <<<"$releases")" for r in $releases; do echo echo "label $r" echo " kernel /boot/$BOOT_SUBDIR/$r/zImage" echo " fdt /boot/$BOOT_SUBDIR/$r/$BOOT_DTB" if [ -n "$BOOT_OVERLAYS" ]; then echo -n " fdtoverlays" for ov in $BOOT_OVERLAYS; do echo -n " /boot/$BOOT_SUBDIR/$r/overlay/$ov.dtbo"; done echo fi echo " append root=PARTUUID=$partuuid rootfstype=$fstype rootwait rw $cmdline_console panic=10 consoleblank=0 $KERNEL_CMDLINE_EXTRA" done } trun 'mkdir -p boot/extlinux && { [ ! -f boot/extlinux/extlinux.conf ] || cp boot/extlinux/extlinux.conf boot/extlinux/extlinux.conf.bak; }' gen_extlinux | tput_file boot/extlinux/extlinux.conf trun 'sync' info "installed; /boot/extlinux/extlinux.conf:" trun 'cat boot/extlinux/extlinux.conf'