RPi-Distro / repo

Issue tracking for the archive.raspberrypi.org repo
37 stars 1 forks source link

[Bookworm] Cleanup /boot/firmware on new kernel package removals #357

Closed MichaIng closed 5 months ago

MichaIng commented 6 months ago

I recognised that after removal of the new RPi kernel packages, the related kernel and initramfs images in /boot/firmware remain. It would make sense to clean this up via postrm maintainer script. I can open a PR for this, if someone can show me where the package build scripts are hosted. At least I could not find them in the Linux repo.

XECDesign commented 6 months ago

The linux packages would install the kernel into /boot/ and then raspi-firmware contains the script that is responsible for copying and renaming the appropriate kernels. It's not on github, so I can't take a PR, but if you attach a patch for this and/or issue #358 , I can take a look. Otherwise, I can take update the package in the new year.

The bookworm image needed to be shipped a bit earlier than I wanted to, so a lot of this is marked as 'TODO' in the script.

MichaIng commented 6 months ago

I just found the ToDo in the script:

# TODO:
# Handle removed files on upgrade
# Handle removal
# Handle custom kernel?
# Handle upstream kernel
# Handle wrong partition

So this patch handles the removal:

--- /etc/kernel/postinst.d/z50-raspi-firmware.old       2023-11-14 13:43:16.000000000 +0100
+++ /etc/kernel/postinst.d/z50-raspi-firmware   2023-12-15 16:09:25.759176315 +0100
@@ -93,5 +93,10 @@
       cp "$latest_kernel" "$kernel_dst"
       cp "$latest_initrd" "$initrd_dst"
     fi
+  else
+    if [ "$KERNEL" = "auto" ]; then
+      [ -e "$latest_kernel" ] || rm -f "$kernel_dst"
+      [ -e "$latest_initrd" ] || rm -f "$initrd_dst"
+    fi
   fi
 done

The whole block:

for flavour in $FLAVOURS; do
  # Copy kernel files to /boot/firmware
  if [ "$KERNEL" = "auto" ] ; then
    latest_kernel=$(ls -1 /boot/vmlinuz-*-rpi-"$flavour" 2> /dev/null | grep -E -v '\.(dpkg-bak|old-dkms)$' | sort -V -r | head -1)
    latest_initrd=$(ls -1 /boot/initrd.img-*-rpi-"$flavour" 2> /dev/null | grep -E -v '\.(dpkg-bak|old-dkms)$' | sort -V -r | head -1)
  fi

  kernel_dst="$firmware_dst/kernel$(echo "$flavour" | sed 's/^v//;s/^6//;s/2712/_2712/;').img"
  initrd_dst="$firmware_dst/initramfs$(echo "$flavour" | sed 's/^v//;s/^6//;s/2712/_2712/;')"
  case $flavour in
    v8|2712)
      dtb_path="/usr/lib/linux-image-${latest_kernel#/boot/vmlinuz-}/broadcom"
      ;;
    *)
      dtb_path="/usr/lib/linux-image-${latest_kernel#/boot/vmlinuz-}"
      ;;
  esac
  overlay_path="/usr/lib/linux-image-${latest_kernel#/boot/vmlinuz-}/overlays"
  if [ "$1" != "remove" ]; then
    if [ "$KERNEL" = "auto" ] ; then
      [ -e "$latest_kernel" ] && [ -e "$latest_initrd" ] || continue
      for dtb in "${dtb_path}"/bcm27*.dtb; do
        [ -e "${dtb}" ] || continue
        cp "${dtb}" /boot/firmware/
      done
      for dtbo in "${overlay_path}"/*.dtb* "${overlay_path}"/README; do
        [ -e "${dtbo}" ] || continue
        cp "${dtbo}" "${firmware_dst}/overlays"
      done
      if [ -e "${firmware_dst}/.firmware_revision" ]; then
        echo "WARNING: raspi-firmware: replacing rpi-update kernels" >&2
        rm -f "${firmware_dst}/.firmware_revision"
      fi
      cp "$latest_kernel" "$kernel_dst"
      cp "$latest_initrd" "$initrd_dst"
    fi
  else
    if [ "$KERNEL" = "auto" ]; then
      [ -e "$latest_kernel" ] || rm -f "$kernel_dst"
      [ -e "$latest_initrd" ] || rm -f "$initrd_dst"
    fi
  fi
done
XECDesign commented 5 months ago

I've added new kernel and raspi-firmware packages to the 'untested' component. They should behave a bit better than what we were shipping previously.