[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Kernel and initramfs hooks for flash-kernel



Hello,

  flash-kernel is a debian-installer ARM utility which is able to
produce bootable kernel and initramfs (aka initrd) images. It converts
vmlinuz and initrd images to bootable format which the bootloader
understands, most common use is to generate uImage and uInitrd for
U-Boot booloader.

  flash-kernel needs to be run after creating or upgrading a kernel
image and after creating or upgrading initrd image. There has been a
long standing open bugreport (#550584) and a kernel hook policy [0].

  While I am not entirely sure, I think proper way to add hooks would be:
  * one hook triggered by kernel scripts creating uImage from vmlinuz
post package installation.
  * and other hook triggered by kernel scripts creating uInitrd after
initrd- has been created.
(the reason why I think it should be triggered by kernel scripts
instead initramfs-tools, is that maybe in future we could have random
initramfs generators, so instead placing a initramfs-tools hook, a
kernel hook after initrd generation might be useful)

  All of the above have several implications as kernel and
flash-kernel code might have to be patched.

  Another way around it, would be to call flash-kernel as a hook from
/etc/initramfs/post-update.d which gets triggered by update target
from update-initramfs.
  I have tried this approach as a proof of concept, but the hook does
not get triggered when initrd is created (although adding
run_bootloader at the end of
  create function in update-initramfs fixes the issue, but according
to quick comment from Maximilian that is wrong approach.

  Maybe someone can provide helpful comments on how to properly add
the hooks and where.

  Just for the record, here is some output I got adding
/etc/initramfs/post-update.d/flash-kernel hook, and commenting out on
update-initramfs:
  (If adding a call to run_bootloader on create(), then it works as expected)

        # FIXME: to be removed once flash-kernel installs a hook
        #if flash-kernel --supported >/dev/null 2>&1; then
        #       flash-kernel ${version}
        #        return 0
        #fi

root@hf08:/boot# apt-get --reinstall install linux-image-2.6.39-2+armhf.1-mx5
[..]
run-parts: executing /etc/kernel/postinst.d/initramfs-tools
2.6.39-2+armhf.1-mx5 /boot/vmlinuz-2.6.3
9-2+armhf.1-mx5
+ [ -r /etc/initramfs-tools/update-initramfs.conf ]
+ . /etc/initramfs-tools/update-initramfs.conf
+ update_initramfs=yes
+ backup_initramfs=no
+ [ -z 1 ]
+ verbose=0
+ yes=0
+ takeover=0
+ getopts k:cudyvtb:h? flag
+ mode=c
+ getopts k:cudyvtb:h? flag
+ takeover=1
+ getopts k:cudyvtb:h? flag
+ version=2.6.39-2+armhf.1-mx5
+ getopts k:cudyvtb:h? flag
+ BOOTDIR=/boot
+ [ ! -d /boot ]
+ getopts k:cudyvtb:h? flag
+ shift 6
+ [ 0 -ne 0 ]
+ [ -z c ]
+ [ 2.6.39-2+armhf.1-mx5 = all ]
+ [ yes = all ]
+ create
+ [ -z 2.6.39-2+armhf.1-mx5 ]
+ set_initramfs
+ initramfs=/boot/initrd.img-2.6.39-2+armhf.1-mx5
+ [ 1 = 0 ]
+ generate_initramfs
+ echo update-initramfs: Generating /boot/initrd.img-2.6.39-2+armhf.1-mx5
update-initramfs: Generating /boot/initrd.img-2.6.39-2+armhf.1-mx5
+ OPTS=-o
+ [ 0 = 1 ]
+ mkinitramfs -o /boot/initrd.img-2.6.39-2+armhf.1-mx5.new 2.6.39-2+armhf.1-mx5
+ mv -f /boot/initrd.img-2.6.39-2+armhf.1-mx5.new
/boot/initrd.img-2.6.39-2+armhf.1-mx5
+ set_sha1
+ sha1sum /boot/initrd.img-2.6.39-2+armhf.1-mx5

root@hf08:/boot# cat /etc/initramfs/post-update.d/flash-kernel
#!/bin/sh -e

version="$1"
bootopt=""

# passing the kernel version is required
if [ -z "${version}" ]; then
        echo >&2 "W: flash-kernel: ${DPKG_MAINTSCRIPT_PACKAGE:-kernel
package} did not pass a version number"
        exit 2
fi

# TODO: flash-kernel hardcodes this info, maybe it can take it from here
# absolute file name of kernel image may be passed as a second argument;
# convert initrd to bootable format in the same directory
#if [ -n "$2" ]; then

#       bootdir=$(dirname "$2")
#       bootopt="-b ${bootdir}"
#fi

# avoid running multiple times
if [ -n "$DEB_MAINT_PARAMS" ]; then
        eval set -- "$DEB_MAINT_PARAMS"
        if [ -z "$1" ] || [ "$1" != "configure" ]; then
                exit 0
        fi
fi

# we're good - convert kernel and initramfs to bootable format.
if flash-kernel --supported >/dev/null 2>&1; then
        flash-kernel "${version}" >&2
        return 0
fi


Comments?

[0] http://kernel-handbook.alioth.debian.org/ch-update-hooks.html
-- 

 Héctor Orón  -.. . -... .. .- -.   -.. . ...- . .-.. --- .--. . .-.

<free spam>
-- Would you like to make a donation for Debian Conference?
   ** http://debconf11.debconf.org/payments.xhtml **
</free spam>


Reply to: