Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/embedded Add GPT support to mkimage.



details:   https://anonhg.NetBSD.org/src/rev/1c2159d50d63
branches:  trunk
changeset: 1010381:1c2159d50d63
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun May 24 14:45:49 2020 +0000

description:
Add GPT support to mkimage.

diffstat:

 distrib/utils/embedded/conf/evbarm.conf |  29 ++++++++++++--
 distrib/utils/embedded/files/resize_gpt |  37 +++++++++++++++++++
 distrib/utils/embedded/mkimage          |  64 +++++++++++++++++++++-----------
 3 files changed, 103 insertions(+), 27 deletions(-)

diffs (209 lines):

diff -r 835971c1e2e9 -r 1c2159d50d63 distrib/utils/embedded/conf/evbarm.conf
--- a/distrib/utils/embedded/conf/evbarm.conf   Sun May 24 14:44:11 2020 +0000
+++ b/distrib/utils/embedded/conf/evbarm.conf   Sun May 24 14:45:49 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: evbarm.conf,v 1.34 2019/12/01 15:07:04 jmcneill Exp $
+# $NetBSD: evbarm.conf,v 1.35 2020/05/24 14:45:49 jmcneill Exp $
 # evbarm shared config
 #
 image=$HOME/${board}.img
@@ -13,6 +13,12 @@
 size=0         # autocompute
 msdosid=12
 
+if $gpt; then
+       partition_type="gpt"
+else
+       partition_type="disklabel"
+fi
+
 mkdir -p ${mnt}/boot
 
 make_label_evbarm() {
@@ -59,6 +65,19 @@
 EOF
 }
 
+make_fstab_evbarm_gpt() {
+       cat > ${mnt}/etc/fstab << EOF
+# NetBSD /etc/fstab
+# See /usr/share/examples/fstab/ for more examples.
+NAME=${gpt_label_ffs:-netbsd-root}     /               ffs     rw,noatime      1 1
+NAME=${gpt_label_efi:-EFI}             /boot           msdos   rw      1 1
+kernfs         /kern           kernfs  rw
+ptyfs          /dev/pts        ptyfs   rw
+procfs         /proc           procfs  rw
+tmpfs          /var/shm        tmpfs   rw,-m1777,-sram%25
+EOF
+}
+
 make_fstab_evbarm_normal() {
        cat > ${mnt}/etc/fstab << EOF
 # NetBSD /etc/fstab
@@ -96,7 +115,9 @@
 }
 
 make_fstab_evbarm() {
-       if $minwrites; then
+       if $gpt; then
+               make_fstab_evbarm_gpt
+       elif $minwrites; then
                make_fstab_evbarm_minwrites
        else
                make_fstab_evbarm_normal
@@ -143,7 +164,7 @@
 
        if $resize; then
                cat >> ${mnt}/etc/rc.conf << EOF
-resize_disklabel=YES
+resize_${partition_type}=YES
 resize_root=YES
 resize_root_flags="-p"
 resize_root_postcmd="/sbin/reboot -n"
@@ -154,7 +175,7 @@
            >> "$tmp/selected_sets"
 
        mkdir ${mnt}/etc/rc.d
-       for _f in resize_disklabel creds_msdos; do
+       for _f in resize_${partition_type} creds_msdos; do
                cp ${DIR}/files/${_f} ${mnt}/etc/rc.d/${_f}
                echo "./etc/rc.d/${_f} type=file uname=root gname=wheel mode=0555" \
                    >> "$tmp/selected_sets"
diff -r 835971c1e2e9 -r 1c2159d50d63 distrib/utils/embedded/files/resize_gpt
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/utils/embedded/files/resize_gpt   Sun May 24 14:45:49 2020 +0000
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# $NetBSD: resize_gpt,v 1.1 2020/05/24 14:45:49 jmcneill Exp $
+#
+
+# PROVIDE: resize_gpt
+# REQUIRE: fsck_root
+# BEFORE: resize_root
+
+$_rc_subr_loaded . /etc/rc.subr
+
+name="resize_gpt"
+rcvar=$name
+start_cmd="resize_gpt_start"
+stop_cmd=":"
+
+resize_gpt_start()
+{
+       ROOT_DEVICE=$(sysctl -n kern.root_device)
+       case ${ROOT_DEVICE} in
+       dk*)
+               ;;
+       *)
+               # Root device is not a wedge, bail out.
+               exit 0
+               ;;
+       esac
+
+       BLOCK_DEVICE=$(dkctl ${ROOT_DEVICE} getwedgeinfo | head -1 | sed 's/://' | awk '{ print $3; }')
+
+       gpt resizedisk -q ${BLOCK_DEVICE}
+       gpt resize -a 4m -i 2 -q ${BLOCK_DEVICE}
+       return
+}
+
+load_rc_config $name
+run_rc_command "$1"
diff -r 835971c1e2e9 -r 1c2159d50d63 distrib/utils/embedded/mkimage
--- a/distrib/utils/embedded/mkimage    Sun May 24 14:44:11 2020 +0000
+++ b/distrib/utils/embedded/mkimage    Sun May 24 14:45:49 2020 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-# $NetBSD: mkimage,v 1.72 2020/05/18 21:19:34 jmcneill Exp $
+# $NetBSD: mkimage,v 1.73 2020/05/24 14:45:49 jmcneill Exp $
 #
 # Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -54,6 +54,7 @@
 MAKE=${TOOL_MAKE:-make}
 DISKLABEL=${TOOL_DISKLABEL:-disklabel}
 FDISK=${TOOL_FDISK:-fdisk}
