1#!/bin/bash
2
3set -eu
4set -x
5
6ARTIFACT_DIR=$(mktemp -d)
7
8trap 'rm -rf ${ARTIFACT_DIR}' EXIT
9
10function acquire() {
11    local target="$1"
12    wget --quiet --show-progress --directory-prefix="${ARTIFACT_DIR}" https://jenkins.openbmc.org/view/latest/job/latest-master/lastSuccessfulBuild/label=docker-builder,target="${target}"/artifact/openbmc/build/tmp/deploy/images/"${target}"/'*zip*'/"${target}".zip
13    unzip -qq -d "${ARTIFACT_DIR}" "${ARTIFACT_DIR}"/"${target}".zip
14    echo "${ARTIFACT_DIR}"/"${target}"
15}
16
17# AST2400
18PALMETTO_ARTIFACTS="$(acquire palmetto)"
19PALMETTO_MTD="$(echo "${PALMETTO_ARTIFACTS}"/obmc-phosphor-image-palmetto-*.static.mtd)"
20# shellcheck disable=SC2016 # 'expect' strings
21expect \
22    -c "spawn qemu-system-arm \
23            -M palmetto-bmc \
24            -drive file=${PALMETTO_MTD},if=mtd,format=raw \
25            -nographic \
26            -net nic \
27    -net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostname=qemu" \
28    -c 'set timeout 300' \
29    -c 'expect timeout { exit 1 } "login:"' \
30    -c 'spawn sshpass -p 0penBmc ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p2222 root@localhost journalctl -b' \
31    -c 'expect -i $spawn_id eof'
32
33# AST2500
34ROMULUS_ARTIFACTS="$(acquire romulus)"
35ROMULUS_MTD="$(echo "${ROMULUS_ARTIFACTS}"/obmc-phosphor-image-romulus*.mtd)"
36# shellcheck disable=SC2016 # 'expect' strings
37expect \
38    -c "spawn qemu-system-arm \
39            -M romulus-bmc \
40            -drive file=${ROMULUS_MTD},if=mtd,format=raw \
41            -nographic \
42            -net nic \
43    -net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostname=qemu" \
44    -c 'set timeout 300' \
45    -c 'expect timeout { exit 1 } "login:"' \
46    -c 'spawn sshpass -p 0penBmc ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p2222 root@localhost journalctl -b' \
47    -c 'expect -i $spawn_id eof'
48
49# AST2600
50P10BMC_ARTIFACTS="$(acquire p10bmc)"
51
52P10BMC_WIC_XZ="$(echo "${P10BMC_ARTIFACTS}"/obmc-phosphor-image-p10bmc-*.wic.xz)"
53P10BMC_MMC="${P10BMC_WIC_XZ%.xz}"
54P10BMC_UBOOT_SPL="$(echo "${P10BMC_ARTIFACTS}"/u-boot-spl.bin-*)"
55P10BMC_UBOOT="$(echo "${P10BMC_ARTIFACTS}"/u-boot-p10bmc-*.bin)"
56
57dd of="$P10BMC_MMC" if=/dev/zero bs=1M count=2
58dd of="$P10BMC_MMC" if="$P10BMC_UBOOT_SPL" conv=notrunc
59dd of="$P10BMC_MMC" if="$P10BMC_UBOOT" conv=notrunc bs=1K seek=64
60
61xz --decompress --stdout --keep "$P10BMC_WIC_XZ" | dd of="$P10BMC_MMC" conv=notrunc bs=1M seek=2
62
63truncate -s 16G "$P10BMC_MMC"
64
65# shellcheck disable=SC2016 # 'expect' strings
66expect \
67    -c "spawn qemu-system-arm -M rainier-bmc \
68            -drive file=${P10BMC_MMC},if=sd,format=raw,index=2 \
69            -net nic \
70            -net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostname=qemu \
71    -nographic" \
72    -c 'set timeout 300' \
73    -c 'expect timeout { exit 1 } "login:"' \
74    -c 'spawn sshpass -p 0penBmc ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p2222 root@localhost journalctl -b' \
75    -c 'expect -i $spawn_id eof'
76