head	1.50;
access;
symbols
	netbsd-11-0-RC4:1.46.2.3
	netbsd-11-0-RC3:1.46.2.3
	netbsd-11-0-RC2:1.46.2.3
	netbsd-11-0-RC1:1.46.2.3
	perseant-exfatfs-base-20250801:1.46
	netbsd-11:1.46.0.2
	netbsd-11-base:1.46
	netbsd-10-1-RELEASE:1.30
	perseant-exfatfs-base-20240630:1.41
	perseant-exfatfs:1.41.0.2
	perseant-exfatfs-base:1.41
	netbsd-8-3-RELEASE:1.17
	netbsd-9-4-RELEASE:1.21.2.2
	netbsd-10-0-RELEASE:1.30
	netbsd-10-0-RC6:1.30
	netbsd-10-0-RC5:1.30
	netbsd-10-0-RC4:1.30
	netbsd-10-0-RC3:1.30
	netbsd-10-0-RC2:1.30
	netbsd-10-0-RC1:1.30
	netbsd-10:1.30.0.2
	netbsd-10-base:1.30
	netbsd-9-3-RELEASE:1.21.2.2
	cjep_sun2x-base1:1.27
	cjep_sun2x:1.26.0.4
	cjep_sun2x-base:1.26
	cjep_staticlib_x-base1:1.26
	netbsd-9-2-RELEASE:1.21.2.2
	cjep_staticlib_x:1.26.0.2
	cjep_staticlib_x-base:1.26
	netbsd-9-1-RELEASE:1.21.2.2
	phil-wifi-20200421:1.24
	phil-wifi-20200411:1.24
	is-mlppp:1.23.0.2
	is-mlppp-base:1.23
	phil-wifi-20200406:1.24
	netbsd-8-2-RELEASE:1.17
	netbsd-9-0-RELEASE:1.21.2.1
	netbsd-9-0-RC2:1.21.2.1
	netbsd-9-0-RC1:1.21.2.1
	phil-wifi-20191119:1.22
	netbsd-9:1.21.0.2
	netbsd-9-base:1.21
	phil-wifi-20190609:1.21
	netbsd-8-1-RELEASE:1.17
	netbsd-8-1-RC1:1.17
	pgoyette-compat-merge-20190127:1.17.10.3
	pgoyette-compat-20190127:1.20
	pgoyette-compat-20190118:1.20
	pgoyette-compat-1226:1.20
	pgoyette-compat-1126:1.19
	pgoyette-compat-1020:1.18
	pgoyette-compat-0930:1.17
	pgoyette-compat-0906:1.17
	netbsd-7-2-RELEASE:1.9.2.1
	pgoyette-compat-0728:1.17
	netbsd-8-0-RELEASE:1.17
	phil-wifi:1.17.0.12
	phil-wifi-base:1.17
	pgoyette-compat-0625:1.17
	netbsd-8-0-RC2:1.17
	pgoyette-compat-0521:1.17
	pgoyette-compat-0502:1.17
	pgoyette-compat-0422:1.17
	netbsd-8-0-RC1:1.17
	pgoyette-compat-0415:1.17
	pgoyette-compat-0407:1.17
	pgoyette-compat-0330:1.17
	pgoyette-compat-0322:1.17
	pgoyette-compat-0315:1.17
	netbsd-7-1-2-RELEASE:1.9.2.1
	pgoyette-compat:1.17.0.10
	pgoyette-compat-base:1.17
	netbsd-7-1-1-RELEASE:1.9.2.1
	matt-nb8-mediatek:1.17.0.8
	matt-nb8-mediatek-base:1.17
	perseant-stdc-iso10646:1.17.0.6
	perseant-stdc-iso10646-base:1.17
	netbsd-8:1.17.0.4
	netbsd-8-base:1.17
	prg-localcount2-base3:1.17
	prg-localcount2-base2:1.17
	prg-localcount2-base1:1.17
	prg-localcount2:1.17.0.2
	prg-localcount2-base:1.17
	pgoyette-localcount-20170426:1.17
	bouyer-socketcan-base1:1.17
	pgoyette-localcount-20170320:1.17
	netbsd-7-1:1.9.2.1.0.6
	netbsd-7-1-RELEASE:1.9.2.1
	netbsd-7-1-RC2:1.9.2.1
	netbsd-7-nhusb-base-20170116:1.9.2.1
	bouyer-socketcan:1.12.0.4
	bouyer-socketcan-base:1.12
	pgoyette-localcount-20170107:1.12
	netbsd-7-1-RC1:1.9.2.1
	pgoyette-localcount-20161104:1.12
	netbsd-7-0-2-RELEASE:1.9.2.1
	localcount-20160914:1.12
	netbsd-7-nhusb:1.9.2.1.0.4
	netbsd-7-nhusb-base:1.9.2.1
	pgoyette-localcount-20160806:1.12
	pgoyette-localcount-20160726:1.12
	pgoyette-localcount:1.12.0.2
	pgoyette-localcount-base:1.12
	netbsd-7-0-1-RELEASE:1.9.2.1
	netbsd-7-0:1.9.2.1.0.2
	netbsd-7-0-RELEASE:1.9.2.1
	netbsd-7-0-RC3:1.9.2.1
	netbsd-7-0-RC2:1.9
	netbsd-7-0-RC1:1.9
	netbsd-6-0-6-RELEASE:1.3.2.1
	netbsd-6-1-5-RELEASE:1.3.2.1
	netbsd-7:1.9.0.2
	netbsd-7-base:1.9
	yamt-pagecache-base9:1.8
	yamt-pagecache-tag8:1.4.2.3
	netbsd-6-1-4-RELEASE:1.3.2.1
	netbsd-6-0-5-RELEASE:1.3.2.1
	tls-earlyentropy:1.8.0.2
	tls-earlyentropy-base:1.9
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.8
	riastradh-drm2-base3:1.8
	netbsd-6-1-3-RELEASE:1.3.2.1
	netbsd-6-0-4-RELEASE:1.3.2.1
	netbsd-6-1-2-RELEASE:1.3.2.1
	netbsd-6-0-3-RELEASE:1.3.2.1
	netbsd-6-1-1-RELEASE:1.3.2.1
	riastradh-drm2-base2:1.6
	riastradh-drm2-base1:1.6
	riastradh-drm2:1.6.0.4
	riastradh-drm2-base:1.6
	netbsd-6-1:1.3.2.1.0.6
	netbsd-6-0-2-RELEASE:1.3.2.1
	netbsd-6-1-RELEASE:1.3.2.1
	khorben-n900:1.6.0.8
	netbsd-6-1-RC4:1.3.2.1
	netbsd-6-1-RC3:1.3.2.1
	agc-symver:1.6.0.6
	agc-symver-base:1.6
	netbsd-6-1-RC2:1.3.2.1
	netbsd-6-1-RC1:1.3.2.1
	yamt-pagecache-base8:1.6
	netbsd-6-0-1-RELEASE:1.3.2.1
	yamt-pagecache-base7:1.6
	matt-nb6-plus-nbase:1.3.2.1
	yamt-pagecache-base6:1.6
	netbsd-6-0:1.3.2.1.0.4
	netbsd-6-0-RELEASE:1.3.2.1
	netbsd-6-0-RC2:1.3.2.1
	tls-maxphys:1.6.0.2
	tls-maxphys-base:1.9
	matt-nb6-plus:1.3.2.1.0.2
	matt-nb6-plus-base:1.3.2.1
	netbsd-6-0-RC1:1.3.2.1
	yamt-pagecache-base5:1.6
	yamt-pagecache:1.4.0.2
	yamt-pagecache-base4:1.4
	netbsd-6:1.3.0.2
	netbsd-6-base:1.3;
locks; strict;
comment	@# @;


1.50
date	2026.01.18.00.07.36;	author tsutsui;	state Exp;
branches;
next	1.49;
commitid	VPhjFPBD5yZW1OqG;

1.49
date	2026.01.16.23.37.19;	author tsutsui;	state Exp;
branches;
next	1.48;
commitid	ucc4HDNG7iXwSFqG;

1.48
date	2026.01.14.11.42.43;	author tsutsui;	state Exp;
branches;
next	1.47;
commitid	OLP8bdGE2coo0mqG;

1.47
date	2026.01.13.14.09.02;	author tsutsui;	state Exp;
branches;
next	1.46;
commitid	UOAG6FfFLbzeQeqG;

1.46
date	2025.04.26.03.01.39;	author pgoyette;	state Exp;
branches
	1.46.2.1;
next	1.45;
commitid	S7ODm2mGraLqzvSF;

1.45
date	2025.02.02.03.19.37;	author tsutsui;	state Exp;
branches;
next	1.44;
commitid	rqqgLASg7xillQHF;

1.44
date	2025.01.18.09.07.14;	author tsutsui;	state Exp;
branches;
next	1.43;
commitid	Rk0qfrUavVWWIWFF;

1.43
date	2025.01.10.18.11.56;	author tsutsui;	state Exp;
branches;
next	1.42;
commitid	LYDRcI4eu3A01YEF;

1.42
date	2024.12.31.06.58.00;	author jmmv;	state Exp;
branches;
next	1.41;
commitid	yAMbeRoexgqEBCDF;

1.41
date	2024.06.26.09.13.47;	author martin;	state Exp;
branches
	1.41.2.1;
next	1.40;
commitid	fwoT1Xd5wzK6ptfF;

1.40
date	2024.06.25.09.07.14;	author martin;	state Exp;
branches;
next	1.39;
commitid	cMC36fSCVP61plfF;

1.39
date	2024.06.25.08.59.52;	author martin;	state Exp;
branches;
next	1.38;
commitid	Ts9MRlbYp1ZWllfF;

1.38
date	2024.06.24.07.43.33;	author martin;	state Exp;
branches;
next	1.37;
commitid	8RJJe81pIiDIXcfF;

1.37
date	2024.05.18.02.03.17;	author christos;	state Exp;
branches;
next	1.36;
commitid	flJt2OujZeW5hqaF;

1.36
date	2024.05.16.15.46.42;	author christos;	state Exp;
branches;
next	1.35;
commitid	biTUDsY6uPnFTeaF;

1.35
date	2024.04.22.14.41.24;	author nia;	state Exp;
branches;
next	1.34;
commitid	i6E7BJGfw4rNi97F;

1.34
date	2024.04.09.15.17.21;	author nia;	state Exp;
branches;
next	1.33;
commitid	JExbVLp22BtkVt5F;

1.33
date	2024.02.08.18.14.02;	author christos;	state Exp;
branches;
next	1.32;
commitid	a2olI5Fc4EvrREXE;

