Andrew Jeffery | 1800ed4 | 2021-09-27 10:24:33 +0930 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | set -eu |
| 4 | |
| 5 | print_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 | |
Joseph Reynolds | 9949cc7 | 2021-12-17 11:40:40 -0600 | [diff] [blame] | 22 | detect_xzdec() { |
| 23 | if command -v xz >/dev/null |
| 24 | then |
| 25 | echo xz -dc |
| 26 | elif command -v xzdec >/dev/null |
| 27 | then |
| 28 | echo xzdec |
| 29 | fi |
| 30 | } |
| 31 | |
Andrew Jeffery | 1800ed4 | 2021-09-27 10:24:33 +0930 | [diff] [blame] | 32 | if [ $# -eq 0 ] |
| 33 | then |
| 34 | print_help |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | if [ "$1" = "-h" -o "$1" = "--help" ] |
| 39 | then |
| 40 | print_help |
| 41 | exit 0 |
| 42 | fi |
| 43 | |
| 44 | if [ $# -lt 2 ] |
| 45 | then |
| 46 | print_help |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
Joseph Reynolds | 9949cc7 | 2021-12-17 11:40:40 -0600 | [diff] [blame] | 50 | |
| 51 | XZDEC=$(detect_xzdec) |
| 52 | if [ -z "$XZDEC" ]; then |
| 53 | echo >&2 "XZ decompress is not available (xz or xzdec). Stopping." |
| 54 | exit 1 |
| 55 | fi |
Konstantin Aladyshev | 5ec6208 | 2021-12-14 11:27:43 +0300 | [diff] [blame] | 56 | |
Andrew Jeffery | 1800ed4 | 2021-09-27 10:24:33 +0930 | [diff] [blame] | 57 | set -x |
| 58 | |
| 59 | target="$1" |
| 60 | build_dir="$2" |
| 61 | image_size=${3:-16G} |
| 62 | |
| 63 | fw_dir=${build_dir}/tmp/deploy/images/${target} |
| 64 | wicxz="${fw_dir}/obmc-phosphor-image-${target}.wic.xz" |
| 65 | mmc="mmc-${target}.img" |
| 66 | |
| 67 | dd of=$mmc if=/dev/zero bs=1M count=128 |
| 68 | dd of=$mmc if=${fw_dir}/u-boot-spl.bin conv=notrunc |
| 69 | dd of=$mmc if=${fw_dir}/u-boot.bin conv=notrunc bs=1K seek=64 |
Joseph Reynolds | 9949cc7 | 2021-12-17 11:40:40 -0600 | [diff] [blame] | 70 | ${XZDEC} $wicxz | dd of=$mmc conv=notrunc bs=1M seek=2 |
Andrew Jeffery | 1800ed4 | 2021-09-27 10:24:33 +0930 | [diff] [blame] | 71 | truncate --size ${image_size} $mmc |
| 72 | |
| 73 | set +x |
| 74 | |
| 75 | echo |
| 76 | echo For an AST2600-based machine, invoke QEMU with the following parameters: |
| 77 | echo |
| 78 | echo '\t'-drive file=$(realpath ${mmc}),if=sd,format=raw,index=2 |