#!/bin/sh # Install a Debian kernel on a Buffalo Linkstation Pro/Live # - intended to be automatically triggered by /etc/kernel-img.conf # That file should contain at least: # do_symlinks = Yes # do_initrd = Yes # link_in_boot = Yes # postinst_hook = /usr/local/bin/install-linkstation-kernel # # Copyright 2008 Tim Small tim@seoss.co.uk # Released under the terms of the GNU General Public License Version 2 # #KERNEL=vmlinuz-2.6.26-rc6-orion5x #INITRD=initrd.img-2.6.26-rc6-orion5x KERNEL=/boot/vmlinuz INITRD=/boot/initrd.img KUIMAGE=/boot/uImage.buffalo IUIMAGE=/boot/initrd.buffalo UBOOT_MKIMAGE=/usr/bin/mkimage DEVIO=/usr/bin/devio cleanup() { rm -f $KERNEL_SHIM $SHIMMED_KERNEL $NEWKUIMAGE $NEWIUIMAGE } if [ ! -x $DEVIO ] then apt-get install devio fi if [ ! -x $UBOOT_MKIMAGE ] then apt-get install uboot-mkimage fi KERNEL_SHIM=`mktemp -t kernelshim.XXXXXXXXXX` || exit 1 SHIMMED_KERNEL=`mktemp -t shimmedkernel.XXXXXXXXXX` if [ $? -ne 0 ]; then cleanup exit 1 fi NEWKUIMAGE=`mktemp -p /boot newkuimage.XXXXXXXXXX` if [ $? -ne 0 ]; then cleanup exit 1 fi NEWIUIMAGE=`mktemp -p /boot newiuimage.XXXXXXXXXX` if [ $? -ne 0 ]; then cleanup exit 1 fi # This devio command writes a machine-code shim to the start of the kernel # image, to change the machine type number passed to the kernel by uboot # First sanity check what we're running on. # First case - a Linkstation which is already running a Debian kernel # Second case - original Buffalo kernel with incorrect machine type if ( ! grep -E -q '^Hardware.*Buffalo.*Pro' /proc/cpuinfo) && ( ! (grep -E -q '^Hardware.*MV-88fxx81' /proc/cpuinfo || grep -q 'panic=5 BOOTVER=' /proc/cmdline)) then echo "Not a linkstation? Refusing to continue..." cleanup exit 1 fi if [ ! -L $KERNEL ] then echo "$0: Kernel symlink $KERNEL doesn't exist! Exiting" cleanup exit 1 fi if [ ! -L $INITRD ] then echo "$0: Kernel symlink $KERNEL doesn't exist! Exiting" cleanup exit 1 fi # For kuropro use a different machine ID - #$DEVIO 'wl 0xe3a01c05,4' 'wl 0xe38110e5,4' > $KERNEL_SHIM # Linkstation version - $DEVIO 'wl 0xe3a01c06,4' 'wl 0xe3811031,4' > $KERNEL_SHIM cat $KERNEL_SHIM $KERNEL > $SHIMMED_KERNEL $UBOOT_MKIMAGE -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n `readlink $KERNEL` -d $SHIMMED_KERNEL $NEWKUIMAGE if [ $? -ne 0 ]; then cleanup exit 1 fi $UBOOT_MKIMAGE -A arm -O linux -T ramdisk -C none -a 0x00000000 -e 0x00000000 -n `readlink $INITRD` -d $INITRD $NEWIUIMAGE if [ $? -ne 0 ]; then cleanup exit 1 fi if mkimage -l /boot/initrd.buffalo | grep -q -E '^Image Name:.*initrd$' && mkimage -l /boot/uImage.buffalo | grep -q -E '^Image Name:.*-arm1' then BACKUP_SUFFIX='_original' else BACKUP_SUFFIX='.old' fi mv -f $KUIMAGE ${KUIMAGE}${BACKUP_SUFFIX} && mv -f $NEWKUIMAGE $KUIMAGE mv -f $IUIMAGE $IUIMAGE${BACKUP_SUFFIX} && mv -f $NEWIUIMAGE $IUIMAGE cleanup