#! /bin/sh
set -e
dist="wily"
dtb="bcm2709-rpi-2-b.dtb"
# download latest deb
PPA_URL="http://ppa.launchpad.net/p-pisati/embedded/ubuntu/"
PPA_DEB="$(wget -O - -q $PPA_URL/dists/devel/main/binary-armhf/Packages |grep linux-bcm2709|grep image-|grep ^Filename|tail -1|sed 's/^Filename: //')"
PKG="$(echo $PPA_DEB|sed 's/^.*\///')"
if ! ls $PKG >/dev/null 2>&1; then
wget $PPA_URL/$PPA_DEB
fi
# set some defaults based on the deb filename
version="$(ls *.deb|cut -d'_' -f1|sed 's/^linux-image-//')"
abi="$(ls *.deb|cut -d'_' -f2)"
# unpack deb
rm -rf unpack
dpkg -x linux-image-${version}_${abi}_armhf.deb unpack
# flush output dirs
rm -rf device && mkdir -p device/system && mkdir -p device/assets/dtbs
# copy kernel and devicetree
cp unpack/boot/vmlinuz-* device/assets/vmlinuz
cp unpack/lib/firmware/${version}/device-tree/$dtb device/assets/dtbs/
# copy extra files
mkdir -p device/system/boot/uboot/
cp unpack/usr/share/doc/linux-image-${version}/changelog.Debian.gz device/system/boot/uboot/changelog-vmlinuz.gz
cp unpack/boot/config-* device/system/boot/uboot/config-vmlinuz
cp unpack/boot/System.map-* device/system/boot/uboot/System.map
# handle modules
cp -a unpack/lib device/system/
modules_dir="$(ls unpack/lib/modules/)"
depmod -ea -F device/system/boot/uboot/System.map -b device/system/ ${modules_dir}
# handle initrd
DEVICE_URL="http://cdimage.ubuntu.com/ubuntu-core/daily-preinstalled/current/"
DEVICE_MD5="$(wget -q -O - $DEVICE_URL/MD5SUMS|grep armhf.device|cut -d ' ' -f1)"
TAR_MD5="$(md5sum initrd/cdimage.tar.gz|cut -d ' ' -f1)"
if [ "$DEVICE_MD5" != "$TAR_MD5" ]; then
wget -O initrd/cdimage.tar.gz $DEVICE_URL/$dist-preinstalled-core-armhf.device.tar.gz
fi
tar xf initrd/cdimage.tar.gz -C initrd
rm -rf initrd/unpack/ && mkdir -p initrd/unpack/
cd initrd/unpack/
cat ../assets/initrd.img | unxz -c | cpio -i
rm -rf lib/modules/*
find . | cpio --create --format=newc | lzma > ../../device/assets/initrd.img
cd -
#cp initrd/assets/initrd.img device/assets/
rm -rf initrd/assets initrd/system initrd/hardware.yaml
cat << EOF > device/README.md
# Device part
This device part has 3 components:
- system: the system part, lands on the system partition, this is
where you would generally layout the kernel modules.
- assets: this holds one or many kernels, initrds, and/or dtbs.
- hardware.yaml: a definition of what each asset is and which one to pick.
Some entries can be OEM overriden in the *oem part*.
Aside from that it determines the partition layout and
the bootloader technology.
# Custom or proprietary solutions for booting
If a custom or proprietary solution is seeked that does not use u-boot
or grub, set the bootloader to custom and the device part can be
provisioned with items in a *boot* directory which will layout the files
in the boot partition.
EOF
cat << EOF > device/hardware.yaml
kernel: assets/vmlinuz
initrd: assets/initrd.img
dtbs: assets/dtbs
EOF
# tar up device subdir
cd device
tar cJvf ../device-pi2-0.14.tar.xz *
cd -
exit 0