Makefile.bootimage revision 1.49
11.49Stsutsui# $NetBSD: Makefile.bootimage,v 1.49 2026/01/16 23:37:19 tsutsui Exp $ 21.1Stsutsui# 31.1Stsutsui# Copyright (c) 2009, 2010, 2011 Izumi Tsutsui. All rights reserved. 41.1Stsutsui# 51.1Stsutsui# Redistribution and use in source and binary forms, with or without 61.1Stsutsui# modification, are permitted provided that the following conditions 71.1Stsutsui# are met: 81.1Stsutsui# 1. Redistributions of source code must retain the above copyright 91.1Stsutsui# notice, this list of conditions and the following disclaimer. 101.1Stsutsui# 2. Redistributions in binary form must reproduce the above copyright 111.1Stsutsui# notice, this list of conditions and the following disclaimer in the 121.1Stsutsui# documentation and/or other materials provided with the distribution. 131.1Stsutsui# 141.1Stsutsui# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 151.1Stsutsui# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 161.1Stsutsui# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 171.1Stsutsui# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 181.1Stsutsui# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 191.1Stsutsui# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 201.1Stsutsui# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 211.1Stsutsui# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 221.1Stsutsui# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 231.1Stsutsui# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 241.1Stsutsui 251.1Stsutsui# 261.1Stsutsui# Makefile to create a bootable FS image for USB flash or emulators 271.1Stsutsui# 281.1Stsutsui 291.1Stsutsui# 301.1Stsutsui# Required variables: 311.1Stsutsui# RELEASEDIR 321.1Stsutsui# Should be defined in nbmake-${MACHINE} 331.1Stsutsui# IMGBASE 341.1Stsutsui# Basename of the image 351.1Stsutsui# 361.1Stsutsui# Optional variables: 371.1Stsutsui# USE_MBR 381.1Stsutsui# set yes if target disk image requires MBR partition 391.6Stsutsui# (default: no) 401.23Sjoerg# USE_GPT 411.23Sjoerg# set yes if target disk image requires GPT partition 421.23Sjoerg# (default: no) 431.31Stsutsui# USE_GPTMBR 441.31Stsutsui# set yes if target disk image requires GPT partition 451.31Stsutsui# with hybrid MBR boot code 461.31Stsutsui# (default: no; valid only if USE_GPT=yes) 471.5Stsutsui# MBR_BOOTCODE 481.5Stsutsui# optional MBR bootcode which should be installed by fdisk(8) 491.5Stsutsui# (default: empty) 501.5Stsutsui# - specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec 511.5Stsutsui# - if MBR_BOOTCODE is not specified, 521.5Stsutsui# MBR_DEFAULT_BOOTCODE (default: mbr) will be used 531.5Stsutsui# if the target ${MACHINE} has the one in /usr/mdec 541.1Stsutsui# USE_SUNLABEL 551.1Stsutsui# set yes if target disk image requires Sun's label 561.1Stsutsui# (default: no) 571.43Stsutsui# INSTALLBOOT_AFTER_DISKLABEL 581.1Stsutsui# set yes if the target ${MACHINE} requires disklabel 591.43Stsutsui# to run installboot(8), like hp300 and vax 601.1Stsutsui# (default: empty) 611.1Stsutsui# IMAGEMB 621.1Stsutsui# target image size in MB 631.1Stsutsui# (default: 2048) 641.1Stsutsui# SWAPMB 651.1Stsutsui# swap size in target image in MB 661.1Stsutsui# (default: 128) 671.23Sjoerg# EFIMB 681.23Sjoerg# EFI partition size in target image in MB 691.23Sjoerg# (default: 128) 701.24Stsutsui# FATMB 711.24Stsutsui# FAT partition size in target image in MB 721.24Stsutsui# (default: 0) 731.31Stsutsui# GPTSECTORS 741.31Stsutsui# Size of a region reserved for the secondary GPT table/entry 751.31Stsutsui# at the end of the target image in sectors 761.31Stsutsui# (default: 2048 if USE_GPT=yes, otherwise 0) 771.1Stsutsui# KERN_SET 781.1Stsutsui# kernel set name which should be extracted into image 791.1Stsutsui# (default: kern-GENERIC) 801.1Stsutsui# SETS 811.1Stsutsui# binary sets that should be extracted into image 821.34Snia# (default: modules base etc comp games gpufw man manhtml misc 831.29Smaya# rescue tests text xbase xcomp xetc xfont xserver) 841.1Stsutsui# SETS_DIR 851.1Stsutsui# directory path where binary sets are stored 861.1Stsutsui# (default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets) 871.1Stsutsui# IMGFILE_EXTRA 881.1Stsutsui# list of additional files to be copied into images, 891.1Stsutsui# containing one or more tuples of the form: 901.1Stsutsui# FILE TARGETPATH 911.1Stsutsui# for installation image etc. 921.1Stsutsui# (default: empty) 931.1Stsutsui# IMGDIR_EXTRA 941.1Stsutsui# list of additional directories to be copied into images, 951.1Stsutsui# containing one or more tuples of the form: 961.1Stsutsui# DIR TARGETPATH 971.1Stsutsui# for installation image etc. 981.1Stsutsui# (default: empty) 991.6Stsutsui# XXX: currently permissions in IMGDIR_EXTRA are not handled 1001.1Stsutsui# IMGDIR_EXCLUDE 1011.1Stsutsui# pax(1) options to exclude files which should not copied 1021.1Stsutsui# into TARGETPATH in IMGDIR_EXTRA 1031.1Stsutsui# (default: empty) 1041.1Stsutsui# FSTAB_IN 1051.1Stsutsui# template file of /etc/fstab 1061.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/fstab.in) 1071.1Stsutsui# SPEC_IN 1081.1Stsutsui# default files of spec file for makefs(8) 1091.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/spec.in) 1101.1Stsutsui# SPEC_EXTRA 1111.1Stsutsui# additional files of spec file for makefs(8) 1121.1Stsutsui# (default: empty) 1131.1Stsutsui# IMGMAKEFSOPTIONS 1141.1Stsutsui# options passed to makefs(8) to create root file system 1151.1Stsutsui# (default: -o bsize=16384,fsize=2048,density=8192) 1161.45Stsutsui# IMGFFSVERSION 1171.45Stsutsui# version of FFS created by makefs(8) 1181.45Stsutsui# (default: 1) 1191.5Stsutsui# INSTALLBOOTOPTIONS 1201.5Stsutsui# options passed to installboot(8), e.g., -o console=com0 1211.5Stsutsui# (default: empty) 1221.1Stsutsui# PRIMARY_BOOT 1231.1Stsutsui# primary boot loader that should be installed into 1241.1Stsutsui# the target image via installboot(8) 1251.1Stsutsui# (default: empty) 1261.1Stsutsui# SECONDARY_BOOT 1271.1Stsutsui# secondary bootloader that should be put into the target image 1281.1Stsutsui# (default: empty) 1291.1Stsutsui# SECONDARY_BOOT_ARG 1301.1Stsutsui# extra arguments that should be passed to installboot(8) 1311.1Stsutsui# to specify the secondary bootloader 1321.1Stsutsui# (default: empty) 1331.1Stsutsui# DISKPROTO_IN 1341.1Stsutsui# template file of disklabel -R 1351.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/diskproto.in 1361.1Stsutsui# or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in) 1371.23Sjoerg# EFIBOOT 1381.23Sjoerg# EFI bootloader 1391.23Sjoerg# (default: empty) 1401.24Stsutsui# MBRFAT 1411.24Stsutsui# MBR partition type value for FAT 1421.24Stsutsui# (default: 6 ("16-bit FAT, more than 32M")) 1431.24Stsutsui# FATMAKEFSOPTIONS 1441.24Stsutsui# options passed to makefs(8) to create a FAT partition 1451.24Stsutsui# (default: -o fat_type=16) 1461.24Stsutsui# FATFILES 1471.24Stsutsui# list of additional files to be copied into FAT partition 1481.24Stsutsui# (default: empty) 1491.26Sjmcneill# IMAGEHOSTNAME 1501.26Sjmcneill# if set, sets the default hostname in rc.conf (default: empty) 1511.1Stsutsui# 1521.1Stsutsui 1531.1Stsutsui.include <bsd.own.mk> # 1541.1Stsutsui.include <bsd.endian.mk> # for TARGET_ENDIANNESS 1551.1Stsutsui 1561.1Stsutsui.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib" 1571.1Stsutsui 1581.13Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no" 1591.13SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1601.23SjoergGPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1611.15SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}" 1621.15Schristos.endif 1631.12Schristos 1641.1Stsutsui.if empty(IMGBASE) 1651.1Stsutsui.BEGIN: 1661.1Stsutsui @echo "Error: IMGBASE is not set" 1671.1Stsutsui @false 1681.1Stsutsui.endif 1691.1Stsutsui 1701.1Stsutsui# should be defined elsewhere? 1711.1StsutsuiCAT?= cat 1721.1StsutsuiCHMOD?= chmod 1731.1StsutsuiDD?= dd 1741.1StsutsuiMKDIR?= mkdir -p 1751.1StsutsuiRM?= rm 1761.1Stsutsui 1771.36SchristosMAKESPEC= ${HOST_SH} ${NETBSDSRCDIR}/etc/makespec 1781.36Schristos 1791.1Stsutsui# 1801.1Stsutsui# common definitions for image 1811.1Stsutsui# 1821.1StsutsuiUSE_MBR?= no 1831.23SjoergUSE_GPT?= no 1841.25SjmcneillUSE_GPTMBR?= no 1851.1StsutsuiUSE_SUNLABEL?= no 1861.1StsutsuiINSTALLBOOT_AFTER_DISKLABEL?= no 1871.1Stsutsui 1881.1Stsutsui# 1891.1Stsutsui# size parameters for image 1901.1Stsutsui# 1911.1StsutsuiIMAGEMB?= 2048 # 2048MB 1921.1StsutsuiSWAPMB?= 128 # 128MB 1931.23Sjoerg.if ${USE_GPT} == "no" 1941.23SjoergEFIMB?= 0 1951.23SjoergGPTSECTORS= 0 1961.23Sjoerg.else 1971.23SjoergEFIMB?= 128 # 128MB 1981.23SjoergGPTSECTORS= 2048 1991.23Sjoerg.endif 2001.24StsutsuiFATMB?= 0 2011.1Stsutsui 2021.3Stsutsui# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case 2031.1StsutsuiIMAGESECTORS!= expr ${IMAGEMB} \* 1024 \* 1024 / 512 2041.3StsutsuiSWAPSECTORS!= expr ${SWAPMB} \* 1024 \* 1024 / 512 || true 2051.23SjoergEFISECTORS!= expr ${EFIMB} \* 1024 \* 1024 / 512 || true 2061.24StsutsuiFATSECTORS!= expr ${FATMB} \* 1024 \* 1024 / 512 || true 2071.1Stsutsui 2081.23Sjoerg.if ${USE_MBR} == "no" && ${USE_GPT} == "no" 2091.1StsutsuiLABELSECTORS?= 0 2101.1Stsutsui.else 2111.1Stsutsui#LABELSECTORS?= 63 # historical 2121.1Stsutsui#LABELSECTORS?= 32 # 16KB aligned 2131.1StsutsuiLABELSECTORS?= 2048 # 1MB aligned for modern flash devices 2141.1Stsutsui.endif 2151.1Stsutsui 2161.23SjoergFSSECTORS!= expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \ 2171.30Smrg - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} || test $$? -eq 1 || exit 1 2181.30SmrgFSSIZE!= expr ${FSSECTORS} \* 512 || test $$? -eq 1 || exit 1 2191.1Stsutsui 2201.1Stsutsui# parameters for disklabel and MBR 2211.1StsutsuiHEADS= 64 2221.1StsutsuiSECTORS= 32 2231.1StsutsuiCYLINDERS!= expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \) 2241.1StsutsuiSECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS} 2251.1StsutsuiMBRHEADS= 255 2261.1StsutsuiMBRSECTORS= 63 2271.1StsutsuiMBRCYLINDERS!= expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \) 2281.1StsutsuiMBRNETBSD= 169 2291.24StsutsuiMBRFAT?= 6 # 16-bit FAT, more than 32M 2301.1Stsutsui 2311.24StsutsuiBSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \ 2321.24Stsutsui - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} 2331.30SmrgFSOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} || test $$? -eq 1 || exit 1 2341.24StsutsuiSWAPOFFSET!= expr ${LABELSECTORS} + ${FSSECTORS} \ 2351.30Smrg + ${EFISECTORS} + ${FATSECTORS} || test $$? -eq 1 || exit 1 2361.24StsutsuiFATOFFSET= ${LABELSECTORS} 2371.1Stsutsui 2381.47Stsutsui# helper script for sunlabel 2391.47StsutsuiDISKPROTO2SUNLABEL?= ${DISTRIBDIR}/common/bootimage/diskproto2sunlabel.awk 2401.1Stsutsui 2411.23Sjoerg.if ${USE_GPT} != "no" 2421.33SchristosBOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2431.33SchristosSWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2441.23Sjoerg.endif 2451.1Stsutsui 2461.1Stsutsui# 2471.1Stsutsui# definitions to create root fs 2481.1Stsutsui# 2491.42SjmmvSETS_DEFAULT= modules base etc comp games gpufw man misc rescue text 2501.42Sjmmv.if ${MKATF} != "no" 2511.42SjmmvSETS_DEFAULT+= tests 2521.42Sjmmv.endif 2531.34Snia.if ${MKCOMPAT} != "no" 2541.34SniaSETS_DEFAULT+= base32 2551.34Snia.endif 2561.35Snia.if ${MKCOMPAT} != "no" && \ 2571.35Snia (${MACHINE_ARCH} == "mips64eb" || ${MACHINE_ARCH} == "mips64el") 2581.35SniaSETS_DEFAULT+= base64 2591.35Snia.endif 2601.34Snia.if ${MKHTML} != "no" 2611.34SniaSETS_DEFAULT+= manhtml 2621.34Snia.endif 2631.1Stsutsui.if ${MKX11} != "no" 2641.1StsutsuiSETS_DEFAULT+= xbase xcomp xetc xfont xserver 2651.1Stsutsui.endif 2661.1Stsutsui 2671.1StsutsuiKERN_SET?= kern-GENERIC 2681.1StsutsuiSETS?= ${SETS_DEFAULT} 2691.1StsutsuiIMG_SETS= ${KERN_SET} ${SETS} 2701.1StsutsuiSETS_DIR?= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 2711.1Stsutsui 2721.1StsutsuiFSTAB_IN?= ${DISTRIBDIR}/common/bootimage/fstab.in 2731.46Spgoyette.if ${KERNEL_DIR:Uno} == "yes" 2741.46SpgoyetteSPEC_IN?= ${DISTRIBDIR}/common/bootimage/spec-dir.in 2751.46Spgoyette.else 2761.1StsutsuiSPEC_IN?= ${DISTRIBDIR}/common/bootimage/spec.in 2771.46Spgoyette.endif 2781.1Stsutsui 2791.1StsutsuiIMGMAKEFSOPTIONS?= -o bsize=16384,fsize=2048,density=8192 2801.45StsutsuiIMGFFSVERSION?= 1 2811.24StsutsuiFATMAKEFSOPTIONS?= -o fat_type=16 2821.1Stsutsui 2831.1StsutsuiWORKDIR?= work 2841.1StsutsuiWORKSPEC?= work.spec 2851.1StsutsuiWORKFSTAB?= work.fstab 2861.1StsutsuiWORKRCCONF?= work.rc.conf 2871.1StsutsuiWORKFS?= work.rootfs 2881.1StsutsuiTARGETFS?= imgroot.fs 2891.19SaymericCOMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}} 2901.18SmartinTAR_SUFF= ${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz} 2911.1Stsutsui 2921.1StsutsuiCLEANFILES+= ${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS} 2931.1StsutsuiCLEANFILES+= ${TARGETFS} 2941.1Stsutsui 2951.1Stsutsui# 2961.23Sjoerg# definitions to create image 2971.23Sjoerg# 2981.23Sjoerg.if ${SWAPSECTORS} == 0 2991.23Sjoerg. if ${USE_MBR} != "no" 3001.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in 3011.23Sjoerg. else 3021.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.in 3031.23Sjoerg. endif 3041.23Sjoerg.else 3051.23Sjoerg. if ${USE_MBR} != "no" 3061.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in 3071.23Sjoerg. else 3081.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.in 3091.23Sjoerg. endif 3101.23Sjoerg.endif 3111.23Sjoerg 3121.23SjoergMBR_DEFAULT_BOOTCODE?= mbr 3131.23Sjoerg 3141.23SjoergWORKMBR?= work.mbr 3151.23SjoergWORKMBRTRUNC?= work.mbr.truncated 3161.23SjoergWORKSWAP?= work.swap 3171.23SjoergWORKEFI?= work.efi 3181.23SjoergWORKGPT?= work.gpt 3191.23SjoergWORKLABEL?= work.diskproto 3201.23SjoergWORKIMG?= work.img 3211.23SjoergEFIWORKDIR?= work.efidir 3221.24StsutsuiWORKFAT?= work.fat 3231.24StsutsuiWORKFATDIR?= work.fatdir 3241.23Sjoerg 3251.23Sjoerg.if ${USE_GPT} != "no" 3261.23Sjoerg${WORKFSTAB}: ${WORKMBR} 3271.27Stsutsui 3281.27Stsutsui.BEGIN: 3291.27Stsutsui @if [ -f ${WORKMBR} ]; then \ 3301.27Stsutsui st_size=`${TOOL_STAT} -f %z ${WORKMBR}`; \ 3311.27Stsutsui if [ "$$st_size" -ne "$$((${IMAGESECTORS} * 512))" ]; then \ 3321.27Stsutsui echo Removing stale ${WORKMBR} ...; \ 3331.27Stsutsui rm -f ${WORKMBR}; \ 3341.27Stsutsui fi \ 3351.27Stsutsui fi 3361.23Sjoerg.endif 3371.23Sjoerg 3381.23Sjoerg${WORKFSTAB}: 3391.23Sjoerg @echo Preparing /etc/fstab ... 3401.23Sjoerg.if ${USE_GPT} != "no" 3411.23Sjoerg. if ${SWAPSECTORS} != 0 3421.23Sjoerg ${TOOL_SED} \ 3431.41Smartin -e "s/ROOT.a/NAME=NBImgRoot/" \ 3441.41Smartin -e "s/ROOT.b/NAME=NBImgSwap/" \ 3451.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3461.23Sjoerg. else 3471.23Sjoerg ${TOOL_SED} \ 3481.41Smartin -e "s/ROOT.a/NAME=NBImgRoot/" \ 3491.23Sjoerg -e "/ROOT.b/d" \ 3501.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3511.23Sjoerg. endif 3521.23Sjoerg.else 3531.23Sjoerg. if ${SWAPSECTORS} != 0 3541.23Sjoerg ${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB} 3551.23Sjoerg. else 3561.23Sjoerg ${TOOL_SED} \ 3571.23Sjoerg -e "/ROOT.b/d" \ 3581.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3591.23Sjoerg. endif 3601.23Sjoerg.endif 3611.23Sjoerg 3621.23Sjoerg# 3631.1Stsutsui# create root file system for the image 3641.1Stsutsui# 3651.23Sjoerg${TARGETFS}: prepare_md_post ${WORKFSTAB} 3661.36Schristos @${RM} -f ${WORKSPEC} 3671.1Stsutsui @if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then \ 3681.1Stsutsui echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \ 3691.1Stsutsui false; \ 3701.1Stsutsui fi; 3711.14Schristos @${MKDIR} ${MKDIRPERM} ${WORKDIR} 3721.1Stsutsui.for set in ${IMG_SETS} 3731.18Smartin @if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then \ 3741.18Smartin echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\ 3751.1Stsutsui false; \ 3761.1Stsutsui fi 3771.18Smartin @echo Extracting ${set}.${TAR_SUFF} ... 3781.19Saymeric @(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \ 3791.19Saymeric --use-compress-program=${COMPRESS_PROGRAM:Q} \ 3801.19Saymeric -f ${SETS_DIR}/${set}.${TAR_SUFF} .) 3811.1Stsutsui.endfor 3821.1Stsutsui.if defined(SECONDARY_BOOT) 3831.1Stsutsui @echo Copying secondary boot... 3841.21Stsutsui ${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR} 3851.1Stsutsui.endif 3861.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab 3871.1Stsutsui @echo Setting rc_configured=YES in /etc/rc.conf ... 3881.1Stsutsui ${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/" \ 3891.1Stsutsui < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF} 3901.26Sjmcneill.if defined(IMAGEHOSTNAME) 3911.26Sjmcneill @echo Setting hostname=${IMAGEHOSTNAME} in /etc/rc.conf ... 3921.26Sjmcneill echo "hostname=${IMAGEHOSTNAME}" >> ${WORKRCCONF} 3931.26Sjmcneill.endif 3941.26Sjmcneill.if ${SWAPSECTORS} == 0 3951.26Sjmcneill @echo Setting no_swap=YES in /etc/rc.conf ... 3961.26Sjmcneill echo "no_swap=YES" >> ${WORKRCCONF} 3971.26Sjmcneill @echo Setting savecore=NO in /etc/rc.conf ... 3981.26Sjmcneill echo "savecore=NO" >> ${WORKRCCONF} 3991.26Sjmcneill.endif 4001.28Sjmcneill.if defined(RC_CONF_EXTRA) 4011.28Sjmcneill @echo Adding contents of ${RC_CONF_EXTRA} to /etc/rc.conf ... 4021.28Sjmcneill cat ${RC_CONF_EXTRA} >> ${WORKRCCONF} 4031.28Sjmcneill.endif 4041.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf 4051.1Stsutsui.if defined(IMGDIR_EXTRA) 4061.1Stsutsui @echo Copying extra dirs... 4071.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA} 4081.1Stsutsui @if [ ! -d ${_SRCDIR} ]; then \ 4091.1Stsutsui echo "${_SRCDIR} is not directory, aborting"; \ 4101.1Stsutsui false; \ 4111.1Stsutsui fi 4121.14Schristos ${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET} 4131.1Stsutsui (cd ${_SRCDIR} ; \ 4141.21Stsutsui ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v \ 4151.1Stsutsui ${IMGDIR_EXCLUDE} \ 4161.1Stsutsui . ${.OBJDIR}/${WORKDIR}/${_TARGET} ) 4171.1Stsutsui.endfor 4181.1Stsutsui.endif 4191.1Stsutsui.if defined(IMGFILE_EXTRA) 4201.1Stsutsui @echo Copying extra files... 4211.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA} 4221.1Stsutsui @if [ ! -f ${_SRC} ]; then \ 4231.1Stsutsui echo "${_SRC} in IMGFILE_EXTRA not found, aborting"; \ 4241.1Stsutsui false; \ 4251.1Stsutsui fi 4261.1Stsutsui @if [ -f ${_SRC} ]; then \ 4271.21Stsutsui echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 4281.21Stsutsui ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 4291.36Schristos echo "./${_TARGET} type=file uname=root gname=wheel mode=0555" >> ${WORKSPEC}; \ 4301.1Stsutsui fi 4311.1Stsutsui.endfor 4321.1Stsutsui.endif 4331.1Stsutsui @echo Preparing spec files for makefs... 4341.1Stsutsui cat ${WORKDIR}/etc/mtree/* | \ 4351.1Stsutsui ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC} 4361.10Ssnj ${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty | \ 4371.1Stsutsui ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC} 4381.1Stsutsui cat ${SPEC_IN} >> ${WORKSPEC} 4391.1Stsutsui.if defined(SECONDARY_BOOT) 4401.1Stsutsui echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \ 4411.1Stsutsui >> ${WORKSPEC} 4421.1Stsutsui.endif 4431.1Stsutsui.if defined(SPEC_EXTRA) 4441.1Stsutsui cat ${SPEC_EXTRA} >> ${WORKSPEC} 4451.1Stsutsui.endif 4461.37Schristos for i in ${WORKDIR}/netbsd.*; do \ 4471.37Schristos if [ -e $$i ]; then \ 4481.37Schristos echo "./$$(basename $$i) type=file uname=root gname=wheel mode=0444" >> ${WORKSPEC}; \ 4491.37Schristos fi; \ 4501.37Schristos done 4511.37Schristos if [ -d ${WORKDIR}/${RELEASEMACHINEDIR} ]; then \ 4521.37Schristos ${MAKESPEC} -d ${WORKDIR} ${RELEASEMACHINEDIR} >> ${WORKSPEC}; \ 4531.36Schristos fi 4541.4Sriz @echo Creating rootfs... 4551.1Stsutsui # XXX /var/spool/ftp/hidden is unreadable 4561.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden 4571.1Stsutsui ${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE} \ 4581.1Stsutsui -B ${TARGET_ENDIANNESS} \ 4591.36Schristos -xx -F ${WORKSPEC} -N ${WORKDIR}/etc \ 4601.13Schristos ${MAKEFS_TIMESTAMP} \ 4611.45Stsutsui -t ffs \ 4621.1Stsutsui ${IMGMAKEFSOPTIONS} \ 4631.45Stsutsui -o version=${IMGFFSVERSION} \ 4641.1Stsutsui ${WORKFS} ${WORKDIR} 4651.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no" 4661.5Stsutsui ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \ 4671.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG} 4681.1Stsutsui.endif 4691.1Stsutsui @echo done. 4701.1Stsutsui mv ${WORKFS} ${.TARGET} 4711.1Stsutsui 4721.23SjoergTARGET_BLOCKS= 4731.23Sjoerg.if ${USE_MBR} != "no" || ${USE_GPT} != "no" 4741.23SjoergTARGET_BLOCKS+= ${WORKMBRTRUNC} 4751.23Sjoerg.endif 4761.23Sjoerg.if ${USE_GPT} != "no" 4771.23SjoergTARGET_BLOCKS+= ${WORKEFI} 4781.23Sjoerg.endif 4791.24Stsutsui.if ${FATSECTORS} != 0 4801.24StsutsuiTARGET_BLOCKS+= ${WORKFAT} 4811.24Stsutsui.endif 4821.23SjoergTARGET_BLOCKS+= ${TARGETFS} 4831.23Sjoerg.if ${SWAPSECTORS} != 0 4841.23SjoergTARGET_BLOCKS+= ${WORKSWAP} 4851.23Sjoerg.endif 4861.23Sjoerg.if ${USE_GPT} != "no" 4871.23SjoergTARGET_BLOCKS+= ${WORKGPT} 4881.1Stsutsui.endif 4891.1Stsutsui 4901.23SjoergCLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP} 4911.23SjoergCLEANFILES+= ${WORKEFI} ${WORKGPT} 4921.24StsutsuiCLEANFILES+= ${WORKFAT} 4931.23SjoergCLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL} 4941.23SjoergCLEANFILES+= ${WORKIMG} ${IMGBASE}.img 4951.5Stsutsui 4961.23Sjoerg${WORKSWAP}: 4971.23Sjoerg.if ${SWAPSECTORS} == 0 4981.23Sjoerg printf "" > ${WORKSWAP} 4991.23Sjoerg.else 5001.23Sjoerg ${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1 5011.23Sjoerg.endif 5021.1Stsutsui 5031.23Sjoerg${WORKMBRTRUNC}: ${WORKMBR} 5041.23Sjoerg ${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC} 5051.1Stsutsui 5061.1Stsutsui${WORKLABEL}: 5071.1Stsutsui ${TOOL_SED} \ 5081.1Stsutsui -e "s/@@SECTORS@@/${SECTORS}/" \ 5091.1Stsutsui -e "s/@@HEADS@@/${HEADS}/" \ 5101.1Stsutsui -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/" \ 5111.1Stsutsui -e "s/@@CYLINDERS@@/${CYLINDERS}/" \ 5121.1Stsutsui -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/" \ 5131.1Stsutsui -e "s/@@FSSECTORS@@/${FSSECTORS}/" \ 5141.1Stsutsui -e "s/@@FSOFFSET@@/${FSOFFSET}/" \ 5151.1Stsutsui -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/" \ 5161.1Stsutsui -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/" \ 5171.1Stsutsui -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/" \ 5181.24Stsutsui -e "s/@@FATSECTORS@@/${FATSECTORS}/" \ 5191.24Stsutsui -e "s/@@FATOFFSET@@/${FATOFFSET}/" \ 5201.1Stsutsui < ${DISKPROTO_IN} > ${WORKLABEL}.tmp 5211.1Stsutsui mv ${WORKLABEL}.tmp ${WORKLABEL} 5221.1Stsutsui 5231.23Sjoerg${WORKEFI}: ${TARGETFS} 5241.23Sjoerg @echo create EFI system partition... 5251.23Sjoerg @${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot 5261.23Sjoerg.for f in ${EFIBOOT} 5271.23Sjoerg ${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}` 5281.23Sjoerg.endfor 5291.23Sjoerg ${RM} -f ${WORKEFI} 5301.23Sjoerg ${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m \ 5311.23Sjoerg ${MAKEFS_TIMESTAMP} \ 5321.23Sjoerg -t msdos -o F=32,c=1 \ 5331.23Sjoerg ${WORKEFI} ${EFIWORKDIR} 5341.23Sjoerg 5351.49Stsutsui.if defined(FATFILES) 5361.48Stsutsui${FATFILES}: ${TARGETFS} 5371.48Stsutsui # Some MD ${FATFILES} (bootloaders etc.) are assumed extracted 5381.48Stsutsui # to ${WORKDIR} from binary sets during ${TARGETFS} image build 5391.49Stsutsui.endif 5401.48Stsutsui 5411.48Stsutsui${WORKFAT}: ${FATFILES} 5421.24Stsutsui @echo create FAT partition for bootstrap files... 5431.24Stsutsui @${MKDIR} ${MKDIRPERM} ${WORKFATDIR} 5441.24Stsutsui.if defined(FATFILES) 5451.24Stsutsui @echo Copying files for FAT partition... 5461.24Stsutsui.for f in ${FATFILES} 5471.24Stsutsui @if [ ! -f ${f} ]; then \ 5481.24Stsutsui echo "${f} in FATFILES not found, aborting"; \ 5491.24Stsutsui false; \ 5501.24Stsutsui fi 5511.24Stsutsui ${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR} 5521.24Stsutsui.endfor 5531.24Stsutsui.endif 5541.24Stsutsui ${RM} -f ${WORKFAT} 5551.24Stsutsui ${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m \ 5561.24Stsutsui ${MAKEFS_TIMESTAMP} \ 5571.24Stsutsui -t msdos \ 5581.24Stsutsui ${FATMAKEFSOPTIONS} \ 5591.24Stsutsui ${WORKFAT} ${WORKFATDIR} 5601.24Stsutsui 5611.23Sjoerg${WORKMBR}: 5621.23Sjoerg.if ${USE_GPT} != "no" 5631.23Sjoerg @echo creating GPT header and partition entries... 5641.23Sjoerg ${RM} -f ${WORKMBR} 5651.23Sjoerg ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5661.33Schristos ${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} create 5671.33Schristos ${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system" 5681.40Smartin ${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs -l "NBImgRoot" 5691.23Sjoerg. if ${SWAPSECTORS} != 0 5701.41Smartin ${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap -l "NBImgSwap" 5711.23Sjoerg. endif 5721.23Sjoerg.elif ${USE_MBR} != "no" 5731.1Stsutsui @echo creating MBR labels... 5741.1Stsutsui ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5751.24Stsutsui. if ${FATSECTORS} != 0 5761.24Stsutsui # create BSD partition 5771.24Stsutsui ${TOOL_FDISK} -f -i -u \ 5781.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5791.24Stsutsui -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5801.24Stsutsui -F ${WORKMBR} 5811.24Stsutsui # create FAT partition 5821.24Stsutsui ${TOOL_FDISK} -f -u \ 5831.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5841.24Stsutsui -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS} \ 5851.24Stsutsui -F ${WORKMBR} 5861.24Stsutsui. else 5871.24Stsutsui # create BSD partition 5881.5Stsutsui ${TOOL_FDISK} -f -i -u \ 5891.1Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5901.1Stsutsui -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5911.1Stsutsui -F ${WORKMBR} 5921.24Stsutsui. endif 5931.23Sjoerg. if empty(MBR_BOOTCODE) 5941.5Stsutsui @if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then \ 5951.5Stsutsui echo ${TOOL_FDISK} -f \ 5961.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5971.5Stsutsui -F ${WORKMBR}; \ 5981.5Stsutsui ${TOOL_FDISK} -f \ 5991.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 6001.5Stsutsui -F ${WORKMBR}; \ 6011.5Stsutsui fi 6021.23Sjoerg. else 6031.5Stsutsui @if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then \ 6041.5Stsutsui echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \ 6051.5Stsutsui false; \ 6061.5Stsutsui fi 6071.5Stsutsui ${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} \ 6081.5Stsutsui -F ${WORKMBR} 6091.23Sjoerg. endif 6101.5Stsutsui.endif 6111.23Sjoerg 6121.23Sjoerg${WORKGPT}: ${WORKMBR} 6131.23Sjoerg @echo create GPT image... 6141.32Stsutsui ${DD} if=${WORKMBR} of=${WORKGPT} \ 6151.32Stsutsui skip=$$((${IMAGESECTORS} - ${GPTSECTORS})) count=${GPTSECTORS} 6161.23Sjoerg 6171.23Sjoerg.if ${USE_GPT} == "no" 6181.23Sjoerg${IMGBASE}.img: ${WORKLABEL} 6191.1Stsutsui.endif 6201.23Sjoerg 6211.23Sjoerg${IMGBASE}.img: ${TARGET_BLOCKS} 6221.23Sjoerg ${CAT} ${TARGET_BLOCKS} > ${WORKIMG} 6231.23Sjoerg.if ${USE_GPT} != "no" 6241.25Sjmcneill.if ${USE_GPTMBR} != "no" 6251.33Schristos ${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKIMG} biosboot -i 2 \ 6261.23Sjoerg -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin 6271.25Sjmcneill.endif 6281.33Schristos ${TOOL_GPT} ${GPT_TIMESTAMP} ${WORKIMG} set -a bootme -i 2 6291.23Sjoerg.endif # USE_GPT != "no" 6301.1Stsutsui.if ${USE_SUNLABEL} != "no" 6311.1Stsutsui @echo Creating sun disklabel... 6321.47Stsutsui ${TOOL_AWK} -f ${DISKPROTO2SUNLABEL} < ${WORKLABEL} | \ 6331.1Stsutsui ${TOOL_SUNLABEL} -nq ${WORKIMG} 6341.1Stsutsui.endif 6351.23Sjoerg.if ${USE_GPT} == "no" 6361.1Stsutsui ${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL} 6371.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no" 6381.11Sriastrad ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \ 6391.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} 6401.1Stsutsui.endif 6411.23Sjoerg.endif 6421.1Stsutsui mv ${WORKIMG} ${.TARGET} 6431.1Stsutsui 6441.1StsutsuiCLEANFILES+= ${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp 6451.1Stsutsui 6461.1Stsutsui${IMGBASE}.img.gz: ${IMGBASE}.img 6471.9Sapb ${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp 6481.1Stsutsui mv ${.TARGET}.tmp ${.TARGET} 6491.1Stsutsui 6501.1Stsutsuiclean: 6511.1Stsutsui @if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then \ 6521.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden; \ 6531.1Stsutsui fi # XXX 6541.1Stsutsui ${RM} -fr ${WORKDIR} 6551.23Sjoerg ${RM} -fr ${EFIWORKDIR} 6561.24Stsutsui ${RM} -fr ${WORKFATDIR} 6571.1Stsutsui 6581.1Stsutsuiprepare_md_post: .PHONY 6591.1Stsutsuiimage_md_post: .PHONY 6601.1Stsutsuiimage_md_pre: .PHONY 6611.1Stsutsui 6621.1Stsutsui.include <bsd.prog.mk> 663