1.32
date	2023.12.03.07.20.23;	author tsutsui;	state Exp;
branches;
next	1.31;
commitid	bYbhnXf8emfPoZOE;

1.31
date	2023.12.03.07.17.11;	author tsutsui;	state Exp;
branches;
next	1.30;
commitid	25QWzljDfuZJnZOE;

1.30
date	2022.05.15.00.05.24;	author mrg;	state Exp;
branches
	1.30.2.1;
next	1.29;
commitid	1kLgUfXumR3md5ED;

1.29
date	2021.09.25.08.54.29;	author maya;	state Exp;
branches;
next	1.28;
commitid	BGRNzDrS01VoBjaD;

1.28
date	2021.07.24.13.59.28;	author jmcneill;	state Exp;
branches;
next	1.27;
commitid	6GZITNlSOFHqjf2D;

1.27
date	2021.06.04.17.09.36;	author tsutsui;	state Exp;
branches;
next	1.26;
commitid	bWNO0mcrX5dzYPVC;

1.26
date	2020.08.05.01.35.18;	author jmcneill;	state Exp;
branches
	1.26.4.1;
next	1.25;
commitid	bDwoU6fcD68PxOiC;

1.25
date	2020.05.28.15.13.21;	author jmcneill;	state Exp;
branches;
next	1.24;
commitid	MChr3jUEHapZh1aC;

1.24
date	2020.03.21.14.19.26;	author tsutsui;	state Exp;
branches;
next	1.23;
commitid	jq4cFpbltAu4bh1C;

1.23
date	2019.11.21.22.29.03;	author joerg;	state Exp;
branches;
next	1.22;
commitid	iULoA7uTNO15MLLB;

1.22
date	2019.10.02.11.15.59;	author maya;	state Exp;
branches;
next	1.21;
commitid	7L8j32uFc906EhFB;

1.21
date	2019.02.22.22.13.58;	author tsutsui;	state Exp;
branches
	1.21.2.1;
next	1.20;
commitid	cu5RG0gN3PwVqOcB;

1.20
date	2018.12.15.18.03.17;	author gson;	state Exp;
branches;
next	1.19;
commitid	VnJTdkyNfhz4gV3B;

1.19
date	2018.11.19.20.05.37;	author aymeric;	state Exp;
branches;
next	1.18;
commitid	ZihtYtNPFtz4LA0B;

1.18
date	2018.10.07.18.07.00;	author martin;	state Exp;
branches;
next	1.17;
commitid	gQYRRwyt39tjv3VA;

1.17
date	2017.02.11.08.08.00;	author pgoyette;	state Exp;
branches
	1.17.10.1
	1.17.12.1;
next	1.16;
commitid	Q8Q3esalvRikzvFz;

1.16
date	2017.02.11.04.19.25;	author christos;	state Exp;
branches;
next	1.15;
commitid	SfAkvT6PdSQ9juFz;

1.15
date	2017.02.11.03.07.06;	author christos;	state Exp;
branches;
next	1.14;
commitid	RQbVHlgh5ObhUtFz;

1.14
date	2017.02.10.16.43.59;	author christos;	state Exp;
branches;
next	1.13;
commitid	uUOMTOtplR3gsqFz;

1.13
date	2017.01.24.18.01.07;	author christos;	state Exp;
branches;
next	1.12;
commitid	SLJQs8A3dr4TqfDz;

1.12
date	2015.11.25.00.50.57;	author christos;	state Exp;
branches
	1.12.2.1
	1.12.4.1;
next	1.11;
commitid	WuiQNbD0f3DSppKy;

1.11
date	2015.05.08.17.46.03;	author riastradh;	state Exp;
branches;
next	1.10;
commitid	156pJgFrWYodvFky;

1.10
date	2015.03.12.04.41.23;	author snj;	state Exp;
branches;
next	1.9;
commitid	H0IfvOk4ogivWgdy;

1.9
date	2014.08.05.15.40.58;	author apb;	state Exp;
branches
	1.9.2.1;
next	1.8;
commitid	1Qp6Y0KwxUnrGbLx;

1.8
date	2014.01.27.21.37.17;	author apb;	state Exp;
branches
	1.8.2.1;
next	1.7;
commitid	SgiF2B7757TFKNmx;

1.7
date	2014.01.16.01.15.32;	author christos;	state Exp;
branches;
next	1.6;
commitid	eohV5AOa1lR3mhlx;

1.6
date	2012.04.22.07.23.42;	author tsutsui;	state Exp;
branches
	1.6.2.1;
next	1.5;

1.5
date	2012.04.22.05.24.39;	author tsutsui;	state Exp;
branches;
next	1.4;

1.4
date	2012.04.09.19.22.49;	author riz;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2012.01.22.16.56.22;	author tsutsui;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2012.01.22.16.50.00;	author tsutsui;	state Exp;
branches;
next	1.1;

1.1
date	2012.01.22.03.53.30;	author tsutsui;	state Exp;
branches;
next	;

1.46.2.1
date	2026.01.22.20.24.45;	author martin;	state Exp;
branches;
next	1.46.2.2;
commitid	uJonHgpYLQBxDqrG;

1.46.2.2
date	2026.01.25.16.21.33;	author martin;	state Exp;
branches;
next	1.46.2.3;
commitid	n6F4VtC9c0M7cNrG;

1.46.2.3
date	2026.01.25.16.31.07;	author martin;	state Exp;
branches;
next	;
commitid	JVDLNyIyKEjpfNrG;

1.41.2.1
date	2025.08.02.05.20.20;	author perseant;	state Exp;
branches;
next	;
commitid	23j6GFaDws3O875G;

1.30.2.1
date	2025.02.20.19.13.29;	author martin;	state Exp;
branches;
next	;
commitid	I2oIxkbnzYzH2fKF;

1.26.4.1
date	2021.06.06.20.30.44;	author cjep;	state Exp;
branches;
next	;
commitid	XNEGuB48YPLw17WC;

1.21.2.1
date	2019.11.17.07.04.34;	author martin;	state Exp;
branches;
next	1.21.2.2;
commitid	fmdLX9M716eYMaLB;

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

1.17.10.1
date	2018.10.20.06.58.17;	author pgoyette;	state Exp;
branches;
next	1.17.10.2;
commitid	mTSoqZEZ4arHnFWA;

1.17.10.2
date	2018.11.26.01.49.56;	author pgoyette;	state Exp;
branches;
next	1.17.10.3;
commitid	Zj4q5SspGdKXto1B;

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

1.17.12.1
date	2019.06.10.21.42.20;	author christos;	state Exp;
branches;
next	1.17.12.2;
commitid	jtc8rnCzWiEEHGqB;

1.17.12.2
date	2020.04.08.14.03.44;	author martin;	state Exp;
branches;
next	1.17.12.3;
commitid	Qli2aW9E74UFuA3C;

1.17.12.3
date	2020.04.13.07.45.25;	author martin;	state Exp;
branches;
next	;
commitid	X01YhRUPVUDaec4C;

1.12.2.1
date	2017.03.20.06.52.04;	author pgoyette;	state Exp;
branches;
next	;
commitid	jjw7cAwgyKq7RfKz;

1.12.4.1
date	2017.04.21.16.51.09;	author bouyer;	state Exp;
branches;
next	;
commitid	dUG7nkTKALCadqOz;

1.9.2.1
date	2015.07.30.15.40.14;	author snj;	state Exp;
branches;
next	;
commitid	ToiIoqh1QLuG8kvy;

1.8.2.1
date	2014.08.10.06.47.57;	author tls;	state Exp;
branches;
next	;
commitid	IkL6EwFPM07DzMLx;

1.6.2.1
date	2014.08.19.23.45.38;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.4.2.1
date	2012.04.09.19.22.49;	author yamt;	state dead;
branches;
next	1.4.2.2;

1.4.2.2
date	2012.04.17.00.02.32;	author yamt;	state Exp;
branches;
next	1.4.2.3;

1.4.2.3
date	2012.05.23.10.07.08;	author yamt;	state Exp;
branches;
next	1.4.2.4;

1.4.2.4
date	2014.05.22.12.01.27;	author yamt;	state Exp;
branches;
next	;
commitid	yqlfOuaAhYmASwBx;

1.3.2.1
date	2012.05.09.19.58.27;	author riz;	state Exp;
branches;
next	;


desc
@@


1.50
log
@bootimage: allow MD Makefiles to add a port-specific boot partition

Some ports require an additional port-specific boot partition even
for live images so that firmware ROMs can load a bootloader.
For example, luna68k ROMs require old 4.3-BSD style FFS, and hp300
ROMs require an HP LIF format diretory entries.

Add a USE_MDBOOTPART switch and adjust size/offset calculations and
image concatination so MD liveimage Makefiles can provide own rules
to build and populate the boot-partition image.
@
text
@#	$NetBSD: Makefile.bootimage,v 1.49 2026/01/16 23:37:19 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)
#	USE_GPTMBR
#		set yes if target disk image requires GPT partition
#		with hybrid MBR boot code
#		(default: no; valid only if USE_GPT=yes)
#	USE_MDBOOTPART
#		set yes if target disk image requires port specific
#		boot partition
#		(default: no; if yes target rules of WORKMDBOOTPART should
#		 be defined in MD liveimage/Makefiles)
#	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
#		set yes if the target ${MACHINE} requires disklabel
#		to run installboot(8), like hp300 and vax
#		(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)
#	FATMB
#		FAT partition size in target image in MB
#		(default: 0)
#	MDBOOTPARTMB
#		port specific boot partition size in target image in MB
#		(default: 0)
#	GPTSECTORS
#		Size of a region reserved for the secondary GPT table/entry
#		at the end of the target image in sectors
#		(default: 2048 if USE_GPT=yes, otherwise 0)
#	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 gpufw man manhtml 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)
#	IMGFFSVERSION
#		version of FFS created by makefs(8)
#		(default: 1)
#	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)
#	EFIBOOT
#		EFI bootloader
#		(default: empty)
#	MBRFAT
#		MBR partition type value for FAT
#		(default: 6 ("16-bit FAT, more than 32M"))
#	FATMAKEFSOPTIONS
#		options passed to makefs(8) to create a FAT partition
#		(default: -o fat_type=16)
#	FATFILES
#		list of additional files to be copied into FAT partition
#		(default: empty)
#	IMAGEHOSTNAME
#		if set, sets the default hostname in rc.conf (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

MAKESPEC=	${HOST_SH} ${NETBSDSRCDIR}/etc/makespec

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

#
# size parameters for image
#
IMAGEMB?=	2048		# 2048MB
SWAPMB?=	128		# 128MB
.if ${USE_GPT} == "no"
EFIMB?=		0
GPTSECTORS=	0
.else
EFIMB?=		128		# 128MB
GPTSECTORS=	2048
.endif
FATMB?=		0
MDBOOTPARTMB?=	0

