File uboot-image-cubietruck-install of Package E17-seattle

#!/bin/bash

set -x

diskname=$1
flavor=cubietruck

#==========================================
# install Raspberry Pi firmware in FAT partition
#------------------------------------------
if [ -f "boot/vc/bootcode.bin" ]; then
	# Changes made here are lost, so we have to (re)mount it rw
	# kiwi already uses loop0 for image, so let's mount p1 which
	# thanks to vboot is already FAT.
	mkdir ./mnt
	mkfs.msdos /dev/mapper/loop0p1
	mount /dev/mapper/loop0p1 ./mnt
	# Copy content of raspberrypi-firmware package
	mv boot/vc/* ./mnt
	mv boot/u-boot.bin ./mnt
	# u-boot checks the first partition, add a jump boot script
	cat > ./mnt/boot.script <<-"EOF"
load mmc 0:2 0x200 boot.scr
source 0x200
EOF
	mkimage -A arm -O linux -a 0 -e 0 -T script -C none  -n 'Boot-Script' -d ./mnt/boot.script ./mnt/boot.scr
	umount ./mnt
	rmdir ./mnt

	# convert GPT to hybrid GPT
	echo "r
h
1 2 3
n
c
y
82
n
83
n
w
y" > gdisk.tmp
	/usr/src/packages/KIWIROOT-oem/usr/sbin/gdisk /dev/loop0 < gdisk.tmp
	rm -f gdisk.tmp
fi

#==========================================
# install MLO as raw
#------------------------------------------
if [ -f "boot/MLO" ];then
	echo "Installing MLO..."
	opt="count=1 seek=1 conv=notrunc"
	if ! dd if=boot/MLO of=$diskname bs=128k $opt; then
		echo "Couldn't install MLO on $diskname"
		exit 1
	fi
	# /.../
	# To avoid any issues when parted leaves x86 boot code
	# in the MBR we better clear that part of the image
	# ----
	dd if=/dev/zero of=$diskname bs=440 count=1 conv=notrunc
fi

#==========================================
# install Origen SPL & u-boot as raw
#------------------------------------------
if [ -f "boot/origen-spl.bin" ];then
	echo "Installing SPL..."
	if ! dd if=boot/origen-spl.bin of=$diskname seek=1 conv=notrunc; then
		echo "Couldn't install SPL on $diskname"
		exit 1
	fi
	if ! dd if=boot/u-boot.bin of=$diskname seek=65 conv=notrunc; then
		echo "Couldn't install u-boot on $diskname"
		exit 1
	fi
fi

#==========================================
# install Arndale SPL & u-boot as raw
#------------------------------------------
if [[ -f "boot/smdk5250-spl.bin" || -f "boot/arndale-spl.bin" ]];then
        echo "Installing SPL..."
        if ! dd if=boot/arndale-bl1.img of=$diskname seek=1 conv=notrunc; then
                echo "Couldn't install BL1 on $diskname"
                exit 1
        fi
        # Get SPL name (depends on u-boot version)
        SPL_FILE=$(ls boot/*-spl.bin);
        if ! dd if=$SPL_FILE of=$diskname seek=17 conv=notrunc; then
                echo "Couldn't install SPL ($SPL_FILE) on $diskname"
                exit 1
        fi
        if ! dd if=boot/u-boot.bin of=$diskname seek=49 conv=notrunc; then
                echo "Couldn't install u-boot on $diskname"
                exit 1
        fi
fi

#==========================================
# install Cubieboard/Cubietruck SPL & u-boot as raw
#------------------------------------------
if [ -f "boot/sunxi-spl.bin" ];then
        echo "Installing SPL..."
        if ! dd if=boot/sunxi-spl.bin of=$diskname bs=1024 seek=8 conv=notrunc; then
                echo "Couldn't install SPL on $diskname"
                exit 1
        fi
        if ! dd if=boot/u-boot.bin of=$diskname bs=1024 seek=40 conv=notrunc; then
                echo "Couldn't install u-boot on $diskname"
                exit 1
        fi
fi

#==========================================
# install Chromebook u-boot as boot kernel
#------------------------------------------
if [ -e /usr/bin/vbutil_kernel ]; then
	pushd /usr/src/packages/KIWIROOT-oem/
	echo "console=tty1 debug verbose" > /tmp/config
	vbutil_kernel --pack /tmp/newkern \
		--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
		--version 1 \
		--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
		--config=/tmp/config --vmlinuz boot/u-boot.img --arch arm
	kpartx -av $diskname
	dd if=/tmp/newkern of=/dev/mapper/loop0p1
	kpartx -d $diskname
	cgpt add -t kernel -i 1 -S 1 -T 5 -P 10 -l U-BOOT $diskname
	popd
fi

#==========================================
# install i.MX u-boot as raw
#------------------------------------------
if [ -f "boot/u-boot.imx" ];then
	pushd /usr/src/packages/KIWIROOT-oem/
	echo "Installing u-boot..."
	if ! dd if=boot/u-boot.imx of=$diskname bs=512 seek=2 conv=notrunc; then
		echo "Couldn't install u-boot on $diskname"
		exit 1
	fi
	popd
fi

#==========================================
# install Cubox-i SPL & u-boot as raw
#------------------------------------------
if [ -f "boot/cuboxi-spl.bin" ];then
        echo "Installing SPL..."
        if ! dd if=boot/cuboxi-spl.bin of=$diskname bs=1024 seek=1 conv=notrunc; then
                echo "Couldn't install SPL on $diskname"
                exit 1
        fi
        if ! dd if=boot/u-boot.img of=$diskname bs=1024 seek=42 conv=notrunc; then
                echo "Couldn't install u-boot on $diskname"
                exit 1
        fi
fi

if [ -f boot/grub2/*efi/grub.efi ];then
	echo "EFI system, installing startup.nsh"
	PART=$(kpartx -asv $diskname | cut -d ' ' -f 3 | head -n1)
	mkdir ./mnt
	mount /dev/mapper/$PART ./mnt
        if [ -f boot/grub2/arm-efi/grub.efi ]; then
		echo "bootarm" > mnt/startup.nsh
	else
		echo "bootaa64" > mnt/startup.nsh
	fi
	umount ./mnt
	rmdir ./mnt
	kpartx -dv $diskname
fi
openSUSE Build Service is sponsored by