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
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.
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
20 # What version of FreeBSD to we snag the ISOs from to extract the binaries
23 # eg https://download.freebsd.org/releases/amd64/amd64/ISO-IMAGES/13.1/FreeBSD-13.1-RELEASE-amd64-bootonly.iso.xz
24 URLBASE="https://download.freebsd.org/releases"
25 : ${STAND_ROOT:="${HOME}/stand-test-root"}
26 CACHE=${STAND_ROOT}/cache
27 TREES=${STAND_ROOT}/trees
28 IMAGES=${STAND_ROOT}/images
29 BIOS=${STAND_ROOT}/bios
30 SCRIPTS=${STAND_ROOT}/scripts
31 OVERRIDE=${STAND_ROOT}/override
33 # hack -- I have extra junk in my qemu, but it's not needed to recreate things
34 if [ $(whoami) = imp ]; then
35 qemu_bin=/home/imp/git/qemu/00-build
37 qemu_bin=/usr/local/bin
40 # All the architectures under test
41 # Note: we can't yet do armv7 because we don't have a good iso for it and would
42 # need root to extract the files.
43 ARCHES="amd64:amd64 i386:i386 powerpc:powerpc powerpc:powerpc64 powerpc:powerpc64le powerpc:powerpcspe arm64:aarch64 riscv:riscv64"
45 # The smallest FAT32 filesystem is 33292 KB
48 SRCTOP=$(make -v SRCTOP)
50 mkdir -p ${CACHE} ${TREES} ${IMAGES} ${BIOS}
64 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
74 local ma_combo=$(ma_combo $m $ma)
75 local file="FreeBSD-${v}-RELEASE-${ma_combo}-${flavor}"
76 local url="${URLBASE}/${m}/${ma}/ISO-IMAGES/${v}/${file}.xz"
79 [ -r ${CACHE}/${file} ] && echo "Using cached ${file}" && return
81 echo "Fetching ${url}"
82 fetch ${url} || die "Can't fetch ${file} from ${url}"
83 xz -d ${file}.xz || die "Can't uncompress ${file}.xz"
87 update_freebsd_img_cache()
94 fetch_one $m $ma ${FREEBSD_VERSION} bootonly.iso
97 fetch_one arm armv7 ${FREEBSD_VERSION} GENERICSD.img
100 make_minimal_freebsd_tree()
107 local ma_combo="${m}"
108 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
110 file="FreeBSD-${v}-RELEASE-${ma_combo}-${flavor}"
111 dir=${TREES}/${ma_combo}/freebsd
114 # Make a super simple userland. It has just enough to print a santiy value,
115 # then say test succeeded, and then halt the system. We assume that /bin/sh
116 # has all the library prereqs for the rest...
119 for d in boot/kernel boot/defaults boot/lua boot/loader.conf.d \
120 sbin bin lib libexec etc dev; do
123 # Pretend we don't have a separate /usr
125 # snag the binaries for my simple /etc/rc file
126 tar -C ${dir} -xf ${CACHE}/$file sbin/reboot sbin/halt sbin/init bin/sh sbin/sysctl \
127 lib/libncursesw.so.9 lib/libc.so.7 lib/libedit.so.8 libexec/ld-elf.so.1
130 cat > ${dir}/etc/rc <<EOF
133 sysctl machdep.bootmethod
134 echo "RC COMMAND RUNNING -- SUCCESS!!!!!"
137 chmod +x ${dir}/etc/rc
139 # Check to see if we have overrides here... So we can insert our own kernel
140 # instead of the one from the release.
141 echo "CHECKING ${OVERRIDE}/${ma_combo}/boot"
142 if [ -d ${OVERRIDE}/${ma_combo}/boot ]; then
143 o=${OVERRIDE}/${ma_combo}
147 boot/kernel/acl_nfs4.ko \
148 boot/kernel/cryptodev.ko \
150 boot/kernel/geom_eli.ko; do
151 [ -r $o/$i ] && echo Copying override $i && cp $o/$i ${dir}/$i
154 # Copy the kernel (but not the boot loader, we'll add the one to test later)
155 # This will take care of both UFS and ZFS boots as well as geli
156 # Note: It's OK for device.hints to be missing. It's mostly for legacy platforms.
157 tar -C ${dir} -xf ${CACHE}/$file \
160 boot/kernel/acl_nfs4.ko \
161 boot/kernel/cryptodev.ko \
163 boot/kernel/geom_eli.ko || true
164 # XXX WHAT TO DO ABOUT LINKER HINTS -- PUNT FOR NOW
165 # XXX also, ZFS not supported on 32-bit powerpc platforms
168 # Setup some common settings for serial console, etc
169 echo -h -D -S115200 > ${dir}/boot.config
170 cat > ${dir}/boot/loader.conf <<EOF
171 comconsole_speed=115200
173 # XXXX TEST with arm64 iso...
174 #vfs.root.mountfrom="cd9660:/dev/iso9660/13_1_RELEASE_AARCH64_BO"
175 # XXX not so good for ZFS, what to do?
176 vfs.root.mountfrom="ufs:/dev/ufs/root"
178 kern.cfg.order="acpi,fdt"
182 make_freebsd_minimal_trees()
187 make_minimal_freebsd_tree $m $ma ${FREEBSD_VERSION} bootonly.iso
189 # Note: armv7 isn't done yet as its the odd-man out -- we need to extract things
190 # in a special way, so punt for the moment
193 make_freebsd_test_trees()
199 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
200 dir=${TREES}/${ma_combo}/test-stand
202 mtree -deUW -f ${SRCTOP}/etc/mtree/BSD.root.dist -p ${dir}
203 echo "Creating tree for ${m}:${ma}"
205 # Indirection needed because our build system is too complex
206 # SHELL="make clean" make buildenv TARGET=${m} TARGET_ARCH=${ma}
207 SHELL="make -j 100 all" make buildenv TARGET=${m} TARGET_ARCH=${ma}
208 SHELL="make install DESTDIR=${dir} MK_MAN=no MK_INSTALL_AS_USER=yes WITHOUT_DEBUG_FILES=yes" \
209 make buildenv TARGET=${m} TARGET_ARCH=${ma}
210 rm -rf ${dir}/bin ${dir}/[ac-z]* # Don't care about anything here
216 # At the moment, we have just two
217 for a in amd64:amd64 arm64:aarch64; do
221 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
222 dir=${TREES}/${ma_combo}/linuxboot
223 dir2=${TREES}/${ma_combo}/test-stand
224 dir3=${TREES}/${ma_combo}/freebsd
225 initrd=${TREES}/${ma_combo}/initrd.img
228 cp ${dir2}/boot/loader.kboot ${dir}/init
229 # Copy the boot loader
230 tar -c -f - -C ${dir2} boot | tar -xf - -C ${dir}
231 # Copy the boot kernel
232 tar -c -f - -C ${dir3} boot | tar -xf - -C ${dir}
233 (cd ${dir} ; find . | LC_ALL=C sort | cpio -o -H newc | gzip > ${initrd})
239 # At the moment, we have just two
240 for a in amd64:amd64 arm64:aarch64; do
244 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
245 dir=${TREES}/${ma_combo}/linuxboot-esp
246 initrd=${TREES}/${ma_combo}/initrd.img
249 amd64) bin=x64 cons="console=ttyS0,115200" ;;
252 mkdir -p ${dir}/efi/boot
253 cp ${CACHE}/linux/linux${bin}.efi ${dir}
254 cp ${CACHE}/linux/shell${bin}.efi ${dir}/efi/boot/boot${bin}.efi
255 cat > ${dir}/startup.nsh <<EOF
257 # Tell it to run with out special initrd that then boot FreeBSD
259 \linux${bin} ${cons} initrd=\initrd.img
265 make_linuxboot_images()
267 # ESP variant: In this variant, amd64 and arm64 are both created more or
268 # less the same way. Both are EFI + ACPI implementations
269 for a in amd64:amd64 arm64:aarch64; do
273 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
274 src=${TREES}/${ma_combo}/linuxboot-esp
275 dir=${TREES}/${ma_combo}/freebsd
276 dir2=${TREES}/${ma_combo}/test-stand
277 esp=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.esp
278 ufs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.ufs
279 zfs=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.zfs
280 img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img
281 img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img
282 pool="linuxboot-testing"
283 mkdir -p ${IMAGES}/${ma_combo}
284 makefs -t msdos -o fat_type=32 -o sectors_per_cluster=1 \
285 -o volume_label=EFISYS -s100m ${esp} ${src}
286 makefs -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2}
287 mkimg -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img}
288 makefs -t zfs -s 200m \
289 -o poolname=${pool} -o bootfs=${pool} -o rootpath=/ \
290 ${zfs} ${dir} ${dir2}
293 -p freebsd-zfs:=${zfs} -o ${img2}
294 rm -f ${esp} # Don't need to keep this around
297 # The raw variant, currently used only on arm64. It boots with the raw interface of qemu
298 # for testing purposes. This means it makes a good test for the DTB variation, but not ACPI
299 # since qemu doesn't currently provide that...
300 for a in arm64:aarch64; do
304 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
305 linux="${CACHE}/linux/vmlinux-${m}*"
306 initrd=${TREES}/${ma_combo}/initrd.img
307 img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw
308 cp ${linux} ${img}.kernel
309 cp ${initrd} ${img}.initrd
313 make_linuxboot_scripts()
315 # At the moment, we have just two -- and the images we've built so far are just
316 # the hostfs boot. The boot off anything more complex isn't here.
317 for a in amd64:amd64 arm64:aarch64; do
321 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
323 # First off, update the edk firmware
324 bios_code=${BIOS}/edk2-${ma_combo}-code.fd
325 bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd
328 if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then
329 cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code}
330 # vars file works on both 32 and 64 bit x86
331 cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars}
335 if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then
336 # aarch64 vars starts as an empty file
337 dd if=/dev/zero of=${bios_code} bs=1M count=64
338 dd if=/dev/zero of=${bios_vars} bs=1M count=64
339 dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc
344 # Now make me a script
345 img=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}.img
346 img2=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-raw
347 img3=${IMAGES}/${ma_combo}/linuxboot-${ma_combo}-zfs.img
348 out=${SCRIPTS}/${ma_combo}/linuxboot-test.sh
349 out2=${SCRIPTS}/${ma_combo}/linuxboot-test-raw.sh
350 out3=${SCRIPTS}/${ma_combo}/linuxboot-test-zfs.sh
351 cd=${CACHE}/FreeBSD-13.1-RELEASE-arm64-aarch64-bootonly.iso
352 mkdir -p ${SCRIPTS}/${ma_combo}
356 ${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\
357 -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\
358 -device virtio-blk,drive=drive0,bootindex=0 \\
359 -drive file=${bios_code},format=raw,if=pflash \\
360 -drive file=${bios_vars},format=raw,if=pflash \\
361 -monitor telnet::4444,server,nowait \\
367 raw=${IMAGES}/${ma_combo}/freebsd-arm64-aarch64.img
369 ${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\
371 -drive file=${img},if=none,id=drive0,cache=writeback \\
372 -device virtio-blk,drive=drive0,bootindex=0 \\
373 -drive file=${raw},if=none,id=drive1,cache=writeback \\
374 -device nvme,serial=fboot,drive=drive1,bootindex=1 \\
375 -drive file=${bios_code},format=raw,if=pflash \\
376 -drive file=${bios_vars},format=raw,if=pflash \\
377 -monitor telnet::4444,server,nowait \\
381 # Note: We have to use cortex-a57 for raw mode because the
382 # kernel we use has issues with max.
384 ${qemu_bin}/qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt \\
385 -kernel ${img2}.kernel -initrd ${img2}.initrd \\
386 -append "console=ttyAMA0" \\
387 -drive file=${cd},if=none,id=drive0,cache=writeback,format=raw \\
388 -device virtio-blk,drive=drive0,bootindex=0 \\
389 -nographic -monitor telnet::4444,server,nowait \\
393 # Note: We have to use cortex-a57 for raw mode because the
394 # kernel we use has issues with max.
396 ${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M -smp 4 \\
398 -drive file=${img3},if=none,id=drive0,cache=writeback \\
399 -device virtio-blk,drive=drive0,bootindex=0 \\
400 -drive file=${bios_code},format=raw,if=pflash \\
401 -drive file=${bios_vars},format=raw,if=pflash \\
402 -monitor telnet::4444,server,nowait \\
412 # At the moment, we have just three (armv7 could also be here too, but we're not doing that)
413 for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do
417 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
418 dir=${TREES}/${ma_combo}/freebsd-esp
419 dir2=${TREES}/${ma_combo}/test-stand
426 mkdir -p ${dir}/efi/boot
427 cp ${dir2}/boot/loader.efi ${dir}/efi/boot/boot${bin}.efi
431 make_freebsd_images()
433 # ESP variant: In this variant, riscv, amd64 and arm64 are created more or
434 # less the same way. UEFI + ACPI implementations
435 for a in amd64:amd64 arm64:aarch64 riscv:riscv64; do
439 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
440 src=${TREES}/${ma_combo}/freebsd-esp
441 dir=${TREES}/${ma_combo}/freebsd
442 dir2=${TREES}/${ma_combo}/test-stand
443 esp=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.esp
444 ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
445 img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
446 mkdir -p ${IMAGES}/${ma_combo}
448 makefs -t msdos -o fat_type=32 -o sectors_per_cluster=1 \
449 -o volume_label=EFISYS -s100m ${esp} ${src}
450 makefs -t ffs -B little -s 200m -o label=root ${ufs} ${dir} ${dir2}
451 mkimg -s gpt -p efi:=${esp} -p freebsd-ufs:=${ufs} -o ${img}
452 # rm -f ${esp} ${ufs} # Don't need to keep this around
457 # PowerPC for 32-bit mac
462 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
463 dir=${TREES}/${ma_combo}/freebsd
464 dir2=${TREES}/${ma_combo}/test-stand
465 ufs=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.ufs
466 img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
467 mkdir -p ${IMAGES}/${ma_combo}
468 makefs -t ffs -B big -s 200m \
469 -o label=root,version=2,bsize=32768,fsize=4096,density=16384 \
470 ${ufs} ${dir} ${dir2}
472 -p freebsd-boot:=${dir2}/boot/boot1.hfs \
473 -p freebsd-ufs:=${ufs} \
479 make_freebsd_scripts()
481 # At the moment, we have just two
482 for a in amd64:amd64 arm64:aarch64; do
486 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
488 # First off, update the edk firmware
489 bios_code=${BIOS}/edk2-${ma_combo}-code.fd
490 bios_vars=${BIOS}/edk2-${ma_combo}-vars.fd
493 if [ ${bios_code} -ot /usr/local/share/qemu/edk2-x86_64-code.fd ]; then
494 cp /usr/local/share/qemu/edk2-x86_64-code.fd ${bios_code}
495 # vars file works on both 32 and 64 bit x86
496 cp /usr/local/share/qemu/edk2-i386-vars.fd ${bios_vars}
500 if [ ${bios_code} -ot /usr/local/share/qemu/edk2-aarch64-code.fd ]; then
501 # aarch64 vars starts as an empty file
502 dd if=/dev/zero of=${bios_code} bs=1M count=64
503 dd if=/dev/zero of=${bios_vars} bs=1M count=64
504 dd if=/usr/local/share/qemu/edk2-aarch64-code.fd of=${bios_code} conv=notrunc
509 # Now make me a script
510 img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
511 out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
512 mkdir -p ${SCRIPTS}/${ma_combo}
516 ${qemu_bin}/qemu-system-x86_64 -nographic -m 512M \\
517 -drive file=${img},if=none,id=drive0,cache=writeback,format=raw \\
518 -device virtio-blk,drive=drive0,bootindex=0 \\
519 -drive file=${bios_code},format=raw,if=pflash \\
520 -drive file=${bios_vars},format=raw,if=pflash \\
521 -monitor telnet::4444,server,nowait \\
527 raw=${IMAGES}/${ma_combo}/nvme-test-empty.raw
529 ${qemu_bin}/qemu-system-aarch64 -nographic -machine virt,gic-version=3 -m 512M \\
530 -cpu cortex-a57 -drive file=${img},if=none,id=drive0,cache=writeback -smp 4 \\
531 -device virtio-blk,drive=drive0,bootindex=0 \\
532 -drive file=${bios_code},format=raw,if=pflash \\
533 -drive file=${bios_vars},format=raw,if=pflash \\
534 -drive file=${raw},if=none,id=drive1,cache=writeback,format=raw \\
535 -device nvme,serial=deadbeef,drive=drive1 \\
536 -monitor telnet::4444,server,nowait \\
548 [ "${m}" != "${ma}" ] && ma_combo="${m}-${ma}"
549 img=${IMAGES}/${ma_combo}/freebsd-${ma_combo}.img
550 out=${SCRIPTS}/${ma_combo}/freebsd-test.sh
551 mkdir -p ${SCRIPTS}/${ma_combo}
553 ${qemu_bin}/qemu-system-ppc -m 1g -M mac99,via=pmu \\
554 -vga none -nographic \\
555 -drive file=${img},if=virtio \\
556 -prom-env "boot-device=/pci@f2000000/scsi/disk@0:,\\\\\\:tbxi" \\
557 -monitor telnet::4444,server,nowait \\
562 # The smallest FAT32 filesystem is 33292 KB
566 echo "src/stand test in ${STAND_ROOT}"
567 update_freebsd_img_cache
568 make_freebsd_minimal_trees
569 make_freebsd_test_trees
575 make_linuxboot_images
576 make_linuxboot_scripts