xref: /freebsd/tools/boot/full-test.sh (revision 905541dd6ba4e94b4aa67d8a0eae6a5eb07f20a0)
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/libtinfow.so.9 lib/libncursesw.so.9 lib/libc.so.7 lib/libedit.so.8 libexec/ld-elf.so.1
164    # My simple etc/rc
165    cat > ${dir}/etc/rc <<EOF
166#!/bin/sh
167
168sysctl machdep.bootmethod
169echo "RC COMMAND RUNNING -- SUCCESS!!!!!"
170halt -p
171EOF
172    chmod +x ${dir}/etc/rc
173
174    # Check to see if we have overrides here... So we can insert our own kernel
175    # instead of the one from the release.
176    echo "CHECKING ${OVERRIDE}/${ma_combo}/boot"
177    if [ -d ${OVERRIDE}/${ma_combo}/boot ]; then
178	o=${OVERRIDE}/${ma_combo}
179	for i in \
180	    boot/device.hints \
181	    boot/kernel/kernel \
182	    boot/kernel/acl_nfs4.ko \
183	    boot/kernel/cryptodev.ko \
184	    boot/kernel/zfs.ko \
185	    boot/kernel/geom_eli.ko; do
186	    [ -r $o/$i ] && echo Copying override $i && cp $o/$i ${dir}/$i
187	done
188    else
189	# Copy the kernel (but not the boot loader, we'll add the one to test later)
190	# This will take care of both UFS and ZFS boots as well as geli
191	# Note: It's OK for device.hints to be missing. It's mostly for legacy platforms.
192	tar -C ${dir} -xf ${CACHE}/$file \
193	    boot/device.hints \
194	    boot/kernel/kernel \
195	    boot/kernel/acl_nfs4.ko \
196	    boot/kernel/cryptodev.ko \
197	    boot/kernel/zfs.ko \
198	    boot/kernel/geom_eli.ko || true
199	# XXX WHAT TO DO ABOUT LINKER HINTS -- PUNT FOR NOW
200	# XXX also, ZFS not supported on 32-bit powerpc platforms
201    fi
202
203    # Setup some common settings for serial console, etc
204    echo -h -D -S115200 > ${dir}/boot.config
205    cat > ${dir}/boot/loader.conf <<EOF
206comconsole_speed=115200
207autoboot_delay=2
208zfs_load="YES"
209boot_verbose=yes
210kern.cfg.order="acpi,fdt"
211boot_serial="YES"
212hw.uart.console="io:1016,br:115200"
213vfs.root.mountfrom="ufs:/dev/ufs/root"
214vfs.root.mountfrom.options="rw"
215EOF
216}
217
218make_freebsd_minimal_trees()
219{
220    for a in $ARCHES; do
221	m=${a%%:*}
222	ma=${a##*:}
223	make_minimal_freebsd_tree $m $ma ${FREEBSD_VERSION} bootonly.iso
224    done
225    # Note: armv7 isn't done yet as its the odd-man out -- we need to extract things
226    # in a special way, so punt for the moment
227}
228
229make_freebsd_test_trees()
230{
231    for a in $ARCHES; do
232	m=${a%%:*}
233	ma=${a##*:}
234	ma_combo="${m}"
235	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
236	dir=${TREES}/${ma_combo}/test-stand
237	mkdir -p ${dir}
238	${MTREE} -deUW -f ${SRCTOP}/etc/mtree/BSD.root.dist -p ${dir}
239	echo "Creating tree for ${m}:${ma}"
240	cd ${SRCTOP}
241	# Indirection needed because our build system is too complex
242	# Also, bare make for 'inside' the buildenv ${MAKE} for outside
243#	SHELL="make clean" ${MAKE} buildenv TARGET=${m} TARGET_ARCH=${ma}
244	SHELL="sh -c 'cd stand ; make -j 100 all'" ${MAKE} TARGET=${m} TARGET_ARCH=${ma} buildenv
245	DESTDIR=${dir} SHELL="sh -c 'cd stand ; make install MK_MAN=no MK_INSTALL_AS_USER=yes WITHOUT_DEBUG_FILES=yes'" \
246	     ${MAKE} buildenv TARGET=${m} TARGET_ARCH=${ma}
247	rm -rf ${dir}/bin ${dir}/[ac-z]*	# Don't care about anything here
248    done
249}
250
251make_linux_initrds()
252{
253    # At the moment, we have just two
254    for a in amd64:amd64 arm64:aarch64; do
255	m=${a%%:*}
256	ma=${a##*:}
257	ma_combo="${m}"
258	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
259	dir=${TREES}/${ma_combo}/linuxboot
260	dir2=${TREES}/${ma_combo}/test-stand
261	dir3=${TREES}/${ma_combo}/freebsd
262	initrd=${TREES}/${ma_combo}/initrd.img
263	rm -rf ${dir}
264	mkdir -p ${dir}
265	cp ${dir2}/boot/loader.kboot ${dir}/init
266	# Copy the boot loader
267	tar -c -f - -C ${dir2} boot | tar -xf - -C ${dir}
268	# Copy the boot kernel
269	tar -c -f - -C ${dir3} boot | tar -xf - -C ${dir}
270	(cd ${dir} ; find . | LC_ALL=C sort | cpio -o -H newc | gzip > ${initrd})
271    done
272}
273
274make_linux_esps()
275{
276    # At the moment, we have just two
277    for a in amd64:amd64 arm64:aarch64; do
278	m=${a%%:*}
279	ma=${a##*:}
280	ma_combo="${m}"
281	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
282	dir=${TREES}/${ma_combo}/linuxboot-esp
283	initrd=${TREES}/${ma_combo}/initrd.img
284	mkdir -p ${dir}
285	case ${ma} in
286	    amd64) bin=x64 cons="console=ttyS0,115200" ;;
287	    aarch64) bin=aa64 ;;
288	esac
289	mkdir -p ${dir}/efi/boot
290	cp ${CACHE}/linux/linux${bin}.efi ${dir}
291	cp ${CACHE}/linux/shell${bin}.efi ${dir}/efi/boot/boot${bin}.efi
292	cat > ${dir}/startup.nsh <<EOF
293# Run linux
294# Tell it to run with out special initrd that then boot FreeBSD
295
296\linux${bin} ${cons} initrd=\initrd.img
297EOF
298	cp $initrd ${dir}
299    done
300}
301
302make_linuxboot_images()
303{
304    # ESP variant: In this variant, amd64 and arm64 are both created more or
305    # less the same way. Both are EFI + ACPI implementations
306    for a in amd64:amd64 arm64:aarch64; do
307	m=${a%%:*}
308	ma=${a##*:}
309	ma_combo="${m}"
310	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
311	src=${TREES}/${ma_combo}/linuxboot-esp
312	dir=${TREES}/${ma_combo}/freebsd
313	dir2=${TREES}/${ma_combo}/test-stand
314	esp=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.esp
315	ufs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.ufs
316	zfs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.zfs
317	img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img
318	img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img
319	pool="linuxboot"
320	mkdir -p ${IMAGES}/${ma_combo}
321	${MAKEFS} -t msdos -o fat_type=32 -o sectors_per_cluster=1 \
322	       -o volume_label=EFISYS -s80m ${esp} ${src}
323	${MAKEFS} -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2}
324	${MKIMG} -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img}
325	${MAKEFS} -t zfs -s 200m \
326	       -o poolname=${pool} -o bootfs=${pool} -o rootpath=/ \
327		${zfs} ${dir} ${dir2}
328	${MKIMG} -s gpt \
329	      -p efi:=${esp} \
330	      -p freebsd-zfs:=${zfs} -o ${img2}
331	rm -f ${esp}	# Don't need to keep this around
332    done
333
334    # The raw variant, currently used only on arm64. It boots with the raw interface of qemu
335    # for testing purposes.  This means it makes a good test for the DTB variation, but not ACPI
336    # since qemu doesn't currently provide that...
337    for a in arm64:aarch64; do
338	m=${a%%:*}
339	ma=${a##*:}
340	ma_combo="${m}"
341	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
342	linux="${CACHE}/linux/vmlinux-${m}*"
343	initrd=${TREES}/${ma_combo}/initrd.img
344	img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw
345	cp ${linux} ${img}.kernel
346	cp ${initrd} ${img}.initrd
347    done
348}
349
350make_linuxboot_scripts()
351{
352    # At the moment, we have just two -- and the images we've built so far are just
353    # the hostfs boot. The boot off anything more complex isn't here.
354    for a in amd64:amd64 arm64:aarch64; do
355	m=${a%%:*}
356	ma=${a##*:}
357	ma_combo="${m}"
358	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
359
360	# First off, update the edk firmware
361	bios_code=${BIOS}/edk2-${ma_combo}-code.fd
362	bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd
363	case ${ma} in
364	    amd64)
365		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then
366		    cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code}
367		    # vars file works on both 32 and 64 bit x86
368#		    cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars}
369		fi
370		;;
371	    aarch64)
372		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then
373		    # aarch64 vars starts as an empty file
374		    dd if=/dev/zero of=${bios_code} bs=1M count=64
375		    dd if=/dev/zero of=${bios_vars} bs=1M count=64
376		    dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc
377		fi
378		;;
379	esac
380
381	# Now make me a script
382	img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img
383	img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw
384	img3=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img
385	out=${SCRIPTS}/${ma_combo}/linuxboot-test.sh
386	out2=${SCRIPTS}/${ma_combo}/linuxboot-test-raw.sh
387	out3=${SCRIPTS}/${ma_combo}/linuxboot-test-zfs.sh
388	cd=${CACHE}/FreeBSD-13.1-RELEASE-arm64-aarch64-bootonly.iso
389	mkdir -p ${SCRIPTS}/${ma_combo}
390	case ${ma} in
391	    amd64)
392		cat > ${out} <<EOF
393${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\
394        -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\
395        -device virtio-blk,drive=drive0,bootindex=0 \\
396        -drive file=${bios_code},format=raw,if=pflash \\
397        -drive file=${bios_vars},format=raw,if=pflash \\
398        -monitor telnet::4444,server,nowait \\
399        -serial stdio \$*
400EOF
401		;;
402	    aarch64)
403		# ESP version
404		raw=${IMAGES}/${ma_combo}/freebsd-arm64-aarch64.img
405		cat > ${out} <<EOF
406${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\
407        -cpu cortex-a57 \\
408	-drive file=${img},if=none,id=drive0,cache=writeback \\
409	-device virtio-blk,drive=drive0,bootindex=0 \\
410        -drive file=${raw},if=none,id=drive1,cache=writeback \\
411	-device nvme,serial=fboot,drive=drive1,bootindex=1 \\
412        -drive file=${bios_code},format=raw,if=pflash \\
413        -drive file=${bios_vars},format=raw,if=pflash \\
414        -monitor telnet::4444,server,nowait \\
415        -serial stdio \$*
416EOF
417		# RAW version
418		# Note: We have to use cortex-a57 for raw mode because the
419		# kernel we use has issues with max.
420		cat > ${out2} <<EOF
421${qemu_bin}/qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt \\
422	-kernel ${img2}.kernel -initrd ${img2}.initrd \\
423	-append "console=ttyAMA0" \\
424        -drive file=${cd},if=none,id=drive0,cache=writeback,format=raw \\
425        -device virtio-blk,drive=drive0,bootindex=0 \\
426	-nographic -monitor telnet::4444,server,nowait \\
427	-serial stdio \$*
428EOF
429		# ZFS version
430		# Note: We have to use cortex-a57 for raw mode because the
431		# kernel we use has issues with max.
432		cat > ${out3} <<EOF
433${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\
434        -cpu cortex-a57 \\
435	-drive file=${img3},if=none,id=drive0,cache=writeback \\
436	-device virtio-blk,drive=drive0,bootindex=0 \\
437        -drive file=${bios_code},format=raw,if=pflash \\
438        -drive file=${bios_vars},format=raw,if=pflash \\
439        -monitor telnet::4444,server,nowait \\
440        -serial stdio \$*
441EOF
442		;;
443	esac
444    done
445}
446
447make_freebsd_esps()
448{
449    # At the moment, we have just three (armv7 could also be here too, but we're not doing that)
450#   for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do
451    for a in amd64:amd64 arm64:aarch64; do
452	m=${a%%:*}
453	ma=${a##*:}
454	ma_combo="${m}"
455	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
456	dir=${TREES}/${ma_combo}/freebsd-esp
457	dir2=${TREES}/${ma_combo}/test-stand
458	rm -rf ${dir}
459	mkdir -p ${dir}
460	case ${ma} in
461	    amd64) bin=x64 ;;
462	    aarch64) bin=aa64 ;;
463	esac
464	mkdir -p ${dir}/efi/boot
465	cp ${dir2}/boot/loader.efi ${dir}/efi/boot/boot${bin}.efi
466    done
467}
468
469make_freebsd_images()
470{
471    # ESP variant: In this variant, riscv, amd64 and arm64 are created more or
472    # less the same way. UEFI + ACPI implementations
473#   for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do
474    for a in amd64:amd64 arm64:aarch64; do
475	m=${a%%:*}
476	ma=${a##*:}
477	ma_combo="${m}"
478	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
479	src=${TREES}/${ma_combo}/freebsd-esp
480	dir=${TREES}/${ma_combo}/freebsd
481	dir2=${TREES}/${ma_combo}/test-stand
482	esp=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.esp
483	ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
484	img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
485	mkdir -p ${IMAGES}/${ma_combo}
486	mkdir -p ${dir2}/etc
487	cat > ${dir2}/etc/fstab <<EOF
488/dev/ufs/root	/		ufs	rw	1	1
489EOF
490	${MAKEFS} -t msdos -o fat_type=32 -o sectors_per_cluster=1 \
491	       -o volume_label=EFISYS -s100m ${esp} ${src}
492	${MAKEFS} -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2}
493	${MKIMG} -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img}
494	# rm -f ${esp} ${ufs}	# Don't need to keep this around
495    done
496
497    set -x
498
499if false; then
500    # BIOS i386
501    a=i386:i386
502    m=${a%%:*}
503    ma=${a##*:}
504    ma_combo="${m}"
505    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
506    dir=${TREES}/${ma_combo}/freebsd
507    dir2=${TREES}/${ma_combo}/test-stand
508    ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
509    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
510    mkdir -p ${IMAGES}/${ma_combo}
511    mkdir -p ${dir2}/etc
512    cat > ${dir2}/etc/fstab <<EOF
513/dev/ufs/root	/		ufs	rw	1	1
514EOF
515    ${MAKEFS} -t ffs -B little -s 200m \
516	   -o label=root,version=2,bsize=32768,fsize=4096,density=16384 \
517	   ${ufs} ${dir} ${dir2}
518    ${MKIMG} -s gpt -b ${dir2}/boot/pmbr \
519	  -p freebsd-boot:=${dir2}/boot/gptboot \
520	  -p freebsd-ufs:=${ufs} \
521	  -o ${img}
522    rm -f ${src}/etc/fstab
523
524    # PowerPC for 32-bit mac
525    a=powerpc:powerpc
526    m=${a%%:*}
527    ma=${a##*:}
528    ma_combo="${m}"
529    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
530    dir=${TREES}/${ma_combo}/freebsd
531    dir2=${TREES}/${ma_combo}/test-stand
532    ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
533    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
534    mkdir -p ${IMAGES}/${ma_combo}
535    mkdir -p ${dir2}/etc
536    cat > ${dir2}/etc/fstab <<EOF
537/dev/ufs/root	/		ufs	rw	1	1
538EOF
539    ${MAKEFS} -t ffs -B big -s 200m \
540	   -o label=root,version=2,bsize=32768,fsize=4096,density=16384 \
541	   ${ufs} ${dir} ${dir2}
542    ${MKIMG} -a 1 -s apm \
543        -p freebsd-boot:=${dir2}/boot/boot1.hfs \
544        -p freebsd-ufs:=${ufs} \
545        -o ${img}
546fi
547
548    set +x
549}
550
551make_freebsd_scripts()
552{
553    # At the moment, we have just two
554    for a in amd64:amd64 arm64:aarch64; do
555	m=${a%%:*}
556	ma=${a##*:}
557	ma_combo="${m}"
558	[ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
559
560	# First off, update the edk firmware
561	bios_code=${BIOS}/edk2-${ma_combo}-code.fd
562	bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd
563	case ${ma} in
564	    amd64)
565		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then
566		    cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code}
567		    # vars file works on both 32 and 64 bit x86
568#		    cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars}
569		fi
570		;;
571	    aarch64)
572		if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then
573		    # aarch64 vars starts as an empty file
574		    dd if=/dev/zero of=${bios_code} bs=1M count=64
575		    dd if=/dev/zero of=${bios_vars} bs=1M count=64
576		    dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc
577		fi
578		;;
579	esac
580
581	# Now make me a script
582	img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
583	out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
584	mkdir -p ${SCRIPTS}/${ma_combo}
585	case ${ma} in
586	    amd64)
587		cat > ${out} <<EOF
588${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\
589        -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\
590        -device virtio-blk,drive=drive0,bootindex=0 \\
591        -drive file=${bios_code},format=raw,if=pflash \\
592        -drive file=${bios_vars},format=raw,if=pflash \\
593        -monitor telnet::4444,server,nowait \\
594        -serial stdio \$*
595EOF
596		;;
597	    aarch64)
598		# ESP version
599		raw=${IMAGES}/${ma_combo}/nvme-test-empty.raw
600		cat > ${out} <<EOF
601${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M \\
602        -cpu cortex-a57 -drive file=${img},if=none,id=drive0,cache=writeback -smp 4 \\
603        -device virtio-blk,drive=drive0,bootindex=0 \\
604        -drive file=${bios_code},format=raw,if=pflash \\
605        -drive file=${bios_vars},format=raw,if=pflash \\
606        -drive file=${raw},if=none,id=drive1,cache=writeback,format=raw \\
607	-device nvme,serial=deadbeef,drive=drive1 \\
608        -monitor telnet::4444,server,nowait \\
609        -serial stdio \$*
610EOF
611		;;
612	esac
613    done
614
615if false; then
616    set -x
617    a=powerpc:powerpc
618    m=${a%%:*}
619    ma=${a##*:}
620    ma_combo="${m}"
621    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
622    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
623    out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
624    mkdir -p ${SCRIPTS}/${ma_combo}
625    cat > ${out} <<EOF
626${qemu_bin}/qemu-system-ppc -m 1g -M mac99,via=pmu \\
627	-vga none -nographic \\
628	-drive file=${img},if=virtio \\
629	-prom-env "boot-device=/pci@f2000000/scsi/disk@0:,\\\\\\:tbxi" \\
630        -monitor telnet::4444,server,nowait \\
631        -serial stdio \$*
632EOF
633
634    set -x
635    a=i386:i386
636    m=${a%%:*}
637    ma=${a##*:}
638    ma_combo="${m}"
639    [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
640    img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
641    out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
642    mkdir -p ${SCRIPTS}/${ma_combo}
643    cat > ${out} <<EOF
644${qemu_bin}/qemu-system-i386 -m 1g \\
645	-vga none -nographic \\
646	-drive file=${img},format=raw \\
647	-nographic \\
648        -monitor telnet::4444,server,nowait \\
649        -serial stdio \$*
650EOF
651fi
652}
653
654# The smallest FAT32 filesystem is 33292 KB
655espsize=33292
656
657set -e
658echo "src/stand test in ${STAND_ROOT}"
659update_freebsd_img_cache
660make_freebsd_minimal_trees
661make_freebsd_test_trees
662make_linux_initrds
663make_linux_esps
664make_freebsd_esps
665make_freebsd_images
666make_freebsd_scripts
667make_linuxboot_images
668make_linuxboot_scripts
669