head	1.14;
access;
symbols
	netbsd-9-5-RELEASE:1.11.2.3
	perseant-exfatfs-base-20250801:1.14
	perseant-exfatfs-base-20240630:1.14
	perseant-exfatfs:1.14.0.6
	perseant-exfatfs-base:1.14
	netbsd-8-3-RELEASE:1.6
	netbsd-9-4-RELEASE:1.11.2.3
	netbsd-9-3-RELEASE:1.11.2.3
	cjep_sun2x:1.14.0.4
	cjep_sun2x-base:1.14
	cjep_staticlib_x-base1:1.14
	netbsd-9-2-RELEASE:1.11.2.3
	cjep_staticlib_x:1.14.0.2
	cjep_staticlib_x-base:1.14
	netbsd-9-1-RELEASE:1.11.2.3
	phil-wifi-20200421:1.13
	phil-wifi-20200411:1.13
	is-mlppp:1.13.0.2
	is-mlppp-base:1.13
	phil-wifi-20200406:1.13
	netbsd-8-2-RELEASE:1.6
	netbsd-9-0-RELEASE:1.11.2.1
	netbsd-9-0-RC2:1.11.2.1
	netbsd-9-0-RC1:1.11.2.1
	phil-wifi-20191119:1.12
	netbsd-9:1.11.0.2
	netbsd-9-base:1.11
	phil-wifi-20190609:1.11
	netbsd-8-1-RELEASE:1.6
	netbsd-8-1-RC1:1.6
	pgoyette-compat-merge-20190127:1.6.14.3
	pgoyette-compat-20190127:1.9
	pgoyette-compat-20190118:1.9
	pgoyette-compat-1226:1.9
	pgoyette-compat-1126:1.8
	pgoyette-compat-1020:1.7
	pgoyette-compat-0930:1.6
	pgoyette-compat-0906:1.6
	pgoyette-compat-0728:1.6
	netbsd-8-0-RELEASE:1.6
	phil-wifi:1.6.0.16
	phil-wifi-base:1.6
	pgoyette-compat-0625:1.6
	netbsd-8-0-RC2:1.6
	pgoyette-compat-0521:1.6
	pgoyette-compat-0502:1.6
	pgoyette-compat-0422:1.6
	netbsd-8-0-RC1:1.6
	pgoyette-compat-0415:1.6
	pgoyette-compat-0407:1.6
	pgoyette-compat-0330:1.6
	pgoyette-compat-0322:1.6
	pgoyette-compat-0315:1.6
	pgoyette-compat:1.6.0.14
	pgoyette-compat-base:1.6
	matt-nb8-mediatek:1.6.0.12
	matt-nb8-mediatek-base:1.6
	perseant-stdc-iso10646:1.6.0.10
	perseant-stdc-iso10646-base:1.6
	netbsd-8:1.6.0.8
	netbsd-8-base:1.6
	prg-localcount2-base3:1.6
	prg-localcount2-base2:1.6
	prg-localcount2-base1:1.6
	prg-localcount2:1.6.0.6
	prg-localcount2-base:1.6
	pgoyette-localcount-20170426:1.6
	bouyer-socketcan:1.6.0.4
	bouyer-socketcan-base1:1.6
	pgoyette-localcount:1.6.0.2
	pgoyette-localcount-20170320:1.6;
locks; strict;
comment	@# @;


1.14
date	2020.05.27.22.27.58;	author maya;	state dead;
branches;
next	1.13;
commitid	cWiFO3sy6MINIV9C;

1.13
date	2019.11.21.22.29.03;	author joerg;	state Exp;
branches;
next	1.12;
commitid	iULoA7uTNO15MLLB;

1.12
date	2019.10.02.11.15.59;	author maya;	state Exp;
branches;
next	1.11;
commitid	7L8j32uFc906EhFB;

1.11
date	2019.02.22.22.20.18;	author tsutsui;	state Exp;
branches
	1.11.2.1;
next	1.10;
commitid	gSDR3LnaF5C3tOcB;

1.10
date	2019.02.22.22.13.58;	author tsutsui;	state Exp;
branches;
next	1.9;
commitid	cu5RG0gN3PwVqOcB;

1.9
date	2018.12.15.18.03.17;	author gson;	state Exp;
branches;
next	1.8;
commitid	VnJTdkyNfhz4gV3B;

1.8
date	2018.11.19.20.05.37;	author aymeric;	state Exp;
branches;
next	1.7;
commitid	ZihtYtNPFtz4LA0B;

1.7
date	2018.10.07.10.33.44;	author martin;	state Exp;
branches;
next	1.6;
commitid	dJm7UgUFQ7JGZ0VA;

1.6
date	2017.02.16.03.47.23;	author christos;	state Exp;
branches
	1.6.2.1
	1.6.4.1
	1.6.14.1
	1.6.16.1;
next	1.5;
commitid	ELWNdDDzSnlbY7Gz;

1.5
date	2017.02.11.08.14.05;	author pgoyette;	state Exp;
branches;
next	1.4;
commitid	q4aJ9j34ouyBBvFz;

1.4
date	2017.02.11.03.07.06;	author christos;	state Exp;
branches;
next	1.3;
commitid	RQbVHlgh5ObhUtFz;

1.3
date	2017.02.10.16.53.51;	author christos;	state Exp;
branches;
next	1.2;
commitid	FcuoEcOyt0pVvqFz;

1.2
date	2017.02.10.16.43.59;	author christos;	state Exp;
branches;
next	1.1;
commitid	uUOMTOtplR3gsqFz;

1.1
date	2017.01.24.11.16.50;	author nonaka;	state Exp;
branches;
next	;
commitid	lOXT4VXtddWMbdDz;

1.11.2.1
date	2019.11.17.07.04.37;	author martin;	state Exp;
branches;
next	1.11.2.2;
commitid	fmdLX9M716eYMaLB;

1.11.2.2
date	2020.04.24.17.19.49;	author martin;	state Exp;
branches;
next	1.11.2.3;
commitid	2GTF2Je9FYVb5F5C;

1.11.2.3
date	2020.05.31.10.21.34;	author martin;	state dead;
branches;
next	;
commitid	evmB07wkPEsYznaC;

1.6.2.1
date	2017.02.16.03.47.23;	author pgoyette;	state dead;
branches;
next	1.6.2.2;
commitid	jjw7cAwgyKq7RfKz;

1.6.2.2
date	2017.03.20.06.52.03;	author pgoyette;	state Exp;
branches;
next	;
commitid	jjw7cAwgyKq7RfKz;

1.6.4.1
date	2017.02.16.03.47.23;	author christos;	state dead;
branches;
next	1.6.4.2;

1.6.4.2
date	2017.02.16.03.47.24;	author christos;	state Exp;
branches;
next	;

1.6.14.1
date	2018.10.20.06.58.17;	author pgoyette;	state Exp;
branches;
next	1.6.14.2;
commitid	mTSoqZEZ4arHnFWA;

1.6.14.2
date	2018.11.26.01.49.55;	author pgoyette;	state Exp;
branches;
next	1.6.14.3;
commitid	Zj4q5SspGdKXto1B;

1.6.14.3
date	2018.12.26.14.01.10;	author pgoyette;	state Exp;
branches;
next	;
commitid	xUhK8IAeBM1azj5B;

1.6.16.1
date	2019.06.10.21.42.18;	author christos;	state Exp;
branches;
next	1.6.16.2;
commitid	jtc8rnCzWiEEHGqB;

1.6.16.2
date	2020.04.13.07.45.23;	author martin;	state Exp;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


1.14
log
@rename amd64 uefi-installimage to be just installimage.

Works for both purposes, no confusing name.
@
text
@@


1.13
log
@Merge amd64's UEFI logic back into the generic bootimage handling.
@
text
@@


1.12
log
@Split out /rescue to its own set and adapt installers/images to add it.

This is meant to make updates safer: if something goes wrong with updating
base, we still have the old, standalone /rescue to recover from.
@
text
@a0 500
#	$NetBSD: Makefile.bootimage,v 1.11 2019/02/22 22:20:18 tsutsui Exp $
#
# Copyright (c) 2009, 2010, 2011 Izumi Tsutsui.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#
# Makefile to create a bootable FS image for USB flash or emulators
#

