check if there is actually anything to extract from the firmware tarball
authorrobert <robert@openbsd.org>
Fri, 14 Apr 2023 15:00:40 +0000 (15:00 +0000)
committerrobert <robert@openbsd.org>
Fri, 14 Apr 2023 15:00:40 +0000 (15:00 +0000)
on apple silicon so that we don't fill up the ramdisk by extracting the
whole tarball

while here, change the code so that the machdep.compatible sysctl gets
read once and then that value is used in the script instead of calling
sysctl several times

from input and ok kn@, kettenis@

distrib/arm64/ramdisk/install.md

index b7ae7b0..4be0425 100644 (file)
@@ -1,4 +1,4 @@
-#      $OpenBSD: install.md,v 1.44 2023/04/04 08:39:40 kn Exp $
+#      $OpenBSD: install.md,v 1.45 2023/04/14 15:00:40 robert Exp $
 #
 #
 # Copyright (c) 1996 The NetBSD Foundation, Inc.
 
 MDBOOTSR=y
 NCPU=$(sysctl -n hw.ncpufound)
+COMPATIBLE=$(sysctl -n machdep.compatible)
 MOUNT_ARGS_msdos="-o-l"
 
 md_installboot() {
        local _disk=$1 _chunks _bootdisk _mdec _plat
 
-       case $(sysctl -n machdep.compatible) in
+       case ${COMPATIBLE} in
        apple,*)                _plat=apple;;
        raspberrypi,*)          _plat=rpi;;
        esac
@@ -89,7 +90,7 @@ md_prep_fdisk() {
        local bootsectorsize="32768"
        local bootfstype="msdos"
 
-       case $(sysctl -n machdep.compatible) in
+       case ${COMPATIBLE} in
        openbsd,acpi)           bootsectorsize=532480;;
        esac
 
@@ -206,18 +207,18 @@ md_consoleinfo() {
                CSPEED=115200;;
        esac
 
-       _fw=$(dmesgtail | sed -n '\!^bwfm0: failed!{s!^.*/\(.*\),.*$!\1!p;q;}')
-       case $(sysctl -n machdep.compatible) in
+       case ${COMPATIBLE} in
        apple,*)
-               _fw2=$(sysctl -n machdep.compatible | sed 's/.*apple,//')
+               _fw=$(dmesgtail | sed -n '\!^bwfm0: failed!{s!^.*/\(.*\),.*$!\1!p;q;}')
+               _fw2=${COMPATIBLE##*apple,}
                make_dev sd0
                if mount -o ro /dev/sd0l /mnt2 2>/dev/null; then
                        rm -rf /usr/mdec/rpi /etc/firmware/apple
                        rm -rf /etc/firmware/brcm /etc/firmware/apple-bwfm
                        if [[ -s /mnt2/vendorfw/firmware.tar ]]; then
-                               tar -x -C /etc/firmware \
+                               [[ -n $_fw ]] && tar -x -C /etc/firmware \
                                    -f /mnt2/vendorfw/firmware.tar "*$_fw*" 2>/dev/null
-                               tar -x -C /etc/firmware \
+                               [[ -n $_fw2 ]] && tar -x -C /etc/firmware \
                                    -f /mnt2/vendorfw/firmware.tar "*$_fw2*" 2>/dev/null
                                mv /etc/firmware/brcm /etc/firmware/apple-bwfm 2>/dev/null
                        fi