# 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
FATSECTORS!=	expr ${FATMB} \* 1024 \* 1024 / 512 || true

.if ${USE_MDBOOTPART} != "no"
MDBOOTPARTSECTORS!=	expr ${MDBOOTPARTMB} \* 1024 \* 1024 / 512 || true
.else
MDBOOTPARTSECTORS=	0
.endif

.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

.if ${USE_MDBOOTPART} != "no"
MDBOOTPARTOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} \
			    || test $$? -eq 1 || exit 1
.else
MDBOOTPARTOFFSET=	0
.endif

FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} \
		    - ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
FSSIZE!=	expr ${FSSECTORS} \* 512 || test $$? -eq 1 || exit 1

# 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
MBRFAT?=	6	# 16-bit FAT, more than 32M

BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} \
		    - ${MDBOOTPARTSECTORS}
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} \
		    + ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} \
		    + ${EFISECTORS} + ${FATSECTORS} \
		    + ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
FATOFFSET=	${LABELSECTORS}

# helper script for sunlabel
DISKPROTO2SUNLABEL?=	${DISTRIBDIR}/common/bootimage/diskproto2sunlabel.awk

.if ${USE_GPT} != "no"
BOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
SWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'`
.endif

#
# definitions to create root fs
#
SETS_DEFAULT=	modules base etc comp games gpufw man misc rescue text
.if ${MKATF} != "no"
SETS_DEFAULT+=	tests
.endif
.if ${MKCOMPAT} != "no"
SETS_DEFAULT+=	base32
.endif
.if ${MKCOMPAT} != "no" && \
    (${MACHINE_ARCH} == "mips64eb" || ${MACHINE_ARCH} == "mips64el")
SETS_DEFAULT+=	base64
.endif
.if ${MKHTML} != "no"
SETS_DEFAULT+=	manhtml
.endif
.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
.if ${KERNEL_DIR:Uno} == "yes"
SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec-dir.in
.else
SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec.in
.endif

IMGMAKEFSOPTIONS?=	-o bsize=16384,fsize=2048,density=8192
IMGFFSVERSION?=		1
FATMAKEFSOPTIONS?=	-o fat_type=16

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}

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

MBR_DEFAULT_BOOTCODE?=	mbr

WORKMBR?=	work.mbr
WORKMBRTRUNC?=	work.mbr.truncated
WORKSWAP?=	work.swap
WORKEFI?=	work.efi
WORKGPT?=	work.gpt
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img
EFIWORKDIR?=	work.efidir
WORKFAT?=	work.fat
WORKFATDIR?=	work.fatdir
WORKMDBOOTPART?= work.mdbootpart
WORKMDBOOTPARTDIR?= work.mdbootpartdir

.if ${USE_GPT} != "no"
${WORKFSTAB}: ${WORKMBR}

.BEGIN:
	@@if [ -f ${WORKMBR} ]; then			 		\
		st_size=`${TOOL_STAT} -f %z ${WORKMBR}`;		\
		if [ "$$st_size" -ne "$$((${IMAGESECTORS} * 512))" ]; then \
			echo Removing stale ${WORKMBR} ...;		\
			rm -f ${WORKMBR};				\
		fi							\
	fi
.endif

${WORKFSTAB}:
	@@echo Preparing /etc/fstab ...
.if ${USE_GPT} != "no"
.  if ${SWAPSECTORS} != 0
	${TOOL_SED}							\
	    -e "s/ROOT.a/NAME=NBImgRoot/"				\
	    -e "s/ROOT.b/NAME=NBImgSwap/"				\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.  else
	${TOOL_SED}							\
	    -e "s/ROOT.a/NAME=NBImgRoot/"				\
	    -e "/ROOT.b/d"						\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.  endif
.else
.  if ${SWAPSECTORS} != 0
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
.  else
	${TOOL_SED}							\
	    -e "/ROOT.b/d"						\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.  endif
.endif

#
# create root file system for the image
#
${TARGETFS}: prepare_md_post ${WORKFSTAB}
	@@${RM} -f ${WORKSPEC}
	@@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
	${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}
.if defined(IMAGEHOSTNAME)
	@@echo Setting hostname=${IMAGEHOSTNAME} in /etc/rc.conf ...
	echo "hostname=${IMAGEHOSTNAME}" >> ${WORKRCCONF}
.endif
.if ${SWAPSECTORS} == 0
	@@echo Setting no_swap=YES in /etc/rc.conf ...
	echo "no_swap=YES" >> ${WORKRCCONF}
	@@echo Setting savecore=NO in /etc/rc.conf ...
	echo "savecore=NO" >> ${WORKRCCONF}
.endif
.if defined(RC_CONF_EXTRA)
	@@echo Adding contents of ${RC_CONF_EXTRA} to /etc/rc.conf ...
	cat ${RC_CONF_EXTRA} >> ${WORKRCCONF}
.endif
	${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}; \
		echo "./${_TARGET} type=file uname=root gname=wheel mode=0555" >> ${WORKSPEC}; \
	fi
.endfor
.endif
	@@echo Preparing spec files for makefs...
	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
	for i in ${WORKDIR}/netbsd.*; do \
	    if [ -e $$i ]; then \
		echo "./$$(basename $$i) type=file uname=root gname=wheel mode=0444" >> ${WORKSPEC}; \
	    fi; \
	done
	if [ -d ${WORKDIR}/${RELEASEMACHINEDIR} ]; then \
	    ${MAKESPEC} -d ${WORKDIR} ${RELEASEMACHINEDIR} >> ${WORKSPEC}; \
	fi
	@@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}					\
	    -xx -F ${WORKSPEC} -N ${WORKDIR}/etc			\
	    ${MAKEFS_TIMESTAMP}						\
	    -t ffs							\
	    ${IMGMAKEFSOPTIONS}						\
	    -o version=${IMGFFSVERSION}					\
	    ${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}

TARGET_BLOCKS=
.if ${USE_MBR} != "no" || ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKMBRTRUNC}
.endif
.if ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKEFI}
.endif
.if ${FATSECTORS} != 0
TARGET_BLOCKS+=	${WORKFAT}
.endif
.if ${USE_MDBOOTPART} != "no"
TARGET_BLOCKS+=	${WORKMDBOOTPART}
.endif
TARGET_BLOCKS+=	 ${TARGETFS}
.if ${SWAPSECTORS} != 0
TARGET_BLOCKS+=	${WORKSWAP}
.endif
.if ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKGPT}
.endif

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

${WORKSWAP}:
.if ${SWAPSECTORS} == 0
	printf "" > ${WORKSWAP}
.else
	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
.endif

${WORKMBRTRUNC}: ${WORKMBR}
	${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC}

${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}/"		\
	    -e "s/@@@@FATSECTORS@@@@/${FATSECTORS}/"			\
	    -e "s/@@@@FATOFFSET@@@@/${FATOFFSET}/"				\
	    -e "s/@@@@MDBOOTPARTSECTORS@@@@/${MDBOOTPARTSECTORS}/"		\
	    -e "s/@@@@MDBOOTPARTOFFSET@@@@/${MDBOOTPARTOFFSET}/"		\
	    < ${DISKPROTO_IN} > ${WORKLABEL}.tmp
	mv ${WORKLABEL}.tmp ${WORKLABEL}

${WORKEFI}: ${TARGETFS}
	@@echo create EFI system partition...
	@@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
.for f in ${EFIBOOT}
	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
.endfor
	${RM} -f ${WORKEFI}
	${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m			\
	    ${MAKEFS_TIMESTAMP}						\
	    -t msdos -o F=32,c=1					\
	    ${WORKEFI} ${EFIWORKDIR}

.if defined(FATFILES)
${FATFILES}: ${TARGETFS}
	# Some MD ${FATFILES} (bootloaders etc.) are assumed extracted
	# to ${WORKDIR} from binary sets during ${TARGETFS} image build
.endif

${WORKFAT}: ${FATFILES}
	@@echo create FAT partition for bootstrap files...
	@@${MKDIR} ${MKDIRPERM} ${WORKFATDIR}
.if defined(FATFILES)
	@@echo Copying files for FAT partition...
.for f in ${FATFILES}
	@@if [ ! -f ${f} ]; then 					\
		echo "${f} in FATFILES not found, aborting";		\
		false; 							\
	fi
	${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR}
.endfor
.endif
	${RM} -f ${WORKFAT}
	${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m			\
	    ${MAKEFS_TIMESTAMP}						\
	    -t msdos							\
	    ${FATMAKEFSOPTIONS}						\
	    ${WORKFAT} ${WORKFATDIR}

${WORKMBR}:
.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_TIMESTAMP} ${WORKMBR} create
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system"
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs -l "NBImgRoot"
.  if ${SWAPSECTORS} != 0
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap -l "NBImgSwap"
.  endif
.elif ${USE_MBR} != "no"
	@@echo creating MBR labels...
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
.  if ${FATSECTORS} != 0
	# create BSD partition
	${TOOL_FDISK} -f -i -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -F ${WORKMBR}
	# create FAT partition
	${TOOL_FDISK} -f -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS}			\
	    -F ${WORKMBR}
.  else
	# create BSD partition
	${TOOL_FDISK} -f -i -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -F ${WORKMBR}
.  endif
.  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
.endif

${WORKGPT}: ${WORKMBR}
	@@echo create GPT image...
	${DD} if=${WORKMBR} of=${WORKGPT} \
	    skip=$$((${IMAGESECTORS} - ${GPTSECTORS})) count=${GPTSECTORS}

.if ${USE_GPT} == "no"
${IMGBASE}.img:	${WORKLABEL}
.endif

${IMGBASE}.img:	${TARGET_BLOCKS}
	${CAT} ${TARGET_BLOCKS} > ${WORKIMG}
.if ${USE_GPT} != "no"
.if ${USE_GPTMBR} != "no"
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKIMG} biosboot -i 2		\
	    -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin
.endif
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKIMG} set -a bootme -i 2
.endif	# USE_GPT != "no"
.if ${USE_SUNLABEL} != "no"
	@@echo Creating sun disklabel...
	${TOOL_AWK} -f ${DISKPROTO2SUNLABEL} < ${WORKLABEL} | \
	    ${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}
	${RM} -fr ${WORKFATDIR}
	${RM} -fr ${WORKMDBOOTPARTDIR}

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

.include <bsd.prog.mk>
@


1.49
log
@bootimage: make ${FATFILES} dependency more explicit for readability

Only add the FATFILES -> TARGETFS dependency in Makefile.bootimage
when FATFILES is defined in MD Makefiles.