#
# Required variables:
#	RELEASEDIR
#		Should be defined in nbmake-${MACHINE}
#	IMGBASE
#		Basename of the image
#
# Optional variables:
#	USE_MBR
#		set yes if target disk image requires MBR partition
#		(default: no)
#	USE_GPT
#		set yes if target disk image requires GPT partition
#		(default: no)
#	MBR_BOOTCODE
#		optional MBR bootcode which should be installed by fdisk(8)
#		(default: empty)
#		- specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec
#		- if MBR_BOOTCODE is not specified,
#		  MBR_DEFAULT_BOOTCODE (default: mbr) will be used
#		  if the target ${MACHINE} has the one in /usr/mdec
#	USE_SUNLABEL
#		set yes if target disk image requires Sun's label
#		(default: no)
#	INSTALLBOOT_AFTER_DISKLABEL (untested)
#		set yes if the target ${MACHINE} requires disklabel
#		to run installboot(8), like hp300
#		(default: empty)
#	IMAGEMB
#		target image size in MB
#		(default: 2048)
#	SWAPMB
#		swap size in target image in MB
#		(default: 128)
#	EFIMB
#		EFI partition size in target image in MB
#		(default: 128)
#	KERN_SET
#		kernel set name which should be extracted into image
#		(default: kern-GENERIC)
#	SETS
#		binary sets that should be extracted into image
#		(default: modules base etc comp games man misc rescue tests
#			  text xbase xcomp xetc xfont xserver)
#	SETS_DIR
#		directory path where binary sets are stored
#		(default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets)
#	IMGFILE_EXTRA
#		list of additional files to be copied into images,
#		containing one or more tuples of the form:
#			FILE	TARGETPATH
#		for installation image etc.
#		(default: empty)
#	IMGDIR_EXTRA
#		list of additional directories to be copied into images,
#		containing one or more tuples of the form:
#			DIR	TARGETPATH
#		for installation image etc.
#		(default: empty)
#		XXX: currently permissions in IMGDIR_EXTRA are not handled
#	IMGDIR_EXCLUDE
#		pax(1) options to exclude files which should not copied
#		into TARGETPATH in IMGDIR_EXTRA
#		(default: empty)
#	FSTAB_IN
#		template file of /etc/fstab
#		(default: ${DISTRIBDIR}/common/bootimage/fstab.in)
#	SPEC_IN
#		default files of spec file for makefs(8)
#		(default: ${DISTRIBDIR}/common/bootimage/spec.in)
#	SPEC_EXTRA
#		additional files of spec file for makefs(8)
#		(default: empty)
#	IMGMAKEFSOPTIONS
#		options passed to makefs(8) to create root file system
#		(default: -o bsize=16384,fsize=2048,density=8192)
#	INSTALLBOOTOPTIONS
#		options passed to installboot(8), e.g., -o console=com0
#		(default: empty)
#	PRIMARY_BOOT
#		primary boot loader that should be installed into
#		the target image via installboot(8)
#		(default: empty)
#	SECONDARY_BOOT
#		secondary bootloader that should be put into the target image
#		(default: empty)
#	SECONDARY_BOOT_ARG
#		extra arguments that should be passed to installboot(8)
#		to specify the secondary bootloader
#		(default: empty)
#	DISKPROTO_IN
#		template file of disklabel -R
#		(default: ${DISTRIBDIR}/common/bootimage/diskproto.in
#		       or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in)
#	OMIT_SWAPIMG
#		no need to put swap partition into image (for USB stick)
#		(default: no)
#	EFIBOOT
#		EFI bootloader
#		(default: empty)
#

.include <bsd.own.mk> 		#
.include <bsd.endian.mk>	# for TARGET_ENDIANNESS

.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"

.if ${MKREPRO_TIMESTAMP:Uno} != "no"
MAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
GPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
.endif

.if empty(IMGBASE)
.BEGIN:
	@@echo "Error: IMGBASE is not set"
	@@false
.endif

# should be defined elsewhere? 
CAT?=		cat
CHMOD?=		chmod
DD?=		dd
MKDIR?=		mkdir -p
RM?=		rm

#
# common definitions for image
#
USE_MBR?=	no
USE_GPT?=	no
USE_SUNLABEL?=	no
INSTALLBOOT_AFTER_DISKLABEL?=	no

#
# size parameters for image
#
IMAGEMB?=	2048		# 2048MB
SWAPMB?=	128		# 128MB
EFIMB?=		128		# 128MB

# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
IMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
SWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true

.if ${USE_MBR} == "no" && ${USE_GPT} == "no"
LABELSECTORS?=	0
.else
#LABELSECTORS?=	63	# historical
#LABELSECTORS?=	32	# 16KB aligned
LABELSECTORS?=	2048	# 1MB aligned for modern flash devices
.endif

FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}
FSSIZE!=	expr ${FSSECTORS} \* 512

# parameters for disklabel and MBR
HEADS=		64
SECTORS=	32
CYLINDERS!=	expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)
SECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS}
MBRHEADS=	255
MBRSECTORS=	63
MBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
MBRNETBSD=	169

BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS}
FSOFFSET=	${LABELSECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS}

# parameters for sunlabel
FSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
SWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true

.if ${USE_GPT} != "no"
# 2048 for Secondary GPT header and entries
FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - 2048
FSSIZE!=	expr ${FSSECTORS} \* 512

BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} - ${EFISECTORS} - 2048
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} + ${EFISECTORS}

BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
.endif

#
# definitions to create root fs
#
SETS_DEFAULT=	modules base etc comp games man misc rescue tests text
.if ${MKX11} != "no"
SETS_DEFAULT+=	xbase xcomp xetc xfont xserver
.endif

KERN_SET?=	kern-GENERIC
SETS?=		${SETS_DEFAULT}
IMG_SETS=	${KERN_SET} ${SETS}
SETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets

FSTAB_IN?=	${DISTRIBDIR}/common/bootimage/fstab.in
SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in

IMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192

WORKDIR?=       work
WORKSPEC?=      work.spec
WORKFSTAB?=	work.fstab
WORKRCCONF?=	work.rc.conf
WORKFS?=        work.rootfs
TARGETFS?=      imgroot.fs
COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}

CLEANFILES+=	${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS}
CLEANFILES+=	${TARGETFS}

#
# create root file system for the image
#
${TARGETFS}: prepare_md_post pre-targetfs
	@@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
		false; 							\
	fi;
	@@${MKDIR} ${MKDIRPERM} ${WORKDIR}
.for set in ${IMG_SETS}
	@@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
		false; 							\
	fi
	@@echo Extracting ${set}.${TAR_SUFF} ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \
		--use-compress-program=${COMPRESS_PROGRAM:Q} \
		-f ${SETS_DIR}/${set}.${TAR_SUFF} .)
.endfor
.if defined(SECONDARY_BOOT)
	@@echo Copying secondary boot...
	${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
.endif
	@@echo Preparing /etc/fstab ...
.if ${USE_GPT} != "no"
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_SED}							\
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
	    -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/"			\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.else
	${TOOL_SED}							\
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
	    -e "/ROOT.b/d"						\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.endif
.else	# USE_GPT == "no"
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
.else
	${TOOL_SED}							\
	    -e "/ROOT.b/d"						\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.endif
