xref: /openbmc/openbmc-tools/prepare-emmc-qemu/prepare-emmc-qemu (revision 1800ed4d798fdb26013cfbbead7e28afc7a96c65)
1#!/bin/sh
2
3set -eu
4
5print_help() {
6    script_name=$(basename $0)
7    echo NAME
8    echo '\t'$script_name: Assemble an OpenBMC eMMC image that can be booted under QEMU
9    echo
10    echo SYNOPSYS
11    echo '\t'$script_name '<TARGET>' '<BUILDDIR>' '[IMAGESIZE]'
12    echo
13    echo DESCRIPTION
14    echo '\t''TARGET':'\t\t'The name of the target machine, used to locate the required images.
15    echo '\t''BUILDDIR':'\t'The path to the OpenBMC build directory.
16    echo '\t''IMAGESIZE':'\t'The output image size, may be specified with units. Defaults to 16G.
17    echo
18    echo EXAMPLE:
19    echo '\t'$script_name 'p10bmc' '~/src/openbmc/openbmc/build/p10bmc'
20}
21
22if [ $# -eq 0 ]
23then
24    print_help
25    exit 1
26fi
27
28if [ "$1" = "-h" -o "$1" = "--help" ]
29then
30    print_help
31    exit 0
32fi
33
34if [ $# -lt 2 ]
35then
36    print_help
37    exit 1
38fi
39
40set -x
41
42target="$1"
43build_dir="$2"
44image_size=${3:-16G}
45
46fw_dir=${build_dir}/tmp/deploy/images/${target}
47wicxz="${fw_dir}/obmc-phosphor-image-${target}.wic.xz"
48mmc="mmc-${target}.img"
49
50dd of=$mmc if=/dev/zero bs=1M count=128
51dd of=$mmc if=${fw_dir}/u-boot-spl.bin conv=notrunc
52dd of=$mmc if=${fw_dir}/u-boot.bin conv=notrunc bs=1K seek=64
53xzdec $wicxz | dd of=$mmc conv=notrunc bs=1M seek=2
54truncate --size ${image_size} $mmc
55
56set +x
57
58echo
59echo For an AST2600-based machine, invoke QEMU with the following parameters:
60echo
61echo '\t'-drive file=$(realpath ${mmc}),if=sd,format=raw,index=2
62