Home | History | Annotate | Line # | Download | only in bootimage
Makefile.bootimage revision 1.23
      1 #	$NetBSD: Makefile.bootimage,v 1.23 2019/11/21 22:29:03 joerg Exp $
      2 #
      3 # Copyright (c) 2009, 2010, 2011 Izumi Tsutsui.  All rights reserved.
      4 #
      5 # Redistribution and use in source and binary forms, with or without
      6 # modification, are permitted provided that the following conditions
      7 # are met:
      8 # 1. Redistributions of source code must retain the above copyright
      9 #    notice, this list of conditions and the following disclaimer.
     10 # 2. Redistributions in binary form must reproduce the above copyright
     11 #    notice, this list of conditions and the following disclaimer in the
     12 #    documentation and/or other materials provided with the distribution.
     13 #
     14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     15 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     16 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     17 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     18 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     19 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     20 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     21 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24 
     25 #
     26 # Makefile to create a bootable FS image for USB flash or emulators
     27 #
     28 
     29 #
     30 # Required variables:
     31 #	RELEASEDIR
     32 #		Should be defined in nbmake-${MACHINE}
     33 #	IMGBASE
     34 #		Basename of the image
     35 #
     36 # Optional variables:
     37 #	USE_MBR
     38 #		set yes if target disk image requires MBR partition
     39 #		(default: no)
     40 #	USE_GPT
     41 #		set yes if target disk image requires GPT partition
     42 #		(default: no)
     43 #	MBR_BOOTCODE
     44 #		optional MBR bootcode which should be installed by fdisk(8)
     45 #		(default: empty)
     46 #		- specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec
     47 #		- if MBR_BOOTCODE is not specified,
     48 #		  MBR_DEFAULT_BOOTCODE (default: mbr) will be used
     49 #		  if the target ${MACHINE} has the one in /usr/mdec
     50 #	USE_SUNLABEL
     51 #		set yes if target disk image requires Sun's label
     52 #		(default: no)
     53 #	INSTALLBOOT_AFTER_DISKLABEL (untested)
     54 #		set yes if the target ${MACHINE} requires disklabel
     55 #		to run installboot(8), like hp300
     56 #		(default: empty)
     57 #	IMAGEMB
     58 #		target image size in MB
     59 #		(default: 2048)
     60 #	SWAPMB
     61 #		swap size in target image in MB
     62 #		(default: 128)
     63 #	EFIMB
     64 #		EFI partition size in target image in MB
     65 #		(default: 128)
     66 #	KERN_SET
     67 #		kernel set name which should be extracted into image
     68 #		(default: kern-GENERIC)
     69 #	SETS
     70 #		binary sets that should be extracted into image
     71 #		(default: modules base etc comp games man misc rescue tests
     72 #			  text xbase xcomp xetc xfont xserver)
     73 #	SETS_DIR
     74 #		directory path where binary sets are stored
     75 #		(default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets)
     76 #	IMGFILE_EXTRA
     77 #		list of additional files to be copied into images,
     78 #		containing one or more tuples of the form:
     79 #			FILE	TARGETPATH
     80 #		for installation image etc.
     81 #		(default: empty)
     82 #	IMGDIR_EXTRA
     83 #		list of additional directories to be copied into images,
     84 #		containing one or more tuples of the form:
     85 #			DIR	TARGETPATH
     86 #		for installation image etc.
     87 #		(default: empty)
     88 #		XXX: currently permissions in IMGDIR_EXTRA are not handled
     89 #	IMGDIR_EXCLUDE
     90 #		pax(1) options to exclude files which should not copied
     91 #		into TARGETPATH in IMGDIR_EXTRA
     92 #		(default: empty)
     93 #	FSTAB_IN
     94 #		template file of /etc/fstab
     95 #		(default: ${DISTRIBDIR}/common/bootimage/fstab.in)
     96 #	SPEC_IN
     97 #		default files of spec file for makefs(8)
     98 #		(default: ${DISTRIBDIR}/common/bootimage/spec.in)
     99 #	SPEC_EXTRA
    100 #		additional files of spec file for makefs(8)
    101 #		(default: empty)
    102 #	IMGMAKEFSOPTIONS
    103 #		options passed to makefs(8) to create root file system
    104 #		(default: -o bsize=16384,fsize=2048,density=8192)
    105 #	INSTALLBOOTOPTIONS
    106 #		options passed to installboot(8), e.g., -o console=com0
    107 #		(default: empty)
    108 #	PRIMARY_BOOT
    109 #		primary boot loader that should be installed into
    110 #		the target image via installboot(8)
    111 #		(default: empty)
    112 #	SECONDARY_BOOT
    113 #		secondary bootloader that should be put into the target image
    114 #		(default: empty)
    115 #	SECONDARY_BOOT_ARG
    116 #		extra arguments that should be passed to installboot(8)
    117 #		to specify the secondary bootloader
    118 #		(default: empty)
    119 #	DISKPROTO_IN
    120 #		template file of disklabel -R
    121 #		(default: ${DISTRIBDIR}/common/bootimage/diskproto.in
    122 #		       or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in)
    123 #	EFIBOOT
    124 #		EFI bootloader
    125 #		(default: empty)
    126 #
    127 
    128 .include <bsd.own.mk> 		#
    129 .include <bsd.endian.mk>	# for TARGET_ENDIANNESS
    130 
    131 .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
    132 
    133 .if ${MKREPRO_TIMESTAMP:Uno} != "no"
    134 MAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
    135 GPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
    136 PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
    137 .endif
    138 
    139 .if empty(IMGBASE)
    140 .BEGIN:
    141 	@echo "Error: IMGBASE is not set"
    142 	@false
    143 .endif
    144 
    145 # should be defined elsewhere? 
    146 CAT?=		cat
    147 CHMOD?=		chmod
    148 DD?=		dd
    149 MKDIR?=		mkdir -p
    150 RM?=		rm
    151 
    152 #
    153 # common definitions for image
    154 #
    155 USE_MBR?=	no
    156 USE_GPT?=	no
    157 USE_SUNLABEL?=	no
    158 INSTALLBOOT_AFTER_DISKLABEL?=	no
    159 
    160 #
    161 # size parameters for image
    162 #
    163 IMAGEMB?=	2048		# 2048MB
    164 SWAPMB?=	128		# 128MB
    165 .if ${USE_GPT} == "no"
    166 EFIMB?=		0
    167 GPTSECTORS=	0
    168 .else
    169 EFIMB?=		128		# 128MB
    170 GPTSECTORS=	2048
    171 .endif
    172 
    173 # XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
    174 IMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
    175 SWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
    176 EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true
    177 
    178 .if ${USE_MBR} == "no" && ${USE_GPT} == "no"
    179 LABELSECTORS?=	0
    180 .else
    181 #LABELSECTORS?=	63	# historical
    182 #LABELSECTORS?=	32	# 16KB aligned
    183 LABELSECTORS?=	2048	# 1MB aligned for modern flash devices
    184 .endif
    185 
    186 FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
    187 		    - ${EFISECTORS} - ${GPTSECTORS}
    188 FSSIZE!=	expr ${FSSECTORS} \* 512
    189 
    190 # parameters for disklabel and MBR
    191 HEADS=		64
    192 SECTORS=	32
    193 CYLINDERS!=	expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)
    194 SECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS}
    195 MBRHEADS=	255
    196 MBRSECTORS=	63
    197 MBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
    198 MBRNETBSD=	169
    199 
    200 BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} - ${EFISECTORS} - ${GPTSECTORS}
    201 FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS}
    202 SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} + ${EFISECTORS}
    203 
    204 # parameters for sunlabel
    205 FSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
    206 SWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true
    207 
    208 .if ${USE_GPT} != "no"
    209 BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
    210 SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
    211 .endif
    212 
    213 #
    214 # definitions to create root fs
    215 #
    216 SETS_DEFAULT=	modules base etc comp games man misc rescue tests text
    217 .if ${MKX11} != "no"
    218 SETS_DEFAULT+=	xbase xcomp xetc xfont xserver
    219 .endif
    220 
    221 KERN_SET?=	kern-GENERIC
    222 SETS?=		${SETS_DEFAULT}
    223 IMG_SETS=	${KERN_SET} ${SETS}
    224 SETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
    225 
    226 FSTAB_IN?=	${DISTRIBDIR}/common/bootimage/fstab.in
    227 SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in
    228 
    229 IMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192
    230 
    231 WORKDIR?=       work
    232 WORKSPEC?=      work.spec
    233 WORKFSTAB?=	work.fstab
    234 WORKRCCONF?=	work.rc.conf
    235 WORKFS?=        work.rootfs
    236 TARGETFS?=      imgroot.fs
    237 COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
    238 TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
    239 
    240 CLEANFILES+=	${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS}
    241 CLEANFILES+=	${TARGETFS}
    242 
    243 #
    244 # definitions to create image
    245 #
    246 .if ${SWAPSECTORS} == 0
    247 .  if ${USE_MBR} != "no"
    248 DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in
    249 .  else
    250 DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.in
    251 .  endif
    252 .else
    253 .  if ${USE_MBR} != "no"
    254 DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
    255 .  else
    256 DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
    257 .  endif
    258 .endif
    259 
    260 MBR_DEFAULT_BOOTCODE?=	mbr
    261 
    262 WORKMBR?=	work.mbr
    263 WORKMBRTRUNC?=	work.mbr.truncated
    264 WORKSWAP?=	work.swap
    265 WORKEFI?=	work.efi
    266 WORKGPT?=	work.gpt
    267 WORKLABEL?=	work.diskproto
    268 WORKIMG?=	work.img
    269 EFIWORKDIR?=	work.efidir
    270 
    271 .if ${USE_GPT} != "no"
    272 ${WORKFSTAB}: ${WORKMBR}
    273 .endif
    274 
    275 ${WORKFSTAB}:
    276 	@echo Preparing /etc/fstab ...
    277 .if ${USE_GPT} != "no"
    278 .  if ${SWAPSECTORS} != 0
    279 	${TOOL_SED}							\
    280 	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
    281 	    -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/"			\
    282 	    < ${FSTAB_IN} > ${WORKFSTAB}
    283 .  else
    284 	${TOOL_SED}							\
    285 	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
    286 	    -e "/ROOT.b/d"						\
    287 	    < ${FSTAB_IN} > ${WORKFSTAB}
    288 .  endif
    289 .else
    290 .  if ${SWAPSECTORS} != 0
    291 	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
    292 .  else
    293 	${TOOL_SED}							\
    294 	    -e "/ROOT.b/d"						\
    295 	    < ${FSTAB_IN} > ${WORKFSTAB}
    296 .  endif
    297 .endif
    298 
    299 #
    300 # create root file system for the image
    301 #
    302 ${TARGETFS}: prepare_md_post ${WORKFSTAB}
    303 	@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
    304 		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
    305 		false; 							\
    306 	fi;
    307 	@${MKDIR} ${MKDIRPERM} ${WORKDIR}
    308 .for set in ${IMG_SETS}
    309 	@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
    310 		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
    311 		false; 							\
    312 	fi
    313 	@echo Extracting ${set}.${TAR_SUFF} ...
    314 	@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \
    315 		--use-compress-program=${COMPRESS_PROGRAM:Q} \
    316 		-f ${SETS_DIR}/${set}.${TAR_SUFF} .)
    317 .endfor
    318 .if defined(SECONDARY_BOOT)
    319 	@echo Copying secondary boot...
    320 	${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
    321 .endif
    322 	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
    323 	@echo Setting rc_configured=YES in /etc/rc.conf ...
    324 	${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/"		\
    325 	    < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF}
    326 	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
    327 .if defined(IMGDIR_EXTRA)
    328 	@echo Copying extra dirs...
    329 .for _SRCDIR _TARGET in ${IMGDIR_EXTRA}
    330 	@if [ ! -d ${_SRCDIR} ]; then 					\
    331 		echo "${_SRCDIR} is not directory, aborting";		\
    332 		false; 							\
    333 	fi
    334 	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
    335 	(cd ${_SRCDIR} ;						\
    336 	    ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v			\
    337 	    ${IMGDIR_EXCLUDE}						\
    338 	    . ${.OBJDIR}/${WORKDIR}/${_TARGET} )
    339 .endfor
    340 .endif
    341 .if defined(IMGFILE_EXTRA)
    342 	@echo Copying extra files...
    343 .for _SRC _TARGET in ${IMGFILE_EXTRA}
    344 	@if [ ! -f ${_SRC} ]; then 					\
    345 		echo "${_SRC} in IMGFILE_EXTRA not found, aborting";	\
    346 		false; 							\
    347 	fi
    348 	@if [ -f ${_SRC} ]; then 					\
    349 		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
    350 		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
    351 	fi
    352 .endfor
    353 .endif
    354 	@echo Preparing spec files for makefs...
    355 	${RM} -f ${WORKSPEC}
    356 	cat ${WORKDIR}/etc/mtree/* |					\
    357 	    ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC}
    358 	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty |			\
    359 	    ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC}
    360 	cat ${SPEC_IN} >> ${WORKSPEC}
    361 .if defined(SECONDARY_BOOT)
    362 	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
    363 	    >> ${WORKSPEC}
    364 .endif
    365 .if defined(SPEC_EXTRA)
    366 	cat ${SPEC_EXTRA} >> ${WORKSPEC}
    367 .endif
    368 	@echo Creating rootfs...
    369 	# XXX /var/spool/ftp/hidden is unreadable
    370 	${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden
    371 	${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE}			\
    372 	    -B ${TARGET_ENDIANNESS}					\
    373 	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
    374 	    ${MAKEFS_TIMESTAMP}						\
    375 	    ${IMGMAKEFSOPTIONS}						\
    376 	    ${WORKFS} ${WORKDIR}
    377 .if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
    378 	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
    379 	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
    380 .endif
    381 	@echo done.
    382 	mv ${WORKFS} ${.TARGET}
    383 
    384 TARGET_BLOCKS=
    385 .if ${USE_MBR} != "no" || ${USE_GPT} != "no"
    386 TARGET_BLOCKS+=	${WORKMBRTRUNC}
    387 .endif
    388 .if ${USE_GPT} != "no"
    389 TARGET_BLOCKS+=	${WORKEFI}
    390 .endif
    391 TARGET_BLOCKS+=	 ${TARGETFS}
    392 .if ${SWAPSECTORS} != 0
    393 TARGET_BLOCKS+=	${WORKSWAP}
    394 .endif
    395 .if ${USE_GPT} != "no"
    396 TARGET_BLOCKS+=	${WORKGPT}
    397 .endif
    398 
    399 CLEANFILES+=	${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP}
    400 CLEANFILES+=	${WORKEFI} ${WORKGPT}
    401 CLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
    402 CLEANFILES+=	${WORKIMG} ${IMGBASE}.img
    403 
    404 ${WORKSWAP}:
    405 .if ${SWAPSECTORS} == 0
    406 	printf "" > ${WORKSWAP}
    407 .else
    408 	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
    409 .endif
    410 
    411 ${WORKMBRTRUNC}: ${WORKMBR}
    412 	${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC}
    413 
    414 ${WORKLABEL}:
    415 	${TOOL_SED}							\
    416 	    -e "s/@@SECTORS@@/${SECTORS}/"				\
    417 	    -e "s/@@HEADS@@/${HEADS}/"					\
    418 	    -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/"		\
    419 	    -e "s/@@CYLINDERS@@/${CYLINDERS}/"				\
    420 	    -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/"			\
    421 	    -e "s/@@FSSECTORS@@/${FSSECTORS}/"				\
    422 	    -e "s/@@FSOFFSET@@/${FSOFFSET}/"				\
    423 	    -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/"			\
    424 	    -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/"			\
    425 	    -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/"		\
    426 	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
    427 	mv ${WORKLABEL}.tmp ${WORKLABEL}
    428 
    429 ${WORKEFI}: ${TARGETFS}
    430 	@echo create EFI system partition...
    431 	@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
    432 .for f in ${EFIBOOT}
    433 	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
    434 .endfor
    435 	${RM} -f ${WORKEFI}
    436 	${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m			\
    437 	    -B ${TARGET_ENDIANNESS}					\
    438 	    ${MAKEFS_TIMESTAMP}						\
    439 	    -t msdos -o F=32,c=1					\
    440 	    ${WORKEFI} ${EFIWORKDIR}
    441 
    442 ${WORKMBR}:
    443 .if ${USE_GPT} != "no"
    444 	@echo creating GPT header and partition entries...
    445 	${RM} -f ${WORKMBR}
    446 	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
    447 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create
    448 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system"
    449 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs
    450 .  if ${SWAPSECTORS} != 0
    451 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
    452 .  endif
    453 .elif ${USE_MBR} != "no"
    454 	@echo creating MBR labels...
    455 	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
    456 	${TOOL_FDISK} -f -i -u \
    457 	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
    458 	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
    459 	    -F ${WORKMBR}
    460 .  if empty(MBR_BOOTCODE)
    461 	@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
    462 		echo ${TOOL_FDISK} -f					\
    463 		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
    464 		    -F ${WORKMBR};					\
    465 		${TOOL_FDISK} -f					\
    466 		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
    467 		    -F ${WORKMBR};					\
    468 	fi
    469 .  else
    470 	@if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then 		\
    471 		echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \
    472 		false; 							\
    473 	fi
    474 	${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE}	\
    475 	    -F ${WORKMBR}
    476 .  endif
    477 .endif
    478 
    479 ${WORKGPT}: ${WORKMBR}
    480 	@echo create GPT image...
    481 	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
    482 	    count=2048
    483 
    484 .if ${USE_GPT} == "no"
    485 ${IMGBASE}.img:	${WORKLABEL}
    486 .endif
    487 
    488 ${IMGBASE}.img:	${TARGET_BLOCKS}
    489 	${CAT} ${TARGET_BLOCKS} > ${WORKIMG}
    490 .if ${USE_GPT} != "no"
    491 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2		\
    492 	    -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin
    493 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2
    494 .endif	# USE_GPT != "no"
    495 .if ${USE_SUNLABEL} != "no"
    496 	@echo Creating sun disklabel...
    497 	printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \
    498 	    ${CYLINDERS} ${HEADS} ${SECTORS} \
    499 	    ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \
    500 	    ${TOOL_SUNLABEL} -nq ${WORKIMG}
    501 .endif
    502 .if ${USE_GPT} == "no"
    503 	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
    504 .if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
    505 	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
    506 	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
    507 .endif
    508 .endif
    509 	mv ${WORKIMG} ${.TARGET}
    510 
    511 CLEANFILES+=	${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp
    512 
    513 ${IMGBASE}.img.gz:	${IMGBASE}.img
    514 	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
    515 	mv ${.TARGET}.tmp ${.TARGET}
    516 
    517 clean:
    518 	@if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then 		\
    519 		${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden;		\
    520 	fi	# XXX
    521 	${RM} -fr ${WORKDIR}
    522 	${RM} -fr ${EFIWORKDIR}
    523 
    524 prepare_md_post: .PHONY
    525 image_md_post: .PHONY
    526 image_md_pre: .PHONY
    527 
    528 .include <bsd.prog.mk>
    529