+GPT=${TOOL_GPT:-gpt}
 MAKEFS=${TOOL_MAKEFS:-makefs}
 MTREE=${TOOL_MTREE:-mtree}
 INSTALLBOOT=${TOOL_INSTALLBOOT:-installboot}
@@ -147,6 +148,7 @@
 fi
 
 resize=false
+gpt=false
 
 . "${DIR}/conf/${h}.conf"
 release="/usr/obj/${MACHINE}/release"
@@ -268,32 +270,48 @@
        compare="$((${newsize} * 2 * 1024))"
 done                      
 
-if [ -n "${msdosid}" ]; then
-       echo ${bar} Running fdisk ${bar}
+if $gpt; then
        initsecs=$((${init} * 1024))
        bootsecs=$((${boot} * 1024))
-       ${FDISK} -f -i ${image}
-       ${FDISK} -f -a -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
-       if [ -z "${bootonly}" ]; then
-               ffsstart="$(getsectors ${ffsoffset})"
-               imagesize="$(getsize "${image}")"
-               imagesecs="$(getsectors ${imagesize})"
-               ffssize="$(expr ${imagesecs} - ${ffsstart})"
-               ${FDISK} -f -u -1 -s 169/${ffsstart}/${ffssize} -F ${image}
-       fi
+       ffsstart="$(getsectors ${ffsoffset})"
+
+       echo ${bar} Clearing existing partitions ${bar}
+       ${GPT} ${image} destroy || true
 
-       echo ${bar} Adding label ${bar}
-       make_label > ${tmp}/label
-       ${DISKLABEL} -R -F ${image} ${tmp}/label
-elif [ -n "${netbsdid}" ]; then
-       echo ${bar} Adding label ${bar}
-       make_label > ${tmp}/label
-       ${DISKLABEL} -R -F ${image} ${tmp}/label
+       echo ${bar} Creating partitions ${bar}
+       ${GPT} ${image} create ${gpt_create_flags}
+       ${GPT} ${image} add -b ${initsecs} -s ${bootsecs} -l ${gpt_label_efi:-EFI} -t efi
+       ${GPT} ${image} set -a required -i 1
+       ${GPT} ${image} add -a 4m -b ${ffsstart} -l ${gpt_label_ffs:-netbsd-root} -t ffs
+       ${GPT} ${image} show
+else
+       if [ -n "${msdosid}" ]; then
+               echo ${bar} Running fdisk ${bar}
+               initsecs=$((${init} * 1024))
+               bootsecs=$((${boot} * 1024))
+               ${FDISK} -f -i ${image}
+               ${FDISK} -f -a -u -0 -s ${msdosid}/${initsecs}/${bootsecs} -F ${image}
+               if [ -z "${bootonly}" ]; then
+                       ffsstart="$(getsectors ${ffsoffset})"
+                       imagesize="$(getsize "${image}")"
+                       imagesecs="$(getsectors ${imagesize})"
+                       ffssize="$(expr ${imagesecs} - ${ffsstart})"
+                       ${FDISK} -f -u -1 -s 169/${ffsstart}/${ffssize} -F ${image}
+               fi
 
-       echo ${bar} Running fdisk ${bar}
-       ${FDISK} -f -i ${image}
-       ${FDISK} -f -a -u -0 -s 169/${init} ${image}
-       ${INSTALLBOOT} -f -v ${image} ${release}/usr/mdec/bootxx_ffsv1
+               echo ${bar} Adding label ${bar}
+               make_label > ${tmp}/label
+               ${DISKLABEL} -R -F ${image} ${tmp}/label
+       elif [ -n "${netbsdid}" ]; then
+               echo ${bar} Adding label ${bar}
+               make_label > ${tmp}/label
+               ${DISKLABEL} -R -F ${image} ${tmp}/label
+
+               echo ${bar} Running fdisk ${bar}
+               ${FDISK} -f -i ${image}
+               ${FDISK} -f -a -u -0 -s 169/${init} ${image}
+               ${INSTALLBOOT} -f -v ${image} ${release}/usr/mdec/bootxx_ffsv1
+       fi
 fi
 
 if $compress; then



Home | Main Index | Thread Index | Old Index