xref: /openbmc/openbmc-tools/prepare-emmc-qemu/prepare-emmc-qemu (revision 5ec6208b5923491396ff554dfb278dd742ef2eca)
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
40xzdec -V > /dev/null
41
42set -x
43
44target="$1"
45build_dir="$2"
46image_size=${3:-16G}
47
48fw_dir=${build_dir}/tmp/deploy/images/${target}
49wicxz="${fw_dir}/obmc-phosphor-image-${target}.wic.xz"
50mmc="mmc-${target}.img"
51
52dd of=$mmc if=/dev/zero bs=1M count=128
53dd of=$mmc if=${fw_dir}/u-boot-spl.bin conv=notrunc
54dd of=$mmc if=${fw_dir}/u-boot.bin conv=notrunc bs=1K seek=64
55xzdec $wicxz | dd of=$mmc conv=notrunc bs=1M seek=2
56truncate --size ${image_size} $mmc
57
58set +x
59
60echo
61echo For an AST2600-based machine, invoke QEMU with the following parameters:
62echo
63echo '\t'-drive file=$(realpath ${mmc}),if=sd,format=raw,index=2
64