1#!/bin/bash
2#
3# XTF test utilities (arm64).
4#
5
6# Arch-specific environment overrides.
7function xtf_arch_prepare()
8{
9    export FW_PREFIX="${FW_PREFIX:-/usr/lib/u-boot/qemu_arm64/}"
10    export QEMU_PREFIX="${QEMU_PREFIX:-${WORKDIR}/}"
11    export XEN_BINARY="${XEN_BINARY:-${WORKDIR}/xen}"
12    export XEN_CMDLINE="${XEN_CMDLINE:-loglvl=all noreboot console_timestamps=boot console=dtuart}"
13    export XTF_SRC_BRANCH="${XTF_SRC_BRANCH:-xtf-arm}"
14    export XTF_SRC_URI="${XTF_SRC_URI:-https://gitlab.com/xen-project/fusa/xtf.git}"
15    export XTF_SRC_VARIANTS="mmu64le"
16}
17
18# Perform arch-specific XTF environment setup.
19function xtf_arch_setup()
20{
21    # QEMU looks for "efi-virtio.rom" even if it is unneeded
22    curl -fsSLO https://github.com/qemu/qemu/raw/v5.2.0/pc-bios/efi-virtio.rom
23
24    # Crude check for local testing
25    if [ ! -d imagebuilder ]; then
26        git clone --depth 1 https://gitlab.com/xen-project/imagebuilder.git
27    fi
28
29    cat > ${WORKDIR}/config <<EOF
30MEMORY_START="0x40000000"
31MEMORY_END="0xC0000000"
32
33XEN="xen"
34DEVICE_TREE="virt-gicv2.dtb"
35
36XEN_CMD="${XEN_CMDLINE}"
37
38DOMU_KERNEL[0]="xtf-test"
39DOMU_MEM[0]="128"
40
41NUM_DOMUS=1
42
43LOAD_CMD="tftpb"
44UBOOT_SOURCE="boot.source"
45UBOOT_SCRIPT="boot.scr"
46EOF
47    cp ${XTF_BINARY} ${WORKDIR}/xtf-test
48
49    # Generate virt-gicv2.dtb
50    ${WORKDIR}/qemu-system-aarch64 \
51        -machine virtualization=true \
52        -cpu cortex-a57 \
53        -machine type=virt \
54        -m 2048 \
55        -smp 2 \
56        -display none \
57        -machine dumpdtb=${WORKDIR}/virt-gicv2.dtb
58
59    # Generate U-Boot environment
60    bash -x imagebuilder/scripts/uboot-script-gen \
61        -t tftp \
62        -d ${WORKDIR}/ \
63        -c ${WORKDIR}/config
64
65    export TEST_CMD="${QEMU_PREFIX}qemu-system-aarch64 \
66        -machine virtualization=true \
67        -cpu cortex-a57 \
68        -machine type=virt \
69        -no-reboot \
70        -nographic \
71        -monitor none \
72        -serial stdio \
73        -m 2048 \
74        -smp 2 \
75        -device virtio-net-pci,netdev=n0 \
76        -netdev user,id=n0,tftp=${WORKDIR} \
77        -bios ${FW_PREFIX}u-boot.bin \
78    "
79
80    export UBOOT_CMD="virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"
81}
82