xref: /freebsd/tools/boot/full-test.sh (revision c84d43b57c48e1185bc593f26ebd51b0d35750df)
1#!/bin/sh
2
3# STAND_ROOT is the root of a tree:
4# cache - Cached binaries that we have downloaded
5# trees - binary trees that we use to make image
6#      trees/${ARCH}/$thing
7# images - bootable images that we use to test
8#	images/${ARCH}/$thing
9# bios - cached bios images (as well as 'vars' files when we start testing
10#	different booting scenarios in the precense / absence of variables).
11# scripts - generated scripts that uses images to run the tests.
12#
13# Strategy:
14#	Download FreeBSD release isos, Linux kernels (for the kboot tests) and
15#	other misc things. We use these to generate dozens of test images that we
16#	use qemu-system-XXXX to boot. They all boot the same thing at the moment:
17#	an /etc/rc script that prints the boot method, echos success and then
18#	halts.
19
20# What version of FreeBSD to we snag the ISOs from to extract the binaries
21# we are testing
22FREEBSD_VERSION=14.2
23# eg https://download.freebsd.org/releases/amd64/amd64/ISO-IMAGES/14.2/FreeBSD-14.2-RELEASE-amd64-bootonly.iso.xz
24URLBASE="https://download.freebsd.org/releases"
25: ${STAND_ROOT:="${HOME}/stand-test-root"}
26CACHE=${STAND_ROOT}/cache
27TREES=${STAND_ROOT}/trees
28IMAGES=${STAND_ROOT}/images
29BIOS=${STAND_ROOT}/bios
30SCRIPTS=${STAND_ROOT}/scripts
31OVERRIDE=${STAND_ROOT}/override
32
33# Find make
34case $(uname) in
35    Darwin)
36	t=$(realpath $(dirname $0)/../..)
37	# Use the python wrapper to find make
38	if [ -f ${t}/tools/build/make.py ]; then
39	    MAKE="${t}/tools/build/make.py"
40	    case $(uname -m) in
41		arm64)
42		    DEFARCH="TARGET_ARCH=aarch64 TARGET=arm64"
43		    ;;
44		x86_64)
45		    DEFARCH="TARGET_ARCH=amd64 TARGET=amd64"
46		    ;;
47		*)
48		    die "Do not know about $(uanme -p)"
49		    ;;
50	    esac
51	else
52	    die "Can't find the make wrapper"
53	fi
54	qemu_bin=/opt/homebrew/bin
55	;;
56    FreeBSD)
57	MAKE=make
58	qemu_bin=/usr/local/bin
59	;;
60    # linux) not yet
61    *)
62	die "Do not know about system $(uname)"
63	;;
64esac
65
66SRCTOP=$(${MAKE} ${DEFARCH} -v SRCTOP)
67echo $SRCTOP
68
69# Find makefs and mkimg
70MAKEFS=$(SHELL="which makefs" ${MAKE} ${DEFARCH} buildenv | tail -1) || die "No makefs try WITH_DISK_IMAGE_TOOLS_BOOTSTRAP=y"
71MKIMG=$(SHELL="which mkimg" ${MAKE} ${DEFARCH} buildenv | tail -1) || die "No mkimg, try buildworld first"
72MTREE=$(SHELL="which mtree" ${MAKE} ${DEFARCH} buildenv | tail -1) || die "No mtree, try buildworld first"
73
74# MAKE=$(SHELL="which make" ${MAKE} ${DEFARCH} buildenv | tail -1) || die "No make, try buildworld first"
75
76
77# All the architectures under test
78# Note: we can't yet do armv7 because we don't have a good iso for it and would
79# need root to extract the files.
80#ARCHES="amd64:amd64 i386:i386 powerpc:powerpc powerpc:powerpc64 powerpc:powerpc64le powerpc:powerpcspe arm64:aarch64 riscv:riscv64"
81ARCHES="amd64:amd64 arm64:aarch64"
82
83# The smallest FAT32 filesystem is 33292 KB
84espsize=33292
85
86mkdir -p ${CACHE} ${TREES} ${IMAGES} ${BIOS}
87
88die()
89{
90    echo Fatal Error: $*
91    exit 1
92}
93
94ma_combo()
95{
96    local m=$1
97    local ma=$2
98    local ma_combo="${m}"
99
100    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
101    echo ${ma_combo}
102}
103
104fetch_one()
105{
106    local m=$1
107    local ma=$2
108    local v=$3
109    local flavor=$4
110    local ma_combo=$(ma_combo $m $ma)
111    local file="FreeBSD-${v}-RELEASE-${ma_combo}-${flavor}"
112    local url="${URLBASE}/${m}/${ma}/ISO-IMAGES/${v}/${file}.xz"
113
114    mkdir -p ${CACHE}
115    [ -r ${CACHE}/${file} ] && echo "Using cached ${file}" && return
116    cd ${CACHE}
117    echo "Fetching ${url}"
118    fetch ${url} || die "Can't fetch ${file} from ${url}"
119    xz -d ${file}.xz || die "Can't uncompress ${file}.xz"
120    cd ..
121}
122
123update_freebsd_img_cache()
124{
125    local a m ma
126
127    for a in $ARCHES; do
128	m=${a%%:*}
129	ma=${a##*:}
130	fetch_one $m $ma ${FREEBSD_VERSION} bootonly.iso
131    done
132
133    fetch_one arm armv7 ${FREEBSD_VERSION} GENERICSD.img
134}
135
136make_minimal_freebsd_tree()
137{
138    local m=$1
139    local ma=$2
140    local v=$3
141    local flavor=$4
142    local file d
143    local ma_combo="${m}"
144    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
145
146    file="FreeBSD-${v}-RELEASE-${ma_combo}-${flavor}"
147    dir=${TREES}/${ma_combo}/freebsd
148    rm -rf ${dir}
149
150    # Make a super simple userland. It has just enough to print a santiy value,
151    # then say test succeeded, and then halt the system. We assume that /bin/sh
152    # has all the library prereqs for the rest...
153    mkdir -p ${dir}
154    # Make required dirs
155    for d in boot/kernel boot/defaults boot/lua boot/loader.conf.d \
156			 sbin bin lib libexec etc dev; do
157	mkdir -p ${dir}/${d}
158    done
159    # Pretend we don't have a separate /usr
160    ln -s . ${dir}/usr
161    # snag the binaries for my simple /etc/rc file
162    tar -C ${dir} -xf ${CACHE}/$file sbin/fastboot sbin/reboot sbin/halt sbin/init bin/sh sbin/sysctl \
163	lib/libncursesw.so.9 lib/libc.so.7 lib/libedit.so.8 libexec/ld-elf.so.1
164
165    # My simple etc/rc
166    cat > ${dir}/etc/rc <<EOF
167#!/bin/sh
168
169sysctl machdep.bootmethod
170echo "RC COMMAND RUNNING -- SUCCESS!!!!!"
171halt -p
172EOF
173    chmod +x ${dir}/etc/rc
174
175    # Check to see if we have overrides here... So we can insert our own kernel
176    # instead of the one from the release.
177    echo "CHECKING ${OVERRIDE}/${ma_combo}/boot"
178    if [ -d ${OVERRIDE}/${ma_combo}/boot ]; then
179	o=${OVERRIDE}/${ma_combo}
180	for i in \
181	    boot/device.hints \
182	    boot/kernel/kernel \
183	    boot/kernel/acl_nfs4.ko \
184	    boot/kernel/cryptodev.ko \
185	    boot/kernel/zfs.ko \
186	    boot/kernel/geom_eli.ko; do
187	    [ -r $o/$i ] && echo Copying override $i && cp $o/$i ${dir}/$i
188	done
189    else
190	# Copy the kernel (but not the boot loader, we'll add the one to test later)
191	# This will take care of both UFS and ZFS boots as well as geli
192	# Note: It's OK for device.hints to be missing. It's mostly for legacy platforms.
193	tar -C ${dir} -xf ${CACHE}/$file \
194	    boot/device.hints \
195	    boot/kernel/kernel \
196	    boot/kernel/acl_nfs4.ko \
197	    boot/kernel/cryptodev.ko \
198	    boot/kernel/zfs.ko \
199	    boot/kernel/geom_eli.ko || true
200	# XXX WHAT TO DO ABOUT LINKER HINTS -- PUNT FOR NOW
201	# XXX also, ZFS not supported on 32-bit powerpc platforms
202    fi
203
204    # Setup some common settings for serial console, etc
205    echo -h -D -S115200 > ${dir}/boot.config
206    cat > ${dir}/boot/loader.conf <<EOF
207comconsole_speed=115200
208autoboot_delay=2
209zfs_load="YES"
210boot_verbose=yes
211kern.cfg.order="acpi,fdt"
212EOF
213}
214
215make_freebsd_minimal_trees()
216{
217    for a in $ARCHES; do
218	m=${a%%:*}
219	ma=${a##*:}
220	make_minimal_freebsd_tree $m $ma ${FREEBSD_VERSION} bootonly.iso
221    done
222    # Note: armv7 isn't done yet as its the odd-man out -- we need to extract things
223    # in a special way, so punt for the moment
224}
225
226make_freebsd_test_trees()
227{
228    for a in $ARCHES; do
229	m=${a%%:*}
230	ma=${a##*:}
231	ma_combo="${m}"
232	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
233	dir=${TREES}/${ma_combo}/test-stand
234	mkdir -p ${dir}
235	${MTREE} -deUW -f ${SRCTOP}/etc/mtree/BSD.root.dist -p ${dir}
236	echo "Creating tree for ${m}:${ma}"
237	cd ${SRCTOP}
238	# Indirection needed because our build system is too complex
239	# Also, bare make for 'inside' the buildenv ${MAKE} for outside
240#	SHELL="make clean" ${MAKE} buildenv TARGET=${m} TARGET_ARCH=${ma}
241	SHELL="sh -c 'cd stand ; make -j 100 all'" ${MAKE} TARGET=${m} TARGET_ARCH=${ma} buildenv
242	DESTDIR=${dir} SHELL="sh -c 'cd stand ; make install MK_MAN=no MK_INSTALL_AS_USER=yes WITHOUT_DEBUG_FILES=yes'" \
243	     ${MAKE} buildenv TARGET=${m} TARGET_ARCH=${ma}
244	rm -rf ${dir}/bin ${dir}/[ac-z]*	# Don't care about anything here
245    done
246}
247
248make_linux_initrds()
249{
250    # At the moment, we have just two
251    for a in amd64:amd64 arm64:aarch64; do
252	m=${a%%:*}
253	ma=${a##*:}
254	ma_combo="${m}"
255	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
256	dir=${TREES}/${ma_combo}/linuxboot
257	dir2=${TREES}/${ma_combo}/test-stand
258	dir3=${TREES}/${ma_combo}/freebsd
259	initrd=${TREES}/${ma_combo}/initrd.img
260	rm -rf ${dir}
261	mkdir -p ${dir}
262	cp ${dir2}/boot/loader.kboot ${dir}/init
263	# Copy the boot loader
264	tar -c -f - -C ${dir2} boot | tar -xf - -C ${dir}
265	# Copy the boot kernel
266	tar -c -f - -C ${dir3} boot | tar -xf - -C ${dir}
267	(cd ${dir} ; find . | LC_ALL=C sort | cpio -o -H newc | gzip > ${initrd})
268    done
269}
270
271make_linux_esps()
272{
273    # At the moment, we have just two
274    for a in amd64:amd64 arm64:aarch64; do
275	m=${a%%:*}
276	ma=${a##*:}
277	ma_combo="${m}"
278	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
279	dir=${TREES}/${ma_combo}/linuxboot-esp
280	initrd=${TREES}/${ma_combo}/initrd.img
281	mkdir -p ${dir}
282	case ${ma} in
283	    amd64) bin=x64 cons="console=ttyS0,115200" ;;
284	    aarch64) bin=aa64 ;;
285	esac
286	mkdir -p ${dir}/efi/boot
287	cp ${CACHE}/linux/linux${bin}.efi ${dir}
288	cp ${CACHE}/linux/shell${bin}.efi ${dir}/efi/boot/boot${bin}.efi
289	cat > ${dir}/startup.nsh <<EOF
290# Run linux
291# Tell it to run with out special initrd that then boot FreeBSD
292
293\linux${bin} ${cons} initrd=\initrd.img
294EOF
295	cp $initrd ${dir}
296    done
297}
298
299make_linuxboot_images()
300{
301    # ESP variant: In this variant, amd64 and arm64 are both created more or
302    # less the same way. Both are EFI + ACPI implementations
303    for a in amd64:amd64 arm64:aarch64; do
304	m=${a%%:*}
305	ma=${a##*:}
306	ma_combo="${m}"
307	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
308	src=${TREES}/${ma_combo}/linuxboot-esp
309	dir=${TREES}/${ma_combo}/freebsd
310	dir2=${TREES}/${ma_combo}/test-stand
311	esp=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.esp
312	ufs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.ufs
313	zfs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.zfs
314	img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img
315	img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img
316	pool="linuxboot"
317	mkdir -p ${IMAGES}/${ma_combo}
318	${MAKEFS} -t msdos -o fat_type=32 -o sectors_per_cluster=1 \
319	       -o volume_label=EFISYS -s80m ${esp} ${src}
320	${MAKEFS} -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2}
321	${MKIMG} -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img}
322	${MAKEFS} -t zfs -s 200m \
323	       -o poolname=${pool} -o bootfs=${pool} -o rootpath=/ \
324		${zfs} ${dir} ${dir2}
325	${MKIMG} -s gpt \
326	      -p efi:=${esp} \
327	      -p freebsd-zfs:=${zfs} -o ${img2}
328	rm -f ${esp}	# Don't need to keep this around
329    done
330
331    # The raw variant, currently used only on arm64. It boots with the raw interface of qemu
332    # for testing purposes.  This means it makes a good test for the DTB variation, but not ACPI
333    # since qemu doesn't currently provide that...
334    for a in arm64:aarch64; do
335	m=${a%%:*}
336	ma=${a##*:}
337	ma_combo="${m}"
338	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
339	linux="${CACHE}/linux/vmlinux-${m}*"
340	initrd=${TREES}/${ma_combo}/initrd.img
341	img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw
342	cp ${linux} ${img}.kernel
343	cp ${initrd} ${img}.initrd
344    done
345}
346
347make_linuxboot_scripts()
348{
349    # At the moment, we have just two -- and the images we've built so far are just
350    # the hostfs boot. The boot off anything more complex isn't here.
351    for a in amd64:amd64 arm64:aarch64; do
352	m=${a%%:*}
353	ma=${a##*:}
354	ma_combo="${m}"
355	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
356
357	# First off, update the edk firmware
358	bios_code=${BIOS}/edk2-${ma_combo}-code.fd
359	bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd
360	case ${ma} in
361	    amd64)
362		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then
363		    cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code}
364		    # vars file works on both 32 and 64 bit x86
365#		    cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars}
366		fi
367		;;
368	    aarch64)
369		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then
370		    # aarch64 vars starts as an empty file
371		    dd if=/dev/zero of=${bios_code} bs=1M count=64
372		    dd if=/dev/zero of=${bios_vars} bs=1M count=64
373		    dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc
374		fi
375		;;
376	esac
377
378	# Now make me a script
379	img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img
380	img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw
381	img3=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img
382	out=${SCRIPTS}/${ma_combo}/linuxboot-test.sh
383	out2=${SCRIPTS}/${ma_combo}/linuxboot-test-raw.sh
384	out3=${SCRIPTS}/${ma_combo}/linuxboot-test-zfs.sh
385	cd=${CACHE}/FreeBSD-13.1-RELEASE-arm64-aarch64-bootonly.iso
386	mkdir -p ${SCRIPTS}/${ma_combo}
387	case ${ma} in
388	    amd64)
389		cat > ${out} <<EOF
390${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\
391        -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\
392        -device virtio-blk,drive=drive0,bootindex=0 \\
393        -drive file=${bios_code},format=raw,if=pflash \\
394        -drive file=${bios_vars},format=raw,if=pflash \\
395        -monitor telnet::4444,server,nowait \\
396        -serial stdio \$*
397EOF
398		;;
399	    aarch64)
400		# ESP version
401		raw=${IMAGES}/${ma_combo}/freebsd-arm64-aarch64.img
402		cat > ${out} <<EOF
403${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\
404        -cpu cortex-a57 \\
405	-drive file=${img},if=none,id=drive0,cache=writeback \\
406	-device virtio-blk,drive=drive0,bootindex=0 \\
407        -drive file=${raw},if=none,id=drive1,cache=writeback \\
408	-device nvme,serial=fboot,drive=drive1,bootindex=1 \\
409        -drive file=${bios_code},format=raw,if=pflash \\
410        -drive file=${bios_vars},format=raw,if=pflash \\
411        -monitor telnet::4444,server,nowait \\
412        -serial stdio \$*
413EOF
414		# RAW version
415		# Note: We have to use cortex-a57 for raw mode because the
416		# kernel we use has issues with max.
417		cat > ${out2} <<EOF
418${qemu_bin}/qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt \\
419	-kernel ${img2}.kernel -initrd ${img2}.initrd \\
420	-append "console=ttyAMA0" \\
421        -drive file=${cd},if=none,id=drive0,cache=writeback,format=raw \\
422        -device virtio-blk,drive=drive0,bootindex=0 \\
423	-nographic -monitor telnet::4444,server,nowait \\
424	-serial stdio \$*
425EOF
426		# ZFS version
427		# Note: We have to use cortex-a57 for raw mode because the
428		# kernel we use has issues with max.
429		cat > ${out3} <<EOF
430${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\
431        -cpu cortex-a57 \\
432	-drive file=${img3},if=none,id=drive0,cache=writeback \\
433	-device virtio-blk,drive=drive0,bootindex=0 \\
434        -drive file=${bios_code},format=raw,if=pflash \\
435        -drive file=${bios_vars},format=raw,if=pflash \\
436        -monitor telnet::4444,server,nowait \\
437        -serial stdio \$*
438EOF
439		;;
440	esac
441    done
442}
443
444make_freebsd_esps()
445{
446    # At the moment, we have just three (armv7 could also be here too, but we're not doing that)
447#   for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do
448    for a in amd64:amd64 arm64:aarch64; do
449	m=${a%%:*}
450	ma=${a##*:}
451	ma_combo="${m}"
452	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
453	dir=${TREES}/${ma_combo}/freebsd-esp
454	dir2=${TREES}/${ma_combo}/test-stand
455	rm -rf ${dir}
456	mkdir -p ${dir}
457	case ${ma} in
458	    amd64) bin=x64 ;;
459	    aarch64) bin=aa64 ;;
460	esac
461	mkdir -p ${dir}/efi/boot
462	cp ${dir2}/boot/loader.efi ${dir}/efi/boot/boot${bin}.efi
463    done
464}
465
466make_freebsd_images()
467{
468    # ESP variant: In this variant, riscv, amd64 and arm64 are created more or
469    # less the same way. UEFI + ACPI implementations
470#   for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do
471    for a in amd64:amd64 arm64:aarch64; do
472	m=${a%%:*}
473	ma=${a##*:}
474	ma_combo="${m}"
475	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
476	src=${TREES}/${ma_combo}/freebsd-esp
477	dir=${TREES}/${ma_combo}/freebsd
478	dir2=${TREES}/${ma_combo}/test-stand
479	esp=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.esp
480	ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
481	img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
482	mkdir -p ${IMAGES}/${ma_combo}
483	mkdir -p ${dir2}/etc
484	cat > ${dir2}/etc/fstab <<EOF
485/dev/ufs/root	/		ufs	rw	1	1
486EOF
487	${MAKEFS} -t msdos -o fat_type=32 -o sectors_per_cluster=1 \
488	       -o volume_label=EFISYS -s100m ${esp} ${src}
489	${MAKEFS} -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2}
490	${MKIMG} -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img}
491	# rm -f ${esp} ${ufs}	# Don't need to keep this around
492    done
493
494    set -x
495
496if false; then
497    # BIOS i386
498    a=i386:i386
499    m=${a%%:*}
500    ma=${a##*:}
501    ma_combo="${m}"
502    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
503    dir=${TREES}/${ma_combo}/freebsd
504    dir2=${TREES}/${ma_combo}/test-stand
505    ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
506    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
507    mkdir -p ${IMAGES}/${ma_combo}
508    mkdir -p ${dir2}/etc
509    cat > ${dir2}/etc/fstab <<EOF
510/dev/ufs/root	/		ufs	rw	1	1
511EOF
512    ${MAKEFS} -t ffs -B little -s 200m \
513	   -o label=root,version=2,bsize=32768,fsize=4096,density=16384 \
514	   ${ufs} ${dir} ${dir2}
515    ${MKIMG} -s gpt -b ${dir2}/boot/pmbr \
516	  -p freebsd-boot:=${dir2}/boot/gptboot \
517	  -p freebsd-ufs:=${ufs} \
518	  -o ${img}
519    rm -f ${src}/etc/fstab
520
521    # PowerPC for 32-bit mac
522    a=powerpc:powerpc
523    m=${a%%:*}
524    ma=${a##*:}
525    ma_combo="${m}"
526    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
527    dir=${TREES}/${ma_combo}/freebsd
528    dir2=${TREES}/${ma_combo}/test-stand
529    ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
530    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
531    mkdir -p ${IMAGES}/${ma_combo}
532    mkdir -p ${dir2}/etc
533    cat > ${dir2}/etc/fstab <<EOF
534/dev/ufs/root	/		ufs	rw	1	1
535EOF
536    ${MAKEFS} -t ffs -B big -s 200m \
537	   -o label=root,version=2,bsize=32768,fsize=4096,density=16384 \
538	   ${ufs} ${dir} ${dir2}
539    ${MKIMG} -a 1 -s apm \
540        -p freebsd-boot:=${dir2}/boot/boot1.hfs \
541        -p freebsd-ufs:=${ufs} \
542        -o ${img}
543fi
544
545    set +x
546}
547
548make_freebsd_scripts()
549{
550    # At the moment, we have just two
551    for a in amd64:amd64 arm64:aarch64; do
552	m=${a%%:*}
553	ma=${a##*:}
554	ma_combo="${m}"
555	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
556
557	# First off, update the edk firmware
558	bios_code=${BIOS}/edk2-${ma_combo}-code.fd
559	bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd
560	case ${ma} in
561	    amd64)
562		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then
563		    cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code}
564		    # vars file works on both 32 and 64 bit x86
565#		    cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars}
566		fi
567		;;
568	    aarch64)
569		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then
570		    # aarch64 vars starts as an empty file
571		    dd if=/dev/zero of=${bios_code} bs=1M count=64
572		    dd if=/dev/zero of=${bios_vars} bs=1M count=64
573		    dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc
574		fi
575		;;
576	esac
577
578	# Now make me a script
579	img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
580	out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
581	mkdir -p ${SCRIPTS}/${ma_combo}
582	case ${ma} in
583	    amd64)
584		cat > ${out} <<EOF
585${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\
586        -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\
587        -device virtio-blk,drive=drive0,bootindex=0 \\
588        -drive file=${bios_code},format=raw,if=pflash \\
589        -drive file=${bios_vars},format=raw,if=pflash \\
590        -monitor telnet::4444,server,nowait \\
591        -serial stdio \$*
592EOF
593		;;
594	    aarch64)
595		# ESP version
596		raw=${IMAGES}/${ma_combo}/nvme-test-empty.raw
597		cat > ${out} <<EOF
598${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M \\
599        -cpu cortex-a57 -drive file=${img},if=none,id=drive0,cache=writeback -smp 4 \\
600        -device virtio-blk,drive=drive0,bootindex=0 \\
601        -drive file=${bios_code},format=raw,if=pflash \\
602        -drive file=${bios_vars},format=raw,if=pflash \\
603        -drive file=${raw},if=none,id=drive1,cache=writeback,format=raw \\
604	-device nvme,serial=deadbeef,drive=drive1 \\
605        -monitor telnet::4444,server,nowait \\
606        -serial stdio \$*
607EOF
608		;;
609	esac
610    done
611
612if false; then
613    set -x
614    a=powerpc:powerpc
615    m=${a%%:*}
616    ma=${a##*:}
617    ma_combo="${m}"
618    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
619    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
620    out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
621    mkdir -p ${SCRIPTS}/${ma_combo}
622    cat > ${out} <<EOF
623${qemu_bin}/qemu-system-ppc -m 1g -M mac99,via=pmu \\
624	-vga none -nographic \\
625	-drive file=${img},if=virtio \\
626	-prom-env "boot-device=/pci@f2000000/scsi/disk@0:,\\\\\\:tbxi" \\
627        -monitor telnet::4444,server,nowait \\
628        -serial stdio \$*
629EOF
630
631    set -x
632    a=i386:i386
633    m=${a%%:*}
634    ma=${a##*:}
635    ma_combo="${m}"
636    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
637    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
638    out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
639    mkdir -p ${SCRIPTS}/${ma_combo}
640    cat > ${out} <<EOF
641${qemu_bin}/qemu-system-i386 -m 1g \\
642	-vga none -nographic \\
643	-drive file=${img},format=raw \\
644	-nographic \\
645        -monitor telnet::4444,server,nowait \\
646        -serial stdio \$*
647EOF
648fi
649}
650
651# The smallest FAT32 filesystem is 33292 KB
652espsize=33292
653
654set -e
655echo "src/stand test in ${STAND_ROOT}"
656update_freebsd_img_cache
657make_freebsd_minimal_trees
658make_freebsd_test_trees
659make_linux_initrds
660make_linux_esps
661make_freebsd_esps
662make_freebsd_images
663make_freebsd_scripts
664make_linuxboot_images
665make_linuxboot_scripts
666