This makes the optional nature of FATFILES clearer for MD ports and
avoids relying on empty-target handling as an implicit make(1) behavior.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.48 2026/01/14 11:42:43 tsutsui Exp $
d47 5
d78 3
d193 1
d210 1
d218 6
d232 7
d240 2
a241 1
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} || test $$? -eq 1 || exit 1
d256 4
a259 2
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} || test $$? -eq 1 || exit 1
d261 2
a262 1
		    + ${EFISECTORS} + ${FATSECTORS} || test $$? -eq 1 || exit 1
d351 2
d511 3
d525 1
d553 2
d692 1
@


1.48
log
@bootimage: fix a build error of zaurus live-image on parallel build

Add an explicit dependency of ${FATFILES} on ${TARGETFS} since
necessary files are assumed to be extracted during ${TARGETFS} image
build (not sure how it worked before).

Should be pulled up to netbsd-11.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.47 2026/01/13 14:09:02 tsutsui Exp $
d535 1
d539 1
@


1.47
log
@bootimage: Derive sunlabel(8) input from the disklabel protofile

For USE_SUNLABEL labeling, stop hard-coding the sunlabel(8) geometry
in cylinders in Makefile.bootimage.  Instead, generate the sunlabel(8)
command stream by parsing the generated disklabel protofile with
a small awk helper.

This keeps the Sun disk label consistent with the disklabel(8) protofile
and avoids maintaining two independent sets of geometry/partition logic.

Tested with a sun3 live-image on TME.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.46 2025/04/26 03:01:39 pgoyette Exp $
d535 5
a539 1
${WORKFAT}: ${TARGETFS} ${FATFILES}
@


1.46
log
@Add new file-system spec.in for KERNEL_DIR=yes
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.45 2025/02/02 03:19:37 tsutsui Exp $
d238 2
a239 3
# parameters for sunlabel
FSCYLINDERS!=	expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)
SWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true
d626 1
a626 3
	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} | \
@


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

	distrib/common/bootimage/Makefile.bootimage: revision 1.47
	distrib/common/bootimage/diskproto2sunlabel.awk: revision 1.1

bootimage: Derive sunlabel(8) input from the disklabel protofile

For USE_SUNLABEL labeling, stop hard-coding the sunlabel(8) geometry
in cylinders in Makefile.bootimage.  Instead, generate the sunlabel(8)
command stream by parsing the generated disklabel protofile with
a small awk helper.

This keeps the Sun disk label consistent with the disklabel(8) protofile
and avoids maintaining two independent sets of geometry/partition logic.

Tested with a sun3 live-image on TME.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.46 2025/04/26 03:01:39 pgoyette Exp $
d238 3
a240 2
# helper script for sunlabel
DISKPROTO2SUNLABEL?=	${DISTRIBDIR}/common/bootimage/diskproto2sunlabel.awk
d627 3
a629 1
	${TOOL_AWK} -f ${DISKPROTO2SUNLABEL} < ${WORKLABEL} | \
@


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

	distrib/common/bootimage/Makefile.bootimage: revision 1.48
	distrib/common/bootimage/Makefile.bootimage: revision 1.49

bootimage: fix a build error of zaurus live-image on parallel build

Add an explicit dependency of ${FATFILES} on ${TARGETFS} since
necessary files are assumed to be extracted during ${TARGETFS} image
build (not sure how it worked before).

bootimage: make ${FATFILES} dependency more explicit for readability

Only add the FATFILES -> TARGETFS dependency in Makefile.bootimage
when FATFILES is defined in MD Makefiles.

This makes the optional nature of FATFILES clearer for MD ports and
avoids relying on empty-target handling as an implicit make(1) behavior.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.46.2.1 2026/01/22 20:24:45 martin Exp $
d535 1
a535 7
.if defined(FATFILES)
${FATFILES}: ${TARGETFS}
	# Some MD ${FATFILES} (bootloaders etc.) are assumed extracted
	# to ${WORKDIR} from binary sets during ${TARGETFS} image build
.endif

${WORKFAT}: ${FATFILES}
@


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

	distrib/luna68k/liveimage/fstab.in: revision 1.1
	distrib/common/bootimage/Makefile.bootimage: revision 1.50
	distrib/luna68k/Makefile: revision 1.3
	distrib/luna68k/liveimage/spec.in: revision 1.1
	distrib/luna68k/liveimage/Makefile: revision 1.1
	distrib/luna68k/liveimage/Makefile: revision 1.2
	distrib/luna68k/liveimage/diskproto.in: revision 1.1
	distrib/luna68k/liveimage/spec.boot.in: revision 1.1

bootimage: allow MD Makefiles to add a port-specific boot partition

Some ports require an additional port-specific boot partition even
for live images so that firmware ROMs can load a bootloader.

For example, luna68k ROMs require old 4.3-BSD style FFS, and hp300
ROMs require an HP LIF format diretory entries.
Add a USE_MDBOOTPART switch and adjust size/offset calculations and
image concatination so MD liveimage Makefiles can provide own rules
to build and populate the boot-partition image.
distrib/luna68k: add "build.sh live-image" support for luna68k

Using recently added "USE_MDBOOTPART" in Makefile.bootimage with MD rules.

A generated live-image is confirmed working on nono 1.6.4 with LUNA's ROM:
---
% nono-cli -V vmtype=luna -V prom-image=LUNAROM.DAT -V dipsw-autoboot=no -V dipsw-serial=yes -V hostcom-driver=stdio -V spc0-id6-image=hd,NetBSD-11.99.5-luna68k-live.img -V spc0-id6-writeignore=1
(PROM) Unknown PROM version
(SCSIHD6) write is ignored
Diagnostic Start....  11.549'836'096 805b XP(HD647180) WriteInternalIO 53H(DERA) <- $07 (NOT IMPLEMENTED)
  11.549'839'519 8060 XP(HD647180) WriteInternalIO 60H(IODRA) <- $50 (NOT IMPLEMENTED)
  11.549'842'942 8065 XP(HD647180) WriteInternalIO 70H(DDRA) <- $70 (NOT IMPLEMENTED)
  11.650'402'532 8528 XP(HD647180) WriteInternalIO 60H(IODRA) <- $20 (NOT IMPLEMENTED)
  11.653'401'080 8bd1 XP(HD647180) ReadInternalIO 48H(T2CSR1) -> $ff (NOT IMPLEMENTED)
  11.653'404'340 8bd6 XP(HD647180) WriteInternalIO 48H(T2CSR1) <- $ff (NOT IMPLEMENTED)
  11.653'406'785 8bd9 XP(HD647180) ReadInternalIO 49H(T2CSR2) -> $ff (NOT IMPLEMENTED)
  11.653'410'045 8bde XP(HD647180) WriteInternalIO 49H(T2CSR2) <- $ff (NOT IMPLEMENTED)
No problems in hardware
OMRON WS Monitor Ver4.25 (Thu May 16 11:54:02 1991) - 0x01000000 bytes of memory
"BSD Monitor-mode"
k
ctlr: dk
drv: 0
par: c  d
fnam: vmunix  boot
g
SPC RESET CONDITION !!
x
> NetBSD/luna68k boot, Revision 1.12 (Sat Jan 17 07:19:27 UTC 2026)
> (based on Stinger ver 0.0 [Phase-31])
Machine model   = LUNA-I
Physical Memory = 0x1000000  (16 MB)
sc0 at 0xe1000000: async, parity, ID 7
 ID 6: NONO SCSIHD rev 0, 512 bytes/sect x 3145728 sectors
le0: Am7990 LANCE Ethernet, mem at 0x71010000
le0: Ethernet address = 00:00:0a:02:4d:36
Press return to boot now, any other key for boot menu
booting sd(6,0)netbsd - starting in 0 seconds.
type "help" for help.
boot> boot -s
Booting sd(6,0)netbsd (howto 0x2)
2358892+97604 [336560+209989]=0x2dd6c8
[   1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
[   1.0000000]     2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
[   1.0000000]     2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023,
[   1.0000000]     2024, 2025, 2026
[   1.0000000]     The NetBSD Foundation, Inc.  All rights reserved.
[   1.0000000] Copyright (c) 1982, 1986, 1989, 1991, 1993
[   1.0000000]     The Regents of the University of California.  All rights reserved.
[   1.0000000] NetBSD 11.99.5 (GENERIC) #0: Sat Jan 17 16:26:14 JST 2026
[   1.0000000]  tsutsui@@proslim:/home/tsutsui/obj.luna68k/sys/arch/luna68k/compile/GENERIC
[   1.0000000] LUNA-I (MC68030 CPU+MMU, MC68881 FPU)
 :

luna68k/liveimage: fix live-image build errors on non-NetBSD hosts
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.46.2.2 2026/01/25 16:21:33 martin Exp $
a46 5
#	USE_MDBOOTPART
#		set yes if target disk image requires port specific
#		boot partition
#		(default: no; if yes target rules of WORKMDBOOTPART should
#		 be defined in MD liveimage/Makefiles)
a72 3
#	MDBOOTPARTMB
#		port specific boot partition size in target image in MB
#		(default: 0)
a184 1
USE_MDBOOTPART?= no
a200 1
MDBOOTPARTMB?=	0
a207 6
.if ${USE_MDBOOTPART} != "no"
MDBOOTPARTSECTORS!=	expr ${MDBOOTPARTMB} \* 1024 \* 1024 / 512 || true
.else
MDBOOTPARTSECTORS=	0
.endif

a215 7
.if ${USE_MDBOOTPART} != "no"
MDBOOTPARTOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} \
			    || test $$? -eq 1 || exit 1
.else
MDBOOTPARTOFFSET=	0
.endif

d217 1
a217 2
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} \
		    - ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
d232 2
a233 4
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} \
		    - ${MDBOOTPARTSECTORS}
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} \
		    + ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
d235 1
a235 2
		    + ${EFISECTORS} + ${FATSECTORS} \
		    + ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
a323 2
WORKMDBOOTPART?= work.mdbootpart
WORKMDBOOTPARTDIR?= work.mdbootpartdir
a481 3
.if ${USE_MDBOOTPART} != "no"
TARGET_BLOCKS+=	${WORKMDBOOTPART}
.endif
a492 1
CLEANFILES+=	${WORKMDBOOTPART}
a519 2
	    -e "s/@@@@MDBOOTPARTSECTORS@@@@/${MDBOOTPARTSECTORS}/"		\
	    -e "s/@@@@MDBOOTPARTOFFSET@@@@/${MDBOOTPARTOFFSET}/"		\
a656 1
	${RM} -fr ${WORKMDBOOTPARTDIR}
@


1.45
log
@Use FFSv2 for amd64 live-image and install-image via new $IMGFFSVERSION.

