This patch allows GPT partitioning when installing a riscv64 system.
Currently, the install.md insists on using MBR.

The patch also adds fdisk -A when a BIOS boot partition is found.
The PolarFire SoC HSS firmware uses the partition to load boot code.

OK?

Index: distrib/miniroot/install.sub
===================================================================
RCS file: src/distrib/miniroot/install.sub,v
retrieving revision 1.1191
diff -u -p -r1.1191 install.sub
--- distrib/miniroot/install.sub        29 Jan 2022 20:17:58 -0000      1.1191
+++ distrib/miniroot/install.sub        3 Feb 2022 13:33:59 -0000
@@ -382,6 +382,7 @@ disk_has() {
        local _p_gpt_apfs='^[ *]...: APFS '
        local _p_gpt_apfsisc='^[ *]...: APFS ISC '
        local _p_gpt_apfsrecovery='^[ *]...: APFS Recovry '
+       local _p_gpt_biosboot='^[ *]...: BIOS Boot '
        local _p_gpt_efisys='^[ *]...: EFI Sys '
        local _p_hfs='^Partition map '
        local _p_hfs_openbsd=' OpenBSD OpenBSD '
Index: distrib/riscv64/ramdisk/install.md
===================================================================
RCS file: src/distrib/riscv64/ramdisk/install.md,v
retrieving revision 1.4
diff -u -p -r1.4 install.md
--- distrib/riscv64/ramdisk/install.md  3 Feb 2022 10:27:33 -0000       1.4
+++ distrib/riscv64/ramdisk/install.md  3 Feb 2022 13:33:59 -0000
@@ -43,8 +43,9 @@ md_installboot() {
 }
 
 md_prep_fdisk() {
-       local _disk=$1 _d
+       local _disk=$1 _d _type=MBR
 
+       local bootpart=
        local bootparttype="C"
        local bootsectorstart="32768"
        local bootsectorsize="32768"
@@ -53,16 +54,27 @@ md_prep_fdisk() {
 
        while :; do
                _d=whole
-               if disk_has $_disk mbr; then
+               if disk_has $_disk gpt; then
+                       [[ $_disk == $ROOTDISK ]] && bootpart="-b 
${bootsectorsize}"
+                       _type=GPT
+                       fdisk $_disk
+               elif disk_has $_disk mbr; then
                        fdisk $_disk
                else
                        echo "MBR has invalid signature; not showing it."
                fi
-               ask "Use (W)hole disk or (E)dit the MBR?" "$_d"
+               ask "Use (W)hole disk or (E)dit the ${_type}?" "$_d"
                case $resp in
                [wW]*)
                        echo -n "Creating a ${bootfstype} partition and an 
OpenBSD partition for rest of $_disk..."
-                       fdisk -e ${_disk} <<__EOT >/dev/null
+                       # Preserve BIOS boot partition as it might contain
+                       # PolarFire SoC HSS payload.
+                       if disk_has $_disk gpt biosboot; then
+                               fdisk -Ay ${bootpart} ${_disk} >/dev/null
+                       elif disk_has $_disk gpt; then
+                               fdisk -gy ${bootpart} ${_disk} >/dev/null
+                       else
+                               fdisk -e ${_disk} <<__EOT >/dev/null
 reinit
 e 0
 ${bootparttype}
@@ -78,12 +90,36 @@ ${bootsectorend}
 write
 quit
 __EOT
+                       fi
                        echo "done."
                        installboot -p $_disk
                        return ;;
                [eE]*)
-                       # Manually configure the MBR.
-                       cat <<__EOT
+                       if disk_has $_disk gpt; then
+                               # Manually configure the GPT.
+                               cat <<__EOT
+
+You will now create two GPT partitions. The first must have an id
+of 'EF' and be large enough to contain the OpenBSD boot programs,
+at least 32768 blocks. The second must have an id of 'A6' and will
+contain your OpenBSD data. Neither may overlap other partitions.
+Inside the fdisk command, the 'manual' command describes the fdisk
+commands in detail.
+
+$(fdisk $_disk)
+__EOT
+                               fdisk -e $_disk
+
+                               if ! disk_has $_disk gpt openbsd; then
+                                       echo -n "No OpenBSD partition in GPT,"
+                               elif ! disk_has $_disk gpt efisys; then
+                                       echo -n "No EFI Sys partition in GPT,"
+                               else
+                                       return
+                               fi
+                       else
+                               # Manually configure the MBR.
+                               cat <<__EOT
 
 You will now create one MBR partition to contain your OpenBSD data
 and one MBR partition on which the OpenBSD boot program is located.
@@ -96,9 +132,11 @@ partition on the disk.
 
 $(fdisk ${_disk})
 __EOT
-                       fdisk -e ${_disk}
-                       disk_has $_disk mbr openbsd && return
-                       echo No OpenBSD partition in MBR, try again. ;;
+                               fdisk -e ${_disk}
+                               disk_has $_disk mbr openbsd && return
+                               echo -n "No OpenBSD partition in MBR,"
+                       fi
+                       echo "try again." ;;
                esac
        done
 }

Reply via email to