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