Module Name:    src
Committed By:   tsutsui
Date:           Sat Mar 21 14:19:27 UTC 2020

Modified Files:
        src/distrib/common/bootimage: Makefile.bootimage
Added Files:
        src/distrib/common/bootimage: diskproto.mbrfat.in

Log Message:
Add "live-image with a FAT partition for bootstrap files" support.

See PR/55075 for more details.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/distrib/common/bootimage/Makefile.bootimage
cvs rdiff -u -r0 -r1.1 src/distrib/common/bootimage/diskproto.mbrfat.in

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

Modified files:

Index: src/distrib/common/bootimage/Makefile.bootimage
diff -u src/distrib/common/bootimage/Makefile.bootimage:1.23 src/distrib/common/bootimage/Makefile.bootimage:1.24
--- src/distrib/common/bootimage/Makefile.bootimage:1.23	Thu Nov 21 22:29:03 2019
+++ src/distrib/common/bootimage/Makefile.bootimage	Sat Mar 21 14:19:26 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.bootimage,v 1.23 2019/11/21 22:29:03 joerg Exp $
+#	$NetBSD: Makefile.bootimage,v 1.24 2020/03/21 14:19:26 tsutsui Exp $
 #
 # Copyright (c) 2009, 2010, 2011 Izumi Tsutsui.  All rights reserved.
 #
@@ -63,6 +63,9 @@
 #	EFIMB
 #		EFI partition size in target image in MB
 #		(default: 128)
+#	FATMB
+#		FAT partition size in target image in MB
+#		(default: 0)
 #	KERN_SET
 #		kernel set name which should be extracted into image
 #		(default: kern-GENERIC)
@@ -123,6 +126,15 @@
 #	EFIBOOT
 #		EFI bootloader
 #		(default: empty)
+#	MBRFAT
+#		MBR partition type value for FAT
+#		(default: 6 ("16-bit FAT, more than 32M"))
+#	FATMAKEFSOPTIONS
+#		options passed to makefs(8) to create a FAT partition
+#		(default: -o fat_type=16)
+#	FATFILES
+#		list of additional files to be copied into FAT partition
+#		(default: empty)
 #
 
 .include <bsd.own.mk> 		#
@@ -169,11 +181,13 @@ GPTSECTORS=	0
 EFIMB?=		128		# 128MB
 GPTSECTORS=	2048
 .endif
+FATMB?=		0
 
 # XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
 IMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
 SWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
 EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true
+FATSECTORS!=	expr ${FATMB} \* 1024 \* 1024 / 512 || true
 
 .if ${USE_MBR} == "no" && ${USE_GPT} == "no"
 LABELSECTORS?=	0
@@ -184,7 +198,7 @@ LABELSECTORS?=	2048	# 1MB aligned for mo
 .endif
 
 FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
-		    - ${EFISECTORS} - ${GPTSECTORS}
+		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
 FSSIZE!=	expr ${FSSECTORS} \* 512
 
 # parameters for disklabel and MBR
@@ -196,10 +210,14 @@ MBRHEADS=	255
 MBRSECTORS=	63
 MBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
 MBRNETBSD=	169
+MBRFAT?=	6	# 16-bit FAT, more than 32M
 
-BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} - ${EFISECTORS} - ${GPTSECTORS}
-FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS}
-SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} + ${EFISECTORS}
+BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \
+		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
+FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS}
+SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} \
+		    + ${EFISECTORS} + ${FATSECTORS}
+FATOFFSET=	${LABELSECTORS}
 
 # parameters for sunlabel
 FSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
@@ -227,6 +245,7 @@ FSTAB_IN?=	${DISTRIBDIR}/common/bootimag
 SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in
 
 IMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192
+FATMAKEFSOPTIONS?=	-o fat_type=16
 
 WORKDIR?=       work
 WORKSPEC?=      work.spec
@@ -267,6 +286,8 @@ WORKGPT?=	work.gpt
 WORKLABEL?=	work.diskproto
 WORKIMG?=	work.img
 EFIWORKDIR?=	work.efidir
+WORKFAT?=	work.fat
+WORKFATDIR?=	work.fatdir
 
 .if ${USE_GPT} != "no"
 ${WORKFSTAB}: ${WORKMBR}
@@ -388,6 +409,9 @@ TARGET_BLOCKS+=	${WORKMBRTRUNC}
 .if ${USE_GPT} != "no"
 TARGET_BLOCKS+=	${WORKEFI}
 .endif
+.if ${FATSECTORS} != 0
+TARGET_BLOCKS+=	${WORKFAT}
+.endif
 TARGET_BLOCKS+=	 ${TARGETFS}
 .if ${SWAPSECTORS} != 0
 TARGET_BLOCKS+=	${WORKSWAP}