Fixes PR/59007.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.44 2025/01/18 09:07:14 tsutsui Exp $
d274 3
d278 1
@


1.44
log
@FAT (for ESP) is always LE so "-B endian" for makefs(8) is not necessary.

(not sure if there is any "EFI on big endian CPU" system though)
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.43 2025/01/10 18:11:56 tsutsui Exp $
d116 3
d277 1
d458 1
d460 1
@


1.43
log
@Remove "(untested)" comment from INSTALLBOOT_AFTER_DISKLABEL.

Also note vax requires it.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.42 2024/12/31 06:58:00 jmmv Exp $
a521 1
	    -B ${TARGET_ENDIANNESS}					\
@


1.42
log
@Do not include tests in boot images if MKATF=no
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.41 2024/06/26 09:13:47 martin Exp $
d57 1
a57 1
#	INSTALLBOOT_AFTER_DISKLABEL (untested)
d59 1
a59 1
#		to run installboot(8), like hp300
@


1.41
log
@Now that we label GPT partitions, adjust the generated fdisk to match.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.40 2024/06/25 09:07:14 martin Exp $
d247 4
a250 1
SETS_DEFAULT=	modules base etc comp games gpufw man misc rescue tests text
@


1.41.2.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.46 2025/04/26 03:01:39 pgoyette Exp $
d57 1
a57 1
#	INSTALLBOOT_AFTER_DISKLABEL
d59 1
a59 1
#		to run installboot(8), like hp300 and vax
a115 3
#	IMGFFSVERSION
#		version of FFS created by makefs(8)
#		(default: 1)
d247 1
a247 4
SETS_DEFAULT=	modules base etc comp games gpufw man misc rescue text
.if ${MKATF} != "no"
SETS_DEFAULT+=	tests
.endif
a267 3
.if ${KERNEL_DIR:Uno} == "yes"
SPEC_IN?=	${DISTRIBDIR}/common/bootimage/spec-dir.in
.else
a268 1
.endif
a270 1
IMGFFSVERSION?=		1
a450 1
	    -t ffs							\
a451 1
	    -o version=${IMGFFSVERSION}					\
d519 1
@


1.40
log
@Short the root wedge name to NBImgRoot (to get NAME=NBImgRoot below 16 chars
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.39 2024/06/25 08:59:52 martin Exp $
d333 2
a334 2
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
	    -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/"			\
d338 1
a338 1
	    -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/"			\
d553 1
a553 1
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
@


1.39
log
@Previous did not work out well - ${INSTIMGBASE} was not always set here
and spaces in the label name confuse the (over simplistic) xen command
line parser. Use (fixed) "NetBSD_ImageRoot" instead for the root partition.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.38 2024/06/24 07:43:33 martin Exp $
d551 1
a551 1
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs -l "NetBSD_ImageRoot"
@


1.38
log
@Try to give the root partition a usable (but unique enough) name
if we use GPT. This helps when booting without a bootloader (e.g. in
qemu) and passing boot arguments to identify the root partition.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.37 2024/05/18 02:03:17 christos Exp $
d551 1
a551 1
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs -l "${INSTIMGBASE} root"
@


1.37
log
@include all extra flavors of the kernel and use the proper variable for
the machine dependent installation directory.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.36 2024/05/16 15:46:42 christos Exp $
d551 1
a551 1
	${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs
@


1.36
log
@Apply the -xx treatment to the rest of the ffs makefs invocations.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.35 2024/04/22 14:41:24 nia Exp $
d436 7
a442 6
	if [ -f ${WORKDIR}/netbsd.gdb ]; then \
	    echo "./netbsd.gdb type=file uname=root gname=wheel mode=0444" \
	    >> ${WORKSPEC}; \
	fi
	if [ -d ${WORKDIR}/${MACHINE} ]; then \
	    ${MAKESPEC} -d ${WORKDIR} ${MACHINE} >> ${WORKSPEC}; \
@


1.35
log
@Move MIPS N64 compat out of {base,debug}32 into {base,debug}64

martin requested separation by ABI and it doesn't make much sense
to have 64-bit binaries in a set called 32.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.34 2024/04/09 15:17:21 nia Exp $
d174 2
d356 1
d419 1
a423 1
	${RM} -f ${WORKSPEC}
d436 7
d448 1
a448 1
	    -F ${WORKSPEC} -N ${WORKDIR}/etc				\
@


1.34
log
@Add new sets: base32, debug32, manhtml

- base32 contains (when MKCOMPAT=yes) shared libraries for 32-bit
  compatibility, previously included in base

- debug32 contains (when MKCOMPAT=yes) debug symbols and static libraries
  containing debug symbols for 32-bit compatiblity, previously included
  in debug

- manhtml contains (when MKHTML=yes) the HTML files previously included
  in 'man', which are of limited utility without third-party software.

The motivation for this change is to be able to easily exclude sets
from CD-ROM images that go over the size limit without xz compression
(which many NetBSD platforms struggle to extract at acceptable speeds).
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.33 2024/02/08 18:14:02 christos Exp $
d249 4
@


1.33
log
@PR/57910: Jan-Benedict Glaw: Fix typo preventing reproducible builds
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.32 2023/12/03 07:20:23 tsutsui Exp $
d82 1
a82 1
#		(default: modules base etc comp games gpufw man misc
d246 6
@


1.32
log
@Use defined ${GPTSECTORS} rather than hardcoded 2048.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.31 2023/12/03 07:17:11 tsutsui Exp $
d238 2
a239 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}'`
d528 3
a530 3
	${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
d532 1
a532 1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
d587 1
a587 1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2		\
d590 1
a590 1
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2
@


1.31
log
@Document USE_GPTMBR and GPTSECTORS.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.30 2022/05/15 00:05:24 mrg Exp $
d576 2
a577 2
	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
	    count=2048
@


1.30
log
@allow some invocations of expr(1) to "fail" - expr(1) returns "1" is
the expression expands to "0" or empty, and sometimes these values end
up correctly being 0.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.29 2021/09/25 08:54:29 maya Exp $
d43 4
d73 4
@


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

	distrib/vax/liveimage/emuimage/Makefile: revision 1.5
	distrib/common/bootimage/Makefile.bootimage: revision 1.43

It turns out vax liveimage requires INSTALLBOOT_AFTER_DISKLABEL.

It looks tools disklabel(8) doesn't preserve installed bootblock
on creating a new label.  Confirmed on simh.

Remove "(untested)" comment from INSTALLBOOT_AFTER_DISKLABEL.
Also note vax requires it.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.30 2022/05/15 00:05:24 mrg Exp $
d53 1
a53 1
#	INSTALLBOOT_AFTER_DISKLABEL
d55 1
a55 1
#		to run installboot(8), like hp300 and vax
@


1.29
log
@Move DRM-driver firmware from base to its own set, gpufw

This set is only installed on amd64,i386,evbarm.
This set is installed on minimal installs and on install media, in
case someone needs it for basic driver functionality.

Comments:
Switched to a single MK tunable for it - that is probably unneeded.

An upcoming DRM update will include even fatter firmware, and we'd
like to minimize the impact of it.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.28 2021/07/24 13:59:28 jmcneill Exp $
d204 2
a205 2
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
FSSIZE!=	expr ${FSSECTORS} \* 512
d220 1
a220 1
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS}
d222 1
a222 1
		    + ${EFISECTORS} + ${FATSECTORS}
@


1.28
log
@bootimage: allow appending additional rc.conf options

If RC_CONF_EXTRA is defined, append the contents of this file to the
target file-system's rc.conf
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.27 2021/06/04 17:09:36 tsutsui Exp $
d74 2
a75 2
#		(default: modules base etc comp games man misc rescue tests
#			  text xbase xcomp xetc xfont xserver)
d237 1
a237 1
SETS_DEFAULT=	modules base etc comp games man misc rescue tests text
@


1.27
log
@Check and remove a stale work file for UEFI images with incorrect size.

Fixes PR/56132 (build.sh target install-image fails in update-mode).
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.26 2020/08/05 01:35:18 jmcneill Exp $
d369 4
@


1.26
log
@Add support for EC2 and resize root to AMD64 live images.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.25 2020/05/28 15:13:21 jmcneill Exp $
d297 9
@


1.26.4.1
log
@sync with head
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.27 2021/06/04 17:09:36 tsutsui Exp $
a296 9

.BEGIN:
	@@if [ -f ${WORKMBR} ]; then			 		\
		st_size=`${TOOL_STAT} -f %z ${WORKMBR}`;		\
		if [ "$$st_size" -ne "$$((${IMAGESECTORS} * 512))" ]; then \
			echo Removing stale ${WORKMBR} ...;		\
			rm -f ${WORKMBR};				\
		fi							\
	fi
@


1.25
log
@Only install gptmbr.bin if USE_GPTMBR=yes
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.24 2020/03/21 14:19:26 tsutsui Exp $
d138 2
d350 10
@


1.24
log
@Add "live-image with a FAT partition for bootstrap files" support.

See PR/55075 for more details.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.23 2019/11/21 22:29:03 joerg Exp $
d169 1
d553 1
d556 1
@


1.23
log
@Merge amd64's UEFI logic back into the generic bootimage handling.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.12 2019/10/02 11:15:59 maya Exp $
d66 3
d129 9
d184 1
d190 1
d201 1
a201 1
		    - ${EFISECTORS} - ${GPTSECTORS}
d213 1
d215 6
a220 3
BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} - ${EFISECTORS} - ${GPTSECTORS}
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} + ${EFISECTORS}
d248 1
d289 2
d412 3
d425 1
d451 2
d469 20
d503 13
d520 1
d584 1
@


1.22
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
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.21 2019/02/22 22:13:58 tsutsui Exp $
d40 3
d63 3
d123 3
a125 3
#	OMIT_SWAPIMG
#		no need to put swap partition into image (for USB stick)
#		(default: no)
d135 1
d156 1
d165 7
d176 1
d178 1
a178 1
.if ${USE_MBR} == "no"
d186 2
a187 1
FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}
d200 3
a202 3
BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS}
FSOFFSET=	${LABELSECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS}
d208 4
d244 56
d302 1
a302 1
${TARGETFS}: prepare_md_post
a321 2
	@@echo Preparing /etc/fstab ...
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
d384 13
a396 7
#
# definitions to create image
#
.if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
.else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
d399 4
a402 1
MBR_DEFAULT_BOOTCODE?=	mbr
d404 6
a409 6
OMIT_SWAPIMG?=	no

