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#
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)
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
182190USE_MBR?= no
183191USE_GPT?= no
184192USE_GPTMBR?= no
193+ USE_MDBOOTPART?= no
185194USE_SUNLABEL?= no
186195INSTALLBOOT_AFTER_DISKLABEL?= no
187196
@@ -198,13 +207,20 @@ EFIMB?= 128 # 128MB
198207GPTSECTORS= 2048
199208.endif
200209FATMB?= 0
210+ MDBOOTPARTMB?= 0
201211
202212# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case
203213IMAGESECTORS!= expr ${IMAGEMB} \* 1024 \* 1024 / 512
204214SWAPSECTORS!= expr ${SWAPMB} \* 1024 \* 1024 / 512 || true
205215EFISECTORS!= expr ${EFIMB} \* 1024 \* 1024 / 512 || true
206216FATSECTORS!= 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"
209225LABELSECTORS?= 0
210226.else
@@ -213,8 +229,16 @@ LABELSECTORS?= 0
213229LABELSECTORS?= 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+
216239FSSECTORS!= expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \
217- - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} || test $$? -eq 1 || exit 1
240+ - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} \
241+ - ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
218242FSSIZE!= expr ${FSSECTORS} \* 512 || test $$? -eq 1 || exit 1
219243
220244# parameters for disklabel and MBR
@@ -229,10 +253,13 @@ MBRNETBSD= 169
229253MBRFAT?= 6 # 16-bit FAT, more than 32M
230254
231255BSDPARTSECTORS!= 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
234260SWAPOFFSET!= expr ${LABELSECTORS} + ${FSSECTORS} \
235- + ${EFISECTORS} + ${FATSECTORS} || test $$? -eq 1 || exit 1
261+ + ${EFISECTORS} + ${FATSECTORS} \
262+ + ${MDBOOTPARTSECTORS} || test $$? -eq 1 || exit 1
236263FATOFFSET= ${LABELSECTORS}
237264
238265# helper script for sunlabel
@@ -321,6 +348,8 @@ WORKIMG?= work.img
321348EFIWORKDIR?= work.efidir
322349WORKFAT?= work.fat
323350WORKFATDIR?= 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
480509TARGET_BLOCKS+= ${WORKFAT}
481510.endif
511+ .if ${USE_MDBOOTPART} != "no"
512+ TARGET_BLOCKS+= ${WORKMDBOOTPART}
513+ .endif
482514TARGET_BLOCKS+= ${TARGETFS}
483515.if ${SWAPSECTORS} != 0
484516TARGET_BLOCKS+= ${WORKSWAP}
@@ -490,6 +522,7 @@ TARGET_BLOCKS+= ${WORKGPT}
490522CLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP}
491523CLEANFILES+= ${WORKEFI} ${WORKGPT}
492524CLEANFILES+= ${WORKFAT}
525+ CLEANFILES+= ${WORKMDBOOTPART}
493526CLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL}
494527CLEANFILES+= ${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
658694prepare_md_post: .PHONY
659695image_md_post: .PHONY
0 commit comments