@@ -398,6 +422,7 @@ TARGET_BLOCKS+=	${WORKGPT}
 
 CLEANFILES+=	${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP}
 CLEANFILES+=	${WORKEFI} ${WORKGPT}
+CLEANFILES+=	${WORKFAT}
 CLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
 CLEANFILES+=	${WORKIMG} ${IMGBASE}.img
 
@@ -423,6 +448,8 @@ ${WORKLABEL}:
 	    -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/"			\
 	    -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/"			\
 	    -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/"		\
+	    -e "s/@@FATSECTORS@@/${FATSECTORS}/"			\
+	    -e "s/@@FATOFFSET@@/${FATOFFSET}/"				\
 	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
 	mv ${WORKLABEL}.tmp ${WORKLABEL}
 
@@ -439,6 +466,26 @@ ${WORKEFI}: ${TARGETFS}
 	    -t msdos -o F=32,c=1					\
 	    ${WORKEFI} ${EFIWORKDIR}
 
+${WORKFAT}: ${TARGETFS} ${FATFILES}
+	@echo create FAT partition for bootstrap files...
+	@${MKDIR} ${MKDIRPERM} ${WORKFATDIR}
+.if defined(FATFILES)
+	@echo Copying files for FAT partition...
+.for f in ${FATFILES}
+	@if [ ! -f ${f} ]; then 					\
+		echo "${f} in FATFILES not found, aborting";		\
+		false; 							\
+	fi
+	${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR}
+.endfor
+.endif
+	${RM} -f ${WORKFAT}
+	${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m			\
+	    ${MAKEFS_TIMESTAMP}						\
+	    -t msdos							\
+	    ${FATMAKEFSOPTIONS}						\
+	    ${WORKFAT} ${WORKFATDIR}
+
 ${WORKMBR}:
 .if ${USE_GPT} != "no"
 	@echo creating GPT header and partition entries...
@@ -453,10 +500,24 @@ ${WORKMBR}:
 .elif ${USE_MBR} != "no"
 	@echo creating MBR labels...
 	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
+.  if ${FATSECTORS} != 0
+	# create BSD partition
+	${TOOL_FDISK} -f -i -u \
+	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
+	    -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
+	    -F ${WORKMBR}
+	# create FAT partition
+	${TOOL_FDISK} -f -u \
+	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
+	    -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS}			\
+	    -F ${WORKMBR}
+.  else
+	# create BSD partition
 	${TOOL_FDISK} -f -i -u \
 	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
 	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
 	    -F ${WORKMBR}
+.  endif
 .  if empty(MBR_BOOTCODE)
 	@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
 		echo ${TOOL_FDISK} -f					\
@@ -520,6 +581,7 @@ clean:
 	fi	# XXX
 	${RM} -fr ${WORKDIR}
 	${RM} -fr ${EFIWORKDIR}
+	${RM} -fr ${WORKFATDIR}
 
 prepare_md_post: .PHONY
 image_md_post: .PHONY

Added files:

Index: src/distrib/common/bootimage/diskproto.mbrfat.in
diff -u /dev/null src/distrib/common/bootimage/diskproto.mbrfat.in:1.1
--- /dev/null	Sat Mar 21 14:19:27 2020
+++ src/distrib/common/bootimage/diskproto.mbrfat.in	Sat Mar 21 14:19:27 2020
@@ -0,0 +1,26 @@
+# $NetBSD: diskproto.mbrfat.in,v 1.1 2020/03/21 14:19:27 tsutsui Exp $
+type: ESDI
+disk: image
+label: 
+flags:
+bytes/sector: 512
+sectors/track: @@SECTORS@@
+tracks/cylinder: @@HEADS@@
+sectors/cylinder: @@SECPERCYLINDERS@@
+cylinders: @@CYLINDERS@@
+total sectors: @@IMAGESECTORS@@
+rpm: 3600
+interleave: 1
+trackskew: 0
+cylinderskew: 0
+headswitch: 0           # microseconds
+track-to-track seek: 0  # microseconds
+drivedata: 0 
+
+8 partitions:
+#        size    offset     fstype [fsize bsize cpg/sgs]
+a:    @@FSSECTORS@@ @@FSOFFSET@@ 4.2BSD 1024 8192 16
+b:    @@SWAPSECTORS@@ @@SWAPOFFSET@@ swap
+c:    @@BSDPARTSECTORS@@ @@FSOFFSET@@ unused 0 0
+d:    @@IMAGESECTORS@@ 0 unused 0 0
+e:    @@FATSECTORS@@ @@FATOFFSET@@ MSDOS

Reply via email to