.endif	# USE_GPT != "no"
	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
	@@echo Setting rc_configured=YES in /etc/rc.conf ...
	${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/"		\
	    < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF}
	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
.if defined(IMGDIR_EXTRA)
	@@echo Copying extra dirs...
.for _SRCDIR _TARGET in ${IMGDIR_EXTRA}
	@@if [ ! -d ${_SRCDIR} ]; then 					\
		echo "${_SRCDIR} is not directory, aborting";		\
		false; 							\
	fi
	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
	(cd ${_SRCDIR} ;						\
	    ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v			\
	    ${IMGDIR_EXCLUDE}						\
	    . ${.OBJDIR}/${WORKDIR}/${_TARGET} )
.endfor
.endif
.if defined(IMGFILE_EXTRA)
	@@echo Copying extra files...
.for _SRC _TARGET in ${IMGFILE_EXTRA}
	@@if [ ! -f ${_SRC} ]; then 					\
		echo "${_SRC} in IMGFILE_EXTRA not found, aborting";	\
		false; 							\
	fi
	@@if [ -f ${_SRC} ]; then 					\
		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
	fi
.endfor
.endif
	@@echo Preparing spec files for makefs...
	${RM} -f ${WORKSPEC}
	cat ${WORKDIR}/etc/mtree/* |					\
	    ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC}
	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty |			\
	    ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC}
	cat ${SPEC_IN} >> ${WORKSPEC}
.if defined(SECONDARY_BOOT)
	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
	    >> ${WORKSPEC}
.endif
.if defined(SPEC_EXTRA)
	cat ${SPEC_EXTRA} >> ${WORKSPEC}
.endif
	@@echo Creating rootfs...
	# XXX /var/spool/ftp/hidden is unreadable
	${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden
	${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE}			\
	    -B ${TARGET_ENDIANNESS}					\
	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
	    ${MAKEFS_TIMESTAMP}						\
	    ${IMGMAKEFSOPTIONS}						\
	    ${WORKFS} ${WORKDIR}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
.endif
	@@echo done.
	mv ${WORKFS} ${.TARGET}

#
# definitions to create image
#
.if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
.else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
.endif

MBR_DEFAULT_BOOTCODE?=	mbr

OMIT_SWAPIMG?=	no

WORKMBR?=	work.mbr
WORKSWAP?=	work.swap
WORKEFI?=	work.efi
WORKGPT?=	work.gpt
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img
EFIWORKDIR?=	work.efidir

CLEANFILES+=	${WORKMBR} ${WORKSWAP}
CLEANFILES+=	${WORKEFI} ${WORKGPT}
CLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
CLEANFILES+=	${WORKIMG} ${IMGBASE}.img

${WORKLABEL}:
	${TOOL_SED}							\
	    -e "s/@@@@SECTORS@@@@/${SECTORS}/"				\
	    -e "s/@@@@HEADS@@@@/${HEADS}/"					\
	    -e "s/@@@@SECPERCYLINDERS@@@@/${SECPERCYLINDERS}/"		\
	    -e "s/@@@@CYLINDERS@@@@/${CYLINDERS}/"				\
	    -e "s/@@@@IMAGESECTORS@@@@/${IMAGESECTORS}/"			\
	    -e "s/@@@@FSSECTORS@@@@/${FSSECTORS}/"				\
	    -e "s/@@@@FSOFFSET@@@@/${FSOFFSET}/"				\
	    -e "s/@@@@SWAPSECTORS@@@@/${SWAPSECTORS}/"			\
	    -e "s/@@@@SWAPOFFSET@@@@/${SWAPOFFSET}/"			\
	    -e "s/@@@@BSDPARTSECTORS@@@@/${BSDPARTSECTORS}/"		\
	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
	mv ${WORKLABEL}.tmp ${WORKLABEL}

pre-targetfs:
.if ${USE_GPT} != "no"
	@@echo creating GPT header and partition entries...
	${RM} -f ${WORKMBR}
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system"
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
.endif

${IMGBASE}.img:	${TARGETFS}
	@@echo create EFI system partition...
	@@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
.if !empty(EFIBOOT)
.for f in ${EFIBOOT}
	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
.endfor
.endif
	${RM} -f ${WORKEFI}
	${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m			\
	    -B ${TARGET_ENDIANNESS}					\
	    ${MAKEFS_TIMESTAMP}						\
	    -t msdos -o F=32,c=1					\
	    ${WORKEFI} ${EFIWORKDIR}
	@@echo create GPT image...
	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
	    count=2048
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${WORKEFI} ${TARGETFS} ${WORKGPT} > ${WORKIMG}
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2		\
	    -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2
.else	# USE_GPT == "no"
${IMGBASE}.img:	${TARGETFS} ${WORKLABEL}
.if ${USE_MBR} != "no"
	@@echo creating MBR labels...
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
	${TOOL_FDISK} -f -i -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -F ${WORKMBR}
.if empty(MBR_BOOTCODE)
	@@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
		echo ${TOOL_FDISK} -f					\
		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
		    -F ${WORKMBR};					\
		${TOOL_FDISK} -f					\
		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
		    -F ${WORKMBR};					\
	fi
.else
	@@if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then 		\
		echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \
		false; 							\
	fi
	${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE}	\
	    -F ${WORKMBR}
.endif
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${TARGETFS} > ${WORKIMG}
.else	# USE_MBR == "no"
	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
.endif	# USE_MBR != "no"
.endif	# USE_GPT != "no"
.if ${OMIT_SWAPIMG} == "no"
	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
	${CAT} ${WORKSWAP} >> ${WORKIMG}
.endif
.if ${USE_SUNLABEL} != "no"
	@@echo Creating sun disklabel...
	printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \
	    ${CYLINDERS} ${HEADS} ${SECTORS} \
	    ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \
	    ${TOOL_SUNLABEL} -nq ${WORKIMG}
.endif
.if ${USE_GPT} == "no"
	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
.endif
.endif
	mv ${WORKIMG} ${.TARGET}


CLEANFILES+=	${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp

${IMGBASE}.img.gz:	${IMGBASE}.img
	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
	mv ${.TARGET}.tmp ${.TARGET}

clean:
	@@if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then 		\
		${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden;		\
	fi	# XXX
	${RM} -fr ${WORKDIR}
	${RM} -fr ${EFIWORKDIR}

prepare_md_post: .PHONY
image_md_post: .PHONY
image_md_pre: .PHONY

.include <bsd.prog.mk>
@


1.11
log
@Explicitly use ${TOOL_AWK} instead of system's awk.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.10 2019/02/22 22:13:58 tsutsui Exp $
d71 2
a72 2
#		(default: modules base etc comp games man misc tests text
#			  xbase xcomp xetc xfont xserver)
d221 1
a221 1
SETS_DEFAULT=	modules base etc comp games man misc tests text
@


1.11.2.1
log
@Pull up following revision(s) (requested by maya in ticket #435):

	distrib/sets/maketars: revision 1.90
	usr.sbin/sysinst/arch/playstation2/md.h: revision 1.2
	usr.sbin/sysinst/arch/sandpoint/md.h: revision 1.3
	usr.sbin/sysinst/arch/evbppc/md.h: revision 1.3
	usr.sbin/sysinst/arch/hpcarm/md.h: revision 1.3
	usr.sbin/sysinst/arch/mvme68k/md.h: revision 1.3
	distrib/sun3/MakeInstTape: revision 1.3
	usr.sbin/sysinst/util.c: revision 1.33
	distrib/sets/lists/rescue/mi: revision 1.1
	distrib/sets/lists/base/rescue.sun2: file removal
	usr.sbin/sysinst/arch/zaurus/md.h: revision 1.3
	distrib/sets/lists/base/rescue.ad.m68k.shl: file removal
	distrib/sets/regpkgset: revision 1.13
	usr.sbin/sysinst/arch/i386/md.h: revision 1.7
	distrib/sets/lists/base/rescue.sparc: file removal
	distrib/notes/mvme68k/xfer: revision 1.19
	distrib/sets/sets.subr: revision 1.187
	distrib/common/bootimage/Makefile.bootimage: revision 1.22
	usr.sbin/sysinst/msg.mi.de: revision 1.16
	usr.sbin/sysinst/arch/atari/md.h: revision 1.3
	rescue/Makefile: revision 1.38
	distrib/sets/lists/base/rescue.macppc: file removal
	usr.sbin/sysinst/arch/arc/md.h: revision 1.4
	distrib/miniroot/install.sub: revision 1.49
	usr.sbin/sysinst/arch/acorn32/md.h: revision 1.3
	usr.sbin/sysinst/arch/x68k/md.h: revision 1.3
	usr.sbin/sysinst/arch/hpcmips/md.h: revision 1.3
	usr.sbin/sysinst/arch/bebox/md.h: revision 1.3
	usr.sbin/sysinst/arch/hpcsh/md.h: revision 1.2
	distrib/sets/lists/base/rescue.shark: file removal
	usr.sbin/sysinst/arch/emips/md.h: revision 1.5
	distrib/utils/embedded/mkimage: revision 1.70
	usr.sbin/sysinst/arch/shark/md.h: revision 1.3
	usr.sbin/sysinst/arch/pmax/md.h: revision 1.4
	usr.sbin/sysinst/arch/amiga/md.h: revision 1.4
	usr.sbin/sysinst/arch/hp300/md.h: revision 1.5
	rescue/list.ldconfig: file removal
	distrib/sets/lists/base/rescue.ad.m68k: file removal
	usr.sbin/sysinst/arch/prep/md.h: revision 1.4
	usr.sbin/sysinst/arch/cats/md.h: revision 1.4
	usr.sbin/sysinst/arch/amd64/md.h: revision 1.7
	usr.sbin/sysinst/msg.mi.es: revision 1.17
	usr.sbin/sysinst/msg.mi.fr: revision 1.20
	usr.sbin/sysinst/msg.mi.pl: revision 1.23
	distrib/sets/lists/base/rescue.i386: file removal
	usr.sbin/sysinst/arch/evbarm/md.h: revision 1.3
	distrib/sets/lists/base/rescue.vax: file removal
	distrib/amd64/uefi-installimage/Makefile.bootimage: revision 1.12
	usr.sbin/sysinst/arch/evbmips/md.h: revision 1.3
	distrib/sets/lists/base/rescue.mi: file removal
	distrib/sets/README: revision 1.14
	usr.sbin/sysinst/arch/sgimips/md.h: revision 1.4
	distrib/sets/lists/base/rescue.sparc64: file removal
	distrib/sets/lists/base/rescue.mi: revision 1.45
	distrib/sets/lists/base/rescue.mi: revision 1.46
	usr.sbin/sysinst/arch/ofppc/md.h: revision 1.4
	usr.sbin/sysinst/arch/cobalt/md.h: revision 1.4
	distrib/sets/lists/base/rescue.ad.arm: file removal
	distrib/sets/lists/base/rescue.mac68k: file removal
	usr.sbin/sysinst/defs.h: revision 1.45
	usr.sbin/sysinst/arch/landisk/md.h: revision 1.2
	distrib/notes/atari/xfer: revision 1.17
	etc/Makefile: revision 1.441
	usr.sbin/sysinst/msg.mi.en: revision 1.22
	distrib/sun2/MakeInstTape: revision 1.2

Remove ldconfig from /rescue, and mark it MI obsolete.
- ldconfig in netbsd refers to a.out binaries only. We've been ELF-only
  since NetBSD 2.0 or so, and having it in /rescue served little purpose
  even before that, as /rescue is standalone.
- Using MI obsolete to avoid the need for MD set lists where ldconfig
  is the sole entry

Mark /rescue/edlabel as MI-obsolete, so we can remove all remaining MD
rescue set list files.

Split out /rescue to its own set and adapt installers/images to add it.

This is meant to make updates safer: if something goes wrong with updating
base, we still have the old, standalone /rescue to recover from.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.11 2019/02/22 22:20:18 tsutsui Exp $
d71 2
a72 2
#		(default: modules base etc comp games man misc rescue tests
#			  text xbase xcomp xetc xfont xserver)
d221 1
a221 1
SETS_DEFAULT=	modules base etc comp games man misc rescue tests text
@


1.11.2.2
log
@Pull up following revision(s) (requested by tsutsui in ticket #846):

	distrib/hpcarm/Makefile: revision 1.7
	distrib/amd64/uefi-installimage/Makefile: revision 1.7
	distrib/common/bootimage/Makefile.installimage: revision 1.6
	distrib/hpcarm/liveimage/spec.in: revision 1.1
	distrib/common/bootimage/Makefile.bootimage: revision 1.23
	distrib/common/bootimage/Makefile.bootimage: revision 1.24
	distrib/zaurus/liveimage/Makefile: revision 1.1
	distrib/amd64/uefi-installimage/Makefile.installimage: revision 1.3
	distrib/zaurus/Makefile: revision 1.3
	distrib/hpcarm/liveimage/Makefile: revision 1.1
	distrib/zaurus/liveimage/spec.in: revision 1.1
	distrib/common/bootimage/diskproto.mbrfat.in: revision 1.1
	distrib/amd64/uefi-installimage/Makefile.bootimage: revision 1.13
	distrib/hpcarm/liveimage/fstab.in: revision 1.1
	distrib/zaurus/liveimage/fstab.in: revision 1.1

Merge amd64's UEFI logic back into the generic bootimage handling.

Add "live-image with a FAT partition for bootstrap files" support.
See PR/55075 for more details.

Add "build.sh live-image" support for zaurus.
Tested on SL-C3000 and SL-C700.
See also PR/55075 for live-image with FAT partition support.

Add "build.sh live-image" support for hpcarm.
Tested on WS003SH.
See also PR/55075 for live-image with FAT partition support.
@
text
@d1 500
@


1.11.2.3
log
@Pull up following revision(s) (requested by maya in ticket #933):

	distrib/amd64/uefi-installimage/spec.inst: file removal
	distrib/amd64/uefi-installimage/etc.rc: file removal
	distrib/amd64/uefi-installimage/Makefile.bootimage: file removal
	distrib/amd64/uefi-installimage/Makefile.installimage: file removal
	distrib/amd64/uefi-installimage/install.sh: file removal
	distrib/amd64/uefi-installimage/etc.ttys: file removal
	distrib/amd64/Makefile: revision 1.14
	distrib/amd64/uefi-installimage/boot.cfg.in: file removal
	distrib/amd64/uefi-installimage/Makefile: file removal
	distrib/amd64/installimage/Makefile: revision 1.11

rename amd64 uefi-installimage to be just installimage.

Works for both purposes, no confusing name.
@
text
@@


1.10
log
@Reduce diffs between common and amd64 uefi Makefile.bootimage files.

No functional change.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.9 2018/12/15 18:03:17 gson Exp $
d214 2
a215 2
BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | awk '/^GUID/ {print $$2}'`
SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | awk '/^GUID/ {print $$2}'`
@


1.9
log
@Use the special device name "ROOT." in /etc/fstab not just on the arm
images, but also on the bootable disk images of other ports, so that
they can be booted from differently named devices.  Merge the i386 and
amd64 -live-sd0root and -live-wd0root images into a single live image
per port, bootable both from usb media and in qemu.  Drop the -xx0root
suffixes from image names as they are no longer meaningful.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.8 2018/11/19 20:05:37 aymeric Exp $
a226 2
COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
d242 2
d376 2
a377 1
CLEANFILES+=	${WORKMBR} ${WORKSWAP} ${WORKEFI} ${WORKGPT}
d427 1
a427 1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2				\
@


1.8
log
@Make building boot images work with xz sets on non-NetBSD hosts.

NetBSD gzip is not toolified so we can't assume the host gzip will be able
to decompress xz files. Use the toolified xz instead in the USE_XZ_SETS case.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.7 2018/10/07 10:33:44 martin Exp $
a36 3
#	BOOTDISK
#		device name of target bootable disk specified in /etc/fstab
#		(default: sd0)
a157 1
BOOTDISK?=	sd0
d275 2
a276 2
	    -e "s/\/dev\/@@@@BOOTDISK@@@@a/NAME=${BOOTDISK_UUID}/"		\
	    -e "s/\/dev\/@@@@BOOTDISK@@@@b/NAME=${SWAPDISK_UUID}/"		\
d280 2
a281 2
	    -e "s/\/dev\/@@@@BOOTDISK@@@@a/NAME=${BOOTDISK_UUID}/"		\
	    -e "/@@@@BOOTDISK@@@@b/d"					\
d286 1
a286 1
	${TOOL_SED} "s/@@@@BOOTDISK@@@@/${BOOTDISK}/" < ${FSTAB_IN} > ${WORKFSTAB}
d289 1
a289 2
	    -e "s/@@@@BOOTDISK@@@@/${BOOTDISK}/"				\
	    -e "/@@@@BOOTDISK@@@@b/d"					\
@


1.7
log
@Support .tar.xz format for sets.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.6 2017/02/16 03:47:23 christos Exp $
d231 1
d267 3
a269 1
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.${TAR_SUFF} .)
@


1.6
log
@Add ${GPT_TIMESTAMP}
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.5 2017/02/11 08:14:05 pgoyette Exp $
d231 1
d261 2
a262 2
	@@if [ ! -f ${SETS_DIR}/${set}.tgz ]; then 			\
		echo "Missing ${SETS_DIR}/${set}.tgz, aborting";	\
d265 2
a266 2
	@@echo Extracting ${set}.tgz ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.tgz .)
@


1.6.16.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.11 2019/02/22 22:20:18 tsutsui Exp $
d37 3
d161 1
d218 2
a219 2
BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
a245 2
COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
d260 2
a261 2
	@@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
d264 2
a265 4
	@@echo Extracting ${set}.${TAR_SUFF} ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \
		--use-compress-program=${COMPRESS_PROGRAM:Q} \
		-f ${SETS_DIR}/${set}.${TAR_SUFF} .)
d275 2
a276 2
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
	    -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/"			\
d280 2
a281 2
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
	    -e "/ROOT.b/d"						\
d286 1
a286 1
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
d289 2
a290 1
	    -e "/ROOT.b/d"						\
d377 1
a377 2
CLEANFILES+=	${WORKMBR} ${WORKSWAP}
CLEANFILES+=	${WORKEFI} ${WORKGPT}
d427 1
a427 1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2		\
@


1.6.16.2
log
@Mostly merge changes from HEAD upto 20200411
@
text
@d1 500
@


1.6.14.1
log
@Sync with head
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.7 2018/10/07 10:33:44 martin Exp $
a230 1
TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
d260 2
a261 2
	@@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
d264 2
a265 2
	@@echo Extracting ${set}.${TAR_SUFF} ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.${TAR_SUFF} .)
@


1.6.14.2
log
@Sync with HEAD, resolve a couple of conflicts
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.8 2018/11/19 20:05:37 aymeric Exp $
a230 1
COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
d266 1
a266 3
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \
		--use-compress-program=${COMPRESS_PROGRAM:Q} \
		-f ${SETS_DIR}/${set}.${TAR_SUFF} .)
@


1.6.14.3
log
@Sync with HEAD, resolve a few conflicts
@
text
@d1 1
a1 1
#	$NetBSD$
d37 3
d161 1
d279 2
a280 2
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
	    -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/"			\
d284 2
a285 2
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
	    -e "/ROOT.b/d"						\
d290 1
a290 1
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
d293 2
a294 1
	    -e "/ROOT.b/d"						\
@


1.6.4.1
log
@file Makefile.bootimage was added on branch bouyer-socketcan on 2017-02-16 03:47:24 +0000
@
text
@d1 500
@


1.6.4.2
log
@1942670
@
text
@a0 500
#	$NetBSD: Makefile.bootimage,v 1.6 2017/02/16 03:47:23 christos Exp $
#
# Copyright (c) 2009, 2010, 2011 Izumi Tsutsui.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#
# Makefile to create a bootable FS image for USB flash or emulators
#

#
# Required variables:
#	RELEASEDIR
#		Should be defined in nbmake-${MACHINE}
#	IMGBASE
#		Basename of the image
#
# Optional variables:
#	BOOTDISK
#		device name of target bootable disk specified in /etc/fstab
#		(default: sd0)
#	USE_MBR
#		set yes if target disk image requires MBR partition
#		(default: no)
#	USE_GPT
#		set yes if target disk image requires GPT partition
#		(default: no)
#	MBR_BOOTCODE
#		optional MBR bootcode which should be installed by fdisk(8)
#		(default: empty)
#		- specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec
#		- if MBR_BOOTCODE is not specified,
#		  MBR_DEFAULT_BOOTCODE (default: mbr) will be used
#		  if the target ${MACHINE} has the one in /usr/mdec
#	USE_SUNLABEL
#		set yes if target disk image requires Sun's label
#		(default: no)
#	INSTALLBOOT_AFTER_DISKLABEL (untested)
#		set yes if the target ${MACHINE} requires disklabel
#		to run installboot(8), like hp300
#		(default: empty)
#	IMAGEMB
#		target image size in MB
#		(default: 2048)
#	SWAPMB
#		swap size in target image in MB
#		(default: 128)
#	EFIMB
#		EFI partition size in target image in MB
#		(default: 128)
#	KERN_SET
#		kernel set name which should be extracted into image
#		(default: kern-GENERIC)
#	SETS
#		binary sets that should be extracted into image
#		(default: modules base etc comp games man misc tests text
#			  xbase xcomp xetc xfont xserver)
#	SETS_DIR
#		directory path where binary sets are stored
#		(default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets)
#	IMGFILE_EXTRA
#		list of additional files to be copied into images,
#		containing one or more tuples of the form:
#			FILE	TARGETPATH
#		for installation image etc.
#		(default: empty)
#	IMGDIR_EXTRA
#		list of additional directories to be copied into images,
#		containing one or more tuples of the form:
#			DIR	TARGETPATH
#		for installation image etc.
#		(default: empty)
#		XXX: currently permissions in IMGDIR_EXTRA are not handled
#	IMGDIR_EXCLUDE
#		pax(1) options to exclude files which should not copied
#		into TARGETPATH in IMGDIR_EXTRA
#		(default: empty)
#	FSTAB_IN
#		template file of /etc/fstab
#		(default: ${DISTRIBDIR}/common/bootimage/fstab.in)
#	SPEC_IN
#		default files of spec file for makefs(8)
#		(default: ${DISTRIBDIR}/common/bootimage/spec.in)
#	SPEC_EXTRA
#		additional files of spec file for makefs(8)
#		(default: empty)
#	IMGMAKEFSOPTIONS
#		options passed to makefs(8) to create root file system
#		(default: -o bsize=16384,fsize=2048,density=8192)
#	INSTALLBOOTOPTIONS
#		options passed to installboot(8), e.g., -o console=com0
#		(default: empty)
#	PRIMARY_BOOT
#		primary boot loader that should be installed into
#		the target image via installboot(8)
#		(default: empty)
#	SECONDARY_BOOT
#		secondary bootloader that should be put into the target image
#		(default: empty)
#	SECONDARY_BOOT_ARG
#		extra arguments that should be passed to installboot(8)
#		to specify the secondary bootloader
#		(default: empty)
#	DISKPROTO_IN
#		template file of disklabel -R
#		(default: ${DISTRIBDIR}/common/bootimage/diskproto.in
#		       or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in)
#	OMIT_SWAPIMG
#		no need to put swap partition into image (for USB stick)
#		(default: no)
#	EFIBOOT
#		EFI bootloader
#		(default: empty)
#

.include <bsd.own.mk> 		#
.include <bsd.endian.mk>	# for TARGET_ENDIANNESS

.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"

.if ${MKREPRO_TIMESTAMP:Uno} != "no"
MAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
GPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
.endif

.if empty(IMGBASE)
.BEGIN:
	@@echo "Error: IMGBASE is not set"
	@@false
.endif

# should be defined elsewhere? 
CAT?=		cat
CHMOD?=		chmod
DD?=		dd
MKDIR?=		mkdir -p
RM?=		rm

#
# common definitions for image
#
BOOTDISK?=	sd0
USE_MBR?=	no
USE_GPT?=	no
USE_SUNLABEL?=	no
INSTALLBOOT_AFTER_DISKLABEL?=	no

#
# size parameters for image
#
IMAGEMB?=	2048		# 2048MB
SWAPMB?=	128		# 128MB
EFIMB?=		128		# 128MB

# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
IMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
SWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true

.if ${USE_MBR} == "no" && ${USE_GPT} == "no"
LABELSECTORS?=	0
.else
#LABELSECTORS?=	63	# historical
#LABELSECTORS?=	32	# 16KB aligned
LABELSECTORS?=	2048	# 1MB aligned for modern flash devices
.endif

FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}
FSSIZE!=	expr ${FSSECTORS} \* 512

# parameters for disklabel and MBR
HEADS=		64
SECTORS=	32
CYLINDERS!=	expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)
SECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS}
MBRHEADS=	255
MBRSECTORS=	63
MBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
MBRNETBSD=	169

BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS}
FSOFFSET=	${LABELSECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS}

# parameters for sunlabel
FSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
SWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true

.if ${USE_GPT} != "no"
# 2048 for Secondary GPT header and entries
FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - 2048
FSSIZE!=	expr ${FSSECTORS} \* 512

BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} - ${EFISECTORS} - 2048
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} + ${EFISECTORS}

BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | awk '/^GUID/ {print $$2}'`
SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | awk '/^GUID/ {print $$2}'`
.endif

#
# definitions to create root fs
#
SETS_DEFAULT=	modules base etc comp games man misc tests text
.if ${MKX11} != "no"
SETS_DEFAULT+=	xbase xcomp xetc xfont xserver
.endif

KERN_SET?=	kern-GENERIC
SETS?=		${SETS_DEFAULT}
IMG_SETS=	${KERN_SET} ${SETS}
SETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets

FSTAB_IN?=	${DISTRIBDIR}/common/bootimage/fstab.in
SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in

IMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192

WORKDIR?=       work
WORKSPEC?=      work.spec
WORKFSTAB?=	work.fstab
WORKRCCONF?=	work.rc.conf
WORKFS?=        work.rootfs
TARGETFS?=      imgroot.fs

CLEANFILES+=	${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS}
CLEANFILES+=	${TARGETFS}

#
# create root file system for the image
#
${TARGETFS}: prepare_md_post pre-targetfs
	@@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
		false; 							\
	fi;
	@@${MKDIR} ${MKDIRPERM} ${WORKDIR}
.for set in ${IMG_SETS}
	@@if [ ! -f ${SETS_DIR}/${set}.tgz ]; then 			\
		echo "Missing ${SETS_DIR}/${set}.tgz, aborting";	\
		false; 							\
	fi
	@@echo Extracting ${set}.tgz ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.tgz .)
.endfor
.if defined(SECONDARY_BOOT)
	@@echo Copying secondary boot...
	${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
.endif
	@@echo Preparing /etc/fstab ...
.if ${USE_GPT} != "no"
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_SED}							\
	    -e "s/\/dev\/@@@@BOOTDISK@@@@a/NAME=${BOOTDISK_UUID}/"		\
	    -e "s/\/dev\/@@@@BOOTDISK@@@@b/NAME=${SWAPDISK_UUID}/"		\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.else
	${TOOL_SED}							\
	    -e "s/\/dev\/@@@@BOOTDISK@@@@a/NAME=${BOOTDISK_UUID}/"		\
	    -e "/@@@@BOOTDISK@@@@b/d"					\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.endif
.else	# USE_GPT == "no"
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_SED} "s/@@@@BOOTDISK@@@@/${BOOTDISK}/" < ${FSTAB_IN} > ${WORKFSTAB}
.else
	${TOOL_SED}							\
	    -e "s/@@@@BOOTDISK@@@@/${BOOTDISK}/"				\
	    -e "/@@@@BOOTDISK@@@@b/d"					\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.endif
.endif	# USE_GPT != "no"
	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
	@@echo Setting rc_configured=YES in /etc/rc.conf ...
	${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/"		\
	    < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF}
	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
.if defined(IMGDIR_EXTRA)
	@@echo Copying extra dirs...
.for _SRCDIR _TARGET in ${IMGDIR_EXTRA}
	@@if [ ! -d ${_SRCDIR} ]; then 					\
		echo "${_SRCDIR} is not directory, aborting";		\
		false; 							\
	fi
	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
	(cd ${_SRCDIR} ;						\
	    ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v			\
	    ${IMGDIR_EXCLUDE}						\
	    . ${.OBJDIR}/${WORKDIR}/${_TARGET} )
.endfor
.endif
.if defined(IMGFILE_EXTRA)
	@@echo Copying extra files...
.for _SRC _TARGET in ${IMGFILE_EXTRA}
	@@if [ ! -f ${_SRC} ]; then 					\
		echo "${_SRC} in IMGFILE_EXTRA not found, aborting";	\
		false; 							\
	fi
	@@if [ -f ${_SRC} ]; then 					\
		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
	fi
.endfor
.endif
	@@echo Preparing spec files for makefs...
	${RM} -f ${WORKSPEC}
	cat ${WORKDIR}/etc/mtree/* |					\
	    ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC}
	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty |			\
	    ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC}
	cat ${SPEC_IN} >> ${WORKSPEC}
.if defined(SECONDARY_BOOT)
	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
	    >> ${WORKSPEC}
.endif
.if defined(SPEC_EXTRA)
	cat ${SPEC_EXTRA} >> ${WORKSPEC}
.endif
	@@echo Creating rootfs...
	# XXX /var/spool/ftp/hidden is unreadable
	${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden
	${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE}			\
	    -B ${TARGET_ENDIANNESS}					\
	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
	    ${MAKEFS_TIMESTAMP}						\
	    ${IMGMAKEFSOPTIONS}						\
	    ${WORKFS} ${WORKDIR}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
.endif
	@@echo done.
	mv ${WORKFS} ${.TARGET}

#
# definitions to create image
#
.if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
.else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
.endif

MBR_DEFAULT_BOOTCODE?=	mbr

OMIT_SWAPIMG?=	no

WORKMBR?=	work.mbr
WORKSWAP?=	work.swap
WORKEFI?=	work.efi
WORKGPT?=	work.gpt
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img
EFIWORKDIR?=	work.efidir

CLEANFILES+=	${WORKMBR} ${WORKSWAP} ${WORKEFI} ${WORKGPT}
CLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
CLEANFILES+=	${WORKIMG} ${IMGBASE}.img

${WORKLABEL}:
	${TOOL_SED}							\
	    -e "s/@@@@SECTORS@@@@/${SECTORS}/"				\
	    -e "s/@@@@HEADS@@@@/${HEADS}/"					\
	    -e "s/@@@@SECPERCYLINDERS@@@@/${SECPERCYLINDERS}/"		\
	    -e "s/@@@@CYLINDERS@@@@/${CYLINDERS}/"				\
	    -e "s/@@@@IMAGESECTORS@@@@/${IMAGESECTORS}/"			\
	    -e "s/@@@@FSSECTORS@@@@/${FSSECTORS}/"				\
	    -e "s/@@@@FSOFFSET@@@@/${FSOFFSET}/"				\
	    -e "s/@@@@SWAPSECTORS@@@@/${SWAPSECTORS}/"			\
	    -e "s/@@@@SWAPOFFSET@@@@/${SWAPOFFSET}/"			\
	    -e "s/@@@@BSDPARTSECTORS@@@@/${BSDPARTSECTORS}/"		\
	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
	mv ${WORKLABEL}.tmp ${WORKLABEL}

pre-targetfs:
.if ${USE_GPT} != "no"
	@@echo creating GPT header and partition entries...
	${RM} -f ${WORKMBR}
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system"
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
.endif

${IMGBASE}.img:	${TARGETFS}
	@@echo create EFI system partition...
	@@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
.if !empty(EFIBOOT)
.for f in ${EFIBOOT}
	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
.endfor
.endif
	${RM} -f ${WORKEFI}
	${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m			\
	    -B ${TARGET_ENDIANNESS}					\
	    ${MAKEFS_TIMESTAMP}						\
	    -t msdos -o F=32,c=1					\
	    ${WORKEFI} ${EFIWORKDIR}
	@@echo create GPT image...
	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
	    count=2048
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${WORKEFI} ${TARGETFS} ${WORKGPT} > ${WORKIMG}
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2				\
	    -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2
.else	# USE_GPT == "no"
${IMGBASE}.img:	${TARGETFS} ${WORKLABEL}
.if ${USE_MBR} != "no"
	@@echo creating MBR labels...
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
	${TOOL_FDISK} -f -i -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -F ${WORKMBR}
.if empty(MBR_BOOTCODE)
	@@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
		echo ${TOOL_FDISK} -f					\
		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
		    -F ${WORKMBR};					\
		${TOOL_FDISK} -f					\
		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
		    -F ${WORKMBR};					\
	fi
.else
	@@if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then 		\
		echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \
		false; 							\
	fi
	${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE}	\
	    -F ${WORKMBR}
.endif
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${TARGETFS} > ${WORKIMG}
.else	# USE_MBR == "no"
	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
.endif	# USE_MBR != "no"
.endif	# USE_GPT != "no"
.if ${OMIT_SWAPIMG} == "no"
	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
	${CAT} ${WORKSWAP} >> ${WORKIMG}
.endif
.if ${USE_SUNLABEL} != "no"
	@@echo Creating sun disklabel...
	printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \
	    ${CYLINDERS} ${HEADS} ${SECTORS} \
	    ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \
	    ${TOOL_SUNLABEL} -nq ${WORKIMG}
.endif
.if ${USE_GPT} == "no"
	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
.endif
.endif
	mv ${WORKIMG} ${.TARGET}


CLEANFILES+=	${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp

${IMGBASE}.img.gz:	${IMGBASE}.img
	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
	mv ${.TARGET}.tmp ${.TARGET}

clean:
	@@if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then 		\
		${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden;		\
	fi	# XXX
	${RM} -fr ${WORKDIR}
	${RM} -fr ${EFIWORKDIR}

prepare_md_post: .PHONY
image_md_post: .PHONY
image_md_pre: .PHONY

.include <bsd.prog.mk>
@


1.6.2.1
log
@file Makefile.bootimage was added on branch pgoyette-localcount on 2017-03-20 06:52:03 +0000
@
text
@d1 500
@


1.6.2.2
log
@Sync with HEAD
@
text
@a0 500
#	$NetBSD: Makefile.bootimage,v 1.6 2017/02/16 03:47:23 christos Exp $
#
# Copyright (c) 2009, 2010, 2011 Izumi Tsutsui.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#
# Makefile to create a bootable FS image for USB flash or emulators
#

#
# Required variables:
#	RELEASEDIR
#		Should be defined in nbmake-${MACHINE}
#	IMGBASE
#		Basename of the image
#
# Optional variables:
#	BOOTDISK
#		device name of target bootable disk specified in /etc/fstab
#		(default: sd0)
#	USE_MBR
#		set yes if target disk image requires MBR partition
#		(default: no)
#	USE_GPT
#		set yes if target disk image requires GPT partition
#		(default: no)
#	MBR_BOOTCODE
#		optional MBR bootcode which should be installed by fdisk(8)
#		(default: empty)
#		- specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec
#		- if MBR_BOOTCODE is not specified,
#		  MBR_DEFAULT_BOOTCODE (default: mbr) will be used
#		  if the target ${MACHINE} has the one in /usr/mdec
#	USE_SUNLABEL
#		set yes if target disk image requires Sun's label
#		(default: no)
#	INSTALLBOOT_AFTER_DISKLABEL (untested)
#		set yes if the target ${MACHINE} requires disklabel
#		to run installboot(8), like hp300
#		(default: empty)
#	IMAGEMB
#		target image size in MB
#		(default: 2048)
#	SWAPMB
#		swap size in target image in MB
#		(default: 128)
#	EFIMB
#		EFI partition size in target image in MB
#		(default: 128)
#	KERN_SET
#		kernel set name which should be extracted into image
#		(default: kern-GENERIC)
#	SETS
#		binary sets that should be extracted into image
#		(default: modules base etc comp games man misc tests text
#			  xbase xcomp xetc xfont xserver)
#	SETS_DIR
#		directory path where binary sets are stored
#		(default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets)
#	IMGFILE_EXTRA
#		list of additional files to be copied into images,
#		containing one or more tuples of the form:
#			FILE	TARGETPATH
#		for installation image etc.
#		(default: empty)
#	IMGDIR_EXTRA
#		list of additional directories to be copied into images,
#		containing one or more tuples of the form:
#			DIR	TARGETPATH
#		for installation image etc.
#		(default: empty)
#		XXX: currently permissions in IMGDIR_EXTRA are not handled
#	IMGDIR_EXCLUDE
#		pax(1) options to exclude files which should not copied
#		into TARGETPATH in IMGDIR_EXTRA
#		(default: empty)
#	FSTAB_IN
#		template file of /etc/fstab
#		(default: ${DISTRIBDIR}/common/bootimage/fstab.in)
#	SPEC_IN
#		default files of spec file for makefs(8)
#		(default: ${DISTRIBDIR}/common/bootimage/spec.in)
#	SPEC_EXTRA
#		additional files of spec file for makefs(8)
#		(default: empty)
#	IMGMAKEFSOPTIONS
#		options passed to makefs(8) to create root file system
#		(default: -o bsize=16384,fsize=2048,density=8192)
#	INSTALLBOOTOPTIONS
#		options passed to installboot(8), e.g., -o console=com0
#		(default: empty)
#	PRIMARY_BOOT
#		primary boot loader that should be installed into
#		the target image via installboot(8)
#		(default: empty)
#	SECONDARY_BOOT
#		secondary bootloader that should be put into the target image
#		(default: empty)
#	SECONDARY_BOOT_ARG
#		extra arguments that should be passed to installboot(8)
#		to specify the secondary bootloader
#		(default: empty)
#	DISKPROTO_IN
#		template file of disklabel -R
#		(default: ${DISTRIBDIR}/common/bootimage/diskproto.in
#		       or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in)
#	OMIT_SWAPIMG
#		no need to put swap partition into image (for USB stick)
#		(default: no)
#	EFIBOOT
#		EFI bootloader
#		(default: empty)
#

.include <bsd.own.mk> 		#
.include <bsd.endian.mk>	# for TARGET_ENDIANNESS

.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib"

.if ${MKREPRO_TIMESTAMP:Uno} != "no"
MAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
GPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
.endif

.if empty(IMGBASE)
.BEGIN:
	@@echo "Error: IMGBASE is not set"
	@@false
.endif

# should be defined elsewhere? 
CAT?=		cat
CHMOD?=		chmod
DD?=		dd
MKDIR?=		mkdir -p
RM?=		rm

#
# common definitions for image
#
BOOTDISK?=	sd0
USE_MBR?=	no
USE_GPT?=	no
USE_SUNLABEL?=	no
INSTALLBOOT_AFTER_DISKLABEL?=	no

#
# size parameters for image
#
IMAGEMB?=	2048		# 2048MB
SWAPMB?=	128		# 128MB
EFIMB?=		128		# 128MB

# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
IMAGESECTORS!=	expr ${IMAGEMB} \* 1024 \* 1024 / 512
SWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true

.if ${USE_MBR} == "no" && ${USE_GPT} == "no"
LABELSECTORS?=	0
.else
#LABELSECTORS?=	63	# historical
#LABELSECTORS?=	32	# 16KB aligned
LABELSECTORS?=	2048	# 1MB aligned for modern flash devices
.endif

FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}
FSSIZE!=	expr ${FSSECTORS} \* 512

# parameters for disklabel and MBR
HEADS=		64
SECTORS=	32
CYLINDERS!=	expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)
SECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS}
MBRHEADS=	255
MBRSECTORS=	63
MBRCYLINDERS!=	expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \)
MBRNETBSD=	169

BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS}
FSOFFSET=	${LABELSECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS}

# parameters for sunlabel
FSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
SWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true

.if ${USE_GPT} != "no"
# 2048 for Secondary GPT header and entries
FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - 2048
FSSIZE!=	expr ${FSSECTORS} \* 512

BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} - ${EFISECTORS} - 2048
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} + ${EFISECTORS}

BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | awk '/^GUID/ {print $$2}'`
SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | awk '/^GUID/ {print $$2}'`
.endif

#
# definitions to create root fs
#
SETS_DEFAULT=	modules base etc comp games man misc tests text
.if ${MKX11} != "no"
SETS_DEFAULT+=	xbase xcomp xetc xfont xserver
.endif

KERN_SET?=	kern-GENERIC
SETS?=		${SETS_DEFAULT}
IMG_SETS=	${KERN_SET} ${SETS}
SETS_DIR?=	${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets

FSTAB_IN?=	${DISTRIBDIR}/common/bootimage/fstab.in
SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in

IMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192

WORKDIR?=       work
WORKSPEC?=      work.spec
WORKFSTAB?=	work.fstab
WORKRCCONF?=	work.rc.conf
WORKFS?=        work.rootfs
TARGETFS?=      imgroot.fs

CLEANFILES+=	${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS}
CLEANFILES+=	${TARGETFS}

#
# create root file system for the image
#
${TARGETFS}: prepare_md_post pre-targetfs
	@@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
		false; 							\
	fi;
	@@${MKDIR} ${MKDIRPERM} ${WORKDIR}
.for set in ${IMG_SETS}
	@@if [ ! -f ${SETS_DIR}/${set}.tgz ]; then 			\
		echo "Missing ${SETS_DIR}/${set}.tgz, aborting";	\
		false; 							\
	fi
	@@echo Extracting ${set}.tgz ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.tgz .)
.endfor
.if defined(SECONDARY_BOOT)
	@@echo Copying secondary boot...
	${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
.endif
	@@echo Preparing /etc/fstab ...
.if ${USE_GPT} != "no"
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_SED}							\
	    -e "s/\/dev\/@@@@BOOTDISK@@@@a/NAME=${BOOTDISK_UUID}/"		\
	    -e "s/\/dev\/@@@@BOOTDISK@@@@b/NAME=${SWAPDISK_UUID}/"		\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.else
	${TOOL_SED}							\
	    -e "s/\/dev\/@@@@BOOTDISK@@@@a/NAME=${BOOTDISK_UUID}/"		\
	    -e "/@@@@BOOTDISK@@@@b/d"					\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.endif
.else	# USE_GPT == "no"
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_SED} "s/@@@@BOOTDISK@@@@/${BOOTDISK}/" < ${FSTAB_IN} > ${WORKFSTAB}
.else
	${TOOL_SED}							\
	    -e "s/@@@@BOOTDISK@@@@/${BOOTDISK}/"				\
	    -e "/@@@@BOOTDISK@@@@b/d"					\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.endif
.endif	# USE_GPT != "no"
	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
	@@echo Setting rc_configured=YES in /etc/rc.conf ...
	${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/"		\
	    < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF}
	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
.if defined(IMGDIR_EXTRA)
	@@echo Copying extra dirs...
.for _SRCDIR _TARGET in ${IMGDIR_EXTRA}
	@@if [ ! -d ${_SRCDIR} ]; then 					\
		echo "${_SRCDIR} is not directory, aborting";		\
		false; 							\
	fi
	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
	(cd ${_SRCDIR} ;						\
	    ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v			\
	    ${IMGDIR_EXCLUDE}						\
	    . ${.OBJDIR}/${WORKDIR}/${_TARGET} )
.endfor
.endif
.if defined(IMGFILE_EXTRA)
	@@echo Copying extra files...
.for _SRC _TARGET in ${IMGFILE_EXTRA}
	@@if [ ! -f ${_SRC} ]; then 					\
		echo "${_SRC} in IMGFILE_EXTRA not found, aborting";	\
		false; 							\
	fi
	@@if [ -f ${_SRC} ]; then 					\
		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
	fi
.endfor
.endif
	@@echo Preparing spec files for makefs...
	${RM} -f ${WORKSPEC}
	cat ${WORKDIR}/etc/mtree/* |					\
	    ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC}
	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty |			\
	    ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC}
	cat ${SPEC_IN} >> ${WORKSPEC}
.if defined(SECONDARY_BOOT)
	echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \
	    >> ${WORKSPEC}
.endif
.if defined(SPEC_EXTRA)
	cat ${SPEC_EXTRA} >> ${WORKSPEC}
.endif
	@@echo Creating rootfs...
	# XXX /var/spool/ftp/hidden is unreadable
	${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden
	${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE}			\
	    -B ${TARGET_ENDIANNESS}					\
	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
	    ${MAKEFS_TIMESTAMP}						\
	    ${IMGMAKEFSOPTIONS}						\
	    ${WORKFS} ${WORKDIR}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
.endif
	@@echo done.
	mv ${WORKFS} ${.TARGET}

#
# definitions to create image
#
.if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
.else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
.endif

MBR_DEFAULT_BOOTCODE?=	mbr

OMIT_SWAPIMG?=	no

WORKMBR?=	work.mbr
WORKSWAP?=	work.swap
WORKEFI?=	work.efi
WORKGPT?=	work.gpt
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img
EFIWORKDIR?=	work.efidir

CLEANFILES+=	${WORKMBR} ${WORKSWAP} ${WORKEFI} ${WORKGPT}
CLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
CLEANFILES+=	${WORKIMG} ${IMGBASE}.img

${WORKLABEL}:
	${TOOL_SED}							\
	    -e "s/@@@@SECTORS@@@@/${SECTORS}/"				\
	    -e "s/@@@@HEADS@@@@/${HEADS}/"					\
	    -e "s/@@@@SECPERCYLINDERS@@@@/${SECPERCYLINDERS}/"		\
	    -e "s/@@@@CYLINDERS@@@@/${CYLINDERS}/"				\
	    -e "s/@@@@IMAGESECTORS@@@@/${IMAGESECTORS}/"			\
	    -e "s/@@@@FSSECTORS@@@@/${FSSECTORS}/"				\
	    -e "s/@@@@FSOFFSET@@@@/${FSOFFSET}/"				\
	    -e "s/@@@@SWAPSECTORS@@@@/${SWAPSECTORS}/"			\
	    -e "s/@@@@SWAPOFFSET@@@@/${SWAPOFFSET}/"			\
	    -e "s/@@@@BSDPARTSECTORS@@@@/${BSDPARTSECTORS}/"		\
	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
	mv ${WORKLABEL}.tmp ${WORKLABEL}

pre-targetfs:
.if ${USE_GPT} != "no"
	@@echo creating GPT header and partition entries...
	${RM} -f ${WORKMBR}
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system"
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs
.if ${OMIT_SWAPIMG} == "no"
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
.endif

${IMGBASE}.img:	${TARGETFS}
	@@echo create EFI system partition...
	@@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
.if !empty(EFIBOOT)
.for f in ${EFIBOOT}
	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
.endfor
.endif
	${RM} -f ${WORKEFI}
	${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m			\
	    -B ${TARGET_ENDIANNESS}					\
	    ${MAKEFS_TIMESTAMP}						\
	    -t msdos -o F=32,c=1					\
	    ${WORKEFI} ${EFIWORKDIR}
	@@echo create GPT image...
	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
	    count=2048
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${WORKEFI} ${TARGETFS} ${WORKGPT} > ${WORKIMG}
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2				\
	    -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2
.else	# USE_GPT == "no"
${IMGBASE}.img:	${TARGETFS} ${WORKLABEL}
.if ${USE_MBR} != "no"
	@@echo creating MBR labels...
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
	${TOOL_FDISK} -f -i -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -F ${WORKMBR}
.if empty(MBR_BOOTCODE)
	@@if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then 	\
		echo ${TOOL_FDISK} -f					\
		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
		    -F ${WORKMBR};					\
		${TOOL_FDISK} -f					\
		    -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE}	\
		    -F ${WORKMBR};					\
	fi
.else
	@@if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then 		\
		echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \
		false; 							\
	fi
	${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE}	\
	    -F ${WORKMBR}
.endif
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${TARGETFS} > ${WORKIMG}
.else	# USE_MBR == "no"
	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
.endif	# USE_MBR != "no"
.endif	# USE_GPT != "no"
.if ${OMIT_SWAPIMG} == "no"
	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
	${CAT} ${WORKSWAP} >> ${WORKIMG}
.endif
.if ${USE_SUNLABEL} != "no"
	@@echo Creating sun disklabel...
	printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \
	    ${CYLINDERS} ${HEADS} ${SECTORS} \
	    ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \
	    ${TOOL_SUNLABEL} -nq ${WORKIMG}
.endif
.if ${USE_GPT} == "no"
	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
.endif
.endif
	mv ${WORKIMG} ${.TARGET}


CLEANFILES+=	${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp

${IMGBASE}.img.gz:	${IMGBASE}.img
	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
	mv ${.TARGET}.tmp ${.TARGET}

clean:
	@@if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then 		\
		${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden;		\
	fi	# XXX
	${RM} -fr ${WORKDIR}
	${RM} -fr ${EFIWORKDIR}

prepare_md_post: .PHONY
image_md_post: .PHONY
image_md_pre: .PHONY

.include <bsd.prog.mk>
@


1.5
log
@Clean up another extraneous -f option
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.4 2017/02/11 03:07:06 christos Exp $
d141 1
d218 2
a219 2
BOOTDISK_UUID=`${TOOL_GPT} ${WORKMBR} show -i 2 | awk '/^GUID/ {print $$2}'`
SWAPDISK_UUID=`${TOOL_GPT} ${WORKMBR} show -i 3 | awk '/^GUID/ {print $$2}'`
d401 3
a403 3
	${TOOL_GPT} ${WORKMBR} create
	${TOOL_GPT} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system"
	${TOOL_GPT} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs
d405 1
a405 1
	${TOOL_GPT} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
d427 1
a427 1
	${TOOL_GPT} ${WORKIMG} biosboot -i 2				\
d429 1
a429 1
	${TOOL_GPT} ${WORKIMG} set -a bootme -i 2
@


1.4
log
@more MKREPRO_TIMESTAMP fixes (for pax/tar generated files)
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.3 2017/02/10 16:53:51 christos Exp $
d412 1
a412 1
	${INSTALL} ${COPY} -m 0644 -f ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
@


1.3
log
@MKREPRO_TIMESTAMP fixes for efiboot
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.2 2017/02/10 16:43:59 christos Exp $
d141 1
d264 1
a264 1
	@@(cd ${WORKDIR}; ${TOOL_PAX} -rnz -f ${SETS_DIR}/${set}.tgz .)
d307 1
a307 1
	    ${TOOL_PAX} -rw -pe	-v					\
@


1.2
log
@Initial pass to be unaffected by build umask on build artifacts
1. ${MKDIR} -> ${MKDIR} ${MKDIRPERM}
2. ${CP} -> ${INSTALL} ${COPY} -m <perm>
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.1 2017/01/24 11:16:50 nonaka Exp $
d139 2
a140 2
.if ${MKREPRO:Uno} == "yes"
TIMESTAMP=-T ${NETBSDSRCDIR}/sys/sys/param.h
d344 1
a344 1
	    ${TIMESTAMP}						\
d417 1
a417 1
	    ${TIMESTAMP}						\
@


1.1
log
@make amd64 EFI install image

XXX merge to installimage?
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.12 2015/11/25 00:50:57 christos Exp $
a151 1
CP?=		cp
d256 1
a256 1
	@@${MKDIR} ${WORKDIR}
d267 1
a267 1
	${CP} -f ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
d292 1
a292 1
	${CP} ${WORKFSTAB} ${WORKDIR}/etc/fstab
d296 1
a296 1
	${CP} ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
d304 1
a304 1
	${MKDIR} ${WORKDIR}/${_TARGET}
d319 2
a320 2
		echo ${CP} ${_SRC} ${WORKDIR}/${_TARGET};		\
		${CP} ${_SRC} ${WORKDIR}/${_TARGET};			\
d408 1
a408 1
	@@${MKDIR} ${EFIWORKDIR}/EFI/boot
d411 1
a411 1
	${CP} -f ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
d457 1
a457 1
	${CP} ${TARGETFS} ${WORKIMG}
@

