1858a73f1SWarner Losh#!/bin/sh 2858a73f1SWarner Losh 3858a73f1SWarner Losh# STAND_ROOT is the root of a tree: 4858a73f1SWarner Losh# cache - Cached binaries that we have downloaded 5858a73f1SWarner Losh# trees - binary trees that we use to make image 6858a73f1SWarner Losh# trees/${ARCH}/$thing 7858a73f1SWarner Losh# images - bootable images that we use to test 8858a73f1SWarner Losh# images/${ARCH}/$thing 9858a73f1SWarner Losh# bios - cached bios images (as well as 'vars' files when we start testing 10858a73f1SWarner Losh# different booting scenarios in the precense / absence of variables). 11858a73f1SWarner Losh# scripts - generated scripts that uses images to run the tests. 12858a73f1SWarner Losh# 13858a73f1SWarner Losh# Strategy: 14858a73f1SWarner Losh# Download FreeBSD release isos, Linux kernels (for the kboot tests) and 15858a73f1SWarner Losh# other misc things. We use these to generate dozens of test images that we 16858a73f1SWarner Losh# use qemu-system-XXXX to boot. They all boot the same thing at the moment: 17858a73f1SWarner Losh# an /etc/rc script that prints the boot method, echos success and then 18858a73f1SWarner Losh# halts. 19858a73f1SWarner Losh 20858a73f1SWarner Losh# What version of FreeBSD to we snag the ISOs from to extract the binaries 21858a73f1SWarner Losh# we are testing 22858a73f1SWarner LoshFREEBSD_VERSION=13.1 23858a73f1SWarner Losh# eg https://download.freebsd.org/releases/amd64/amd64/ISO-IMAGES/13.1/FreeBSD-13.1-RELEASE-amd64-bootonly.iso.xz 24858a73f1SWarner LoshURLBASE="https://download.freebsd.org/releases" 25858a73f1SWarner Losh: ${STAND_ROOT:="${HOME}/stand-test-root"} 26858a73f1SWarner LoshCACHE=${STAND_ROOT}/cache 27858a73f1SWarner LoshTREES=${STAND_ROOT}/trees 28858a73f1SWarner LoshIMAGES=${STAND_ROOT}/images 29858a73f1SWarner LoshBIOS=${STAND_ROOT}/bios 30858a73f1SWarner LoshSCRIPTS=${STAND_ROOT}/scripts 31858a73f1SWarner LoshOVERRIDE=${STAND_ROOT}/override 32858a73f1SWarner Losh 33858a73f1SWarner Losh# hack -- I have extra junk in my qemu, but it's not needed to recreate things 34858a73f1SWarner Loshif [ $(whoami) = imp ]; then 35858a73f1SWarner Losh qemu_bin=/home/imp/git/qemu/00-build 36858a73f1SWarner Loshelse 37858a73f1SWarner Losh qemu_bin=/usr/local/bin 38858a73f1SWarner Loshfi 39858a73f1SWarner Losh 40858a73f1SWarner Losh# All the architectures under test 41858a73f1SWarner Losh# Note: we can't yet do armv7 because we don't have a good iso for it and would 42858a73f1SWarner Losh# need root to extract the files. 43858a73f1SWarner LoshARCHES="amd64:amd64 i386:i386 powerpc:powerpc powerpc:powerpc64 powerpc:powerpc64le powerpc:powerpcspe arm64:aarch64 riscv:riscv64" 44858a73f1SWarner Losh 45858a73f1SWarner Losh# The smallest FAT32 filesystem is 33292 KB 46858a73f1SWarner Loshespsize=33292 47858a73f1SWarner Losh 48858a73f1SWarner LoshSRCTOP=$(make -v SRCTOP) 49858a73f1SWarner Losh 50858a73f1SWarner Loshmkdir -p ${CACHE} ${TREES} ${IMAGES} ${BIOS} 51858a73f1SWarner Losh 52858a73f1SWarner Loshdie() 53858a73f1SWarner Losh{ 54858a73f1SWarner Losh echo Fatal Error: $* 55858a73f1SWarner Losh exit 1 56858a73f1SWarner Losh} 57858a73f1SWarner Losh 58858a73f1SWarner Loshma_combo() 59858a73f1SWarner Losh{ 60858a73f1SWarner Losh local m=$1 61858a73f1SWarner Losh local ma=$2 62858a73f1SWarner Losh local ma_combo="${m}" 63858a73f1SWarner Losh 64858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 65858a73f1SWarner Losh echo ${ma_combo} 66858a73f1SWarner Losh} 67858a73f1SWarner Losh 68858a73f1SWarner Loshfetch_one() 69858a73f1SWarner Losh{ 70858a73f1SWarner Losh local m=$1 71858a73f1SWarner Losh local ma=$2 72858a73f1SWarner Losh local v=$3 73858a73f1SWarner Losh local flavor=$4 74858a73f1SWarner Losh local ma_combo=$(ma_combo $m $ma) 75858a73f1SWarner Losh local file="FreeBSD-${v}-RELEASE-${ma_combo}-${flavor}" 76858a73f1SWarner Losh local url="${URLBASE}/${m}/${ma}/ISO-IMAGES/${v}/${file}.xz" 77858a73f1SWarner Losh 78858a73f1SWarner Losh mkdir -p ${CACHE} 79858a73f1SWarner Losh [ -r ${CACHE}/${file} ] && echo "Using cached ${file}" && return 80858a73f1SWarner Losh cd ${CACHE} 81858a73f1SWarner Losh echo "Fetching ${url}" 82858a73f1SWarner Losh fetch ${url} || die "Can't fetch ${file} from ${url}" 83858a73f1SWarner Losh xz -d ${file}.xz || die "Can't uncompress ${file}.xz" 84858a73f1SWarner Losh cd .. 85858a73f1SWarner Losh} 86858a73f1SWarner Losh 87858a73f1SWarner Loshupdate_freebsd_img_cache() 88858a73f1SWarner Losh{ 89858a73f1SWarner Losh local a m ma 90858a73f1SWarner Losh 91858a73f1SWarner Losh for a in $ARCHES; do 92858a73f1SWarner Losh m=${a%%:*} 93858a73f1SWarner Losh ma=${a##*:} 94858a73f1SWarner Losh fetch_one $m $ma ${FREEBSD_VERSION} bootonly.iso 95858a73f1SWarner Losh done 96858a73f1SWarner Losh 97858a73f1SWarner Losh fetch_one arm armv7 ${FREEBSD_VERSION} GENERICSD.img 98858a73f1SWarner Losh} 99858a73f1SWarner Losh 100858a73f1SWarner Loshmake_minimal_freebsd_tree() 101858a73f1SWarner Losh{ 102858a73f1SWarner Losh local m=$1 103858a73f1SWarner Losh local ma=$2 104858a73f1SWarner Losh local v=$3 105858a73f1SWarner Losh local flavor=$4 106858a73f1SWarner Losh local file d 107858a73f1SWarner Losh local ma_combo="${m}" 108858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 109858a73f1SWarner Losh 110858a73f1SWarner Losh file="FreeBSD-${v}-RELEASE-${ma_combo}-${flavor}" 111858a73f1SWarner Losh dir=${TREES}/${ma_combo}/freebsd 112858a73f1SWarner Losh rm -rf ${dir} 113858a73f1SWarner Losh 114858a73f1SWarner Losh # Make a super simple userland. It has just enough to print a santiy value, 115858a73f1SWarner Losh # then say test succeeded, and then halt the system. We assume that /bin/sh 116858a73f1SWarner Losh # has all the library prereqs for the rest... 117858a73f1SWarner Losh mkdir -p ${dir} 118858a73f1SWarner Losh # Make required dirs 119858a73f1SWarner Losh for d in boot/kernel boot/defaults boot/lua boot/loader.conf.d \ 120858a73f1SWarner Losh sbin bin lib libexec etc dev; do 121858a73f1SWarner Losh mkdir -p ${dir}/${d} 122858a73f1SWarner Losh done 123858a73f1SWarner Losh # Pretend we don't have a separate /usr 124858a73f1SWarner Losh ln -s . ${dir}/usr 125858a73f1SWarner Losh # snag the binaries for my simple /etc/rc file 126858a73f1SWarner Losh tar -C ${dir} -xf ${CACHE}/$file sbin/reboot sbin/halt sbin/init bin/sh sbin/sysctl \ 127858a73f1SWarner Losh lib/libncursesw.so.9 lib/libc.so.7 lib/libedit.so.8 libexec/ld-elf.so.1 128858a73f1SWarner Losh 129858a73f1SWarner Losh # My simple etc/rc 130858a73f1SWarner Losh cat > ${dir}/etc/rc <<EOF 131858a73f1SWarner Losh#!/bin/sh 132858a73f1SWarner Losh 133858a73f1SWarner Loshsysctl machdep.bootmethod 134858a73f1SWarner Loshecho "RC COMMAND RUNNING -- SUCCESS!!!!!" 135858a73f1SWarner Loshhalt -p 136858a73f1SWarner LoshEOF 137858a73f1SWarner Losh chmod +x ${dir}/etc/rc 138858a73f1SWarner Losh 139858a73f1SWarner Losh # Check to see if we have overrides here... So we can insert our own kernel 140858a73f1SWarner Losh # instead of the one from the release. 141858a73f1SWarner Losh echo "CHECKING ${OVERRIDE}/${ma_combo}/boot" 142858a73f1SWarner Losh if [ -d ${OVERRIDE}/${ma_combo}/boot ]; then 143858a73f1SWarner Losh o=${OVERRIDE}/${ma_combo} 144858a73f1SWarner Losh for i in \ 145858a73f1SWarner Losh boot/device.hints \ 146858a73f1SWarner Losh boot/kernel/kernel \ 147858a73f1SWarner Losh boot/kernel/acl_nfs4.ko \ 148858a73f1SWarner Losh boot/kernel/cryptodev.ko \ 149858a73f1SWarner Losh boot/kernel/zfs.ko \ 150858a73f1SWarner Losh boot/kernel/geom_eli.ko; do 151858a73f1SWarner Losh [ -r $o/$i ] && echo Copying override $i && cp $o/$i ${dir}/$i 152858a73f1SWarner Losh done 153858a73f1SWarner Losh else 154858a73f1SWarner Losh # Copy the kernel (but not the boot loader, we'll add the one to test later) 155858a73f1SWarner Losh # This will take care of both UFS and ZFS boots as well as geli 156858a73f1SWarner Losh # Note: It's OK for device.hints to be missing. It's mostly for legacy platforms. 157858a73f1SWarner Losh tar -C ${dir} -xf ${CACHE}/$file \ 158858a73f1SWarner Losh boot/device.hints \ 159858a73f1SWarner Losh boot/kernel/kernel \ 160858a73f1SWarner Losh boot/kernel/acl_nfs4.ko \ 161858a73f1SWarner Losh boot/kernel/cryptodev.ko \ 162858a73f1SWarner Losh boot/kernel/zfs.ko \ 163858a73f1SWarner Losh boot/kernel/geom_eli.ko || true 164858a73f1SWarner Losh # XXX WHAT TO DO ABOUT LINKER HINTS -- PUNT FOR NOW 165858a73f1SWarner Losh # XXX also, ZFS not supported on 32-bit powerpc platforms 166858a73f1SWarner Losh fi 167858a73f1SWarner Losh 168858a73f1SWarner Losh # Setup some common settings for serial console, etc 169858a73f1SWarner Losh echo -h -D -S115200 > ${dir}/boot.config 170858a73f1SWarner Losh cat > ${dir}/boot/loader.conf <<EOF 171858a73f1SWarner Loshcomconsole_speed=115200 172858a73f1SWarner Loshautoboot_delay=2 173*a5c0d551SWarner Loshzfs_load="YES" 174858a73f1SWarner Loshboot_verbose=yes 175858a73f1SWarner Loshkern.cfg.order="acpi,fdt" 176858a73f1SWarner LoshEOF 177858a73f1SWarner Losh} 178858a73f1SWarner Losh 179858a73f1SWarner Loshmake_freebsd_minimal_trees() 180858a73f1SWarner Losh{ 181858a73f1SWarner Losh for a in $ARCHES; do 182858a73f1SWarner Losh m=${a%%:*} 183858a73f1SWarner Losh ma=${a##*:} 184858a73f1SWarner Losh make_minimal_freebsd_tree $m $ma ${FREEBSD_VERSION} bootonly.iso 185858a73f1SWarner Losh done 186858a73f1SWarner Losh # Note: armv7 isn't done yet as its the odd-man out -- we need to extract things 187858a73f1SWarner Losh # in a special way, so punt for the moment 188858a73f1SWarner Losh} 189858a73f1SWarner Losh 190858a73f1SWarner Loshmake_freebsd_test_trees() 191858a73f1SWarner Losh{ 192858a73f1SWarner Losh for a in $ARCHES; do 193858a73f1SWarner Losh m=${a%%:*} 194858a73f1SWarner Losh ma=${a##*:} 195858a73f1SWarner Losh ma_combo="${m}" 196858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 197858a73f1SWarner Losh dir=${TREES}/${ma_combo}/test-stand 198858a73f1SWarner Losh mkdir -p ${dir} 199858a73f1SWarner Losh mtree -deUW -f ${SRCTOP}/etc/mtree/BSD.root.dist -p ${dir} 200858a73f1SWarner Losh echo "Creating tree for ${m}:${ma}" 201858a73f1SWarner Losh cd ${SRCTOP}/stand 202858a73f1SWarner Losh # Indirection needed because our build system is too complex 203858a73f1SWarner Losh# SHELL="make clean" make buildenv TARGET=${m} TARGET_ARCH=${ma} 204858a73f1SWarner Losh SHELL="make -j 100 all" make buildenv TARGET=${m} TARGET_ARCH=${ma} 205858a73f1SWarner Losh SHELL="make install DESTDIR=${dir} MK_MAN=no MK_INSTALL_AS_USER=yes WITHOUT_DEBUG_FILES=yes" \ 206858a73f1SWarner Losh make buildenv TARGET=${m} TARGET_ARCH=${ma} 207858a73f1SWarner Losh rm -rf ${dir}/bin ${dir}/[ac-z]* # Don't care about anything here 208858a73f1SWarner Losh done 209858a73f1SWarner Losh} 210858a73f1SWarner Losh 211858a73f1SWarner Loshmake_linux_initrds() 212858a73f1SWarner Losh{ 213858a73f1SWarner Losh # At the moment, we have just two 214858a73f1SWarner Losh for a in amd64:amd64 arm64:aarch64; do 215858a73f1SWarner Losh m=${a%%:*} 216858a73f1SWarner Losh ma=${a##*:} 217858a73f1SWarner Losh ma_combo="${m}" 218858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 219858a73f1SWarner Losh dir=${TREES}/${ma_combo}/linuxboot 220858a73f1SWarner Losh dir2=${TREES}/${ma_combo}/test-stand 221858a73f1SWarner Losh dir3=${TREES}/${ma_combo}/freebsd 222858a73f1SWarner Losh initrd=${TREES}/${ma_combo}/initrd.img 223858a73f1SWarner Losh rm -rf ${dir} 224858a73f1SWarner Losh mkdir -p ${dir} 225858a73f1SWarner Losh cp ${dir2}/boot/loader.kboot ${dir}/init 226858a73f1SWarner Losh # Copy the boot loader 227858a73f1SWarner Losh tar -c -f - -C ${dir2} boot | tar -xf - -C ${dir} 228858a73f1SWarner Losh # Copy the boot kernel 229858a73f1SWarner Losh tar -c -f - -C ${dir3} boot | tar -xf - -C ${dir} 230858a73f1SWarner Losh (cd ${dir} ; find . | LC_ALL=C sort | cpio -o -H newc | gzip > ${initrd}) 231858a73f1SWarner Losh done 232858a73f1SWarner Losh} 233858a73f1SWarner Losh 234858a73f1SWarner Loshmake_linux_esps() 235858a73f1SWarner Losh{ 236858a73f1SWarner Losh # At the moment, we have just two 237858a73f1SWarner Losh for a in amd64:amd64 arm64:aarch64; do 238858a73f1SWarner Losh m=${a%%:*} 239858a73f1SWarner Losh ma=${a##*:} 240858a73f1SWarner Losh ma_combo="${m}" 241858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 242858a73f1SWarner Losh dir=${TREES}/${ma_combo}/linuxboot-esp 243858a73f1SWarner Losh initrd=${TREES}/${ma_combo}/initrd.img 244858a73f1SWarner Losh mkdir -p ${dir} 245858a73f1SWarner Losh case ${ma} in 246858a73f1SWarner Losh amd64) bin=x64 cons="console=ttyS0,115200" ;; 247858a73f1SWarner Losh aarch64) bin=aa64 ;; 248858a73f1SWarner Losh esac 249858a73f1SWarner Losh mkdir -p ${dir}/efi/boot 250858a73f1SWarner Losh cp ${CACHE}/linux/linux${bin}.efi ${dir} 251858a73f1SWarner Losh cp ${CACHE}/linux/shell${bin}.efi ${dir}/efi/boot/boot${bin}.efi 252858a73f1SWarner Losh cat > ${dir}/startup.nsh <<EOF 253858a73f1SWarner Losh# Run linux 254858a73f1SWarner Losh# Tell it to run with out special initrd that then boot FreeBSD 255858a73f1SWarner Losh 256858a73f1SWarner Losh\linux${bin} ${cons} initrd=\initrd.img 257858a73f1SWarner LoshEOF 258858a73f1SWarner Losh cp $initrd ${dir} 259858a73f1SWarner Losh done 260858a73f1SWarner Losh} 261858a73f1SWarner Losh 262858a73f1SWarner Loshmake_linuxboot_images() 263858a73f1SWarner Losh{ 264858a73f1SWarner Losh # ESP variant: In this variant, amd64 and arm64 are both created more or 265858a73f1SWarner Losh # less the same way. Both are EFI + ACPI implementations 266858a73f1SWarner Losh for a in amd64:amd64 arm64:aarch64; do 267858a73f1SWarner Losh m=${a%%:*} 268858a73f1SWarner Losh ma=${a##*:} 269858a73f1SWarner Losh ma_combo="${m}" 270858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 271858a73f1SWarner Losh src=${TREES}/${ma_combo}/linuxboot-esp 272858a73f1SWarner Losh dir=${TREES}/${ma_combo}/freebsd 273858a73f1SWarner Losh dir2=${TREES}/${ma_combo}/test-stand 274858a73f1SWarner Losh esp=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.esp 275858a73f1SWarner Losh ufs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.ufs 276858a73f1SWarner Losh zfs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.zfs 277858a73f1SWarner Losh img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img 278858a73f1SWarner Losh img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img 279eaf5ec88SWarner Losh pool="linuxboot" 280858a73f1SWarner Losh mkdir -p ${IMAGES}/${ma_combo} 281858a73f1SWarner Losh makefs -t msdos -o fat_type=32 -o sectors_per_cluster=1 \ 282*a5c0d551SWarner Losh -o volume_label=EFISYS -s80m ${esp} ${src} 283858a73f1SWarner Losh makefs -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2} 284858a73f1SWarner Losh mkimg -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img} 285858a73f1SWarner Losh makefs -t zfs -s 200m \ 286858a73f1SWarner Losh -o poolname=${pool} -o bootfs=${pool} -o rootpath=/ \ 287858a73f1SWarner Losh ${zfs} ${dir} ${dir2} 288858a73f1SWarner Losh mkimg -s gpt \ 289858a73f1SWarner Losh -p efi:=${esp} \ 290858a73f1SWarner Losh -p freebsd-zfs:=${zfs} -o ${img2} 291858a73f1SWarner Losh rm -f ${esp} # Don't need to keep this around 292858a73f1SWarner Losh done 293858a73f1SWarner Losh 294858a73f1SWarner Losh # The raw variant, currently used only on arm64. It boots with the raw interface of qemu 295858a73f1SWarner Losh # for testing purposes. This means it makes a good test for the DTB variation, but not ACPI 296858a73f1SWarner Losh # since qemu doesn't currently provide that... 297858a73f1SWarner Losh for a in arm64:aarch64; do 298858a73f1SWarner Losh m=${a%%:*} 299858a73f1SWarner Losh ma=${a##*:} 300858a73f1SWarner Losh ma_combo="${m}" 301858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 302858a73f1SWarner Losh linux="${CACHE}/linux/vmlinux-${m}*" 303858a73f1SWarner Losh initrd=${TREES}/${ma_combo}/initrd.img 304858a73f1SWarner Losh img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw 305858a73f1SWarner Losh cp ${linux} ${img}.kernel 306858a73f1SWarner Losh cp ${initrd} ${img}.initrd 307858a73f1SWarner Losh done 308858a73f1SWarner Losh} 309858a73f1SWarner Losh 310858a73f1SWarner Loshmake_linuxboot_scripts() 311858a73f1SWarner Losh{ 312858a73f1SWarner Losh # At the moment, we have just two -- and the images we've built so far are just 313858a73f1SWarner Losh # the hostfs boot. The boot off anything more complex isn't here. 314858a73f1SWarner Losh for a in amd64:amd64 arm64:aarch64; do 315858a73f1SWarner Losh m=${a%%:*} 316858a73f1SWarner Losh ma=${a##*:} 317858a73f1SWarner Losh ma_combo="${m}" 318858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 319858a73f1SWarner Losh 320858a73f1SWarner Losh # First off, update the edk firmware 321858a73f1SWarner Losh bios_code=${BIOS}/edk2-${ma_combo}-code.fd 322858a73f1SWarner Losh bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd 323858a73f1SWarner Losh case ${ma} in 324858a73f1SWarner Losh amd64) 325858a73f1SWarner Losh if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then 326858a73f1SWarner Losh cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code} 327858a73f1SWarner Losh # vars file works on both 32 and 64 bit x86 328858a73f1SWarner Losh cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars} 329858a73f1SWarner Losh fi 330858a73f1SWarner Losh ;; 331858a73f1SWarner Losh aarch64) 332858a73f1SWarner Losh if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then 333858a73f1SWarner Losh # aarch64 vars starts as an empty file 334858a73f1SWarner Losh dd if=/dev/zero of=${bios_code} bs=1M count=64 335858a73f1SWarner Losh dd if=/dev/zero of=${bios_vars} bs=1M count=64 336858a73f1SWarner Losh dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc 337858a73f1SWarner Losh fi 338858a73f1SWarner Losh ;; 339858a73f1SWarner Losh esac 340858a73f1SWarner Losh 341858a73f1SWarner Losh # Now make me a script 342858a73f1SWarner Losh img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img 343858a73f1SWarner Losh img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw 344858a73f1SWarner Losh img3=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img 345858a73f1SWarner Losh out=${SCRIPTS}/${ma_combo}/linuxboot-test.sh 346858a73f1SWarner Losh out2=${SCRIPTS}/${ma_combo}/linuxboot-test-raw.sh 347858a73f1SWarner Losh out3=${SCRIPTS}/${ma_combo}/linuxboot-test-zfs.sh 348858a73f1SWarner Losh cd=${CACHE}/FreeBSD-13.1-RELEASE-arm64-aarch64-bootonly.iso 349858a73f1SWarner Losh mkdir -p ${SCRIPTS}/${ma_combo} 350858a73f1SWarner Losh case ${ma} in 351858a73f1SWarner Losh amd64) 352858a73f1SWarner Losh cat > ${out} <<EOF 353858a73f1SWarner Losh${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\ 354858a73f1SWarner Losh -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\ 355858a73f1SWarner Losh -device virtio-blk,drive=drive0,bootindex=0 \\ 356858a73f1SWarner Losh -drive file=${bios_code},format=raw,if=pflash \\ 357858a73f1SWarner Losh -drive file=${bios_vars},format=raw,if=pflash \\ 358858a73f1SWarner Losh -monitor telnet::4444,server,nowait \\ 359858a73f1SWarner Losh -serial stdio \$* 360858a73f1SWarner LoshEOF 361858a73f1SWarner Losh ;; 362858a73f1SWarner Losh aarch64) 363858a73f1SWarner Losh # ESP version 364858a73f1SWarner Losh raw=${IMAGES}/${ma_combo}/freebsd-arm64-aarch64.img 365858a73f1SWarner Losh cat > ${out} <<EOF 366858a73f1SWarner Losh${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\ 367858a73f1SWarner Losh -cpu cortex-a57 \\ 368858a73f1SWarner Losh -drive file=${img},if=none,id=drive0,cache=writeback \\ 369858a73f1SWarner Losh -device virtio-blk,drive=drive0,bootindex=0 \\ 370858a73f1SWarner Losh -drive file=${raw},if=none,id=drive1,cache=writeback \\ 371858a73f1SWarner Losh -device nvme,serial=fboot,drive=drive1,bootindex=1 \\ 372858a73f1SWarner Losh -drive file=${bios_code},format=raw,if=pflash \\ 373858a73f1SWarner Losh -drive file=${bios_vars},format=raw,if=pflash \\ 374858a73f1SWarner Losh -monitor telnet::4444,server,nowait \\ 375858a73f1SWarner Losh -serial stdio \$* 376858a73f1SWarner LoshEOF 377858a73f1SWarner Losh # RAW version 378858a73f1SWarner Losh # Note: We have to use cortex-a57 for raw mode because the 379858a73f1SWarner Losh # kernel we use has issues with max. 380858a73f1SWarner Losh cat > ${out2} <<EOF 381858a73f1SWarner Losh${qemu_bin}/qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt \\ 382858a73f1SWarner Losh -kernel ${img2}.kernel -initrd ${img2}.initrd \\ 383858a73f1SWarner Losh -append "console=ttyAMA0" \\ 384858a73f1SWarner Losh -drive file=${cd},if=none,id=drive0,cache=writeback,format=raw \\ 385858a73f1SWarner Losh -device virtio-blk,drive=drive0,bootindex=0 \\ 386858a73f1SWarner Losh -nographic -monitor telnet::4444,server,nowait \\ 387858a73f1SWarner Losh -serial stdio \$* 388858a73f1SWarner LoshEOF 389858a73f1SWarner Losh # ZFS version 390858a73f1SWarner Losh # Note: We have to use cortex-a57 for raw mode because the 391858a73f1SWarner Losh # kernel we use has issues with max. 392858a73f1SWarner Losh cat > ${out3} <<EOF 393858a73f1SWarner Losh${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\ 394858a73f1SWarner Losh -cpu cortex-a57 \\ 395858a73f1SWarner Losh -drive file=${img3},if=none,id=drive0,cache=writeback \\ 396858a73f1SWarner Losh -device virtio-blk,drive=drive0,bootindex=0 \\ 397858a73f1SWarner Losh -drive file=${bios_code},format=raw,if=pflash \\ 398858a73f1SWarner Losh -drive file=${bios_vars},format=raw,if=pflash \\ 399858a73f1SWarner Losh -monitor telnet::4444,server,nowait \\ 400858a73f1SWarner Losh -serial stdio \$* 401858a73f1SWarner LoshEOF 402858a73f1SWarner Losh ;; 403858a73f1SWarner Losh esac 404858a73f1SWarner Losh done 405858a73f1SWarner Losh} 406858a73f1SWarner Losh 407858a73f1SWarner Loshmake_freebsd_esps() 408858a73f1SWarner Losh{ 409858a73f1SWarner Losh # At the moment, we have just three (armv7 could also be here too, but we're not doing that) 410858a73f1SWarner Losh for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do 411858a73f1SWarner Losh m=${a%%:*} 412858a73f1SWarner Losh ma=${a##*:} 413858a73f1SWarner Losh ma_combo="${m}" 414858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 415858a73f1SWarner Losh dir=${TREES}/${ma_combo}/freebsd-esp 416858a73f1SWarner Losh dir2=${TREES}/${ma_combo}/test-stand 417858a73f1SWarner Losh rm -rf ${dir} 418858a73f1SWarner Losh mkdir -p ${dir} 419858a73f1SWarner Losh case ${ma} in 420858a73f1SWarner Losh amd64) bin=x64 ;; 421858a73f1SWarner Losh aarch64) bin=aa64 ;; 422858a73f1SWarner Losh esac 423858a73f1SWarner Losh mkdir -p ${dir}/efi/boot 424858a73f1SWarner Losh cp ${dir2}/boot/loader.efi ${dir}/efi/boot/boot${bin}.efi 425858a73f1SWarner Losh done 426858a73f1SWarner Losh} 427858a73f1SWarner Losh 428858a73f1SWarner Loshmake_freebsd_images() 429858a73f1SWarner Losh{ 430858a73f1SWarner Losh # ESP variant: In this variant, riscv, amd64 and arm64 are created more or 431858a73f1SWarner Losh # less the same way. UEFI + ACPI implementations 432858a73f1SWarner Losh for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do 433858a73f1SWarner Losh m=${a%%:*} 434858a73f1SWarner Losh ma=${a##*:} 435858a73f1SWarner Losh ma_combo="${m}" 436858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 437858a73f1SWarner Losh src=${TREES}/${ma_combo}/freebsd-esp 438858a73f1SWarner Losh dir=${TREES}/${ma_combo}/freebsd 439858a73f1SWarner Losh dir2=${TREES}/${ma_combo}/test-stand 440858a73f1SWarner Losh esp=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.esp 441858a73f1SWarner Losh ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs 442858a73f1SWarner Losh img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img 443858a73f1SWarner Losh mkdir -p ${IMAGES}/${ma_combo} 444*a5c0d551SWarner Losh mkdir -p ${dir2}/etc 445*a5c0d551SWarner Losh cat > ${dir2}/etc/fstab <<EOF 446*a5c0d551SWarner Losh/dev/ufs/root / ufs rw 1 1 447*a5c0d551SWarner LoshEOF 448858a73f1SWarner Losh makefs -t msdos -o fat_type=32 -o sectors_per_cluster=1 \ 449858a73f1SWarner Losh -o volume_label=EFISYS -s100m ${esp} ${src} 450858a73f1SWarner Losh makefs -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2} 451858a73f1SWarner Losh mkimg -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img} 452858a73f1SWarner Losh # rm -f ${esp} ${ufs} # Don't need to keep this around 453858a73f1SWarner Losh done 454858a73f1SWarner Losh 455858a73f1SWarner Losh set -x 456858a73f1SWarner Losh 457eaf5ec88SWarner Losh # BIOS i386 458eaf5ec88SWarner Losh a=i386:i386 459eaf5ec88SWarner Losh m=${a%%:*} 460eaf5ec88SWarner Losh ma=${a##*:} 461eaf5ec88SWarner Losh ma_combo="${m}" 462eaf5ec88SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 463eaf5ec88SWarner Losh dir=${TREES}/${ma_combo}/freebsd 464eaf5ec88SWarner Losh dir2=${TREES}/${ma_combo}/test-stand 465eaf5ec88SWarner Losh ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs 466eaf5ec88SWarner Losh img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img 467eaf5ec88SWarner Losh mkdir -p ${IMAGES}/${ma_combo} 468eaf5ec88SWarner Losh mkdir -p ${dir2}/etc 469eaf5ec88SWarner Losh cat > ${dir2}/etc/fstab <<EOF 470eaf5ec88SWarner Losh/dev/ufs/root / ufs rw 1 1 471eaf5ec88SWarner LoshEOF 472eaf5ec88SWarner Losh makefs -t ffs -B little -s 200m \ 473eaf5ec88SWarner Losh -o label=root,version=2,bsize=32768,fsize=4096,density=16384 \ 474eaf5ec88SWarner Losh ${ufs} ${dir} ${dir2} 475eaf5ec88SWarner Losh mkimg -s gpt -b ${dir2}/boot/pmbr \ 476eaf5ec88SWarner Losh -p freebsd-boot:=${dir2}/boot/gptboot \ 477eaf5ec88SWarner Losh -p freebsd-ufs:=${ufs} \ 478eaf5ec88SWarner Losh -o ${img} 479eaf5ec88SWarner Losh rm -f ${src}/etc/fstab 480eaf5ec88SWarner Losh 481858a73f1SWarner Losh # PowerPC for 32-bit mac 482858a73f1SWarner Losh a=powerpc:powerpc 483858a73f1SWarner Losh m=${a%%:*} 484858a73f1SWarner Losh ma=${a##*:} 485858a73f1SWarner Losh ma_combo="${m}" 486858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 487858a73f1SWarner Losh dir=${TREES}/${ma_combo}/freebsd 488858a73f1SWarner Losh dir2=${TREES}/${ma_combo}/test-stand 489858a73f1SWarner Losh ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs 490858a73f1SWarner Losh img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img 491858a73f1SWarner Losh mkdir -p ${IMAGES}/${ma_combo} 492*a5c0d551SWarner Losh mkdir -p ${dir2}/etc 493*a5c0d551SWarner Losh cat > ${dir2}/etc/fstab <<EOF 494*a5c0d551SWarner Losh/dev/ufs/root / ufs rw 1 1 495*a5c0d551SWarner LoshEOF 496858a73f1SWarner Losh makefs -t ffs -B big -s 200m \ 497858a73f1SWarner Losh -o label=root,version=2,bsize=32768,fsize=4096,density=16384 \ 498858a73f1SWarner Losh ${ufs} ${dir} ${dir2} 499858a73f1SWarner Losh mkimg -a 1 -s apm \ 500858a73f1SWarner Losh -p freebsd-boot:=${dir2}/boot/boot1.hfs \ 501858a73f1SWarner Losh -p freebsd-ufs:=${ufs} \ 502858a73f1SWarner Losh -o ${img} 503858a73f1SWarner Losh 504858a73f1SWarner Losh set +x 505858a73f1SWarner Losh} 506858a73f1SWarner Losh 507858a73f1SWarner Loshmake_freebsd_scripts() 508858a73f1SWarner Losh{ 509858a73f1SWarner Losh # At the moment, we have just two 510858a73f1SWarner Losh for a in amd64:amd64 arm64:aarch64; do 511858a73f1SWarner Losh m=${a%%:*} 512858a73f1SWarner Losh ma=${a##*:} 513858a73f1SWarner Losh ma_combo="${m}" 514858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 515858a73f1SWarner Losh 516858a73f1SWarner Losh # First off, update the edk firmware 517858a73f1SWarner Losh bios_code=${BIOS}/edk2-${ma_combo}-code.fd 518858a73f1SWarner Losh bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd 519858a73f1SWarner Losh case ${ma} in 520858a73f1SWarner Losh amd64) 521858a73f1SWarner Losh if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then 522858a73f1SWarner Losh cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code} 523858a73f1SWarner Losh # vars file works on both 32 and 64 bit x86 524858a73f1SWarner Losh cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars} 525858a73f1SWarner Losh fi 526858a73f1SWarner Losh ;; 527858a73f1SWarner Losh aarch64) 528858a73f1SWarner Losh if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then 529858a73f1SWarner Losh # aarch64 vars starts as an empty file 530858a73f1SWarner Losh dd if=/dev/zero of=${bios_code} bs=1M count=64 531858a73f1SWarner Losh dd if=/dev/zero of=${bios_vars} bs=1M count=64 532858a73f1SWarner Losh dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc 533858a73f1SWarner Losh fi 534858a73f1SWarner Losh ;; 535858a73f1SWarner Losh esac 536858a73f1SWarner Losh 537858a73f1SWarner Losh # Now make me a script 538858a73f1SWarner Losh img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img 539858a73f1SWarner Losh out=${SCRIPTS}/${ma_combo}/freebsd-test.sh 540858a73f1SWarner Losh mkdir -p ${SCRIPTS}/${ma_combo} 541858a73f1SWarner Losh case ${ma} in 542858a73f1SWarner Losh amd64) 543858a73f1SWarner Losh cat > ${out} <<EOF 544858a73f1SWarner Losh${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\ 545858a73f1SWarner Losh -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\ 546858a73f1SWarner Losh -device virtio-blk,drive=drive0,bootindex=0 \\ 547858a73f1SWarner Losh -drive file=${bios_code},format=raw,if=pflash \\ 548858a73f1SWarner Losh -drive file=${bios_vars},format=raw,if=pflash \\ 549858a73f1SWarner Losh -monitor telnet::4444,server,nowait \\ 550858a73f1SWarner Losh -serial stdio \$* 551858a73f1SWarner LoshEOF 552858a73f1SWarner Losh ;; 553858a73f1SWarner Losh aarch64) 554858a73f1SWarner Losh # ESP version 555858a73f1SWarner Losh raw=${IMAGES}/${ma_combo}/nvme-test-empty.raw 556858a73f1SWarner Losh cat > ${out} <<EOF 557858a73f1SWarner Losh${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M \\ 558858a73f1SWarner Losh -cpu cortex-a57 -drive file=${img},if=none,id=drive0,cache=writeback -smp 4 \\ 559858a73f1SWarner Losh -device virtio-blk,drive=drive0,bootindex=0 \\ 560858a73f1SWarner Losh -drive file=${bios_code},format=raw,if=pflash \\ 561858a73f1SWarner Losh -drive file=${bios_vars},format=raw,if=pflash \\ 562858a73f1SWarner Losh -drive file=${raw},if=none,id=drive1,cache=writeback,format=raw \\ 563858a73f1SWarner Losh -device nvme,serial=deadbeef,drive=drive1 \\ 564858a73f1SWarner Losh -monitor telnet::4444,server,nowait \\ 565858a73f1SWarner Losh -serial stdio \$* 566858a73f1SWarner LoshEOF 567858a73f1SWarner Losh ;; 568858a73f1SWarner Losh esac 569858a73f1SWarner Losh done 570858a73f1SWarner Losh 571858a73f1SWarner Losh set -x 572858a73f1SWarner Losh a=powerpc:powerpc 573858a73f1SWarner Losh m=${a%%:*} 574858a73f1SWarner Losh ma=${a##*:} 575858a73f1SWarner Losh ma_combo="${m}" 576858a73f1SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 577858a73f1SWarner Losh img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img 578858a73f1SWarner Losh out=${SCRIPTS}/${ma_combo}/freebsd-test.sh 579858a73f1SWarner Losh mkdir -p ${SCRIPTS}/${ma_combo} 580858a73f1SWarner Losh cat > ${out} <<EOF 581858a73f1SWarner Losh${qemu_bin}/qemu-system-ppc -m 1g -M mac99,via=pmu \\ 582858a73f1SWarner Losh -vga none -nographic \\ 583858a73f1SWarner Losh -drive file=${img},if=virtio \\ 584858a73f1SWarner Losh -prom-env "boot-device=/pci@f2000000/scsi/disk@0:,\\\\\\:tbxi" \\ 585858a73f1SWarner Losh -monitor telnet::4444,server,nowait \\ 586858a73f1SWarner Losh -serial stdio \$* 587858a73f1SWarner LoshEOF 588eaf5ec88SWarner Losh 589eaf5ec88SWarner Losh set -x 590eaf5ec88SWarner Losh a=i386:i386 591eaf5ec88SWarner Losh m=${a%%:*} 592eaf5ec88SWarner Losh ma=${a##*:} 593eaf5ec88SWarner Losh ma_combo="${m}" 594eaf5ec88SWarner Losh [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}" 595eaf5ec88SWarner Losh img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img 596eaf5ec88SWarner Losh out=${SCRIPTS}/${ma_combo}/freebsd-test.sh 597eaf5ec88SWarner Losh mkdir -p ${SCRIPTS}/${ma_combo} 598eaf5ec88SWarner Losh cat > ${out} <<EOF 599eaf5ec88SWarner Losh${qemu_bin}/qemu-system-i386 -m 1g \\ 600eaf5ec88SWarner Losh -vga none -nographic \\ 601eaf5ec88SWarner Losh -drive file=${img},format=raw \\ 602eaf5ec88SWarner Losh -nographic \\ 603eaf5ec88SWarner Losh -monitor telnet::4444,server,nowait \\ 604eaf5ec88SWarner Losh -serial stdio \$* 605eaf5ec88SWarner LoshEOF 606858a73f1SWarner Losh} 607858a73f1SWarner Losh 608858a73f1SWarner Losh# The smallest FAT32 filesystem is 33292 KB 609858a73f1SWarner Loshespsize=33292 610858a73f1SWarner Losh 611858a73f1SWarner Loshset -e 612858a73f1SWarner Loshecho "src/stand test in ${STAND_ROOT}" 613858a73f1SWarner Loshupdate_freebsd_img_cache 614858a73f1SWarner Loshmake_freebsd_minimal_trees 615858a73f1SWarner Loshmake_freebsd_test_trees 616858a73f1SWarner Loshmake_linux_initrds 617858a73f1SWarner Loshmake_linux_esps 618858a73f1SWarner Loshmake_freebsd_esps 619858a73f1SWarner Loshmake_freebsd_images 620858a73f1SWarner Loshmake_freebsd_scripts 621858a73f1SWarner Loshmake_linuxboot_images 622858a73f1SWarner Loshmake_linuxboot_scripts 623