Skip to content

Commit 6e965e2

Browse files
committed
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.
1 parent 4b2f8bd commit 6e965e2

1 file changed

Lines changed: 41 additions & 5 deletions

File tree

distrib/common/bootimage/Makefile.bootimage

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $NetBSD: Makefile.bootimage,v 1.49 2026/01/16 23:37:19 tsutsui Exp $
1+
# $NetBSD: Makefile.bootimage,v 1.50 2026/01/18 00:07:36 tsutsui Exp $
22
#
33
# Copyright (c) 2009, 2010, 2011 Izumi Tsutsui. All rights reserved.
44
#
@@ -44,6 +44,11 @@
4444
# set yes if target disk image requires GPT partition
4545
# with hybrid MBR boot code
4646
# (default: no; valid only if USE_GPT=yes)
47+
# USE_MDBOOTPART
48+
# set yes if target disk image requires port specific
49+
# boot partition
50+
# (default: no; if yes target rules of WORKMDBOOTPART should
51+
# be defined in MD liveimage/Makefiles)
4752
# MBR_BOOTCODE
4853
# optional MBR bootcode which should be installed by fdisk(8)
4954
# (default: empty)
@@ -70,6 +75,9 @@
7075
# FATMB
7176
# FAT partition size in target image in MB
7277
# (default: 0)
78+
# MDBOOTPARTMB
79+
# port specific boot partition size in target image in MB
80+
# (default: 0)
7381
# GPTSECTORS
7482
# Size of a region reserved for the secondary GPT table/entry
7583
# at the end of the target image in sectors
@@ -182,6 +190,7 @@ MAKESPEC= ${HOST_SH} ${NETBSDSRCDIR}/etc/makespec
182190
USE_MBR?= no
183191
USE_GPT?= no
184192
USE_GPTMBR?= no
193+
USE_MDBOOTPART?= no
185194
USE_SUNLABEL?= no
186195
INSTALLBOOT_AFTER_DISKLABEL?= no
187196

@@ -198,13 +207,20 @@ EFIMB?= 128 # 128MB
198207
GPTSECTORS= 2048
199208
.endif
200209
FATMB?= 0
210+
MDBOOTPARTMB?= 0
201211

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

218+
.if ${USE_MDBOOTPART} != "no"
219+
MDBOOTPARTSECTORS!= expr ${MDBOOTPARTMB} \* 1024 \* 1024 / 512 || true
220+
.else
221+
MDBOOTPARTSECTORS= 0
222+
.endif
223+
208224
.if ${USE_MBR} == "no" && ${USE_GPT} == "no"
209225
LABELSECTORS?= 0
210226
.else
@@ -213,8 +229,16 @@ LABELSECTORS?= 0
213229
LABELSECTORS?= 2048 # 1MB aligned for modern flash devices
214230
.endif
215231

232+
.if ${USE_MDBOOTPART} != "no"
233+
MDBOOTPARTOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} \
234+
|| test $$? -eq 1 || exit 1
235+
.else
236+
MDBOOTPARTOFFSET= 0
237+
.endif
238+
216239
FSSECTORS!= expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
217-
- ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} || test $$? -eq 1 || exit 1
240+
- ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} \
241+
- ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
218242
FSSIZE!= expr ${FSSECTORS} \* 512 || test $$? -eq 1 || exit 1
219243

220244
# parameters for disklabel and MBR
@@ -229,10 +253,13 @@ MBRNETBSD= 169
229253
MBRFAT?= 6 # 16-bit FAT, more than 32M
230254

231255
BSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \
232-
- ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS}
233-
FSOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} || test $$? -eq 1 || exit 1
256+
- ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} \
257+
- ${MDBOOTPARTSECTORS}
258+
FSOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} \
259+
+ ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
234260
SWAPOFFSET!= expr ${LABELSECTORS} + ${FSSECTORS} \
235-
+ ${EFISECTORS} + ${FATSECTORS} || test $$? -eq 1 || exit 1
261+
+ ${EFISECTORS} + ${FATSECTORS} \
262+
+ ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
236263
FATOFFSET= ${LABELSECTORS}
237264

238265
# helper script for sunlabel
@@ -321,6 +348,8 @@ WORKIMG?= work.img
321348
EFIWORKDIR?= work.efidir
322349
WORKFAT?= work.fat
323350
WORKFATDIR?= work.fatdir
351+
WORKMDBOOTPART?= work.mdbootpart
352+
WORKMDBOOTPARTDIR?= work.mdbootpartdir
324353

325354
.if ${USE_GPT} != "no"
326355
${WORKFSTAB}: ${WORKMBR}
@@ -479,6 +508,9 @@ TARGET_BLOCKS+= ${WORKEFI}
479508
.if ${FATSECTORS} != 0
480509
TARGET_BLOCKS+= ${WORKFAT}
481510
.endif
511+
.if ${USE_MDBOOTPART} != "no"
512+
TARGET_BLOCKS+= ${WORKMDBOOTPART}
513+
.endif
482514
TARGET_BLOCKS+= ${TARGETFS}
483515
.if ${SWAPSECTORS} != 0
484516
TARGET_BLOCKS+= ${WORKSWAP}
@@ -490,6 +522,7 @@ TARGET_BLOCKS+= ${WORKGPT}
490522
CLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP}
491523
CLEANFILES+= ${WORKEFI} ${WORKGPT}
492524
CLEANFILES+= ${WORKFAT}
525+
CLEANFILES+= ${WORKMDBOOTPART}
493526
CLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL}
494527
CLEANFILES+= ${WORKIMG} ${IMGBASE}.img
495528

@@ -517,6 +550,8 @@ ${WORKLABEL}:
517550
-e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/" \
518551
-e "s/@@FATSECTORS@@/${FATSECTORS}/" \
519552
-e "s/@@FATOFFSET@@/${FATOFFSET}/" \
553+
-e "s/@@MDBOOTPARTSECTORS@@/${MDBOOTPARTSECTORS}/" \
554+
-e "s/@@MDBOOTPARTOFFSET@@/${MDBOOTPARTOFFSET}/" \
520555
< ${DISKPROTO_IN} > ${WORKLABEL}.tmp
521556
mv ${WORKLABEL}.tmp ${WORKLABEL}
522557

@@ -654,6 +689,7 @@ clean:
654689
${RM} -fr ${WORKDIR}
655690
${RM} -fr ${EFIWORKDIR}
656691
${RM} -fr ${WORKFATDIR}
692+
${RM} -fr ${WORKMDBOOTPARTDIR}
657693

658694
prepare_md_post: .PHONY
659695
image_md_post: .PHONY

0 commit comments

Comments
 (0)