Add prepare-emmc-qemu

prepare-emmc-qemu is a script that assembles a bootable eMMC image from
the WIC and u-boot artefacts of an eMMC-based build of OpenBMC:

```
andrew@mistburn:~/src/openbmc/openbmc/build/p10bmc $ prepare-emmc-qemu -h
NAME
        prepare-emmc-qemu: Assemble an OpenBMC eMMC image that can be booted under QEMU

SYNOPSYS
        prepare-emmc-qemu <TARGET> <BUILDDIR> [IMAGESIZE]

DESCRIPTION
        TARGET:         The name of the target machine, used to locate the required images.
        BUILDDIR:       The path to the OpenBMC build directory.
        IMAGESIZE:      The output image size, may be specified with units. Defaults to 16G.

EXAMPLE:
        prepare-emmc-qemu p10bmc ~/src/openbmc/openbmc/build/p10bmc
andrew@mistburn:~/src/openbmc/openbmc/build/p10bmc $ prepare-emmc-qemu p10bmc .
+ target=p10bmc
+ build_dir=.
+ image_size=16G
+ fw_dir=./tmp/deploy/images/p10bmc
+ wicxz=./tmp/deploy/images/p10bmc/obmc-phosphor-image-p10bmc.wic.xz
+ mmc=mmc-p10bmc.img
+ dd of=mmc-p10bmc.img if=/dev/zero bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB, 128 MiB) copied, 0.115718 s, 1.2 GB/s
+ dd of=mmc-p10bmc.img if=./tmp/deploy/images/p10bmc/u-boot-spl.bin conv=notrunc
107+0 records in
107+0 records out
54784 bytes (55 kB, 54 KiB) copied, 0.00642483 s, 8.5 MB/s
+ dd of=mmc-p10bmc.img if=./tmp/deploy/images/p10bmc/u-boot.bin conv=notrunc bs=1K seek=64
411+1 records in
411+1 records out
421275 bytes (421 kB, 411 KiB) copied, 0.0129515 s, 32.5 MB/s
+ xzdec ./tmp/deploy/images/p10bmc/obmc-phosphor-image-p10bmc.wic.xz
+ dd of=mmc-p10bmc.img conv=notrunc bs=1M seek=2
0+1846910 records in
0+1846910 records out
15167689728 bytes (15 GB, 14 GiB) copied, 100.126 s, 151 MB/s
+ truncate --size 16G mmc-p10bmc.img
+ set +x

For an AST2600-based machine, invoke QEMU with the following parameters:

        -drive file=/home/andrew/src/openbmc/openbmc/build/p10bmc/mmc-p10bmc.img,if=sd,format=raw,index=2
```

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I9dff01b4f85aa51e3253a6989bcd80bb2c48b6a9
diff --git a/prepare-emmc-qemu/prepare-emmc-qemu b/prepare-emmc-qemu/prepare-emmc-qemu
new file mode 100755
index 0000000..e7cbadf
--- /dev/null
+++ b/prepare-emmc-qemu/prepare-emmc-qemu
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+set -eu
+
+print_help() {
+    script_name=$(basename $0)
+    echo NAME
+    echo '\t'$script_name: Assemble an OpenBMC eMMC image that can be booted under QEMU
+    echo
+    echo SYNOPSYS
+    echo '\t'$script_name '<TARGET>' '<BUILDDIR>' '[IMAGESIZE]'
+    echo
+    echo DESCRIPTION
+    echo '\t''TARGET':'\t\t'The name of the target machine, used to locate the required images.
+    echo '\t''BUILDDIR':'\t'The path to the OpenBMC build directory.
+    echo '\t''IMAGESIZE':'\t'The output image size, may be specified with units. Defaults to 16G.
+    echo
+    echo EXAMPLE:
+    echo '\t'$script_name 'p10bmc' '~/src/openbmc/openbmc/build/p10bmc'
+}
+
+if [ $# -eq 0 ]
+then
+    print_help
+    exit 1
+fi
+
+if [ "$1" = "-h" -o "$1" = "--help" ]
+then
+    print_help
+    exit 0
+fi
+
+if [ $# -lt 2 ]
+then
+    print_help
+    exit 1
+fi
+
+set -x
+
+target="$1"
+build_dir="$2"
+image_size=${3:-16G}
+
+fw_dir=${build_dir}/tmp/deploy/images/${target}
+wicxz="${fw_dir}/obmc-phosphor-image-${target}.wic.xz"
+mmc="mmc-${target}.img"
+
+dd of=$mmc if=/dev/zero bs=1M count=128
+dd of=$mmc if=${fw_dir}/u-boot-spl.bin conv=notrunc
+dd of=$mmc if=${fw_dir}/u-boot.bin conv=notrunc bs=1K seek=64
+xzdec $wicxz | dd of=$mmc conv=notrunc bs=1M seek=2
+truncate --size ${image_size} $mmc
+
+set +x
+
+echo
+echo For an AST2600-based machine, invoke QEMU with the following parameters:
+echo
+echo '\t'-drive file=$(realpath ${mmc}),if=sd,format=raw,index=2