X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mkimage.sh;h=3f1102208d7fc372959eacb51e61f66da20f419b;hb=2e14b6ffa6e6723989d40400e9837ea60ac3b666;hp=f2d0e5d3cf2657992df0a8e1f5106a134c2a94ef;hpb=00d5cb6d93566a131ab9201efe9d51b8b7101c14;p=debian-xu4 diff --git a/mkimage.sh b/mkimage.sh index f2d0e5d..3f11022 100755 --- a/mkimage.sh +++ b/mkimage.sh @@ -1,41 +1,56 @@ -#! /bin/sh +#! /bin/bash # Install a bog-standard Debian bootable for ODROID XU3/XU4. -# Note that this will only work for SD cards; MMC devices -# have a different layout. See -# /usr/share/doc/u-boot-exynos/README.odroid.gz for more details. -# -# Note: You will need u-boot-exynos >= 2016.05~rc3+dfsg1-1, -# which at the time of writing is in experimental (it will -# probably eventually hit stretch). # -# Beware: This will ERASE ALL DATA on the target SD card. +# Beware: This will ERASE ALL DATA on the target SD card +# or MMC partition. # # # Copyright 2016 Steinar H. Gunderson . # Licensed under the GNU GPL, v2 or (at your option) any later version. set -e -set -x -DEVICE=$1 -BOOTPART_MB=$2 +DEVICE= +BOOTPART_MB=256 +SUITE=stretch +TYPE=sd + +while getopts "b:s:t:" opt; do + case $opt in + b) + BOOTPART_MB=$OPTARG + ;; + s) + # Sorry, jessie won't work; the kernel doesn't support XU3/XU4. + SUITE=$OPTARG + ;; + t) + TYPE=$OPTARG + ;; + :) + echo "Option -$OPTARG requires an argument." + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) -if [ ! -b "$DEVICE" ] || [ ! "$BOOTPART_MB" -gt 0 ]; then - echo "Usage: $0 DEVICE BOOTPARTITION_SIZE [SUITE [OTHER_DEBOOTSTRAP_ARGS...]]" +DEVICE=$1 +if [ ! -b "$DEVICE" ]; then + echo "Usage: $0 [-b BOOTPARTITION_SIZE] [-s SUITE] [-t sd|mmc|mmcbootonly] DEVICE [OTHER_DEBOOTSTRAP_ARGS...]" echo "DEVICE is an SD card device, e.g. /dev/sdb." exit 1 fi -shift 2 +shift -SUITE=$1 -if [ -z "$SUITE" ]; then - # Sorry, jessie won't work; the kernel doesn't support XU3/XU4. - SUITE=stretch -else - shift +if [ "$TYPE" != "sd" ] && [ "$TYPE" != "mmc" ] && [ "$TYPE" != "mmcbootonly" ]; then + echo "Card type must be 'sd', 'mmc' or 'mmcbootonly'." + exit 1 fi +set -x + # Prerequisites. dpkg --add-architecture armhf apt update @@ -48,37 +63,55 @@ if [ ! -d u-boot ]; then git clone https://github.com/hardkernel/u-boot -b odroidxu3-v2012.07 fi -# Partition the device. -parted ${DEVICE} mklabel msdos -parted ${DEVICE} mkpart primary fat32 2MB $(( BOOTPART_MB + 2 ))MB -parted ${DEVICE} set 1 boot on -parted ${DEVICE} mkpart primary ext2 $(( BOOTPART_MB + 2))MB 100% - -# Figure out if the partitions are of type ${DEVICE}1 or ${DEVICE}p1. -if [ -b "${DEVICE}1" ]; then - DEVICE_STEM=${DEVICE} -elif [ -b "${DEVICE}p1" ]; then - DEVICE_STEM=${DEVICE}p -else - echo "Could not find device files for partitions of ${DEVICE}. Exiting." - exit 1 +if [ "$TYPE" != "mmcbootonly" ]; then + # Partition the device. + parted ${DEVICE} mklabel msdos + parted ${DEVICE} mkpart primary fat32 2MB $(( BOOTPART_MB + 2 ))MB + parted ${DEVICE} set 1 boot on + parted ${DEVICE} mkpart primary ext2 $(( BOOTPART_MB + 2))MB 100% + + # Figure out if the partitions are of type ${DEVICE}1 or ${DEVICE}p1. + if [ -b "${DEVICE}1" ]; then + DEVICE_STEM=${DEVICE} + elif [ -b "${DEVICE}p1" ]; then + DEVICE_STEM=${DEVICE}p + else + echo "Could not find device files for partitions of ${DEVICE}. Exiting." + exit 1 + fi fi # Put the different stages of U-Boot into the right place. -# The offsets come from README.odroid.gz. -dd if=u-boot/sd_fuse/hardkernel_1mb_uboot/bl1.bin.hardkernel of=${DEVICE} seek=1 conv=sync -dd if=u-boot/sd_fuse/hardkernel_1mb_uboot/bl2.bin.hardkernel.1mb_uboot of=${DEVICE} seek=31 conv=sync -dd if=/usr/lib/u-boot/odroid-xu3/u-boot-dtb.bin of=${DEVICE} seek=63 conv=sync -dd if=u-boot/sd_fuse/hardkernel_1mb_uboot/tzsw.bin.hardkernel of=${DEVICE} seek=2111 conv=sync +# The offsets come from /usr/share/doc/u-boot-exynos/README.odroid.gz. +if [ "$TYPE" = "sd" ]; then + UBOOT_DEVICE=${DEVICE} + UBOOT_OFFSET=1 +elif [ "$TYPE" = "mmcbootonly" ]; then + UBOOT_DEVICE=${DEVICE} + UBOOT_OFFSET=0 +else + UBOOT_DEVICE=${DEVICE}boot0 + UBOOT_OFFSET=0 +fi +dd if=u-boot/sd_fuse/hardkernel_1mb_uboot/bl1.bin.hardkernel of=${UBOOT_DEVICE} seek=${UBOOT_OFFSET} conv=sync +dd if=u-boot/sd_fuse/hardkernel_1mb_uboot/bl2.bin.hardkernel.1mb_uboot of=${UBOOT_DEVICE} seek=$((UBOOT_OFFSET + 30)) conv=sync +dd if=/usr/lib/u-boot/odroid-xu3/u-boot-dtb.bin of=${UBOOT_DEVICE} seek=$((UBOOT_OFFSET + 62)) conv=sync +dd if=u-boot/sd_fuse/hardkernel_1mb_uboot/tzsw.bin.hardkernel of=${UBOOT_DEVICE} seek=$((UBOOT_OFFSET + 2110)) conv=sync # Clear out the environment. dd if=/dev/zero of=${DEVICE} seek=2560 count=32 bs=512 conv=sync +if [ "$TYPE" = "mmcbootonly" ]; then + # The user asked us to only create the MMC boot partition, so exit. + exit 0 +fi + # Create a /boot partition. Strictly speaking, almost everything could be loaded # from ext4, but using FAT is somehow traditional and less likely to be broken # at any given time. (It doesn't support symlinks, though, which breaks flash-kernel, # but we don't use that anyway.) -mkfs.vfat -F 32 ${DEVICE_STEM}1 +BOOT_PART=${DEVICE_STEM}1 +mkfs.vfat -F 32 ${BOOT_PART} # Put an LVM on the other partition; it's easier to deal with when expanding # partitions or otherwise moving them around. @@ -97,7 +130,7 @@ mkfs.ext4 /dev/odroid/root mkdir -p /mnt/xu4/ mount /dev/odroid/root /mnt/xu4 mkdir /mnt/xu4/boot/ -mount ${DEVICE_STEM}1 /mnt/xu4/boot +mount ${BOOT_PART} /mnt/xu4/boot debootstrap --include=linux-image-armmp-lpae,grub-efi-arm,lvm2,isc-dhcp-client --foreign --arch armhf ${SUITE} /mnt/xu4 "$@" # Run the second stage debootstrap under qemu (via binfmt_misc). @@ -113,7 +146,7 @@ if [ "$SUITE" != "unstable" ] && [ "$SUITE" != "sid" ]; then fi # Create an fstab (this is normally done by partconf, in d-i). -BOOT_UUID=$( blkid -s UUID -o value ${DEVICE_STEM}1 ) +BOOT_UUID=$( blkid -s UUID -o value ${BOOT_PART} ) cat < /mnt/xu4/etc/fstab # /etc/fstab: static file system information. # @@ -132,6 +165,9 @@ echo odroid > /mnt/xu4/etc/hostname # Work around Debian bug #824391. echo ttySAC2 >> /mnt/xu4/etc/securetty +# Work around Debian bug #825026. +echo ledtrig-heartbeat >> /mnt/xu4/etc/modules + # Install GRUB, chainloaded from U-Boot via UEFI. mount --bind /dev /mnt/xu4/dev mount --bind /proc /mnt/xu4/proc @@ -151,16 +187,13 @@ cat < /mnt/xu4/etc/grub.d/25_devicetree #! /bin/sh set -e -# Hack added by prepare.sh when building the root image, +# Hack added by mkimage.sh when building the root image, # to work around Debian bug #824399. echo "echo 'Loading device tree ...'" echo "devicetree /exynos5422-odroidxu4.dtb" EOF chmod 0755 /mnt/xu4/etc/grub.d/25_devicetree -# Work around Debian bug #823552. -sed -i 's/\(GRUB_CMDLINE_LINUX_DEFAULT=".*\)"/\1 loglevel=4"/' /mnt/xu4/etc/default/grub - # Now we can create the GRUB boot menu. chroot /mnt/xu4 /usr/sbin/update-grub