Module Name:    src
Committed By:   jmcneill
Date:           Sun May 24 14:45:49 UTC 2020

Modified Files:
        src/distrib/utils/embedded: mkimage
        src/distrib/utils/embedded/conf: evbarm.conf
Added Files:
        src/distrib/utils/embedded/files: resize_gpt

Log Message:
Add GPT support to mkimage.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/distrib/utils/embedded/mkimage
cvs rdiff -u -r1.34 -r1.35 src/distrib/utils/embedded/conf/evbarm.conf
cvs rdiff -u -r0 -r1.1 src/distrib/utils/embedded/files/resize_gpt

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/utils/embedded/mkimage
diff -u src/distrib/utils/embedded/mkimage:1.72 src/distrib/utils/embedded/mkimage:1.73
--- src/distrib/utils/embedded/mkimage:1.72	Mon May 18 21:19:34 2020
+++ src/distrib/utils/embedded/mkimage	Sun May 24 14:45:49 2020
@@ -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 @@ PROG="$(basename "$0")"
 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 @@ then
 fi
 
 resize=false
+gpt=false
 
 . "${DIR}/conf/${h}.conf"
 release="/usr/obj/${MACHINE}/release"
@@ -268,32 +270,48 @@ do    
 	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} 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} 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} 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

Index: src/distrib/utils/embedded/conf/evbarm.conf
diff -u src/distrib/utils/embedded/conf/evbarm.conf:1.34 src/distrib/utils/embedded/conf/evbarm.conf:1.35
--- src/distrib/utils/embedded/conf/evbarm.conf:1.34	Sun Dec  1 15:07:04 2019
+++ src/distrib/utils/embedded/conf/evbarm.conf	Sun May 24 14:45:49 2020
@@ -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 @@ ffsoffset=$(( (${init} + ${boot}) / 2 ))
 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 @@ drivedata: 0 
 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 @@ EOF
 }
 
 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 @@ EOF
 
 	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 @@ EOF
 	    >> "$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"

Added files:

Index: src/distrib/utils/embedded/files/resize_gpt
diff -u /dev/null src/distrib/utils/embedded/files/resize_gpt:1.1
--- /dev/null	Sun May 24 14:45:49 2020
+++ src/distrib/utils/embedded/files/resize_gpt	Sun May 24 14:45:49 2020
@@ -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"

Reply via email to