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