Home | History | Annotate | Line # | Download | only in bootimage
Makefile.bootimage revision 1.21.2.2
      1  1.21.2.2    martin #	$NetBSD: Makefile.bootimage,v 1.21.2.2 2020/04/24 17:19:49 martin 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 #	USE_MBR
     38       1.1   tsutsui #		set yes if target disk image requires MBR partition
     39       1.6   tsutsui #		(default: no)
     40  1.21.2.2    martin #	USE_GPT
     41  1.21.2.2    martin #		set yes if target disk image requires GPT partition
     42  1.21.2.2    martin #		(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.21.2.2    martin #	EFIMB
     64  1.21.2.2    martin #		EFI partition size in target image in MB
     65  1.21.2.2    martin #		(default: 128)
     66  1.21.2.2    martin #	FATMB
     67  1.21.2.2    martin #		FAT partition size in target image in MB
     68  1.21.2.2    martin #		(default: 0)
     69       1.1   tsutsui #	KERN_SET
     70       1.1   tsutsui #		kernel set name which should be extracted into image
     71       1.1   tsutsui #		(default: kern-GENERIC)
     72       1.1   tsutsui #	SETS
     73       1.1   tsutsui #		binary sets that should be extracted into image
     74  1.21.2.1    martin #		(default: modules base etc comp games man misc rescue tests
     75  1.21.2.1    martin #			  text xbase xcomp xetc xfont xserver)
     76       1.1   tsutsui #	SETS_DIR
     77       1.1   tsutsui #		directory path where binary sets are stored
     78       1.1   tsutsui #		(default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets)
     79       1.1   tsutsui #	IMGFILE_EXTRA
     80       1.1   tsutsui #		list of additional files to be copied into images,
     81       1.1   tsutsui #		containing one or more tuples of the form:
     82       1.1   tsutsui #			FILE	TARGETPATH
     83       1.1   tsutsui #		for installation image etc.
     84       1.1   tsutsui #		(default: empty)
     85       1.1   tsutsui #	IMGDIR_EXTRA
     86       1.1   tsutsui #		list of additional directories to be copied into images,
     87       1.1   tsutsui #		containing one or more tuples of the form:
     88       1.1   tsutsui #			DIR	TARGETPATH
     89       1.1   tsutsui #		for installation image etc.
     90       1.1   tsutsui #		(default: empty)
     91       1.6   tsutsui #		XXX: currently permissions in IMGDIR_EXTRA are not handled
     92       1.1   tsutsui #	IMGDIR_EXCLUDE
     93       1.1   tsutsui #		pax(1) options to exclude files which should not copied
     94       1.1   tsutsui #		into TARGETPATH in IMGDIR_EXTRA
     95       1.1   tsutsui #		(default: empty)
     96       1.1   tsutsui #	FSTAB_IN
     97       1.1   tsutsui #		template file of /etc/fstab
     98       1.1   tsutsui #		(default: ${DISTRIBDIR}/common/bootimage/fstab.in)
     99       1.1   tsutsui #	SPEC_IN
    100       1.1   tsutsui #		default files of spec file for makefs(8)
    101       1.1   tsutsui #		(default: ${DISTRIBDIR}/common/bootimage/spec.in)
    102       1.1   tsutsui #	SPEC_EXTRA
    103       1.1   tsutsui #		additional files of spec file for makefs(8)
    104       1.1   tsutsui #		(default: empty)
    105       1.1   tsutsui #	IMGMAKEFSOPTIONS
    106       1.1   tsutsui #		options passed to makefs(8) to create root file system
    107       1.1   tsutsui #		(default: -o bsize=16384,fsize=2048,density=8192)
    108       1.5   tsutsui #	INSTALLBOOTOPTIONS
    109       1.5   tsutsui #		options passed to installboot(8), e.g., -o console=com0
    110       1.5   tsutsui #		(default: empty)
    111       1.1   tsutsui #	PRIMARY_BOOT
    112       1.1   tsutsui #		primary boot loader that should be installed into
    113       1.1   tsutsui #		the target image via installboot(8)
    114       1.1   tsutsui #		(default: empty)
    115       1.1   tsutsui #	SECONDARY_BOOT
    116       1.1   tsutsui #		secondary bootloader that should be put into the target image
    117       1.1   tsutsui #		(default: empty)
    118       1.1   tsutsui #	SECONDARY_BOOT_ARG
    119       1.1   tsutsui #		extra arguments that should be passed to installboot(8)
    120       1.1   tsutsui #		to specify the secondary bootloader
    121       1.1   tsutsui #		(default: empty)
    122       1.1   tsutsui #	DISKPROTO_IN
    123       1.1   tsutsui #		template file of disklabel -R
    124       1.1   tsutsui #		(default: ${DISTRIBDIR}/common/bootimage/diskproto.in
    125       1.1   tsutsui #		       or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in)
    126  1.21.2.2    martin #	EFIBOOT
    127  1.21.2.2    martin #		EFI bootloader
    128  1.21.2.2    martin #		(default: empty)
    129  1.21.2.2    martin #	MBRFAT
    130  1.21.2.2    martin #		MBR partition type value for FAT
    131  1.21.2.2    martin #		(default: 6 ("16-bit FAT, more than 32M"))
    132  1.21.2.2    martin #	FATMAKEFSOPTIONS
    133  1.21.2.2    martin #		options passed to makefs(8) to create a FAT partition
    134  1.21.2.2    martin #		(default: -o fat_type=16)
    135  1.21.2.2    martin #	FATFILES
    136  1.21.2.2    martin #		list of additional files to be copied into FAT partition
    137  1.21.2.2    martin #		(default: empty)
    138       1.1   tsutsui #
    139       1.1   tsutsui 
    140       1.1   tsutsui .include <bsd.own.mk> 		#
    141       1.1   tsutsui .include <bsd.endian.mk>	# for TARGET_ENDIANNESS
    142       1.1   tsutsui 
    143       1.1   tsutsui .include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"
    144       1.1   tsutsui 
    145      1.13  christos .if ${MKREPRO_TIMESTAMP:Uno} != "no"
    146      1.13  christos MAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
    147  1.21.2.2    martin GPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
    148      1.15  christos PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
    149      1.15  christos .endif
    150      1.12  christos 
    151       1.1   tsutsui .if empty(IMGBASE)
    152       1.1   tsutsui .BEGIN:
    153       1.1   tsutsui 	@echo "Error: IMGBASE is not set"
    154       1.1   tsutsui 	@false
    155       1.1   tsutsui .endif
    156       1.1   tsutsui 
    157       1.1   tsutsui # should be defined elsewhere? 
    158       1.1   tsutsui CAT?=		cat
    159       1.1   tsutsui CHMOD?=		chmod
    160       1.1   tsutsui DD?=		dd
    161       1.1   tsutsui MKDIR?=		mkdir -p
    162       1.1   tsutsui RM?=		rm
    163       1.1   tsutsui 
    164       1.1   tsutsui #
    165       1.1   tsutsui # common definitions for image
    166       1.1   tsutsui #
    167       1.1   tsutsui USE_MBR?=	no
    168  1.21.2.2    martin USE_GPT?=	no
    169       1.1   tsutsui USE_SUNLABEL?=	no
    170       1.1   tsutsui INSTALLBOOT_AFTER_DISKLABEL?=	no
    171       1.1   tsutsui 
    172       1.1   tsutsui #
    173       1.1   tsutsui # size parameters for image
    174       1.1   tsutsui #
    175       1.1   tsutsui IMAGEMB?=	2048		# 2048MB
    176       1.1   tsutsui SWAPMB?=	128		# 128MB
    177  1.21.2.2    martin .if ${USE_GPT} == "no"
    178  1.21.2.2    martin EFIMB?=		0
    179  1.21.2.2    martin GPTSECTORS=	0
    180  1.21.2.2    martin .else
    181  1.21.2.2    martin EFIMB?=		128		# 128MB
    182  1.21.2.2    martin GPTSECTORS=	2048
    183  1.21.2.2    martin .endif
    184  1.21.2.2    martin FATMB?=		0
    185       1.1   tsutsui 
    186       1.3   tsutsui # XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
    187       1.1   tsutsui IMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
    188       1.3   tsutsui SWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
    189  1.21.2.2    martin EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true
    190  1.21.2.2    martin FATSECTORS!=	expr ${FATMB} \* 1024 \* 1024 / 512 || true
    191       1.1   tsutsui 
    192  1.21.2.2    martin .if ${USE_MBR} == "no" && ${USE_GPT} == "no"
    193       1.1   tsutsui LABELSECTORS?=	0
    194       1.1   tsutsui .else
    195       1.1   tsutsui #LABELSECTORS?=	63	# historical
    196       1.1   tsutsui #LABELSECTORS?=	32	# 16KB aligned
    197       1.1   tsutsui LABELSECTORS?=	2048	# 1MB aligned for modern flash devices
    198       1.1   tsutsui .endif
    199       1.1   tsutsui 
    200  1.21.2.2    martin FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
    201  1.21.2.2    martin 		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
    202       1.1   tsutsui FSSIZE!=	expr ${FSSECTORS} \* 512
    203       1.1   tsutsui 
    204       1.1   tsutsui # parameters for disklabel and MBR
    205       1.1   tsutsui HEADS=		64
    206       1.1   tsutsui SECTORS=	32
    207       1.1   tsutsui CYLINDERS!=	expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)
    208       1.1   tsutsui SECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS}
    209       1.1   tsutsui MBRHEADS=	255
    210       1.1   tsutsui MBRSECTORS=	63
    211       1.1   tsutsui MBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
    212       1.1   tsutsui MBRNETBSD=	169
    213  1.21.2.2    martin MBRFAT?=	6	# 16-bit FAT, more than 32M
    214       1.1   tsutsui 
    215  1.21.2.2    martin BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \
    216  1.21.2.2    martin 		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
    217  1.21.2.2    martin FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS}
    218  1.21.2.2    martin SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} \
    219  1.21.2.2    martin 		    + ${EFISECTORS} + ${FATSECTORS}
    220  1.21.2.2    martin FATOFFSET=	${LABELSECTORS}
    221       1.1   tsutsui 
    222       1.1   tsutsui # parameters for sunlabel
    223       1.1   tsutsui FSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
    224       1.3   tsutsui SWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true
    225       1.1   tsutsui 
    226  1.21.2.2    martin .if ${USE_GPT} != "no"
    227  1.21.2.2    martin BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
    228  1.21.2.2    martin SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
    229  1.21.2.2    martin .endif
    230       1.1   tsutsui 
    231       1.1   tsutsui #
    232       1.1   tsutsui # definitions to create root fs
    233       1.1   tsutsui #
    234  1.21.2.1    martin SETS_DEFAULT=	modules base etc comp games man misc rescue tests text
    235       1.1   tsutsui .if ${MKX11} != "no"
    236       1.1   tsutsui SETS_DEFAULT+=	xbase xcomp xetc xfont xserver
    237       1.1   tsutsui .endif
    238       1.1   tsutsui 
    239       1.1   tsutsui KERN_SET?=	kern-GENERIC
    240       1.1   tsutsui SETS?=		${SETS_DEFAULT}
    241       1.1   tsutsui IMG_SETS=	${KERN_SET} ${SETS}
    242       1.1   tsutsui SETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
    243       1.1   tsutsui 
    244       1.1   tsutsui FSTAB_IN?=	${DISTRIBDIR}/common/bootimage/fstab.in
    245       1.1   tsutsui SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in
    246       1.1   tsutsui 
    247       1.1   tsutsui IMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192
    248  1.21.2.2    martin FATMAKEFSOPTIONS?=	-o fat_type=16
    249       1.1   tsutsui 
    250       1.1   tsutsui WORKDIR?=       work
    251       1.1   tsutsui WORKSPEC?=      work.spec
    252       1.1   tsutsui WORKFSTAB?=	work.fstab
    253       1.1   tsutsui WORKRCCONF?=	work.rc.conf
    254       1.1   tsutsui WORKFS?=        work.rootfs
    255       1.1   tsutsui TARGETFS?=      imgroot.fs
    256      1.19   aymeric COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
    257      1.18    martin TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
    258       1.1   tsutsui 
    259       1.1   tsutsui CLEANFILES+=	${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS}
    260       1.1   tsutsui CLEANFILES+=	${TARGETFS}
    261       1.1   tsutsui 
    262       1.1   tsutsui #
    263  1.21.2.2    martin # definitions to create image
    264  1.21.2.2    martin #
    265  1.21.2.2    martin .if ${SWAPSECTORS} == 0
    266  1.21.2.2    martin .  if ${USE_MBR} != "no"
    267  1.21.2.2    martin DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in
    268  1.21.2.2    martin .  else
    269  1.21.2.2    martin DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.in
    270  1.21.2.2    martin .  endif
    271  1.21.2.2    martin .else
    272  1.21.2.2    martin .  if ${USE_MBR} != "no"
    273  1.21.2.2    martin DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
    274  1.21.2.2    martin .  else
    275  1.21.2.2    martin DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
    276  1.21.2.2    martin .  endif
    277  1.21.2.2    martin .endif
    278  1.21.2.2    martin 
    279  1.21.2.2    martin MBR_DEFAULT_BOOTCODE?=	mbr
    280  1.21.2.2    martin 
    281  1.21.2.2    martin WORKMBR?=	work.mbr
    282  1.21.2.2    martin WORKMBRTRUNC?=	work.mbr.truncated
    283  1.21.2.2    martin WORKSWAP?=	work.swap
    284  1.21.2.2    martin WORKEFI?=	work.efi
    285  1.21.2.2    martin WORKGPT?=	work.gpt
    286  1.21.2.2    martin WORKLABEL?=	work.diskproto
    287  1.21.2.2    martin WORKIMG?=	work.img
    288  1.21.2.2    martin EFIWORKDIR?=	work.efidir
    289  1.21.2.2    martin WORKFAT?=	work.fat
    290  1.21.2.2    martin WORKFATDIR?=	work.fatdir
    291  1.21.2.2    martin 
    292  1.21.2.2    martin .if ${USE_GPT} != "no"
    293  1.21.2.2    martin ${WORKFSTAB}: ${WORKMBR}
    294  1.21.2.2    martin .endif
    295  1.21.2.2    martin 
    296  1.21.2.2    martin ${WORKFSTAB}:
    297  1.21.2.2    martin 	@echo Preparing /etc/fstab ...
    298  1.21.2.2    martin .if ${USE_GPT} != "no"
    299  1.21.2.2    martin .  if ${SWAPSECTORS} != 0
    300  1.21.2.2    martin 	${TOOL_SED}							\
    301  1.21.2.2    martin 	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
    302  1.21.2.2    martin 	    -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/"			\
    303  1.21.2.2    martin 	    < ${FSTAB_IN} > ${WORKFSTAB}
    304  1.21.2.2    martin .  else
    305  1.21.2.2    martin 	${TOOL_SED}							\
    306  1.21.2.2    martin 	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
    307  1.21.2.2    martin 	    -e "/ROOT.b/d"						\
    308  1.21.2.2    martin 	    < ${FSTAB_IN} > ${WORKFSTAB}
    309  1.21.2.2    martin .  endif
    310  1.21.2.2    martin .else
    311  1.21.2.2    martin .  if ${SWAPSECTORS} != 0
    312  1.21.2.2    martin 	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
    313  1.21.2.2    martin .  else
    314  1.21.2.2    martin 	${TOOL_SED}							\
    315  1.21.2.2    martin 	    -e "/ROOT.b/d"						\
    316  1.21.2.2    martin 	    < ${FSTAB_IN} > ${WORKFSTAB}
    317  1.21.2.2    martin .  endif
    318  1.21.2.2    martin .endif
    319  1.21.2.2    martin 
    320  1.21.2.2    martin #
    321       1.1   tsutsui # create root file system for the image
    322       1.1   tsutsui #
    323  1.21.2.2    martin ${TARGETFS}: prepare_md_post ${WORKFSTAB}
    324       1.1   tsutsui 	@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
    325       1.1   tsutsui 		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
    326       1.1   tsutsui 		false; 							\
    327       1.1   tsutsui 	fi;
    328      1.14  christos 	@${MKDIR} ${MKDIRPERM} ${WORKDIR}
    329       1.1   tsutsui .for set in ${IMG_SETS}
    330      1.18    martin 	@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
    331      1.18    martin 		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
    332       1.1   tsutsui 		false; 							\
    333       1.1   tsutsui 	fi
    334      1.18    martin 	@echo Extracting ${set}.${TAR_SUFF} ...
    335      1.19   aymeric 	@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \
    336      1.19   aymeric 		--use-compress-program=${COMPRESS_PROGRAM:Q} \
    337      1.19   aymeric 		-f ${SETS_DIR}/${set}.${TAR_SUFF} .)
    338       1.1   tsutsui .endfor
    339       1.1   tsutsui .if defined(SECONDARY_BOOT)
    340       1.1   tsutsui 	@echo Copying secondary boot...
    341      1.21   tsutsui 	${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
    342       1.1   tsutsui .endif
    343      1.14  christos 	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
    344       1.1   tsutsui 	@echo Setting rc_configured=YES in /etc/rc.conf ...
    345       1.1   tsutsui 	${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/"		\
    346       1.1   tsutsui 	    < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF}
    347      1.14  christos 	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
    348       1.1   tsutsui .if defined(IMGDIR_EXTRA)
    349       1.1   tsutsui 	@echo Copying extra dirs...
    350       1.1   tsutsui .for _SRCDIR _TARGET in ${IMGDIR_EXTRA}
    351       1.1   tsutsui 	@if [ ! -d ${_SRCDIR} ]; then 					\
    352       1.1   tsutsui 		echo "${_SRCDIR} is not directory, aborting";		\
    353       1.1   tsutsui 		false; 							\
    354       1.1   tsutsui 	fi
    355      1.14  christos 	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
    356       1.1   tsutsui 	(cd ${_SRCDIR} ;						\
    357      1.21   tsutsui 	    ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v			\
    358       1.1   tsutsui 	    ${IMGDIR_EXCLUDE}						\
    359       1.1   tsutsui 	    . ${.OBJDIR}/${WORKDIR}/${_TARGET} )
    360       1.1   tsutsui .endfor
    361       1.1   tsutsui .endif
    362       1.1   tsutsui .if defined(IMGFILE_EXTRA)
    363       1.1   tsutsui 	@echo Copying extra files...
    364       1.1   tsutsui .for _SRC _TARGET in ${IMGFILE_EXTRA}
    365       1.1   tsutsui 	@if [ ! -f ${_SRC} ]; then 					\
    366       1.1   tsutsui 		echo "${_SRC} in IMGFILE_EXTRA not found, aborting";	\
    367       1.1   tsutsui 		false; 							\
    368       1.1   tsutsui 	fi
    369       1.1   tsutsui 	@if [ -f ${_SRC} ]; then 					\
    370      1.21   tsutsui 		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
    371      1.21   tsutsui 		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
    372       1.1   tsutsui 	fi
    373       1.1   tsutsui .endfor
    374       1.1   tsutsui .endif
    375       1.1   tsutsui 	@echo Preparing spec files for makefs...
    376       1.1   tsutsui 	${RM} -f ${WORKSPEC}
    377       1.1   tsutsui 	cat ${WORKDIR}/etc/mtree/* |					\
    378       1.1   tsutsui 	    ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC}
    379      1.10       snj 	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty |			\
    380       1.1   tsutsui 	    ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC}
    381       1.1   tsutsui 	cat ${SPEC_IN} >> ${WORKSPEC}
    382       1.1   tsutsui .if defined(SECONDARY_BOOT)
    383       1.1   tsutsui 	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
    384       1.1   tsutsui 	    >> ${WORKSPEC}
    385       1.1   tsutsui .endif
    386       1.1   tsutsui .if defined(SPEC_EXTRA)
    387       1.1   tsutsui 	cat ${SPEC_EXTRA} >> ${WORKSPEC}
    388       1.1   tsutsui .endif
    389       1.4       riz 	@echo Creating rootfs...
    390       1.1   tsutsui 	# XXX /var/spool/ftp/hidden is unreadable
    391       1.1   tsutsui 	${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden
    392       1.1   tsutsui 	${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE}			\
    393       1.1   tsutsui 	    -B ${TARGET_ENDIANNESS}					\
    394       1.1   tsutsui 	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
    395      1.13  christos 	    ${MAKEFS_TIMESTAMP}						\
    396       1.1   tsutsui 	    ${IMGMAKEFSOPTIONS}						\
    397       1.1   tsutsui 	    ${WORKFS} ${WORKDIR}
    398       1.1   tsutsui .if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
    399       1.5   tsutsui 	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
    400       1.1   tsutsui 	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
    401       1.1   tsutsui .endif
    402       1.1   tsutsui 	@echo done.
    403       1.1   tsutsui 	mv ${WORKFS} ${.TARGET}
    404       1.1   tsutsui 
    405  1.21.2.2    martin TARGET_BLOCKS=
    406  1.21.2.2    martin .if ${USE_MBR} != "no" || ${USE_GPT} != "no"
    407  1.21.2.2    martin TARGET_BLOCKS+=	${WORKMBRTRUNC}
    408  1.21.2.2    martin .endif
    409  1.21.2.2    martin .if ${USE_GPT} != "no"
    410  1.21.2.2    martin TARGET_BLOCKS+=	${WORKEFI}
    411  1.21.2.2    martin .endif
    412  1.21.2.2    martin .if ${FATSECTORS} != 0
    413  1.21.2.2    martin TARGET_BLOCKS+=	${WORKFAT}
    414  1.21.2.2    martin .endif
    415  1.21.2.2    martin TARGET_BLOCKS+=	 ${TARGETFS}
    416  1.21.2.2    martin .if ${SWAPSECTORS} != 0
    417  1.21.2.2    martin TARGET_BLOCKS+=	${WORKSWAP}
    418  1.21.2.2    martin .endif
    419  1.21.2.2    martin .if ${USE_GPT} != "no"
    420  1.21.2.2    martin TARGET_BLOCKS+=	${WORKGPT}
    421       1.1   tsutsui .endif
    422       1.1   tsutsui 
    423  1.21.2.2    martin CLEANFILES+=	${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP}
    424  1.21.2.2    martin CLEANFILES+=	${WORKEFI} ${WORKGPT}
    425  1.21.2.2    martin CLEANFILES+=	${WORKFAT}
    426       1.1   tsutsui CLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
    427       1.1   tsutsui CLEANFILES+=	${WORKIMG} ${IMGBASE}.img
    428       1.1   tsutsui 
    429  1.21.2.2    martin ${WORKSWAP}:
    430  1.21.2.2    martin .if ${SWAPSECTORS} == 0
    431  1.21.2.2    martin 	printf "" > ${WORKSWAP}
    432  1.21.2.2    martin .else
    433  1.21.2.2    martin 	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
    434  1.21.2.2    martin .endif
    435  1.21.2.2    martin 
    436  1.21.2.2    martin ${WORKMBRTRUNC}: ${WORKMBR}
    437  1.21.2.2    martin 	${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC}
    438  1.21.2.2    martin 
    439       1.1   tsutsui ${WORKLABEL}:
    440       1.1   tsutsui 	${TOOL_SED}							\
    441       1.1   tsutsui 	    -e "s/@@SECTORS@@/${SECTORS}/"				\
    442       1.1   tsutsui 	    -e "s/@@HEADS@@/${HEADS}/"					\
    443       1.1   tsutsui 	    -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/"		\
    444       1.1   tsutsui 	    -e "s/@@CYLINDERS@@/${CYLINDERS}/"				\
    445       1.1   tsutsui 	    -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/"			\
    446       1.1   tsutsui 	    -e "s/@@FSSECTORS@@/${FSSECTORS}/"				\
    447       1.1   tsutsui 	    -e "s/@@FSOFFSET@@/${FSOFFSET}/"				\
    448       1.1   tsutsui 	    -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/"			\
    449       1.1   tsutsui 	    -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/"			\
    450       1.1   tsutsui 	    -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/"		\
    451  1.21.2.2    martin 	    -e "s/@@FATSECTORS@@/${FATSECTORS}/"			\
    452  1.21.2.2    martin 	    -e "s/@@FATOFFSET@@/${FATOFFSET}/"				\
    453       1.1   tsutsui 	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
    454       1.1   tsutsui 	mv ${WORKLABEL}.tmp ${WORKLABEL}
    455       1.1   tsutsui 
    456  1.21.2.2    martin ${WORKEFI}: ${TARGETFS}
    457  1.21.2.2    martin 	@echo create EFI system partition...
    458  1.21.2.2    martin 	@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
    459  1.21.2.2    martin .for f in ${EFIBOOT}
    460  1.21.2.2    martin 	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
    461  1.21.2.2    martin .endfor
    462  1.21.2.2    martin 	${RM} -f ${WORKEFI}
    463  1.21.2.2    martin 	${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m			\
    464  1.21.2.2    martin 	    -B ${TARGET_ENDIANNESS}					\
    465  1.21.2.2    martin 	    ${MAKEFS_TIMESTAMP}						\
    466  1.21.2.2    martin 	    -t msdos -o F=32,c=1					\
    467  1.21.2.2    martin 	    ${WORKEFI} ${EFIWORKDIR}
    468  1.21.2.2    martin 
    469  1.21.2.2    martin ${WORKFAT}: ${TARGETFS} ${FATFILES}
    470  1.21.2.2    martin 	@echo create FAT partition for bootstrap files...
    471  1.21.2.2    martin 	@${MKDIR} ${MKDIRPERM} ${WORKFATDIR}
    472  1.21.2.2    martin .if defined(FATFILES)
    473  1.21.2.2    martin 	@echo Copying files for FAT partition...
    474  1.21.2.2    martin .for f in ${FATFILES}
    475  1.21.2.2    martin 	@if [ ! -f ${f} ]; then 					\
    476  1.21.2.2    martin 		echo "${f} in FATFILES not found, aborting";		\
    477  1.21.2.2    martin 		false; 							\
    478  1.21.2.2    martin 	fi
    479  1.21.2.2    martin 	${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR}
    480  1.21.2.2    martin .endfor
    481  1.21.2.2    martin .endif
    482  1.21.2.2    martin 	${RM} -f ${WORKFAT}
    483  1.21.2.2    martin 	${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m			\
    484  1.21.2.2    martin 	    ${MAKEFS_TIMESTAMP}						\
    485  1.21.2.2    martin 	    -t msdos							\
    486  1.21.2.2    martin 	    ${FATMAKEFSOPTIONS}						\
    487  1.21.2.2    martin 	    ${WORKFAT} ${WORKFATDIR}
    488  1.21.2.2    martin 
    489  1.21.2.2    martin ${WORKMBR}:
    490  1.21.2.2    martin .if ${USE_GPT} != "no"
    491  1.21.2.2    martin 	@echo creating GPT header and partition entries...
    492  1.21.2.2    martin 	${RM} -f ${WORKMBR}
    493  1.21.2.2    martin 	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
    494  1.21.2.2    martin 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create
    495  1.21.2.2    martin 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system"
    496  1.21.2.2    martin 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs
    497  1.21.2.2    martin .  if ${SWAPSECTORS} != 0
    498  1.21.2.2    martin 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
    499  1.21.2.2    martin .  endif
    500  1.21.2.2    martin .elif ${USE_MBR} != "no"
    501       1.1   tsutsui 	@echo creating MBR labels...
    502       1.1   tsutsui 	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
    503  1.21.2.2    martin .  if ${FATSECTORS} != 0
    504  1.21.2.2    martin 	# create BSD partition
    505  1.21.2.2    martin 	${TOOL_FDISK} -f -i -u \
    506  1.21.2.2    martin 	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
    507  1.21.2.2    martin 	    -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
    508  1.21.2.2    martin 	    -F ${WORKMBR}
    509  1.21.2.2    martin 	# create FAT partition
    510  1.21.2.2    martin 	${TOOL_FDISK} -f -u \
    511  1.21.2.2    martin 	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
    512  1.21.2.2    martin 	    -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS}			\
    513  1.21.2.2    martin 	    -F ${WORKMBR}
    514  1.21.2.2    martin .  else
    515  1.21.2.2    martin 	# create BSD partition
    516       1.5   tsutsui 	${TOOL_FDISK} -f -i -u \
    517       1.1   tsutsui 	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
    518       1.1   tsutsui 	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
    519       1.1   tsutsui 	    -F ${WORKMBR}
    520  1.21.2.2    martin .  endif
    521  1.21.2.2    martin .  if empty(MBR_BOOTCODE)
    522       1.5   tsutsui 	@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
    523       1.5   tsutsui 		echo ${TOOL_FDISK} -f					\
    524       1.5   tsutsui 		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
    525       1.5   tsutsui 		    -F ${WORKMBR};					\
    526       1.5   tsutsui 		${TOOL_FDISK} -f					\
    527       1.5   tsutsui 		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
    528       1.5   tsutsui 		    -F ${WORKMBR};					\
    529       1.5   tsutsui 	fi
    530  1.21.2.2    martin .  else
    531       1.5   tsutsui 	@if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then 		\
    532       1.5   tsutsui 		echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \
    533       1.5   tsutsui 		false; 							\
    534       1.5   tsutsui 	fi
    535       1.5   tsutsui 	${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE}	\
    536       1.5   tsutsui 	    -F ${WORKMBR}
    537  1.21.2.2    martin .  endif
    538       1.5   tsutsui .endif
    539  1.21.2.2    martin 
    540  1.21.2.2    martin ${WORKGPT}: ${WORKMBR}
    541  1.21.2.2    martin 	@echo create GPT image...
    542  1.21.2.2    martin 	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
    543  1.21.2.2    martin 	    count=2048
    544  1.21.2.2    martin 
    545  1.21.2.2    martin .if ${USE_GPT} == "no"
    546  1.21.2.2    martin ${IMGBASE}.img:	${WORKLABEL}
    547       1.1   tsutsui .endif
    548  1.21.2.2    martin 
    549  1.21.2.2    martin ${IMGBASE}.img:	${TARGET_BLOCKS}
    550  1.21.2.2    martin 	${CAT} ${TARGET_BLOCKS} > ${WORKIMG}
    551  1.21.2.2    martin .if ${USE_GPT} != "no"
    552  1.21.2.2    martin 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2		\
    553  1.21.2.2    martin 	    -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin
    554  1.21.2.2    martin 	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2
    555  1.21.2.2    martin .endif	# USE_GPT != "no"
    556       1.1   tsutsui .if ${USE_SUNLABEL} != "no"
    557       1.1   tsutsui 	@echo Creating sun disklabel...
    558       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' \
    559       1.1   tsutsui 	    ${CYLINDERS} ${HEADS} ${SECTORS} \
    560       1.1   tsutsui 	    ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \
    561       1.1   tsutsui 	    ${TOOL_SUNLABEL} -nq ${WORKIMG}
    562       1.1   tsutsui .endif
    563  1.21.2.2    martin .if ${USE_GPT} == "no"
    564       1.1   tsutsui 	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
    565       1.1   tsutsui .if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
    566      1.11  riastrad 	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
    567       1.1   tsutsui 	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
    568       1.1   tsutsui .endif
    569  1.21.2.2    martin .endif
    570       1.1   tsutsui 	mv ${WORKIMG} ${.TARGET}
    571       1.1   tsutsui 
    572       1.1   tsutsui CLEANFILES+=	${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp
    573       1.1   tsutsui 
    574       1.1   tsutsui ${IMGBASE}.img.gz:	${IMGBASE}.img
    575       1.9       apb 	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
    576       1.1   tsutsui 	mv ${.TARGET}.tmp ${.TARGET}
    577       1.1   tsutsui 
    578       1.1   tsutsui clean:
    579       1.1   tsutsui 	@if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then 		\
    580       1.1   tsutsui 		${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden;		\
    581       1.1   tsutsui 	fi	# XXX
    582       1.1   tsutsui 	${RM} -fr ${WORKDIR}
    583  1.21.2.2    martin 	${RM} -fr ${EFIWORKDIR}
    584  1.21.2.2    martin 	${RM} -fr ${WORKFATDIR}
    585       1.1   tsutsui 
    586       1.1   tsutsui prepare_md_post: .PHONY
    587       1.1   tsutsui image_md_post: .PHONY
    588       1.1   tsutsui image_md_pre: .PHONY
    589       1.1   tsutsui 
    590       1.1   tsutsui .include <bsd.prog.mk>
    591