2019-04-10 13:41:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-09-05 19:03:34 +00:00
|
|
|
# Install pkgbase packages for loader, kernel, and enough of userland to boot
|
|
|
|
# in QEMU and echo "Hello world." from init, as a very quick smoke test for CI.
|
|
|
|
# Uses QEMU's virtual FAT filesystem to avoid the need to create a disk image.
|
|
|
|
# While designed for CI automated testing, this script can also be run by hand
|
|
|
|
# as a quick smoke-test as long as pkgbase packages have been built. The
|
|
|
|
# rootgen.sh and related scripts generate much more extensive tests for many
|
|
|
|
# combinations of boot env (ufs, zfs, geli, etc).
|
2019-04-10 13:41:34 +00:00
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-04-17 16:27:43 +00:00
|
|
|
die()
|
|
|
|
{
|
|
|
|
echo "$*" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
tempdir_cleanup()
|
|
|
|
{
|
|
|
|
trap - EXIT SIGINT SIGHUP SIGTERM SIGQUIT
|
|
|
|
rm -rf ${ROOTDIR}
|
|
|
|
}
|
|
|
|
|
|
|
|
tempdir_setup()
|
|
|
|
{
|
|
|
|
# Create minimal directory structure and populate it.
|
|
|
|
|
|
|
|
for dir in dev bin efi/boot etc lib libexec sbin usr/lib usr/libexec; do
|
|
|
|
mkdir -p ${ROOTDIR}/${dir}
|
|
|
|
done
|
|
|
|
|
|
|
|
# Install kernel, loader and minimal userland.
|
2020-09-05 19:03:34 +00:00
|
|
|
cat<<EOF >${ROOTDIR}/pkg.conf
|
|
|
|
REPOS_DIR=[]
|
|
|
|
repositories={local {url = file://$(dirname $OBJTOP)/repo/\${ABI}/latest}}
|
|
|
|
EOF
|
|
|
|
ASSUME_ALWAYS_YES=true INSTALL_AS_USER=true pkg \
|
|
|
|
-o ABI_FILE=$OBJTOP/bin/sh/sh \
|
|
|
|
-C ${ROOTDIR}/pkg.conf -r ${ROOTDIR} install \
|
|
|
|
FreeBSD-kernel-generic FreeBSD-bootloader \
|
|
|
|
FreeBSD-clibs FreeBSD-runtime
|
2019-04-17 16:27:43 +00:00
|
|
|
|
|
|
|
# Put loader in standard EFI location.
|
2021-06-23 19:24:23 +00:00
|
|
|
mv ${ROOTDIR}/boot/loader.efi ${ROOTDIR}/efi/boot/$EFIBOOT
|
2019-04-17 16:27:43 +00:00
|
|
|
|
|
|
|
# Configuration files.
|
|
|
|
cat > ${ROOTDIR}/boot/loader.conf <<EOF
|
2021-06-23 19:24:23 +00:00
|
|
|
vfs.root.mountfrom="msdosfs:/dev/$ROOTDEV"
|
2019-04-10 13:41:34 +00:00
|
|
|
autoboot_delay=-1
|
|
|
|
boot_verbose=YES
|
|
|
|
EOF
|
2019-04-17 16:27:43 +00:00
|
|
|
cat > ${ROOTDIR}/etc/rc <<EOF
|
2019-04-10 13:41:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
echo "Hello world."
|
2020-02-29 19:59:21 +00:00
|
|
|
/sbin/sysctl vm.stats.vm.v_wire_count
|
2019-04-10 13:41:34 +00:00
|
|
|
/sbin/shutdown -p now
|
|
|
|
EOF
|
|
|
|
|
2019-04-17 19:16:26 +00:00
|
|
|
# Entropy needed to boot, see r346250 and followup commits/discussion.
|
|
|
|
dd if=/dev/random of=${ROOTDIR}/boot/entropy bs=4k count=1
|
|
|
|
|
2019-04-17 16:27:43 +00:00
|
|
|
# Remove unnecessary files to keep FAT filesystem size down.
|
|
|
|
rm -rf ${ROOTDIR}/METALOG ${ROOTDIR}/usr/lib
|
|
|
|
}
|
|
|
|
|
|
|
|
# Locate the top of the source tree, to run make install from.
|
|
|
|
: ${SRCTOP:=$(make -V SRCTOP)}
|
|
|
|
if [ -z "${SRCTOP}" ]; then
|
|
|
|
die "Cannot locate top of source tree"
|
|
|
|
fi
|
2020-09-05 19:03:34 +00:00
|
|
|
: ${OBJTOP:=$(make -V OBJTOP)}
|
|
|
|
if [ -z "${OBJTOP}" ]; then
|
|
|
|
die "Cannot locate top of object tree"
|
|
|
|
fi
|
2019-04-17 16:27:43 +00:00
|
|
|
|
2021-06-23 19:24:23 +00:00
|
|
|
: ${TARGET:=$(uname -m)}
|
|
|
|
case $TARGET in
|
|
|
|
amd64)
|
|
|
|
# Locate the uefi firmware file used by qemu.
|
|
|
|
: ${OVMF:=/usr/local/share/qemu/edk2-x86_64-code.fd}
|
|
|
|
if [ ! -r "${OVMF}" ]; then
|
|
|
|
die "Cannot read UEFI firmware file ${OVMF}"
|
|
|
|
fi
|
|
|
|
QEMU="qemu-system-x86_64 -drive if=pflash,format=raw,readonly,file=${OVMF}"
|
|
|
|
EFIBOOT=BOOTx64.EFI
|
|
|
|
ROOTDEV=ada0s1
|
|
|
|
;;
|
|
|
|
arm64)
|
|
|
|
QEMU="qemu-system-aarch64 -cpu cortex-a57 -M virt -bios edk2-aarch64-code.fd"
|
|
|
|
EFIBOOT=BOOTAA64.EFI
|
|
|
|
ROOTDEV=vtbd0s1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
die "Unknown TARGET:TARGET_ARCH $TARGET:$TARGET_ARCH"
|
|
|
|
esac
|
2019-04-17 16:27:43 +00:00
|
|
|
|
|
|
|
# Create a temp dir to hold the boot image.
|
|
|
|
ROOTDIR=$(mktemp -d -t ci-qemu-test-fat-root)
|
|
|
|
trap tempdir_cleanup EXIT SIGINT SIGHUP SIGTERM SIGQUIT
|
|
|
|
|
|
|
|
# Populate the boot image in a temp dir.
|
|
|
|
( cd ${SRCTOP} && tempdir_setup )
|
2019-04-10 13:41:34 +00:00
|
|
|
|
|
|
|
# And, boot in QEMU.
|
2019-04-17 19:24:41 +00:00
|
|
|
: ${BOOTLOG:=${TMPDIR:-/tmp}/ci-qemu-test-boot.log}
|
2019-04-10 13:41:34 +00:00
|
|
|
timeout 300 \
|
2021-06-23 19:24:23 +00:00
|
|
|
$QEMU -m 256M -nodefaults \
|
2019-04-17 16:27:43 +00:00
|
|
|
-serial stdio -vga none -nographic -monitor none \
|
|
|
|
-snapshot -hda fat:${ROOTDIR} 2>&1 | tee ${BOOTLOG}
|
|
|
|
|
|
|
|
# Check whether we succesfully booted...
|
|
|
|
if grep -q 'Hello world.' ${BOOTLOG}; then
|
|
|
|
echo "OK"
|
|
|
|
else
|
|
|
|
die "Did not boot successfully, see ${BOOTLOG}"
|
|
|
|
fi
|