Makefile.bootimage revision 1.21
11.21Stsutsui#	$NetBSD: Makefile.bootimage,v 1.21 2019/02/22 22:13:58 tsutsui Exp $
21.1Stsutsui#
31.1Stsutsui# Copyright (c) 2009, 2010, 2011 Izumi Tsutsui.  All rights reserved.
41.1Stsutsui#
51.1Stsutsui# Redistribution and use in source and binary forms, with or without
61.1Stsutsui# modification, are permitted provided that the following conditions
71.1Stsutsui# are met:
81.1Stsutsui# 1. Redistributions of source code must retain the above copyright
91.1Stsutsui#    notice, this list of conditions and the following disclaimer.
101.1Stsutsui# 2. Redistributions in binary form must reproduce the above copyright
111.1Stsutsui#    notice, this list of conditions and the following disclaimer in the
121.1Stsutsui#    documentation and/or other materials provided with the distribution.
131.1Stsutsui#
141.1Stsutsui# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
151.1Stsutsui# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
161.1Stsutsui# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
171.1Stsutsui# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
181.1Stsutsui# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
191.1Stsutsui# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
201.1Stsutsui# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
211.1Stsutsui# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
221.1Stsutsui# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
231.1Stsutsui# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
241.1Stsutsui
251.1Stsutsui#
261.1Stsutsui# Makefile to create a bootable FS image for USB flash or emulators
271.1Stsutsui#
281.1Stsutsui
291.1Stsutsui#
301.1Stsutsui# Required variables:
311.1Stsutsui#	RELEASEDIR
321.1Stsutsui#		Should be defined in nbmake-${MACHINE}
331.1Stsutsui#	IMGBASE
341.1Stsutsui#		Basename of the image
351.1Stsutsui#
361.1Stsutsui# Optional variables:
371.1Stsutsui#	USE_MBR
381.1Stsutsui#		set yes if target disk image requires MBR partition
391.6Stsutsui#		(default: no)
401.5Stsutsui#	MBR_BOOTCODE
411.5Stsutsui#		optional MBR bootcode which should be installed by fdisk(8)
421.5Stsutsui#		(default: empty)
431.5Stsutsui#		- specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec
441.5Stsutsui#		- if MBR_BOOTCODE is not specified,
451.5Stsutsui#		  MBR_DEFAULT_BOOTCODE (default: mbr) will be used
461.5Stsutsui#		  if the target ${MACHINE} has the one in /usr/mdec
471.1Stsutsui#	USE_SUNLABEL
481.1Stsutsui#		set yes if target disk image requires Sun's label
491.1Stsutsui#		(default: no)
501.1Stsutsui#	INSTALLBOOT_AFTER_DISKLABEL (untested)
511.1Stsutsui#		set yes if the target ${MACHINE} requires disklabel
521.1Stsutsui#		to run installboot(8), like hp300
531.1Stsutsui#		(default: empty)
541.1Stsutsui#	IMAGEMB
551.1Stsutsui#		target image size in MB
561.1Stsutsui#		(default: 2048)
571.1Stsutsui#	SWAPMB
581.1Stsutsui#		swap size in target image in MB
591.1Stsutsui#		(default: 128)
601.1Stsutsui#	KERN_SET
611.1Stsutsui#		kernel set name which should be extracted into image
621.1Stsutsui#		(default: kern-GENERIC)
631.1Stsutsui#	SETS
641.1Stsutsui#		binary sets that should be extracted into image
651.1Stsutsui#		(default: modules base etc comp games man misc tests text
661.1Stsutsui#			  xbase xcomp xetc xfont xserver)
671.1Stsutsui#	SETS_DIR
681.1Stsutsui#		directory path where binary sets are stored
691.1Stsutsui#		(default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets)
701.1Stsutsui#	IMGFILE_EXTRA
711.1Stsutsui#		list of additional files to be copied into images,
721.1Stsutsui#		containing one or more tuples of the form:
731.1Stsutsui#			FILE	TARGETPATH
741.1Stsutsui#		for installation image etc.
751.1Stsutsui#		(default: empty)
761.1Stsutsui#	IMGDIR_EXTRA
771.1Stsutsui#		list of additional directories to be copied into images,
781.1Stsutsui#		containing one or more tuples of the form:
791.1Stsutsui#			DIR	TARGETPATH
801.1Stsutsui#		for installation image etc.
811.1Stsutsui#		(default: empty)
821.6Stsutsui#		XXX: currently permissions in IMGDIR_EXTRA are not handled
831.1Stsutsui#	IMGDIR_EXCLUDE
841.1Stsutsui#		pax(1) options to exclude files which should not copied
851.1Stsutsui#		into TARGETPATH in IMGDIR_EXTRA
861.1Stsutsui#		(default: empty)
871.1Stsutsui#	FSTAB_IN
881.1Stsutsui#		template file of /etc/fstab
891.1Stsutsui#		(default: ${DISTRIBDIR}/common/bootimage/fstab.in)
901.1Stsutsui#	SPEC_IN
911.1Stsutsui#		default files of spec file for makefs(8)
921.1Stsutsui#		(default: ${DISTRIBDIR}/common/bootimage/spec.in)
931.1Stsutsui#	SPEC_EXTRA
941.1Stsutsui#		additional files of spec file for makefs(8)
951.1Stsutsui#		(default: empty)
961.1Stsutsui#	IMGMAKEFSOPTIONS
971.1Stsutsui#		options passed to makefs(8) to create root file system
981.1Stsutsui#		(default: -o bsize=16384,fsize=2048,density=8192)
991.5Stsutsui#	INSTALLBOOTOPTIONS
1001.5Stsutsui#		options passed to installboot(8), e.g., -o console=com0
1011.5Stsutsui#		(default: empty)
1021.1Stsutsui#	PRIMARY_BOOT
1031.1Stsutsui#		primary boot loader that should be installed into
1041.1Stsutsui#		the target image via installboot(8)
1051.1Stsutsui#		(default: empty)
1061.1Stsutsui#	SECONDARY_BOOT
1071.1Stsutsui#		secondary bootloader that should be put into the target image
1081.1Stsutsui#		(default: empty)
1091.1Stsutsui#	SECONDARY_BOOT_ARG
1101.1Stsutsui#		extra arguments that should be passed to installboot(8)
1111.1Stsutsui#		to specify the secondary bootloader
1121.1Stsutsui#		(default: empty)
1131.1Stsutsui#	DISKPROTO_IN
1141.1Stsutsui#		template file of disklabel -R
1151.1Stsutsui#		(default: ${DISTRIBDIR}/common/bootimage/diskproto.in
1161.1Stsutsui#		       or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in)
1171.1Stsutsui#	OMIT_SWAPIMG
1181.1Stsutsui#		no need to put swap partition into image (for USB stick)
1191.1Stsutsui#		(default: no)
1201.1Stsutsui#
1211.1Stsutsui
1221.1Stsutsui.include <bsd.own.mk> 		#
1231.1Stsutsui.include <bsd.endian.mk>	# for TARGET_ENDIANNESS
1241.1Stsutsui
1251.1Stsutsui.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
1261.1Stsutsui
1271.13Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no"
1281.13SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
1291.15SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
1301.15Schristos.endif
1311.12Schristos
1321.1Stsutsui.if empty(IMGBASE)
1331.1Stsutsui.BEGIN:
1341.1Stsutsui	@echo "Error: IMGBASE is not set"
1351.1Stsutsui	@false
1361.1Stsutsui.endif
1371.1Stsutsui
1381.1Stsutsui# should be defined elsewhere? 
1391.1StsutsuiCAT?=		cat
1401.1StsutsuiCHMOD?=		chmod
1411.1StsutsuiDD?=		dd
1421.1StsutsuiMKDIR?=		mkdir -p
1431.1StsutsuiRM?=		rm
1441.1Stsutsui
1451.1Stsutsui#
1461.1Stsutsui# common definitions for image
1471.1Stsutsui#
1481.1StsutsuiUSE_MBR?=	no
1491.1StsutsuiUSE_SUNLABEL?=	no
1501.1StsutsuiINSTALLBOOT_AFTER_DISKLABEL?=	no
1511.1Stsutsui
1521.1Stsutsui#
1531.1Stsutsui# size parameters for image
1541.1Stsutsui#
1551.1StsutsuiIMAGEMB?=	2048		# 2048MB
1561.1StsutsuiSWAPMB?=	128		# 128MB
1571.1Stsutsui
1581.3Stsutsui# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
1591.1StsutsuiIMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
1601.3StsutsuiSWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
1611.1Stsutsui
1621.1Stsutsui.if ${USE_MBR} == "no"
1631.1StsutsuiLABELSECTORS?=	0
1641.1Stsutsui.else
1651.1Stsutsui#LABELSECTORS?=	63	# historical
1661.1Stsutsui#LABELSECTORS?=	32	# 16KB aligned
1671.1StsutsuiLABELSECTORS?=	2048	# 1MB aligned for modern flash devices
1681.1Stsutsui.endif
1691.1Stsutsui
1701.1StsutsuiFSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}
1711.1StsutsuiFSSIZE!=	expr ${FSSECTORS} \* 512
1721.1Stsutsui
1731.1Stsutsui# parameters for disklabel and MBR
1741.1StsutsuiHEADS=		64
1751.1StsutsuiSECTORS=	32
1761.1StsutsuiCYLINDERS!=	expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)
1771.1StsutsuiSECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS}
1781.1StsutsuiMBRHEADS=	255
1791.1StsutsuiMBRSECTORS=	63
1801.1StsutsuiMBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
1811.1StsutsuiMBRNETBSD=	169
1821.1Stsutsui
1831.1StsutsuiBSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS}
1841.1StsutsuiFSOFFSET=	${LABELSECTORS}
1851.1StsutsuiSWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS}
1861.1Stsutsui
1871.1Stsutsui# parameters for sunlabel
1881.1StsutsuiFSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
1891.3StsutsuiSWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true
1901.1Stsutsui
1911.1Stsutsui
1921.1Stsutsui#
1931.1Stsutsui# definitions to create root fs
1941.1Stsutsui#
1951.1StsutsuiSETS_DEFAULT=	modules base etc comp games man misc tests text
1961.1Stsutsui.if ${MKX11} != "no"
1971.1StsutsuiSETS_DEFAULT+=	xbase xcomp xetc xfont xserver
1981.1Stsutsui.endif
1991.1Stsutsui
2001.1StsutsuiKERN_SET?=	kern-GENERIC
2011.1StsutsuiSETS?=		${SETS_DEFAULT}
2021.1StsutsuiIMG_SETS=	${KERN_SET} ${SETS}
2031.1StsutsuiSETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
2041.1Stsutsui
2051.1StsutsuiFSTAB_IN?=	${DISTRIBDIR}/common/bootimage/fstab.in
2061.1StsutsuiSPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in
2071.1Stsutsui
2081.1StsutsuiIMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192
2091.1Stsutsui
2101.1StsutsuiWORKDIR?=       work
2111.1StsutsuiWORKSPEC?=      work.spec
2121.1StsutsuiWORKFSTAB?=	work.fstab
2131.1StsutsuiWORKRCCONF?=	work.rc.conf
2141.1StsutsuiWORKFS?=        work.rootfs
2151.1StsutsuiTARGETFS?=      imgroot.fs
2161.19SaymericCOMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
2171.18SmartinTAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
2181.1Stsutsui
2191.1StsutsuiCLEANFILES+=	${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS}
2201.1StsutsuiCLEANFILES+=	${TARGETFS}
2211.1Stsutsui
2221.1Stsutsui#
2231.1Stsutsui# create root file system for the image
2241.1Stsutsui#
2251.1Stsutsui${TARGETFS}: prepare_md_post
2261.1Stsutsui	@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
2271.1Stsutsui		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
2281.1Stsutsui		false; 							\
2291.1Stsutsui	fi;
2301.14Schristos	@${MKDIR} ${MKDIRPERM} ${WORKDIR}
2311.1Stsutsui.for set in ${IMG_SETS}
2321.18Smartin	@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
2331.18Smartin		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
2341.1Stsutsui		false; 							\
2351.1Stsutsui	fi
2361.18Smartin	@echo Extracting ${set}.${TAR_SUFF} ...
2371.19Saymeric	@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \
2381.19Saymeric		--use-compress-program=${COMPRESS_PROGRAM:Q} \
2391.19Saymeric		-f ${SETS_DIR}/${set}.${TAR_SUFF} .)
2401.1Stsutsui.endfor
2411.1Stsutsui.if defined(SECONDARY_BOOT)
2421.1Stsutsui	@echo Copying secondary boot...
2431.21Stsutsui	${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
2441.1Stsutsui.endif
2451.1Stsutsui	@echo Preparing /etc/fstab ...
2461.20Sgson	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
2471.14Schristos	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
2481.1Stsutsui	@echo Setting rc_configured=YES in /etc/rc.conf ...
2491.1Stsutsui	${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/"		\
2501.1Stsutsui	    < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF}
2511.14Schristos	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
2521.1Stsutsui.if defined(IMGDIR_EXTRA)
2531.1Stsutsui	@echo Copying extra dirs...
2541.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA}
2551.1Stsutsui	@if [ ! -d ${_SRCDIR} ]; then 					\
2561.1Stsutsui		echo "${_SRCDIR} is not directory, aborting";		\
2571.1Stsutsui		false; 							\
2581.1Stsutsui	fi
2591.14Schristos	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
2601.1Stsutsui	(cd ${_SRCDIR} ;						\
2611.21Stsutsui	    ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v			\
2621.1Stsutsui	    ${IMGDIR_EXCLUDE}						\
2631.1Stsutsui	    . ${.OBJDIR}/${WORKDIR}/${_TARGET} )
2641.1Stsutsui.endfor
2651.1Stsutsui.endif
2661.1Stsutsui.if defined(IMGFILE_EXTRA)
2671.1Stsutsui	@echo Copying extra files...
2681.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA}
2691.1Stsutsui	@if [ ! -f ${_SRC} ]; then 					\
2701.1Stsutsui		echo "${_SRC} in IMGFILE_EXTRA not found, aborting";	\
2711.1Stsutsui		false; 							\
2721.1Stsutsui	fi
2731.1Stsutsui	@if [ -f ${_SRC} ]; then 					\
2741.21Stsutsui		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
2751.21Stsutsui		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
2761.1Stsutsui	fi
2771.1Stsutsui.endfor
2781.1Stsutsui.endif
2791.1Stsutsui	@echo Preparing spec files for makefs...
2801.1Stsutsui	${RM} -f ${WORKSPEC}
2811.1Stsutsui	cat ${WORKDIR}/etc/mtree/* |					\
2821.1Stsutsui	    ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC}
2831.10Ssnj	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty |			\
2841.1Stsutsui	    ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC}
2851.1Stsutsui	cat ${SPEC_IN} >> ${WORKSPEC}
2861.1Stsutsui.if defined(SECONDARY_BOOT)
2871.1Stsutsui	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
2881.1Stsutsui	    >> ${WORKSPEC}
2891.1Stsutsui.endif
2901.1Stsutsui.if defined(SPEC_EXTRA)
2911.1Stsutsui	cat ${SPEC_EXTRA} >> ${WORKSPEC}
2921.1Stsutsui.endif
2931.4Sriz	@echo Creating rootfs...
2941.1Stsutsui	# XXX /var/spool/ftp/hidden is unreadable
2951.1Stsutsui	${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden
2961.1Stsutsui	${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE}			\
2971.1Stsutsui	    -B ${TARGET_ENDIANNESS}					\
2981.1Stsutsui	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
2991.13Schristos	    ${MAKEFS_TIMESTAMP}						\
3001.1Stsutsui	    ${IMGMAKEFSOPTIONS}						\
3011.1Stsutsui	    ${WORKFS} ${WORKDIR}
3021.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
3031.5Stsutsui	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
3041.1Stsutsui	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
3051.1Stsutsui.endif
3061.1Stsutsui	@echo done.
3071.1Stsutsui	mv ${WORKFS} ${.TARGET}
3081.1Stsutsui
3091.1Stsutsui#
3101.1Stsutsui# definitions to create image
3111.1Stsutsui#
3121.1Stsutsui.if ${USE_MBR} != "no"
3131.1StsutsuiDISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
3141.1Stsutsui.else
3151.1StsutsuiDISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
3161.1Stsutsui.endif
3171.1Stsutsui
3181.5StsutsuiMBR_DEFAULT_BOOTCODE?=	mbr
3191.5Stsutsui
3201.1StsutsuiOMIT_SWAPIMG?=	no
3211.1Stsutsui
3221.1StsutsuiWORKMBR?=	work.mbr
3231.1StsutsuiWORKSWAP?=	work.swap
3241.1StsutsuiWORKLABEL?=	work.diskproto
3251.1StsutsuiWORKIMG?=	work.img
3261.1Stsutsui
3271.1StsutsuiCLEANFILES+=	${WORKMBR} ${WORKSWAP}
3281.1StsutsuiCLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
3291.1StsutsuiCLEANFILES+=	${WORKIMG} ${IMGBASE}.img
3301.1Stsutsui
3311.1Stsutsui${WORKLABEL}:
3321.1Stsutsui	${TOOL_SED}							\
3331.1Stsutsui	    -e "s/@@SECTORS@@/${SECTORS}/"				\
3341.1Stsutsui	    -e "s/@@HEADS@@/${HEADS}/"					\
3351.1Stsutsui	    -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/"		\
3361.1Stsutsui	    -e "s/@@CYLINDERS@@/${CYLINDERS}/"				\
3371.1Stsutsui	    -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/"			\
3381.1Stsutsui	    -e "s/@@FSSECTORS@@/${FSSECTORS}/"				\
3391.1Stsutsui	    -e "s/@@FSOFFSET@@/${FSOFFSET}/"				\
3401.1Stsutsui	    -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/"			\
3411.1Stsutsui	    -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/"			\
3421.1Stsutsui	    -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/"		\
3431.1Stsutsui	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
3441.1Stsutsui	mv ${WORKLABEL}.tmp ${WORKLABEL}
3451.1Stsutsui
3461.1Stsutsui${IMGBASE}.img:	${TARGETFS} ${WORKLABEL}
3471.5Stsutsui.if ${USE_MBR} != "no"
3481.1Stsutsui	@echo creating MBR labels...
3491.1Stsutsui	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
3501.5Stsutsui	${TOOL_FDISK} -f -i -u \
3511.1Stsutsui	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
3521.1Stsutsui	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
3531.1Stsutsui	    -F ${WORKMBR}
3541.5Stsutsui.if empty(MBR_BOOTCODE)
3551.5Stsutsui	@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
3561.5Stsutsui		echo ${TOOL_FDISK} -f					\
3571.5Stsutsui		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
3581.5Stsutsui		    -F ${WORKMBR};					\
3591.5Stsutsui		${TOOL_FDISK} -f					\
3601.5Stsutsui		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
3611.5Stsutsui		    -F ${WORKMBR};					\
3621.5Stsutsui	fi
3631.5Stsutsui.else
3641.5Stsutsui	@if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then 		\
3651.5Stsutsui		echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \
3661.5Stsutsui		false; 							\
3671.5Stsutsui	fi
3681.5Stsutsui	${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE}	\
3691.5Stsutsui	    -F ${WORKMBR}
3701.5Stsutsui.endif
3711.1Stsutsui	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
3721.1Stsutsui	    ${CAT} - ${TARGETFS} > ${WORKIMG}
3731.21Stsutsui.else	# USE_MBR == "no"
3741.14Schristos	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
3751.21Stsutsui.endif	# USE_MBR != "no"
3761.1Stsutsui.if ${OMIT_SWAPIMG} == "no"
3771.1Stsutsui	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
3781.1Stsutsui	${CAT} ${WORKSWAP} >> ${WORKIMG}
3791.1Stsutsui.endif
3801.1Stsutsui.if ${USE_SUNLABEL} != "no"
3811.1Stsutsui	@echo Creating sun disklabel...
3821.1Stsutsui	printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \
3831.1Stsutsui	    ${CYLINDERS} ${HEADS} ${SECTORS} \
3841.1Stsutsui	    ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \
3851.1Stsutsui	    ${TOOL_SUNLABEL} -nq ${WORKIMG}
3861.1Stsutsui.endif
3871.1Stsutsui	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
3881.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
3891.11Sriastrad	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
3901.1Stsutsui	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
3911.1Stsutsui.endif
3921.1Stsutsui	mv ${WORKIMG} ${.TARGET}
3931.1Stsutsui
3941.1Stsutsui
3951.1StsutsuiCLEANFILES+=	${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp
3961.1Stsutsui
3971.1Stsutsui${IMGBASE}.img.gz:	${IMGBASE}.img
3981.9Sapb	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
3991.1Stsutsui	mv ${.TARGET}.tmp ${.TARGET}
4001.1Stsutsui
4011.1Stsutsuiclean:
4021.1Stsutsui	@if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then 		\
4031.1Stsutsui		${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden;		\
4041.1Stsutsui	fi	# XXX
4051.1Stsutsui	${RM} -fr ${WORKDIR}
4061.1Stsutsui
4071.1Stsutsuiprepare_md_post: .PHONY
4081.1Stsutsuiimage_md_post: .PHONY
4091.1Stsutsuiimage_md_pre: .PHONY
4101.1Stsutsui
4111.1Stsutsui.include <bsd.prog.mk>
412