WORKMBR?=	work.mbr
WORKSWAP?=	work.swap
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img
d411 2
a412 3
CLEANFILES+=	${WORKMBR} ${WORKSWAP}
CLEANFILES+=	${WORKLABEL}.tmp ${WORKLABEL}
CLEANFILES+=	${WORKIMG} ${IMGBASE}.img
d429 25
a453 2
${IMGBASE}.img:	${TARGETFS} ${WORKLABEL}
.if ${USE_MBR} != "no"
d460 1
a460 1
.if empty(MBR_BOOTCODE)
d469 1
a469 1
.else
d476 1
d478 8
a485 8
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${TARGETFS} > ${WORKIMG}
.else	# USE_MBR == "no"
	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
.endif	# USE_MBR != "no"
.if ${OMIT_SWAPIMG} == "no"
	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
	${CAT} ${WORKSWAP} >> ${WORKIMG}
d487 8
d502 1
d508 1
a510 1

d522 1
@


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

No functional change.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.20 2018/12/15 18:03:17 gson Exp $
d65 2
a66 2
#		(default: modules base etc comp games man misc tests text
#			  xbase xcomp xetc xfont xserver)
d195 1
a195 1
SETS_DEFAULT=	modules base etc comp games man misc tests text
@


1.21.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.21 2019/02/22 22:13:58 tsutsui Exp $
d65 2
a66 2
#		(default: modules base etc comp games man misc rescue tests
#			  text xbase xcomp xetc xfont xserver)
d195 1
a195 1
SETS_DEFAULT=	modules base etc comp games man misc rescue tests text
@


1.21.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 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.21.2.1 2019/11/17 07:04:34 martin Exp $
a39 3
#	USE_GPT
#		set yes if target disk image requires GPT partition
#		(default: no)
a59 6
#	EFIMB
#		EFI partition size in target image in MB
#		(default: 128)
#	FATMB
#		FAT partition size in target image in MB
#		(default: 0)
d117 3
a119 12
#	EFIBOOT
#		EFI bootloader
#		(default: empty)
#	MBRFAT
#		MBR partition type value for FAT
#		(default: 6 ("16-bit FAT, more than 32M"))
#	FATMAKEFSOPTIONS
#		options passed to makefs(8) to create a FAT partition
#		(default: -o fat_type=16)
#	FATFILES
#		list of additional files to be copied into FAT partition
#		(default: empty)
a128 1
GPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
a148 1
USE_GPT?=	no
a156 8
.if ${USE_GPT} == "no"
EFIMB?=		0
GPTSECTORS=	0
.else
EFIMB?=		128		# 128MB
GPTSECTORS=	2048
.endif
FATMB?=		0
a160 2
EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true
FATSECTORS!=	expr ${FATMB} \* 1024 \* 1024 / 512 || true
d162 1
a162 1
.if ${USE_MBR} == "no" && ${USE_GPT} == "no"
d170 1
a170 2
FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
a181 1
MBRFAT?=	6	# 16-bit FAT, more than 32M
d183 3
a185 6
BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} \
		    + ${EFISECTORS} + ${FATSECTORS}
FATOFFSET=	${LABELSECTORS}
a190 4
.if ${USE_GPT} != "no"
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
a208 1
FATMAKEFSOPTIONS?=	-o fat_type=16
a222 58
# definitions to create image
#
.if ${SWAPSECTORS} == 0
.  if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in
.  else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.in
.  endif
.else
.  if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
.  else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
.  endif
.endif

MBR_DEFAULT_BOOTCODE?=	mbr

WORKMBR?=	work.mbr
WORKMBRTRUNC?=	work.mbr.truncated
WORKSWAP?=	work.swap
WORKEFI?=	work.efi
WORKGPT?=	work.gpt
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img
EFIWORKDIR?=	work.efidir
WORKFAT?=	work.fat
WORKFATDIR?=	work.fatdir

.if ${USE_GPT} != "no"
${WORKFSTAB}: ${WORKMBR}
.endif

${WORKFSTAB}:
	@@echo Preparing /etc/fstab ...
.if ${USE_GPT} != "no"
.  if ${SWAPSECTORS} != 0
	${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
.  if ${SWAPSECTORS} != 0
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
.  else
	${TOOL_SED}							\
	    -e "/ROOT.b/d"						\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.  endif
.endif

#
d225 1
a225 1
${TARGETFS}: prepare_md_post ${WORKFSTAB}
d245 2
d309 7
a315 16
TARGET_BLOCKS=
.if ${USE_MBR} != "no" || ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKMBRTRUNC}
.endif
.if ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKEFI}
.endif
.if ${FATSECTORS} != 0
TARGET_BLOCKS+=	${WORKFAT}
.endif
TARGET_BLOCKS+=	 ${TARGETFS}
.if ${SWAPSECTORS} != 0
TARGET_BLOCKS+=	${WORKSWAP}
.endif
.if ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKGPT}
d318 10
a327 3
CLEANFILES+=	${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP}
CLEANFILES+=	${WORKEFI} ${WORKGPT}
CLEANFILES+=	${WORKFAT}
a330 10
${WORKSWAP}:
.if ${SWAPSECTORS} == 0
	printf "" > ${WORKSWAP}
.else
	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
.endif

${WORKMBRTRUNC}: ${WORKMBR}
	${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC}

a342 2
	    -e "s/@@@@FATSECTORS@@@@/${FATSECTORS}/"			\
	    -e "s/@@@@FATOFFSET@@@@/${FATOFFSET}/"				\
d346 2
a347 45
${WORKEFI}: ${TARGETFS}
	@@echo create EFI system partition...
	@@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
.for f in ${EFIBOOT}
	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
.endfor
	${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}

${WORKFAT}: ${TARGETFS} ${FATFILES}
	@@echo create FAT partition for bootstrap files...
	@@${MKDIR} ${MKDIRPERM} ${WORKFATDIR}
.if defined(FATFILES)
	@@echo Copying files for FAT partition...
.for f in ${FATFILES}
	@@if [ ! -f ${f} ]; then 					\
		echo "${f} in FATFILES not found, aborting";		\
		false; 							\
	fi
	${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR}
.endfor
.endif
	${RM} -f ${WORKFAT}
	${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m			\
	    ${MAKEFS_TIMESTAMP}						\
	    -t msdos							\
	    ${FATMAKEFSOPTIONS}						\
	    ${WORKFAT} ${WORKFATDIR}

${WORKMBR}:
.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 ${SWAPSECTORS} != 0
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
.  endif
.elif ${USE_MBR} != "no"
a349 13
.  if ${FATSECTORS} != 0
	# create BSD partition
	${TOOL_FDISK} -f -i -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -F ${WORKMBR}
	# create FAT partition
	${TOOL_FDISK} -f -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS}			\
	    -F ${WORKMBR}
.  else
	# create BSD partition
d354 1
a354 2
.  endif
.  if empty(MBR_BOOTCODE)
d363 1
a363 1
.  else
a369 1
.  endif
d371 8
a378 8

${WORKGPT}: ${WORKMBR}
	@@echo create GPT image...
	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
	    count=2048

.if ${USE_GPT} == "no"
${IMGBASE}.img:	${WORKLABEL}
a379 8

${IMGBASE}.img:	${TARGET_BLOCKS}
	${CAT} ${TARGET_BLOCKS} > ${WORKIMG}
.if ${USE_GPT} != "no"
	${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
.endif	# USE_GPT != "no"
a386 1
.if ${USE_GPT} == "no"
a391 1
.endif
d394 1
a405 2
	${RM} -fr ${EFIWORKDIR}
	${RM} -fr ${WORKFATDIR}
@


1.20
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.19 2018/11/19 20:05:37 aymeric Exp $
d243 1
a243 1
	${INSTALL} ${COPY} -m 0644 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
d261 1
a261 1
	    ${TOOL_PAX} -rw -pe	-v ${PAX_TIMESTAMP}			\
d274 2
a275 2
		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};		\
		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};			\
d373 1
a373 1
.else
d375 1
a375 1
.endif
@


1.19
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.18 2018/10/07 18:07:00 martin Exp $
a36 3
#	BOOTDISK
#		device name of target bootable disk specified in /etc/fstab
#		(default: sd0)
a147 1
BOOTDISK?=	sd0
d246 1
a246 1
	${TOOL_SED} "s/@@@@BOOTDISK@@@@/${BOOTDISK}/" < ${FSTAB_IN} > ${WORKFSTAB}
@


1.18
log
@Support .tar.xz sets
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.17 2017/02/11 08:08:00 pgoyette Exp $
d220 1
d241 3
a243 1
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.${TAR_SUFF} .)
@


1.17
log
@Remove leftover "-f" from when this used to be a cp command.

Unbreak the build for install-image target.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.16 2017/02/11 04:19:25 christos Exp $
d220 1
d235 2
a236 2
	@@if [ ! -f ${SETS_DIR}/${set}.tgz ]; then 			\
		echo "Missing ${SETS_DIR}/${set}.tgz, aborting";	\
d239 2
a240 2
	@@echo Extracting ${set}.tgz ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.tgz .)
@


1.17.12.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.21 2019/02/22 22:13:58 tsutsui Exp $
d37 3
d151 1
a219 2
COMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}}
TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
d234 2
a235 2
	@@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
d238 2
a239 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} .)
d243 1
a243 1
	${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
d246 1
a246 1
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
d261 1
a261 1
	    ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v			\
d274 2
a275 2
		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \
d373 1
a373 1
.else	# USE_MBR == "no"
d375 1
a375 1
.endif	# USE_MBR != "no"
@


1.17.12.2
log
@Merge changes from current as of 20200406
@
text
@d1 1
a1 1
#	$NetBSD$
a39 3
#	USE_GPT
#		set yes if target disk image requires GPT partition
#		(default: no)
a59 6
#	EFIMB
#		EFI partition size in target image in MB
#		(default: 128)
#	FATMB
#		FAT partition size in target image in MB
#		(default: 0)
d117 3
a119 12
#	EFIBOOT
#		EFI bootloader
#		(default: empty)
#	MBRFAT
#		MBR partition type value for FAT
#		(default: 6 ("16-bit FAT, more than 32M"))
#	FATMAKEFSOPTIONS
#		options passed to makefs(8) to create a FAT partition
#		(default: -o fat_type=16)
#	FATFILES
#		list of additional files to be copied into FAT partition
#		(default: empty)
a128 1
GPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
a148 1
USE_GPT?=	no
a156 8
.if ${USE_GPT} == "no"
EFIMB?=		0
GPTSECTORS=	0
.else
EFIMB?=		128		# 128MB
GPTSECTORS=	2048
.endif
FATMB?=		0
a160 2
EFISECTORS!=	expr ${EFIMB} \* 1024 \* 1024 / 512 || true
FATSECTORS!=	expr ${FATMB} \* 1024 \* 1024 / 512 || true
d162 1
a162 1
.if ${USE_MBR} == "no" && ${USE_GPT} == "no"
d170 1
a170 2
FSSECTORS!=	expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
a181 1
MBRFAT?=	6	# 16-bit FAT, more than 32M
d183 3
a185 6
BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \
		    - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
FSOFFSET!=	expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS}
SWAPOFFSET!=	expr ${LABELSECTORS} + ${FSSECTORS} \
		    + ${EFISECTORS} + ${FATSECTORS}
