#!/bin/bash # # cubieboard-oS13.2-transplant-boot [--fk|--no-fk] # # --fk Use factory kernel for initial boot (default). # (The 13.2 kernel doesn't boot, but it's good for testing.) # # Copy a new boot loader (u-boot) version from factory to an openSUSE 13.2 # installation image for cubieboard (the provided one does not boot). # Optionally copy a factory kernel as well. # # The install image does not boot with the factory boot loader and the oS 13.2 # kernel. The initial boot must be with the factory kernel. # # Copyright (C) by Volker Kuhlmann # http://volker.top.geek.nz/contact.html # All rights reserved. # Released under the terms of the GNU General Public License (GPL) Version 2. # See http://www.gnu.org/ for details. # # Volker Kuhlmann # 1.0, 26 Apr 2015 Created. # 1.1, 27 Apr 2015 More comments. Fine tuned. Create sunxi_modules.conf. # 1.2, 27 Apr 2015 For Factory 1.12.1-Build293.8. # 1.3, 28 Apr 2015 Update a dracut file to factory. Auto-detect disk ID. # Clean text output at end. # Fix variable value causing dracut errors. # #### #### Constants and initialised variables #### opensuse132_image="img/openSUSE-13.2-ARM-JeOS-cubieboard.armv7l-1.12.1-Build33.6.raw.xz" #opensusefactory_image="img/openSUSE-Factory-ARM-JeOS-cubieboard.armv7l-1.12.1-Build269.1.raw.xz" opensusefactory_image="img/openSUSE-Factory-ARM-JeOS-cubieboard.armv7l-1.12.1-Build293.8.raw.xz" # Kernel version of openSUSE factory. # Leave empty to auto-detect. #factkernver="3.19.1-1-default" #factkernver="3.19.3-1-default" # Disk IDs # Get them with fdisk -l . # # Disk IDs: 13.2 33.2: 0xf7d8c328 # 13.2 33.3: 0x70c4fe14 # 13.2 33.6: 0xae829f54 # factory 269.1: 0xbb5f4012 # factory 293.8: 0xabdb6a39 # Leave empty to auto-detect. #diskid_132="0xae829f54" #diskid_factory="0xbb5f4012" #diskid_factory="0xabdb6a39" #### #### Variables #### #### #### Version, Usage, Help #### #### #### Functions #### # Extract the disk ID from the disk image file. get_disk_id() { local imgfile="$1" exec 6< <( fdisk -l "$imgfile" 2>&1 ) local line id while read -r line; do case "$line" in "Disk identifier"*) id="${line##* }" echo "$id" return;; esac done <&6 false } # Get the version of the kernel included in the disk image. get_factory_kernver() { local mpdir="$1" local ver ver="`ls -l "$mpdir/boot/zImage-"*`" ver="${ver#*zImage-}" echo "$ver" test -n "$ver" } #### #### Main #### # Also copy factory kernel? factkern=1 case "$1" in --fk) factkern=1; shift;; --no-fk) factkern=; shift;; esac # Show versions of some pre-requisites. echo "Using:" #rpm -q u-boot-tools rpm -qf `type -p mkimage` | sort | uniq if [ -n "$factkern" ]; then echo " Copying factory kernel to oS 13.2 installation system. " else echo " Not copying factory kernel to oS 13.2 installation system. " fi # Root is required. if [ `id -un` != root ]; then echo >&2 "This script must run as root! (mount commands)." exit 2 fi # Unmount before starting, to be sure. umount 13.2-[12] fact-[12] 2>/dev/null # Exit on error. set -e # Unpack the compressed installation image files. ( set -x xz -dc "$opensuse132_image" > oS-13.2-moded.img xz -dc "$opensusefactory_image" > oS-factory.img ) # Get disk IDs. echo " Getting disk IDs:" test -n "$diskid_132" || diskid_132=`get_disk_id oS-13.2-moded.img` test -n "$diskid_factory" || diskid_factory=`get_disk_id oS-factory.img` echo "\ Disk ID oS 13.2: $diskid_132 Disk ID oS factory: $diskid_factory " # Mount all partitions of all image files. # (Use script for that, it's more universally useful and more than a 1-liner.) ( set -x mount-img-partitions -m 13.2 oS-13.2-moded.img mount-img-partitions -m fact oS-factory.img ) # Get kernel version of factory. echo " Getting kernel version:" test -n "$factkernver" || factkernver=`get_factory_kernver fact-2` echo "\ Kernel version oS factory: $factkernver " # Show all commands. set -x # Copy uboot, boot.scr from factory to 13.2. rm 13.2-1/sunxi-spl.bin 13.2-1/u-boot.bin cp -p fact-1/dtb/* 13.2-1/dtb/ cp -p fact-1/boot.scr 13.2-1 cp -p fact-1/boot/boot.script 13.2-1/boot cp -p fact-1/sunxi-spl.bin fact-1/u-boot-sunxi-with-spl.bin fact-1/u-boot.img 13.2-1/ # Copy boot kernel, from factory to 13.2. [ -n "$factkern" ] && \ cp -p fact-1/boot/linux.vmx 13.2-1/boot # Copy initrd. # Disk IDs must be adjusted or the initrd will be rejected. # [ -n "$factkern" ] && { tail -c +65 < fact-1/boot/initrd.uboot | gunzip > initrd.img #strreplace 0xbb5f4012 0xae829f54 initrd.img sed s/$diskid_factory/$diskid_132/g < initrd.img > initrd-id.img : "Checking number of bytes changed." : "Must be >0 <= 8 (enforced) and in one location (unchecked)." changedbytes=$(cmp -l initrd.img initrd-id.img | wc -l) test $changedbytes -le 8 -a $changedbytes -gt 0 gzip < initrd-id.img > initrd.img.gz mkimage -C none -A arm -O linux -T ramdisk -n Initrd -d initrd.img.gz 13.2-1/boot/initrd.uboot # mkimage -l fact-1/boot/initrd.uboot } mkimage -l 13.2-1/boot/initrd.uboot # Copy full kernel. # Needed to boot the system properly with the factory linux.vmx, initrd.uboot. [ -n "$factkern" ] && { cp -p -a fact-2/lib/modules/$factkernver 13.2-2/lib/modules/ cp -p -a fact-2/lib/firmware/$factkernver 13.2-2/lib/firmware/ # cp -p fact-2/boot/.zImage-$factkernver.hmac 13.2-2/boot cp -p fact-2/boot/System.map-$factkernver 13.2-2/boot cp -p fact-2/boot/config-$factkernver 13.2-2/boot #cp -p fact-2/boot/initrd-$factkernver 13.2-2/boot cp -p fact-2/boot/symvers-$factkernver.gz 13.2-2/boot cp -p fact-2/boot/sysctl.conf-$factkernver 13.2-2/boot cp -p fact-2/boot/vmlinux-$factkernver.gz 13.2-2/boot cp -p fact-2/boot/zImage-$factkernver 13.2-2/boot } # Copy uboot, mkimage (u-boot-tools) from factory to /boot directory of rootfs # (not the same as the boot partition of the image file!). cp -p fact-1/sunxi-spl.bin fact-1/u-boot-sunxi-with-spl.bin fact-1/u-boot.img 13.2-2/boot/ cp -p fact-1/dtb/* 13.2-2/boot/dtb/ ln -sf u-boot.img 13.2-2/boot/u-boot.bin cp -p fact-2/usr/bin/mkimage 13.2-2/usr/bin/mkimage # Symlink boot kernel, initrd to version used. # Note: the initrd doesn't exist yet, but create the symlink. if [ -n "$factkern" ]; then ln -sf zImage-$factkernver 13.2-2/boot/zImage ln -sf initrd-$factkernver 13.2-2/boot/initrd else ln -sf zImage-3.16.7-11-default 13.2-2/boot/zImage ln -sf initrd-3.16.7-11-default 13.2-2/boot/initrd fi # Fix up dracut for sunxi CPUs. # echo "# CPUs (Allwinner?) using sunxi MMC storage require this module in initrd # or the rootfs on SD card can't be accessed! add_drivers+=\" sunxi-mmc\" " >> 13.2-2/etc/dracut.conf.d/sunxi_modules.conf # # This file causes inclusion of the module to access the SATA disk from initrd. file=/usr/lib/dracut/modules.d/90kernel-modules/module-setup.sh cp -p 13.2-2$file 13.2-2$file.orig cp -p fact-2$file 13.2-2$file # Delete unused oS 13.2 kernel modules to ensure the partition (rootfs) doesn't # run out of space. [ -n "$factkern" ] && \ rm -rf 13.2-2/lib/modules/3.16.7-11-default # Unmount umount 13.2-[12] fact-[12] # Copy a boot loader stored on the boot disk from factory to 13.2 dd skip=1 seek=1 count=2047 conv=notrunc if=oS-factory.img of=oS-13.2-moded.img sync set +e +x # Copy to microSD card. echo " Copy to microSD card, e.g. dd bs=1M oflag=direct if=oS-13.2-moded.img of=/dev/sd_card_uSD; sync " # On target system. echo " The rest must be done on the target system once booted. *** CRITICAL: The initrd created on first boot MUST CONTAIN module sunxi-mmc! If it does not, re-create it because the system WILL NOT BOOT! Check with: xz -dc /boot/initrd--default | cpio -t | grep mmc --- mkinitrd -k /boot/zImage-3.19.3-1-default -i /boot/initrd-3.19.3-1-default -m sunxi_mmc mkinitrd -v -k /boot/zImage-3.19.1-1-default -i /boot/initrd-3.19.1-1-default -m sunxi_mmc mkinitrd -v -k /boot/zImage-3.16.7-11-default -i /boot/initrd-3.16.7-11-default -m sunxi_mmc --- Because mkinitrd is buggy absolute paths must be used with -k, -i. --- Possibly useful commands (copy/paste to terminal): export TERM=xterm stty rows 30 columns 100 ln -sf /usr/share/zoneinfo/Pacific/Auckland /etc/localtime alias d='ls -la' alias t=more alias c='cp -p' rpm -Uvh u-boot-cubieboard-2015.04~rc4-1.1.armv7hl.rpm u-boot-cubieboard-doc-2015.04~rc4-1.1.armv7hl.rpm rpm -Uvh u-boot-tools-2015.04~rc4-1.1.armv7hl.rpm rpm -Uvh dracut-037-31.1.armv7hl.rpm rpm -ivh kernel-default-3.19.3-1.1.armv7hl.rpm # (Don't have rpm of 3.19.3-1-default) mkinitrd -k /boot/zImage-3.19.3-1.1-default -i /boot/initrd-3.19.3-1.1-default -m sunxi_mmc rpm -ivh kernel-default-3.19.1-2.1.armv7hl.rpm # (Don't have rpm of 3.19.1-1-default) mkinitrd -k /boot/zImage-3.19.1-2.1-default -i /boot/initrd-3.19.1-2.1-default -m sunxi_mmc rpm -ivh kernel-default-3.16.7-11.1.armv7hl.rpm --force (Doesn't boot on cubieboard) zypper -vv up zypper -vv in lsof util-linux-systemd rsync joe Could put this into /etc/zypp/repos.d/factory-oss.repo --- [openSUSE-Factory-repo-oss] name=openSUSE-Factory-repo-oss enabled=0 autorefresh=1 baseurl=http://download.opensuse.org/ports/armv7hl/factory/repo/oss/ type=yast2 priority=140 keeppackages=1 --- Finished creating a modified installation image in oS-13.2-moded.img "