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