FATOFFSET=	${LABELSECTORS}
a190 4
.if ${USE_GPT} != "no"
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
a208 1
FATMAKEFSOPTIONS?=	-o fat_type=16
a222 58
# definitions to create image
#
.if ${SWAPSECTORS} == 0
.  if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in
.  else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.noswap.in
.  endif
.else
.  if ${USE_MBR} != "no"
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.mbr.in
.  else
DISKPROTO_IN?=	${DISTRIBDIR}/common/bootimage/diskproto.in
.  endif
.endif

MBR_DEFAULT_BOOTCODE?=	mbr

WORKMBR?=	work.mbr
WORKMBRTRUNC?=	work.mbr.truncated
WORKSWAP?=	work.swap
WORKEFI?=	work.efi
WORKGPT?=	work.gpt
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img
EFIWORKDIR?=	work.efidir
WORKFAT?=	work.fat
WORKFATDIR?=	work.fatdir

.if ${USE_GPT} != "no"
${WORKFSTAB}: ${WORKMBR}
.endif

${WORKFSTAB}:
	@@echo Preparing /etc/fstab ...
.if ${USE_GPT} != "no"
.  if ${SWAPSECTORS} != 0
	${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
.  if ${SWAPSECTORS} != 0
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
.  else
	${TOOL_SED}							\
	    -e "/ROOT.b/d"						\
	    < ${FSTAB_IN} > ${WORKFSTAB}
.  endif
.endif

#
d225 1
a225 1
${TARGETFS}: prepare_md_post ${WORKFSTAB}
d245 2
d309 7
a315 16
TARGET_BLOCKS=
.if ${USE_MBR} != "no" || ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKMBRTRUNC}
.endif
.if ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKEFI}
.endif
.if ${FATSECTORS} != 0
TARGET_BLOCKS+=	${WORKFAT}
.endif
TARGET_BLOCKS+=	 ${TARGETFS}
.if ${SWAPSECTORS} != 0
TARGET_BLOCKS+=	${WORKSWAP}
.endif
.if ${USE_GPT} != "no"
TARGET_BLOCKS+=	${WORKGPT}
d318 10
a327 3
CLEANFILES+=	${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP}
CLEANFILES+=	${WORKEFI} ${WORKGPT}
CLEANFILES+=	${WORKFAT}
a330 10
${WORKSWAP}:
.if ${SWAPSECTORS} == 0
	printf "" > ${WORKSWAP}
