Makefile.bootimage revision 1.15
11.15Schristos#	$NetBSD: Makefile.bootimage,v 1.15 2017/02/11 03:07:06 christos 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#	BOOTDISK
381.1Stsutsui#		device name of target bootable disk specified in /etc/fstab
391.1Stsutsui#		(default: sd0)
401.1Stsutsui#	USE_MBR
411.1Stsutsui#		set yes if target disk image requires MBR partition
421.6Stsutsui#		(default: no)
431.5Stsutsui#	MBR_BOOTCODE
441.5Stsutsui#		optional MBR bootcode which should be installed by fdisk(8)
451.5Stsutsui#		(default: empty)
461.5Stsutsui#		- specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec
471.5Stsutsui#		- if MBR_BOOTCODE is not specified,
481.5Stsutsui#		  MBR_DEFAULT_BOOTCODE (default: mbr) will be used
491.5Stsutsui#		  if the target ${MACHINE} has the one in /usr/mdec
501.1Stsutsui#	USE_SUNLABEL
511.1Stsutsui#		set yes if target disk image requires Sun's label
521.1Stsutsui#		(default: no)
531.1Stsutsui#	INSTALLBOOT_AFTER_DISKLABEL (untested)
541.1Stsutsui#		set yes if the target ${MACHINE} requires disklabel
551.1Stsutsui#		to run installboot(8), like hp300
561.1Stsutsui#		(default: empty)
571.1Stsutsui#	IMAGEMB
581.1Stsutsui#		target image size in MB
591.1Stsutsui#		(default: 2048)
601.1Stsutsui#	SWAPMB
611.1Stsutsui#		swap size in target image in MB
621.1Stsutsui#		(default: 128)
631.1Stsutsui#	KERN_SET
641.1Stsutsui#		kernel set name which should be extracted into image
651.1Stsutsui#		(default: kern-GENERIC)
661.1Stsutsui#	SETS
671.1Stsutsui#		binary sets that should be extracted into image
681.1Stsutsui#		(default: modules base etc comp games man misc tests text
691.1Stsutsui#			  xbase xcomp xetc xfont xserver)
701.1Stsutsui#	SETS_DIR
711.1Stsutsui#		directory path where binary sets are stored
721.1Stsutsui#		(default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets)
731.1Stsutsui#	IMGFILE_EXTRA
741.1Stsutsui#		list of additional files to be copied into images,
751.1Stsutsui#		containing one or more tuples of the form:
761.1Stsutsui#			FILE	TARGETPATH
771.1Stsutsui#		for installation image etc.
781.1Stsutsui#		(default: empty)
791.1Stsutsui#	IMGDIR_EXTRA
801.1Stsutsui#		list of additional directories to be copied into images,
811.1Stsutsui#		containing one or more tuples of the form:
821.1Stsutsui#			DIR	TARGETPATH
831.1Stsutsui#		for installation image etc.
841.1Stsutsui#		(default: empty)
851.6Stsutsui#		XXX: currently permissions in IMGDIR_EXTRA are not handled
861.1Stsutsui#	IMGDIR_EXCLUDE
871.1Stsutsui#		pax(1) options to exclude files which should not copied
881.1Stsutsui#		into TARGETPATH in IMGDIR_EXTRA
891.1Stsutsui#		(default: empty)
901.1Stsutsui#	FSTAB_IN
911.1Stsutsui#		template file of /etc/fstab
921.1Stsutsui#		(default: ${DISTRIBDIR}/common/bootimage/fstab.in)
931.1Stsutsui#	SPEC_IN
941.1Stsutsui#		default files of spec file for makefs(8)
951.1Stsutsui#		(default: ${DISTRIBDIR}/common/bootimage/spec.in)
961.1Stsutsui#	SPEC_EXTRA
971.1Stsutsui#		additional files of spec file for makefs(8)
981.1Stsutsui#		(default: empty)
991.1Stsutsui#	IMGMAKEFSOPTIONS
1001.1Stsutsui#		options passed to makefs(8) to create root file system
1011.1Stsutsui#		(default: -o bsize=16384,fsize=2048,density=8192)
1021.5Stsutsui#	INSTALLBOOTOPTIONS
1031.5Stsutsui#		options passed to installboot(8), e.g., -o console=com0
1041.5Stsutsui#		(default: empty)
1051.1Stsutsui#	PRIMARY_BOOT
1061.1Stsutsui#		primary boot loader that should be installed into
1071.1Stsutsui#		the target image via installboot(8)
1081.1Stsutsui#		(default: empty)
1091.1Stsutsui#	SECONDARY_BOOT
1101.1Stsutsui#		secondary bootloader that should be put into the target image
1111.1Stsutsui#		(default: empty)
1121.1Stsutsui#	SECONDARY_BOOT_ARG
1131.1Stsutsui#		extra arguments that should be passed to installboot(8)
1141.1Stsutsui#		to specify the secondary bootloader
1151.1Stsutsui#		(default: empty)
1161.1Stsutsui#	DISKPROTO_IN
1171.1Stsutsui#		template file of disklabel -R
1181.1Stsutsui#		(default: ${DISTRIBDIR}/common/bootimage/diskproto.in
1191.1Stsutsui#		       or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in)
1201.1Stsutsui#	OMIT_SWAPIMG
1211.1Stsutsui#		no need to put swap partition into image (for USB stick)
1221.1Stsutsui#		(default: no)
1231.1Stsutsui#
1241.1Stsutsui
1251.1Stsutsui.include <bsd.own.mk> 		#
1261.1Stsutsui.include <bsd.endian.mk>	# for TARGET_ENDIANNESS
1271.1Stsutsui
1281.1Stsutsui.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
1291.1Stsutsui
1301.13Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no"
1311.13SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
1321.15SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
1331.15Schristos.endif
1341.12Schristos.endif
1351.12Schristos
1361.1Stsutsui.if empty(IMGBASE)
1371.1Stsutsui.BEGIN:
1381.1Stsutsui	@echo "Error: IMGBASE is not set"
1391.1Stsutsui	@false
1401.1Stsutsui.endif
1411.1Stsutsui
1421.1Stsutsui# should be defined elsewhere? 
1431.1StsutsuiCAT?=		cat
1441.1StsutsuiCHMOD?=		chmod
1451.1StsutsuiDD?=		dd
1461.1StsutsuiMKDIR?=		mkdir -p
1471.1StsutsuiRM?=		rm
1481.1Stsutsui
1491.1Stsutsui#
1501.1Stsutsui# common definitions for image
1511.1Stsutsui#
1521.1StsutsuiBOOTDISK?=	sd0
1531.1StsutsuiUSE_MBR?=	no
1541.1StsutsuiUSE_SUNLABEL?=	no
1551.1StsutsuiINSTALLBOOT_AFTER_DISKLABEL?=	no
1561.1Stsutsui
1571.1Stsutsui#
1581.1Stsutsui# size parameters for image
1591.1Stsutsui#
1601.1StsutsuiIMAGEMB?=	2048		# 2048MB
1611.1StsutsuiSWAPMB?=	128		# 128MB
1621.1Stsutsui
1631.3Stsutsui# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
1641.1StsutsuiIMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
1651.3StsutsuiSWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
1661.1Stsutsui
1671.1Stsutsui.if ${USE_MBR} == "no"
1681.1StsutsuiLABELSECTORS?=	0
1691.1Stsutsui.else
1701.1Stsutsui#LABELSECTORS?=	63	# historical
1711.1Stsutsui#LABELSECTORS?=	32	# 16KB aligned
1721.1StsutsuiLABELSECTORS?=	2048	# 1MB aligned for modern flash devices
1731.1Stsutsui.endif
1741.1Stsutsui
1751.1StsutsuiFSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}
1761.1StsutsuiFSSIZE!=	expr ${FSSECTORS} \* 512
1771.1Stsutsui
1781.1Stsutsui# parameters for disklabel and MBR
1791.1StsutsuiHEADS=		64
1801.1StsutsuiSECTORS=	32
1811.1StsutsuiCYLINDERS!=	expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)
1821.1StsutsuiSECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS}
1831.1StsutsuiMBRHEADS=	255
1841.1StsutsuiMBRSECTORS=	63
1851.1StsutsuiMBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
1861.1StsutsuiMBRNETBSD=	169
1871.1Stsutsui
1881.1StsutsuiBSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS}
1891.1StsutsuiFSOFFSET=	${LABELSECTORS}
1901.1StsutsuiSWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS}
1911.1Stsutsui
1921.1Stsutsui# parameters for sunlabel
1931.1StsutsuiFSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
1941.3StsutsuiSWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true
1951.1Stsutsui
1961.1Stsutsui
1971.1Stsutsui#
1981.1Stsutsui# definitions to create root fs
1991.1Stsutsui#
2001.1StsutsuiSETS_DEFAULT=	modules base etc comp games man misc tests text
2011.1Stsutsui.if ${MKX11} != "no"
2021.1StsutsuiSETS_DEFAULT+=	xbase xcomp xetc xfont xserver
2031.1Stsutsui.endif
2041.1Stsutsui
2051.1StsutsuiKERN_SET?=	kern-GENERIC
2061.1StsutsuiSETS?=		${SETS_DEFAULT}
2071.1StsutsuiIMG_SETS=	${KERN_SET} ${SETS}
2081.1StsutsuiSETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
2091.1Stsutsui
2101.1StsutsuiFSTAB_IN?=	${DISTRIBDIR}/common/bootimage/fstab.in
2111.1StsutsuiSPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in
2121.1Stsutsui
2131.1StsutsuiIMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192
2141.1Stsutsui
2151.1StsutsuiWORKDIR?=       work
2161.1StsutsuiWORKSPEC?=      work.spec
2171.1StsutsuiWORKFSTAB?=	work.fstab
2181.1StsutsuiWORKRCCONF?=	work.rc.conf
2191.1StsutsuiWORKFS?=        work.rootfs
2201.1StsutsuiTARGETFS?=      imgroot.fs
2211.1Stsutsui
2221.1StsutsuiCLEANFILES+=	${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS}
2231.1StsutsuiCLEANFILES+=	${TARGETFS}
2241.1Stsutsui
2251.1Stsutsui#
2261.1Stsutsui# create root file system for the image
2271.1Stsutsui#
2281.1Stsutsui${TARGETFS}: prepare_md_post
2291.1Stsutsui	@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
2301.1Stsutsui		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
2311.1Stsutsui		false; 							\
2321.1Stsutsui	fi;
2331.14Schristos	@${MKDIR} ${MKDIRPERM} ${WORKDIR}
2341.1Stsutsui.for set in ${IMG_SETS}
2351.1Stsutsui	@if [ ! -f ${SETS_DIR}/${set}.tgz ]; then 			\
2361.1Stsutsui		echo "Missing ${SETS_DIR}/${set}.tgz, aborting";	\
2371.1Stsutsui		false; 							\
2381.1Stsutsui	fi
2391.1Stsutsui	@echo Extracting ${set}.tgz ...
2401.15Schristos	@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.tgz .)
2411.1Stsutsui.endfor
2421.1Stsutsui.if defined(SECONDARY_BOOT)
2431.1Stsutsui	@echo Copying secondary boot...
2441.14Schristos	${INSTALL} ${COPY} -m 0644 -f ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
2451.1Stsutsui.endif
2461.1Stsutsui	@echo Preparing /etc/fstab ...
2471.1Stsutsui	${TOOL_SED} "s/@@BOOTDISK@@/${BOOTDISK}/" < ${FSTAB_IN} > ${WORKFSTAB}
2481.14Schristos	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
2491.1Stsutsui	@echo Setting rc_configured=YES in /etc/rc.conf ...
2501.1Stsutsui	${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/"		\
2511.1Stsutsui	    < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF}
2521.14Schristos	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
2531.1Stsutsui.if defined(IMGDIR_EXTRA)
2541.1Stsutsui	@echo Copying extra dirs...
2551.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA}
2561.1Stsutsui	@if [ ! -d ${_SRCDIR} ]; then 					\
2571.1Stsutsui		echo "${_SRCDIR} is not directory, aborting";		\
2581.1Stsutsui		false; 							\
2591.1Stsutsui	fi
2601.14Schristos	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
2611.1Stsutsui	(cd ${_SRCDIR} ;						\
2621.15Schristos	    ${TOOL_PAX} -rw -pe	-v ${PAX_TIMESTAMP}			\
2631.1Stsutsui	    ${IMGDIR_EXCLUDE}						\
2641.1Stsutsui	    . ${.OBJDIR}/${WORKDIR}/${_TARGET} )
2651.1Stsutsui.endfor
2661.1Stsutsui.endif
2671.1Stsutsui.if defined(IMGFILE_EXTRA)
2681.1Stsutsui	@echo Copying extra files...
2691.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA}
2701.1Stsutsui	@if [ ! -f ${_SRC} ]; then 					\
2711.1Stsutsui		echo "${_SRC} in IMGFILE_EXTRA not found, aborting";	\
2721.1Stsutsui		false; 							\
2731.1Stsutsui	fi
2741.1Stsutsui	@if [ -f ${_SRC} ]; then 					\
2751.14Schristos		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};		\
2761.14Schristos		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};			\
2771.1Stsutsui	fi
2781.1Stsutsui.endfor
2791.1Stsutsui.endif
2801.1Stsutsui	@echo Preparing spec files for makefs...
2811.1Stsutsui	${RM} -f ${WORKSPEC}
2821.1Stsutsui	cat ${WORKDIR}/etc/mtree/* |					\
2831.1Stsutsui	    ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC}
2841.10Ssnj	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty |			\
2851.1Stsutsui	    ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC}
2861.1Stsutsui	cat ${SPEC_IN} >> ${WORKSPEC}
2871.1Stsutsui.if defined(SECONDARY_BOOT)
2881.1Stsutsui	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
2891.1Stsutsui	    >> ${WORKSPEC}
2901.1Stsutsui.endif
2911.1Stsutsui.if defined(SPEC_EXTRA)
2921.1Stsutsui	cat ${SPEC_EXTRA} >> ${WORKSPEC}
2931.1Stsutsui.endif
2941.4Sriz	@echo Creating rootfs...
2951.1Stsutsui	# XXX /var/spool/ftp/hidden is unreadable
2961.1Stsutsui	${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden
2971.1Stsutsui	${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE}			\
2981.1Stsutsui	    -B ${TARGET_ENDIANNESS}					\
2991.1Stsutsui	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
3001.13Schristos	    ${MAKEFS_TIMESTAMP}						\
3011.1Stsutsui	    ${IMGMAKEFSOPTIONS}						\
3021.1Stsutsui	    ${WORKFS} ${WORKDIR}
3031.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
3041.5Stsutsui	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
3051.1Stsutsui	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
3061.1Stsutsui.endif
3071.1Stsutsui	@echo done.
3081.1Stsutsui	mv ${WORKFS} ${.TARGET}
3091.1Stsutsui
3101.1Stsutsui#
3111.1Stsutsui# definitions to create image
3121.1Stsutsui#
3131.1Stsutsui.if ${USE_MBR} != "no"
3141.1StsutsuiDISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
3151.1Stsutsui.else
3161.1StsutsuiDISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
3171.1Stsutsui.endif
3181.1Stsutsui
3191.5StsutsuiMBR_DEFAULT_BOOTCODE?=	mbr
3201.5Stsutsui
3211.1StsutsuiOMIT_SWAPIMG?=	no
3221.1Stsutsui
3231.1StsutsuiWORKMBR?=	work.mbr
3241.1StsutsuiWORKSWAP?=	work.swap
3251.1StsutsuiWORKLABEL?=	work.diskproto
3261.1StsutsuiWORKIMG?=	work.img
3271.1Stsutsui
3281.1StsutsuiCLEANFILES+=	${WORKMBR} ${WORKSWAP}
3291.1StsutsuiCLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
3301.1StsutsuiCLEANFILES+=	${WORKIMG} ${IMGBASE}.img
3311.1Stsutsui
3321.1Stsutsui${WORKLABEL}:
3331.1Stsutsui	${TOOL_SED}							\
3341.1Stsutsui	    -e "s/@@SECTORS@@/${SECTORS}/"				\
3351.1Stsutsui	    -e "s/@@HEADS@@/${HEADS}/"					\
3361.1Stsutsui	    -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/"		\
3371.1Stsutsui	    -e "s/@@CYLINDERS@@/${CYLINDERS}/"				\
3381.1Stsutsui	    -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/"			\
3391.1Stsutsui	    -e "s/@@FSSECTORS@@/${FSSECTORS}/"				\
3401.1Stsutsui	    -e "s/@@FSOFFSET@@/${FSOFFSET}/"				\
3411.1Stsutsui	    -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/"			\
3421.1Stsutsui	    -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/"			\
3431.1Stsutsui	    -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/"		\
3441.1Stsutsui	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
3451.1Stsutsui	mv ${WORKLABEL}.tmp ${WORKLABEL}
3461.1Stsutsui
3471.1Stsutsui${IMGBASE}.img:	${TARGETFS} ${WORKLABEL}
3481.5Stsutsui.if ${USE_MBR} != "no"
3491.1Stsutsui	@echo creating MBR labels...
3501.1Stsutsui	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
3511.5Stsutsui	${TOOL_FDISK} -f -i -u \
3521.1Stsutsui	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
3531.1Stsutsui	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
3541.1Stsutsui	    -F ${WORKMBR}
3551.5Stsutsui.if empty(MBR_BOOTCODE)
3561.5Stsutsui	@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
3571.5Stsutsui		echo ${TOOL_FDISK} -f					\
3581.5Stsutsui		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
3591.5Stsutsui		    -F ${WORKMBR};					\
3601.5Stsutsui		${TOOL_FDISK} -f					\
3611.5Stsutsui		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
3621.5Stsutsui		    -F ${WORKMBR};					\
3631.5Stsutsui	fi
3641.5Stsutsui.else
3651.5Stsutsui	@if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then 		\
3661.5Stsutsui		echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \
3671.5Stsutsui		false; 							\
3681.5Stsutsui	fi
3691.5Stsutsui	${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE}	\
3701.5Stsutsui	    -F ${WORKMBR}
3711.5Stsutsui.endif
3721.1Stsutsui	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
3731.1Stsutsui	    ${CAT} - ${TARGETFS} > ${WORKIMG}
3741.1Stsutsui.else
3751.14Schristos	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
3761.1Stsutsui.endif
3771.1Stsutsui.if ${OMIT_SWAPIMG} == "no"
3781.1Stsutsui	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
3791.1Stsutsui	${CAT} ${WORKSWAP} >> ${WORKIMG}
3801.1Stsutsui.endif
3811.1Stsutsui.if ${USE_SUNLABEL} != "no"
3821.1Stsutsui	@echo Creating sun disklabel...
3831.1Stsutsui	printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \
3841.1Stsutsui	    ${CYLINDERS} ${HEADS} ${SECTORS} \
3851.1Stsutsui	    ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \
3861.1Stsutsui	    ${TOOL_SUNLABEL} -nq ${WORKIMG}
3871.1Stsutsui.endif
3881.1Stsutsui	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
3891.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
3901.11Sriastrad	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
3911.1Stsutsui	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
3921.1Stsutsui.endif
3931.1Stsutsui	mv ${WORKIMG} ${.TARGET}
3941.1Stsutsui
3951.1Stsutsui
3961.1StsutsuiCLEANFILES+=	${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp
3971.1Stsutsui
3981.1Stsutsui${IMGBASE}.img.gz:	${IMGBASE}.img
3991.9Sapb	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
4001.1Stsutsui	mv ${.TARGET}.tmp ${.TARGET}
4011.1Stsutsui
4021.1Stsutsuiclean:
4031.1Stsutsui	@if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then 		\
4041.1Stsutsui		${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden;		\
4051.1Stsutsui	fi	# XXX
4061.1Stsutsui	${RM} -fr ${WORKDIR}
4071.1Stsutsui
4081.1Stsutsuiprepare_md_post: .PHONY
4091.1Stsutsuiimage_md_post: .PHONY
4101.1Stsutsuiimage_md_pre: .PHONY
4111.1Stsutsui
4121.1Stsutsui.include <bsd.prog.mk>
413