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