.else
	${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1
.endif

${WORKMBRTRUNC}: ${WORKMBR}
	${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC}

a342 2
	    -e "s/@@@@FATSECTORS@@@@/${FATSECTORS}/"			\
	    -e "s/@@@@FATOFFSET@@@@/${FATOFFSET}/"				\
d346 2
a347 45
${WORKEFI}: ${TARGETFS}
	@@echo create EFI system partition...
	@@${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot
.for f in ${EFIBOOT}
	${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}`
.endfor
	${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}

${WORKFAT}: ${TARGETFS} ${FATFILES}
	@@echo create FAT partition for bootstrap files...
	@@${MKDIR} ${MKDIRPERM} ${WORKFATDIR}
.if defined(FATFILES)
	@@echo Copying files for FAT partition...
.for f in ${FATFILES}
	@@if [ ! -f ${f} ]; then 					\
		echo "${f} in FATFILES not found, aborting";		\
		false; 							\
	fi
	${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR}
.endfor
.endif
	${RM} -f ${WORKFAT}
	${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m			\
	    ${MAKEFS_TIMESTAMP}						\
	    -t msdos							\
	    ${FATMAKEFSOPTIONS}						\
	    ${WORKFAT} ${WORKFATDIR}

${WORKMBR}:
.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 ${SWAPSECTORS} != 0
	${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap
.  endif
.elif ${USE_MBR} != "no"
a349 13
.  if ${FATSECTORS} != 0
	# create BSD partition
	${TOOL_FDISK} -f -i -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -F ${WORKMBR}
	# create FAT partition
	${TOOL_FDISK} -f -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS}			\
	    -F ${WORKMBR}
.  else
	# create BSD partition
d354 1
a354 2
.  endif
.  if empty(MBR_BOOTCODE)
d363 1
a363 1
.  else
a369 1
.  endif
d371 8
a378 8

${WORKGPT}: ${WORKMBR}
	@@echo create GPT image...
	${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \
	    count=2048

.if ${USE_GPT} == "no"
${IMGBASE}.img:	${WORKLABEL}
a379 8

${IMGBASE}.img:	${TARGET_BLOCKS}
	${CAT} ${TARGET_BLOCKS} > ${WORKIMG}
.if ${USE_GPT} != "no"
	${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
.endif	# USE_GPT != "no"
a386 1
.if ${USE_GPT} == "no"
a391 1
.endif
d394 1
a405 2
	${RM} -fr ${EFIWORKDIR}
	${RM} -fr ${WORKFATDIR}
@


1.17.12.3
log
@Mostly merge changes from HEAD upto 20200411
@
text
@d74 2
a75 2
#		(default: modules base etc comp games man misc rescue tests
#			  text xbase xcomp xetc xfont xserver)
d234 1
a234 1
SETS_DEFAULT=	modules base etc comp games man misc rescue tests text
@


1.17.10.1
log
@Sync with head
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.18 2018/10/07 18:07:00 martin Exp $
a219 1
TAR_SUFF=	${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz}
d234 2
a235 2
	@@if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then 		\
		echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\
d238 2
a239 2
	@@echo Extracting ${set}.${TAR_SUFF} ...
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.${TAR_SUFF} .)
@


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


1.17.10.3
log
@Sync with HEAD, resolve a few conflicts
@
text
@d1 1
a1 1
#	$NetBSD$
d37 3
d151 1
d250 1
a250 1
	${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB}
@


1.16
log
@remove extra endif
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.15 2017/02/11 03:07:06 christos Exp $
d243 1
a243 1
	${INSTALL} ${COPY} -m 0644 -f ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
@


1.15
log
@more MKREPRO_TIMESTAMP fixes (for pax/tar generated files)
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.14 2017/02/10 16:43:59 christos Exp $
a133 1
.endif
@


1.14
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.13 2017/01/24 18:01:07 christos Exp $
d132 2
d240 1
a240 1
	@@(cd ${WORKDIR}; ${TOOL_PAX} -rnz -f ${SETS_DIR}/${set}.tgz .)
d262 1
a262 1
	    ${TOOL_PAX} -rw -pe	-v					\
@


1.13
log
@use the same logic to compute the timestamp like the other files
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.12 2015/11/25 00:50:57 christos Exp $
a142 1
CP?=		cp
d231 1
a231 1
	@@${MKDIR} ${WORKDIR}
d242 1
a242 1
	${CP} -f ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
d246 1
a246 1
	${CP} ${WORKFSTAB} ${WORKDIR}/etc/fstab
d250 1
a250 1
	${CP} ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
d258 1
a258 1
	${MKDIR} ${WORKDIR}/${_TARGET}
d273 2
a274 2
		echo ${CP} ${_SRC} ${WORKDIR}/${_TARGET};		\
		${CP} ${_SRC} ${WORKDIR}/${_TARGET};			\
d373 1
a373 1
	${CP} ${TARGETFS} ${WORKIMG}
@


1.12
log
@PR/50360: Thomas Klausner: if MKREPRO is set, provide a consistent timestamp
for the files in the cdroms to be built. For now we copy the timestamp of
<sys/param.h>. We could set an absolute timestamp too like -T 0 for the epoch.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.11 2015/05/08 17:46:03 riastradh Exp $
d130 2
a131 2
.if ${MKREPRO:Uno} == "yes"
TIMESTAMP=-T ${NETBSDSRCDIR}/sys/sys/param.h
d299 1
a299 1
	    ${TIMESTAMP}						\
@


1.12.4.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.17 2017/02/11 08:08:00 pgoyette Exp $
d130 2
a131 3
.if ${MKREPRO_TIMESTAMP:Uno} != "no"
MAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
d143 1
d232 1
a232 1
	@@${MKDIR} ${MKDIRPERM} ${WORKDIR}
d239 1
a239 1
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.tgz .)
d243 1
a243 1
	${INSTALL} ${COPY} -m 0644 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
d247 1
a247 1
	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
d251 1
a251 1
	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
d259 1
a259 1
	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
d261 1
a261 1
	    ${TOOL_PAX} -rw -pe	-v ${PAX_TIMESTAMP}			\
d274 2
a275 2
		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};		\
		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};			\
d299 1
a299 1
	    ${MAKEFS_TIMESTAMP}						\
d374 1
a374 1
	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
@


1.12.2.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.17 2017/02/11 08:08:00 pgoyette Exp $
d130 2
a131 3
.if ${MKREPRO_TIMESTAMP:Uno} != "no"
MAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}"
PAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}"
d143 1
d232 1
a232 1
	@@${MKDIR} ${MKDIRPERM} ${WORKDIR}
d239 1
a239 1
	@@(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rnz -f ${SETS_DIR}/${set}.tgz .)
d243 1
a243 1
	${INSTALL} ${COPY} -m 0644 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
d247 1
a247 1
	${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab
d251 1
a251 1
	${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf
d259 1
a259 1
	${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET}
d261 1
a261 1
	    ${TOOL_PAX} -rw -pe	-v ${PAX_TIMESTAMP}			\
d274 2
a275 2
		echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};		\
		${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET};			\
d299 1
a299 1
	    ${MAKEFS_TIMESTAMP}						\
d374 1
a374 1
	${INSTALL} ${COPY} -m 0644 ${TARGETFS} ${WORKIMG}
@


1.11
log
@Fix ytpo: INSTALLBOOTOPTIONS, not INSTALLBOOTOPTOINS.

From qjsgkem on Freenode.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.10 2015/03/12 04:41:23 snj Exp $
d130 4
d299 1
@


1.10
log
@unbreak amd64 install images by passing ipty to MAKEDEV.  revision 1.21
of etc/etc.amd64/MAKEDEV.conf removed them from 'all'.  (hi christos!)
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.9 2014/08/05 15:40:58 apb Exp $
d384 1
a384 1
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTOINS} ${WORKIMG} \
@


1.9
log
@Use ${TOOL_GZIP_N} instead of ${TOOL_GZIP} -n, and similarly
use ${TOOL_GZIP_N} -9 instead of ${TOOL_GZIP} -9n, etc.

This will pass -nT instead of just -n if the gzip program is
actually pigz.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.8 2014/01/27 21:37:17 apb Exp $
d279 1
a279 1
	${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all |			\
@


1.9.2.1
log
@Pull up following revision(s) (requested by riastradh in ticket #902):
	distrib/common/bootimage/Makefile.bootimage: revision 1.11
Fix ytpo: INSTALLBOOTOPTIONS, not INSTALLBOOTOPTOINS.
From qjsgkem on Freenode.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.9 2014/08/05 15:40:58 apb Exp $
d384 1
a384 1
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \
@


1.8
log
@Pass the -n flag to gzip invocations.

This prevents it from embedding a timestamp in the output.  We pass
"-n" unconditionally, not conditional on MKREPRO, because many other
invocations of gzip already passed the -n flag unconditionally.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.7 2014/01/16 01:15:32 christos Exp $
d393 1
a393 1
	${TOOL_GZIP} -9nc ${IMGBASE}.img > ${.TARGET}.tmp
@


1.8.2.1
log
@Rebase.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.9 2014/08/05 15:40:58 apb Exp $
d393 1
a393 1
	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
@


1.7
log
@eliminate use of bsd.sys.mk from Makefiles
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.6 2012/04/22 07:23:42 tsutsui Exp $
d393 1
a393 1
	${TOOL_GZIP} -9c ${IMGBASE}.img > ${.TARGET}.tmp
@


1.6
log
@Fix typo in comments.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.5 2012/04/22 05:24:39 tsutsui Exp $
a124 1
.include <bsd.sys.mk>		# for HOST_SH
@


1.6.2.1
log
@Rebase to HEAD as of a few days ago.
@
text
@d1 1
a1 1
#	$NetBSD$
d125 1
d394 1
a394 1
	${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp
@


1.5
log
@Add two optional variables for liveimage/installimage builds:
---
	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

	INSTALLBOOTOPTIONS
		options passed to installboot(8), e.g., -o console=com0
		(default: empty)
---
Proposed by Brook Milligan on current-users@@:
http://mail-index.NetBSD.org/current-users/2012/04/16/msg019892.html

Also make USE_MBR work on ${MACHINE}s which don't have the default
/usr/mdec/mbr bootcode. (no such port has the liveimage target yet though)

XXX: tools fdisk(8) implicitly uses host's /usr/mdec/mbr for the default
XXX: bootcode even for non-x86 targets if host is x86
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.4 2012/04/09 19:22:49 riz Exp $
d42 1
a42 1
#		(defautl: no)
d85 1
a85 1
#		XXX: currently permittions in IMGDIR_EXTRA are not handled
@


1.4
log
@s/Createing/Creating/
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.3 2012/01/22 16:56:22 tsutsui Exp $
d43 7
d102 3
d299 1
a299 1
	${TOOL_INSTALLBOOT} -vm ${MACHINE} ${WORKFS} \
d314 2
d343 1
a343 1
.if ${LABELSECTORS} != "0"
d346 1
a346 1
	${TOOL_FDISK} -f -u \
a348 1
	    -i -c ${WORKDIR}/usr/mdec/mbr				\
d350 17
d385 1
a385 1
	${TOOL_INSTALLBOOT}  -vm ${MACHINE} ${WORKIMG}			\
@


1.4.2.1
log
@file Makefile.bootimage was added on branch yamt-pagecache on 2012-04-17 00:02:32 +0000
@
text
@d1 379
@


1.4.2.2
log
@sync with head
@
text
@a0 379
#	$NetBSD$
#
# 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
#		(defautl: no)
#	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)
#	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 permittions 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)
#	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)
#

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

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

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

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

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

#
# size parameters for image
#
IMAGEMB?=	2048		# 2048MB
SWAPMB?=	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

.if ${USE_MBR} == "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


#
# 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
	@@if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then 		\
		echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \
		false; 							\
	fi;
	@@${MKDIR} ${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} -rnz -f ${SETS_DIR}/${set}.tgz .)
.endfor
.if defined(SECONDARY_BOOT)
	@@echo Copying secondary boot...
	${CP} -f ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR}
.endif
	@@echo Preparing /etc/fstab ...
	${TOOL_SED} "s/@@@@BOOTDISK@@@@/${BOOTDISK}/" < ${FSTAB_IN} > ${WORKFSTAB}
	${CP} ${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}
	${CP} ${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} ${WORKDIR}/${_TARGET}
	(cd ${_SRCDIR} ;						\
	    ${TOOL_PAX} -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 ${CP} ${_SRC} ${WORKDIR}/${_TARGET};		\
		${CP} ${_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 |			\
	    ${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				\
	    ${IMGMAKEFSOPTIONS}						\
	    ${WORKFS} ${WORKDIR}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no"
	${TOOL_INSTALLBOOT} -vm ${MACHINE} ${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

OMIT_SWAPIMG?=	no

WORKMBR?=	work.mbr
WORKSWAP?=	work.swap
WORKLABEL?=	work.diskproto
WORKIMG?=	work.img

CLEANFILES+=	${WORKMBR} ${WORKSWAP}
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}

${IMGBASE}.img:	${TARGETFS} ${WORKLABEL}
.if ${LABELSECTORS} != "0"
	@@echo creating MBR labels...
	${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1
	${TOOL_FDISK} -f -u \
	    -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS}		\
	    -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS}		\
	    -i -c ${WORKDIR}/usr/mdec/mbr				\
	    -F ${WORKMBR}
	${DD} if=${WORKMBR} count=${LABELSECTORS} |			\
	    ${CAT} - ${TARGETFS} > ${WORKIMG}
.else
	${CP} ${TARGETFS} ${WORKIMG}
.endif
.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
	${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL}
.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no"
	${TOOL_INSTALLBOOT}  -vm ${MACHINE} ${WORKIMG}			\
	    ${WORKDIR}/usr/mdec/${PRIMARY_BOOT}
.endif
	mv ${WORKIMG} ${.TARGET}


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

${IMGBASE}.img.gz:	${IMGBASE}.img
	${TOOL_GZIP} -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}

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

.include <bsd.prog.mk>
@


1.4.2.3
log
@sync with head.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.4.2.2 2012/04/17 00:02:32 yamt Exp $
d42 1
a42 8
#		(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
d78 1
a78 1
#		XXX: currently permissions in IMGDIR_EXTRA are not handled
a94 3
#	INSTALLBOOTOPTIONS
#		options passed to installboot(8), e.g., -o console=com0
#		(default: empty)
d289 1
a289 1
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
a303 2
MBR_DEFAULT_BOOTCODE?=	mbr

d331 1
a331 1
.if ${USE_MBR} != "no"
d334 1
a334 1
	${TOOL_FDISK} -f -i -u \
d337 1
a338 17
.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
d357 1
a357 1
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTOINS} ${WORKIMG} \
@


1.4.2.4
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.4.2.3 2012/05/23 10:07:08 yamt Exp $
d125 1
d394 1
a394 1
	${TOOL_GZIP} -9nc ${IMGBASE}.img > ${.TARGET}.tmp
@


1.3
log
@Appease warnings `"expr 0 \* 1024 \* 1024 / 512" returned non-zero status.'

SWAPMB could be zero (in install-image case) and
expr(1) returns exit status 1 in that case.  Umm.
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.2 2012/01/22 16:50:00 tsutsui Exp $
d280 1
a280 1
	@@echo Createing rootfs...
@


1.3.2.1
log
@Pull up following revision(s) (requested by tsutsui in ticket #235):
	distrib/common/bootimage/Makefile.bootimage: revision 1.5
Add two optional variables for liveimage/installimage builds:
---
	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
	INSTALLBOOTOPTIONS
		options passed to installboot(8), e.g., -o console=com0
		(default: empty)
---
Proposed by Brook Milligan on current-users@@:
http://mail-index.NetBSD.org/current-users/2012/04/16/msg019892.html
Also make USE_MBR work on ${MACHINE}s which don't have the default
/usr/mdec/mbr bootcode. (no such port has the liveimage target yet though)
XXX: tools fdisk(8) implicitly uses host's /usr/mdec/mbr for the default
XXX: bootcode even for non-x86 targets if host is x86
@
text
@d1 1
a1 1
#	$NetBSD$
a42 7
#	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
a94 3
#	INSTALLBOOTOPTIONS
#		options passed to installboot(8), e.g., -o console=com0
#		(default: empty)
d289 1
a289 1
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \
a303 2
MBR_DEFAULT_BOOTCODE?=	mbr

d331 1
a331 1
.if ${USE_MBR} != "no"
d334 1
a334 1
	${TOOL_FDISK} -f -i -u \
d337 1
a338 17
.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
d357 1
a357 1
	${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTOINS} ${WORKIMG} \
@


1.2
log
@Fix checks for RELEASEDIR (and xxxxIMGBASE) variables to perform it
only on live_image or install_image targets.  PR toolchain/45864
@
text
@d1 1
a1 1
#	$NetBSD: Makefile.bootimage,v 1.1 2012/01/22 03:53:30 tsutsui Exp $
d149 1
d151 1
a151 1
SWAPSECTORS!=	expr ${SWAPMB} \* 1024 \* 1024 / 512
d180 1
a180 1
SWAPCYLINDERS!=	expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \)
@


1.1
log
@Add "live-image" and "install-image" target support to build.sh.

"live-image" target builds pre-installed disk images that can be used on
emulators or boot from USB memory sticks to try NetBSD without installation.
Currently amd64, i386, pmax, sparc, sparc64, sun2, sun3, and vax
(which have working emulators and don't require extra tools like preparing
 msdosfs or partitioning MD label structures) support this target.

"install-image" target builds an bootable installation disk image that can
be used as an install CD but burned into USB memory sticks etc.
Current only amd64 and i386 (which would support USB boot) have this target.

For more details (and known issue) see following posts on netbsd-bugs@@:
http://mail-index.NetBSD.org/netbsd-bugs/2011/08/06/msg023639.html
http://mail-index.NetBSD.org/netbsd-bugs/2011/09/23/msg024207.html
http://mail-index.NetBSD.org/netbsd-bugs/2011/12/07/msg025166.html
http://mail-index.NetBSD.org/netbsd-bugs/2011/12/08/msg025178.html

No particular comments about implementation, and
"go ahead" comments from mrg@@, riz@@ and christos@@.

Closes PR toolchain/45153 and PR misc/45155.
@
text
@d1 1
a1 1
#	$NetBSD$
a125 5
.if empty(RELEASEDIR)
.BEGIN:
	@@echo "Error: RELEASEDIR is not set"
	@@false
.endif
@

