#!/bin/sh # emmc_deploy.sh -- write a Zynq-7000 production system (FAT boot + ext4 root) to # eMMC/SD from the QSPI rescue Linux. TEMPLATE from the release_zynq7k skill: # fill the variables below from the board's evidence (fdisk -l / /proc/partitions, # the project's proven deploy script), then test it once on the board and say so # in the README until that happened. # # sh emmc_deploy.sh [--partition] # # The PC serves, by TFTP: every file in BOOT_FILES, ROOTFS and SUMS. set -e # ---------------------------------------------------------------- board profile DEV=/dev/mmcblk1 # verified device node (NOT inferred from the name) P1_START=16 # DOS partition plan, sectors (only used with --partition) P1_SIZE=250032 P1_TYPE=b # b = FAT32 P2_START=250048 # p2 runs to the end of the device BOOT_FILES="image.ub system_top.bin" # copied to p1 (FAT); keep FAT capacity in mind ROOTFS=rootfs.tar.gz # extracted to p2 (ext4) SUMS=EMMC_SHA256SUMS # sha256sum -c format for BOOT_FILES + ROOTFS CHECK_IN_ROOT="usr/bin/app etc/init.d/app-init" # read back after writing # ------------------------------------------------------------------------------ PC=${1:?usage: emmc_deploy.sh [--partition]} W=/tmp/e2 if grep " / " /proc/mounts | grep -q "$(basename $DEV)"; then echo "running from $DEV: boot the QSPI rescue system"; exit 1 fi [ -b $DEV ] || { echo "$DEV missing"; exit 1; } cat /sys/block/$(basename $DEV)/device/type /sys/block/$(basename $DEV)/device/name /sys/block/$(basename $DEV)/size mkdir -p $W && cd $W for f in $SUMS $BOOT_FILES $ROOTFS; do rm -f $f; tftp -g -r $f $PC done sha256sum -c $SUMS # a failed transfer stops here, before any write echo SHA_OK [ -f /etc/udev/rules.d/automount.rules ] && mv /etc/udev/rules.d/automount.rules /tmp/automount.rules.off && udevadm control --reload-rules || true umount ${DEV}p1 2>/dev/null || true umount ${DEV}p2 2>/dev/null || true if grep -q "$(basename $DEV)" /proc/mounts; then echo "$DEV still mounted"; exit 1; fi if [ "$2" = "--partition" ]; then printf 'label: dos\nstart=%s, size=%s, type=%s\nstart=%s, type=83\n' \ $P1_START $P1_SIZE $P1_TYPE $P2_START | sfdisk $DEV sleep 1 fi [ -b ${DEV}p1 ] && [ -b ${DEV}p2 ] || { echo "no p1/p2 on $DEV (use --partition)"; exit 1; } mkfs.vfat -F 32 -n BOOT ${DEV}p1 mkfs.ext4 -F -q -L rootfs ${DEV}p2 mkdir -p /mnt/b /mnt/r mount -t vfat ${DEV}p1 /mnt/b mount -t ext4 ${DEV}p2 /mnt/r for f in $BOOT_FILES; do cp $W/$f /mnt/b/$f; done tar xzf $W/$ROOTFS -C /mnt/r sync cd / umount /mnt/b umount /mnt/r sync fsck.vfat -n ${DEV}p1 | tail -n 1 e2fsck -fn ${DEV}p2 | tail -n 1 echo 3 > /proc/sys/vm/drop_caches mount -o ro -t vfat ${DEV}p1 /mnt/b mount -o ro -t ext4 ${DEV}p2 /mnt/r for f in $BOOT_FILES; do sha256sum /mnt/b/$f; done for f in $CHECK_IN_ROOT; do sha256sum /mnt/r/$f; done umount /mnt/b umount /mnt/r [ -f /tmp/automount.rules.off ] && mv /tmp/automount.rules.off /etc/udev/rules.d/automount.rules || true echo "EMMC_DEPLOY_DONE -- compare the hashes above with 00_SHA256SUMS, then power-cycle"