Makefile.bootimage revision 1.25
11.25Sjmcneill# $NetBSD: Makefile.bootimage,v 1.25 2020/05/28 15:13:21 jmcneill 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.5Stsutsui# MBR_BOOTCODE 441.5Stsutsui# optional MBR bootcode which should be installed by fdisk(8) 451.5Stsutsui# (default: empty) 461.5Stsutsui# - specified MBR_BOOTCODE must exist in ${DESTDIR}/usr/mdec 471.5Stsutsui# - if MBR_BOOTCODE is not specified, 481.5Stsutsui# MBR_DEFAULT_BOOTCODE (default: mbr) will be used 491.5Stsutsui# if the target ${MACHINE} has the one in /usr/mdec 501.1Stsutsui# USE_SUNLABEL 511.1Stsutsui# set yes if target disk image requires Sun's label 521.1Stsutsui# (default: no) 531.1Stsutsui# INSTALLBOOT_AFTER_DISKLABEL (untested) 541.1Stsutsui# set yes if the target ${MACHINE} requires disklabel 551.1Stsutsui# to run installboot(8), like hp300 561.1Stsutsui# (default: empty) 571.1Stsutsui# IMAGEMB 581.1Stsutsui# target image size in MB 591.1Stsutsui# (default: 2048) 601.1Stsutsui# SWAPMB 611.1Stsutsui# swap size in target image in MB 621.1Stsutsui# (default: 128) 631.23Sjoerg# EFIMB 641.23Sjoerg# EFI partition size in target image in MB 651.23Sjoerg# (default: 128) 661.24Stsutsui# FATMB 671.24Stsutsui# FAT partition size in target image in MB 681.24Stsutsui# (default: 0) 691.1Stsutsui# KERN_SET 701.1Stsutsui# kernel set name which should be extracted into image 711.1Stsutsui# (default: kern-GENERIC) 721.1Stsutsui# SETS 731.1Stsutsui# binary sets that should be extracted into image 741.22Smaya# (default: modules base etc comp games man misc rescue tests 751.22Smaya# text xbase xcomp xetc xfont xserver) 761.1Stsutsui# SETS_DIR 771.1Stsutsui# directory path where binary sets are stored 781.1Stsutsui# (default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets) 791.1Stsutsui# IMGFILE_EXTRA 801.1Stsutsui# list of additional files to be copied into images, 811.1Stsutsui# containing one or more tuples of the form: 821.1Stsutsui# FILE TARGETPATH 831.1Stsutsui# for installation image etc. 841.1Stsutsui# (default: empty) 851.1Stsutsui# IMGDIR_EXTRA 861.1Stsutsui# list of additional directories to be copied into images, 871.1Stsutsui# containing one or more tuples of the form: 881.1Stsutsui# DIR TARGETPATH 891.1Stsutsui# for installation image etc. 901.1Stsutsui# (default: empty) 911.6Stsutsui# XXX: currently permissions in IMGDIR_EXTRA are not handled 921.1Stsutsui# IMGDIR_EXCLUDE 931.1Stsutsui# pax(1) options to exclude files which should not copied 941.1Stsutsui# into TARGETPATH in IMGDIR_EXTRA 951.1Stsutsui# (default: empty) 961.1Stsutsui# FSTAB_IN 971.1Stsutsui# template file of /etc/fstab 981.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/fstab.in) 991.1Stsutsui# SPEC_IN 1001.1Stsutsui# default files of spec file for makefs(8) 1011.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/spec.in) 1021.1Stsutsui# SPEC_EXTRA 1031.1Stsutsui# additional files of spec file for makefs(8) 1041.1Stsutsui# (default: empty) 1051.1Stsutsui# IMGMAKEFSOPTIONS 1061.1Stsutsui# options passed to makefs(8) to create root file system 1071.1Stsutsui# (default: -o bsize=16384,fsize=2048,density=8192) 1081.5Stsutsui# INSTALLBOOTOPTIONS 1091.5Stsutsui# options passed to installboot(8), e.g., -o console=com0 1101.5Stsutsui# (default: empty) 1111.1Stsutsui# PRIMARY_BOOT 1121.1Stsutsui# primary boot loader that should be installed into 1131.1Stsutsui# the target image via installboot(8) 1141.1Stsutsui# (default: empty) 1151.1Stsutsui# SECONDARY_BOOT 1161.1Stsutsui# secondary bootloader that should be put into the target image 1171.1Stsutsui# (default: empty) 1181.1Stsutsui# SECONDARY_BOOT_ARG 1191.1Stsutsui# extra arguments that should be passed to installboot(8) 1201.1Stsutsui# to specify the secondary bootloader 1211.1Stsutsui# (default: empty) 1221.1Stsutsui# DISKPROTO_IN 1231.1Stsutsui# template file of disklabel -R 1241.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/diskproto.in 1251.1Stsutsui# or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in) 1261.23Sjoerg# EFIBOOT 1271.23Sjoerg# EFI bootloader 1281.23Sjoerg# (default: empty) 1291.24Stsutsui# MBRFAT 1301.24Stsutsui# MBR partition type value for FAT 1311.24Stsutsui# (default: 6 ("16-bit FAT, more than 32M")) 1321.24Stsutsui# FATMAKEFSOPTIONS 1331.24Stsutsui# options passed to makefs(8) to create a FAT partition 1341.24Stsutsui# (default: -o fat_type=16) 1351.24Stsutsui# FATFILES 1361.24Stsutsui# list of additional files to be copied into FAT partition 1371.24Stsutsui# (default: empty) 1381.1Stsutsui# 1391.1Stsutsui 1401.1Stsutsui.include <bsd.own.mk> # 1411.1Stsutsui.include <bsd.endian.mk> # for TARGET_ENDIANNESS 1421.1Stsutsui 1431.1Stsutsui.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib" 1441.1Stsutsui 1451.13Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no" 1461.13SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1471.23SjoergGPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1481.15SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}" 1491.15Schristos.endif 1501.12Schristos 1511.1Stsutsui.if empty(IMGBASE) 1521.1Stsutsui.BEGIN: 1531.1Stsutsui @echo "Error: IMGBASE is not set" 1541.1Stsutsui @false 1551.1Stsutsui.endif 1561.1Stsutsui 1571.1Stsutsui# should be defined elsewhere? 1581.1StsutsuiCAT?= cat 1591.1StsutsuiCHMOD?= chmod 1601.1StsutsuiDD?= dd 1611.1StsutsuiMKDIR?= mkdir -p 1621.1StsutsuiRM?= rm 1631.1Stsutsui 1641.1Stsutsui# 1651.1Stsutsui# common definitions for image 1661.1Stsutsui# 1671.1StsutsuiUSE_MBR?= no 1681.23SjoergUSE_GPT?= no 1691.25SjmcneillUSE_GPTMBR?= no 1701.1StsutsuiUSE_SUNLABEL?= no 1711.1StsutsuiINSTALLBOOT_AFTER_DISKLABEL?= no 1721.1Stsutsui 1731.1Stsutsui# 1741.1Stsutsui# size parameters for image 1751.1Stsutsui# 1761.1StsutsuiIMAGEMB?= 2048 # 2048MB 1771.1StsutsuiSWAPMB?= 128 # 128MB 1781.23Sjoerg.if ${USE_GPT} == "no" 1791.23SjoergEFIMB?= 0 1801.23SjoergGPTSECTORS= 0 1811.23Sjoerg.else 1821.23SjoergEFIMB?= 128 # 128MB 1831.23SjoergGPTSECTORS= 2048 1841.23Sjoerg.endif 1851.24StsutsuiFATMB?= 0 1861.1Stsutsui 1871.3Stsutsui# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case 1881.1StsutsuiIMAGESECTORS!= expr ${IMAGEMB} \* 1024 \* 1024 / 512 1891.3StsutsuiSWAPSECTORS!= expr ${SWAPMB} \* 1024 \* 1024 / 512 || true 1901.23SjoergEFISECTORS!= expr ${EFIMB} \* 1024 \* 1024 / 512 || true 1911.24StsutsuiFATSECTORS!= expr ${FATMB} \* 1024 \* 1024 / 512 || true 1921.1Stsutsui 1931.23Sjoerg.if ${USE_MBR} == "no" && ${USE_GPT} == "no" 1941.1StsutsuiLABELSECTORS?= 0 1951.1Stsutsui.else 1961.1Stsutsui#LABELSECTORS?= 63 # historical 1971.1Stsutsui#LABELSECTORS?= 32 # 16KB aligned 1981.1StsutsuiLABELSECTORS?= 2048 # 1MB aligned for modern flash devices 1991.1Stsutsui.endif 2001.1Stsutsui 2011.23SjoergFSSECTORS!= expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \ 2021.24Stsutsui - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} 2031.1StsutsuiFSSIZE!= expr ${FSSECTORS} \* 512 2041.1Stsutsui 2051.1Stsutsui# parameters for disklabel and MBR 2061.1StsutsuiHEADS= 64 2071.1StsutsuiSECTORS= 32 2081.1StsutsuiCYLINDERS!= expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \) 2091.1StsutsuiSECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS} 2101.1StsutsuiMBRHEADS= 255 2111.1StsutsuiMBRSECTORS= 63 2121.1StsutsuiMBRCYLINDERS!= expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \) 2131.1StsutsuiMBRNETBSD= 169 2141.24StsutsuiMBRFAT?= 6 # 16-bit FAT, more than 32M 2151.1Stsutsui 2161.24StsutsuiBSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \ 2171.24Stsutsui - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} 2181.24StsutsuiFSOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} 2191.24StsutsuiSWAPOFFSET!= expr ${LABELSECTORS} + ${FSSECTORS} \ 2201.24Stsutsui + ${EFISECTORS} + ${FATSECTORS} 2211.24StsutsuiFATOFFSET= ${LABELSECTORS} 2221.1Stsutsui 2231.1Stsutsui# parameters for sunlabel 2241.1StsutsuiFSCYLINDERS!= expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \) 2251.3StsutsuiSWAPCYLINDERS!= expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true 2261.1Stsutsui 2271.23Sjoerg.if ${USE_GPT} != "no" 2281.23SjoergBOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2291.23SjoergSWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2301.23Sjoerg.endif 2311.1Stsutsui 2321.1Stsutsui# 2331.1Stsutsui# definitions to create root fs 2341.1Stsutsui# 2351.22SmayaSETS_DEFAULT= modules base etc comp games man misc rescue tests text 2361.1Stsutsui.if ${MKX11} != "no" 2371.1StsutsuiSETS_DEFAULT+= xbase xcomp xetc xfont xserver 2381.1Stsutsui.endif 2391.1Stsutsui 2401.1StsutsuiKERN_SET?= kern-GENERIC 2411.1StsutsuiSETS?= ${SETS_DEFAULT} 2421.1StsutsuiIMG_SETS= ${KERN_SET} ${SETS} 2431.1StsutsuiSETS_DIR?= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 2441.1Stsutsui 2451.1StsutsuiFSTAB_IN?= ${DISTRIBDIR}/common/bootimage/fstab.in 2461.1StsutsuiSPEC_IN?= ${DISTRIBDIR}/common/bootimage/spec.in 2471.1Stsutsui 2481.1StsutsuiIMGMAKEFSOPTIONS?= -o bsize=16384,fsize=2048,density=8192 2491.24StsutsuiFATMAKEFSOPTIONS?= -o fat_type=16 2501.1Stsutsui 2511.1StsutsuiWORKDIR?= work 2521.1StsutsuiWORKSPEC?= work.spec 2531.1StsutsuiWORKFSTAB?= work.fstab 2541.1StsutsuiWORKRCCONF?= work.rc.conf 2551.1StsutsuiWORKFS?= work.rootfs 2561.1StsutsuiTARGETFS?= imgroot.fs 2571.19SaymericCOMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}} 2581.18SmartinTAR_SUFF= ${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz} 2591.1Stsutsui 2601.1StsutsuiCLEANFILES+= ${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS} 2611.1StsutsuiCLEANFILES+= ${TARGETFS} 2621.1Stsutsui 2631.1Stsutsui# 2641.23Sjoerg# definitions to create image 2651.23Sjoerg# 2661.23Sjoerg.if ${SWAPSECTORS} == 0 2671.23Sjoerg. if ${USE_MBR} != "no" 2681.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in 2691.23Sjoerg. else 2701.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.in 2711.23Sjoerg. endif 2721.23Sjoerg.else 2731.23Sjoerg. if ${USE_MBR} != "no" 2741.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in 2751.23Sjoerg. else 2761.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.in 2771.23Sjoerg. endif 2781.23Sjoerg.endif 2791.23Sjoerg 2801.23SjoergMBR_DEFAULT_BOOTCODE?= mbr 2811.23Sjoerg 2821.23SjoergWORKMBR?= work.mbr 2831.23SjoergWORKMBRTRUNC?= work.mbr.truncated 2841.23SjoergWORKSWAP?= work.swap 2851.23SjoergWORKEFI?= work.efi 2861.23SjoergWORKGPT?= work.gpt 2871.23SjoergWORKLABEL?= work.diskproto 2881.23SjoergWORKIMG?= work.img 2891.23SjoergEFIWORKDIR?= work.efidir 2901.24StsutsuiWORKFAT?= work.fat 2911.24StsutsuiWORKFATDIR?= work.fatdir 2921.23Sjoerg 2931.23Sjoerg.if ${USE_GPT} != "no" 2941.23Sjoerg${WORKFSTAB}: ${WORKMBR} 2951.23Sjoerg.endif 2961.23Sjoerg 2971.23Sjoerg${WORKFSTAB}: 2981.23Sjoerg @echo Preparing /etc/fstab ... 2991.23Sjoerg.if ${USE_GPT} != "no" 3001.23Sjoerg. if ${SWAPSECTORS} != 0 3011.23Sjoerg ${TOOL_SED} \ 3021.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 3031.23Sjoerg -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/" \ 3041.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3051.23Sjoerg. else 3061.23Sjoerg ${TOOL_SED} \ 3071.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 3081.23Sjoerg -e "/ROOT.b/d" \ 3091.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3101.23Sjoerg. endif 3111.23Sjoerg.else 3121.23Sjoerg. if ${SWAPSECTORS} != 0 3131.23Sjoerg ${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB} 3141.23Sjoerg. else 3151.23Sjoerg ${TOOL_SED} \ 3161.23Sjoerg -e "/ROOT.b/d" \ 3171.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3181.23Sjoerg. endif 3191.23Sjoerg.endif 3201.23Sjoerg 3211.23Sjoerg# 3221.1Stsutsui# create root file system for the image 3231.1Stsutsui# 3241.23Sjoerg${TARGETFS}: prepare_md_post ${WORKFSTAB} 3251.1Stsutsui @if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then \ 3261.1Stsutsui echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \ 3271.1Stsutsui false; \ 3281.1Stsutsui fi; 3291.14Schristos @${MKDIR} ${MKDIRPERM} ${WORKDIR} 3301.1Stsutsui.for set in ${IMG_SETS} 3311.18Smartin @if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then \ 3321.18Smartin echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\ 3331.1Stsutsui false; \ 3341.1Stsutsui fi 3351.18Smartin @echo Extracting ${set}.${TAR_SUFF} ... 3361.19Saymeric @(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \ 3371.19Saymeric --use-compress-program=${COMPRESS_PROGRAM:Q} \ 3381.19Saymeric -f ${SETS_DIR}/${set}.${TAR_SUFF} .) 3391.1Stsutsui.endfor 3401.1Stsutsui.if defined(SECONDARY_BOOT) 3411.1Stsutsui @echo Copying secondary boot... 3421.21Stsutsui ${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR} 3431.1Stsutsui.endif 3441.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab 3451.1Stsutsui @echo Setting rc_configured=YES in /etc/rc.conf ... 3461.1Stsutsui ${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/" \ 3471.1Stsutsui < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF} 3481.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf 3491.1Stsutsui.if defined(IMGDIR_EXTRA) 3501.1Stsutsui @echo Copying extra dirs... 3511.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA} 3521.1Stsutsui @if [ ! -d ${_SRCDIR} ]; then \ 3531.1Stsutsui echo "${_SRCDIR} is not directory, aborting"; \ 3541.1Stsutsui false; \ 3551.1Stsutsui fi 3561.14Schristos ${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET} 3571.1Stsutsui (cd ${_SRCDIR} ; \ 3581.21Stsutsui ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v \ 3591.1Stsutsui ${IMGDIR_EXCLUDE} \ 3601.1Stsutsui . ${.OBJDIR}/${WORKDIR}/${_TARGET} ) 3611.1Stsutsui.endfor 3621.1Stsutsui.endif 3631.1Stsutsui.if defined(IMGFILE_EXTRA) 3641.1Stsutsui @echo Copying extra files... 3651.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA} 3661.1Stsutsui @if [ ! -f ${_SRC} ]; then \ 3671.1Stsutsui echo "${_SRC} in IMGFILE_EXTRA not found, aborting"; \ 3681.1Stsutsui false; \ 3691.1Stsutsui fi 3701.1Stsutsui @if [ -f ${_SRC} ]; then \ 3711.21Stsutsui echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3721.21Stsutsui ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3731.1Stsutsui fi 3741.1Stsutsui.endfor 3751.1Stsutsui.endif 3761.1Stsutsui @echo Preparing spec files for makefs... 3771.1Stsutsui ${RM} -f ${WORKSPEC} 3781.1Stsutsui cat ${WORKDIR}/etc/mtree/* | \ 3791.1Stsutsui ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC} 3801.10Ssnj ${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty | \ 3811.1Stsutsui ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC} 3821.1Stsutsui cat ${SPEC_IN} >> ${WORKSPEC} 3831.1Stsutsui.if defined(SECONDARY_BOOT) 3841.1Stsutsui echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \ 3851.1Stsutsui >> ${WORKSPEC} 3861.1Stsutsui.endif 3871.1Stsutsui.if defined(SPEC_EXTRA) 3881.1Stsutsui cat ${SPEC_EXTRA} >> ${WORKSPEC} 3891.1Stsutsui.endif 3901.4Sriz @echo Creating rootfs... 3911.1Stsutsui # XXX /var/spool/ftp/hidden is unreadable 3921.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden 3931.1Stsutsui ${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE} \ 3941.1Stsutsui -B ${TARGET_ENDIANNESS} \ 3951.1Stsutsui -F ${WORKSPEC} -N ${WORKDIR}/etc \ 3961.13Schristos ${MAKEFS_TIMESTAMP} \ 3971.1Stsutsui ${IMGMAKEFSOPTIONS} \ 3981.1Stsutsui ${WORKFS} ${WORKDIR} 3991.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no" 4001.5Stsutsui ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \ 4011.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG} 4021.1Stsutsui.endif 4031.1Stsutsui @echo done. 4041.1Stsutsui mv ${WORKFS} ${.TARGET} 4051.1Stsutsui 4061.23SjoergTARGET_BLOCKS= 4071.23Sjoerg.if ${USE_MBR} != "no" || ${USE_GPT} != "no" 4081.23SjoergTARGET_BLOCKS+= ${WORKMBRTRUNC} 4091.23Sjoerg.endif 4101.23Sjoerg.if ${USE_GPT} != "no" 4111.23SjoergTARGET_BLOCKS+= ${WORKEFI} 4121.23Sjoerg.endif 4131.24Stsutsui.if ${FATSECTORS} != 0 4141.24StsutsuiTARGET_BLOCKS+= ${WORKFAT} 4151.24Stsutsui.endif 4161.23SjoergTARGET_BLOCKS+= ${TARGETFS} 4171.23Sjoerg.if ${SWAPSECTORS} != 0 4181.23SjoergTARGET_BLOCKS+= ${WORKSWAP} 4191.23Sjoerg.endif 4201.23Sjoerg.if ${USE_GPT} != "no" 4211.23SjoergTARGET_BLOCKS+= ${WORKGPT} 4221.1Stsutsui.endif 4231.1Stsutsui 4241.23SjoergCLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP} 4251.23SjoergCLEANFILES+= ${WORKEFI} ${WORKGPT} 4261.24StsutsuiCLEANFILES+= ${WORKFAT} 4271.23SjoergCLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL} 4281.23SjoergCLEANFILES+= ${WORKIMG} ${IMGBASE}.img 4291.5Stsutsui 4301.23Sjoerg${WORKSWAP}: 4311.23Sjoerg.if ${SWAPSECTORS} == 0 4321.23Sjoerg printf "" > ${WORKSWAP} 4331.23Sjoerg.else 4341.23Sjoerg ${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1 4351.23Sjoerg.endif 4361.1Stsutsui 4371.23Sjoerg${WORKMBRTRUNC}: ${WORKMBR} 4381.23Sjoerg ${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC} 4391.1Stsutsui 4401.1Stsutsui${WORKLABEL}: 4411.1Stsutsui ${TOOL_SED} \ 4421.1Stsutsui -e "s/@@SECTORS@@/${SECTORS}/" \ 4431.1Stsutsui -e "s/@@HEADS@@/${HEADS}/" \ 4441.1Stsutsui -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/" \ 4451.1Stsutsui -e "s/@@CYLINDERS@@/${CYLINDERS}/" \ 4461.1Stsutsui -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/" \ 4471.1Stsutsui -e "s/@@FSSECTORS@@/${FSSECTORS}/" \ 4481.1Stsutsui -e "s/@@FSOFFSET@@/${FSOFFSET}/" \ 4491.1Stsutsui -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/" \ 4501.1Stsutsui -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/" \ 4511.1Stsutsui -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/" \ 4521.24Stsutsui -e "s/@@FATSECTORS@@/${FATSECTORS}/" \ 4531.24Stsutsui -e "s/@@FATOFFSET@@/${FATOFFSET}/" \ 4541.1Stsutsui < ${DISKPROTO_IN} > ${WORKLABEL}.tmp 4551.1Stsutsui mv ${WORKLABEL}.tmp ${WORKLABEL} 4561.1Stsutsui 4571.23Sjoerg${WORKEFI}: ${TARGETFS} 4581.23Sjoerg @echo create EFI system partition... 4591.23Sjoerg @${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot 4601.23Sjoerg.for f in ${EFIBOOT} 4611.23Sjoerg ${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}` 4621.23Sjoerg.endfor 4631.23Sjoerg ${RM} -f ${WORKEFI} 4641.23Sjoerg ${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m \ 4651.23Sjoerg -B ${TARGET_ENDIANNESS} \ 4661.23Sjoerg ${MAKEFS_TIMESTAMP} \ 4671.23Sjoerg -t msdos -o F=32,c=1 \ 4681.23Sjoerg ${WORKEFI} ${EFIWORKDIR} 4691.23Sjoerg 4701.24Stsutsui${WORKFAT}: ${TARGETFS} ${FATFILES} 4711.24Stsutsui @echo create FAT partition for bootstrap files... 4721.24Stsutsui @${MKDIR} ${MKDIRPERM} ${WORKFATDIR} 4731.24Stsutsui.if defined(FATFILES) 4741.24Stsutsui @echo Copying files for FAT partition... 4751.24Stsutsui.for f in ${FATFILES} 4761.24Stsutsui @if [ ! -f ${f} ]; then \ 4771.24Stsutsui echo "${f} in FATFILES not found, aborting"; \ 4781.24Stsutsui false; \ 4791.24Stsutsui fi 4801.24Stsutsui ${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR} 4811.24Stsutsui.endfor 4821.24Stsutsui.endif 4831.24Stsutsui ${RM} -f ${WORKFAT} 4841.24Stsutsui ${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m \ 4851.24Stsutsui ${MAKEFS_TIMESTAMP} \ 4861.24Stsutsui -t msdos \ 4871.24Stsutsui ${FATMAKEFSOPTIONS} \ 4881.24Stsutsui ${WORKFAT} ${WORKFATDIR} 4891.24Stsutsui 4901.23Sjoerg${WORKMBR}: 4911.23Sjoerg.if ${USE_GPT} != "no" 4921.23Sjoerg @echo creating GPT header and partition entries... 4931.23Sjoerg ${RM} -f ${WORKMBR} 4941.23Sjoerg ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 4951.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create 4961.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system" 4971.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs 4981.23Sjoerg. if ${SWAPSECTORS} != 0 4991.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap 5001.23Sjoerg. endif 5011.23Sjoerg.elif ${USE_MBR} != "no" 5021.1Stsutsui @echo creating MBR labels... 5031.1Stsutsui ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5041.24Stsutsui. if ${FATSECTORS} != 0 5051.24Stsutsui # create BSD partition 5061.24Stsutsui ${TOOL_FDISK} -f -i -u \ 5071.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5081.24Stsutsui -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5091.24Stsutsui -F ${WORKMBR} 5101.24Stsutsui # create FAT partition 5111.24Stsutsui ${TOOL_FDISK} -f -u \ 5121.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5131.24Stsutsui -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS} \ 5141.24Stsutsui -F ${WORKMBR} 5151.24Stsutsui. else 5161.24Stsutsui # create BSD partition 5171.5Stsutsui ${TOOL_FDISK} -f -i -u \ 5181.1Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5191.1Stsutsui -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5201.1Stsutsui -F ${WORKMBR} 5211.24Stsutsui. endif 5221.23Sjoerg. if empty(MBR_BOOTCODE) 5231.5Stsutsui @if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then \ 5241.5Stsutsui echo ${TOOL_FDISK} -f \ 5251.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5261.5Stsutsui -F ${WORKMBR}; \ 5271.5Stsutsui ${TOOL_FDISK} -f \ 5281.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5291.5Stsutsui -F ${WORKMBR}; \ 5301.5Stsutsui fi 5311.23Sjoerg. else 5321.5Stsutsui @if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then \ 5331.5Stsutsui echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \ 5341.5Stsutsui false; \ 5351.5Stsutsui fi 5361.5Stsutsui ${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} \ 5371.5Stsutsui -F ${WORKMBR} 5381.23Sjoerg. endif 5391.5Stsutsui.endif 5401.23Sjoerg 5411.23Sjoerg${WORKGPT}: ${WORKMBR} 5421.23Sjoerg @echo create GPT image... 5431.23Sjoerg ${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \ 5441.23Sjoerg count=2048 5451.23Sjoerg 5461.23Sjoerg.if ${USE_GPT} == "no" 5471.23Sjoerg${IMGBASE}.img: ${WORKLABEL} 5481.1Stsutsui.endif 5491.23Sjoerg 5501.23Sjoerg${IMGBASE}.img: ${TARGET_BLOCKS} 5511.23Sjoerg ${CAT} ${TARGET_BLOCKS} > ${WORKIMG} 5521.23Sjoerg.if ${USE_GPT} != "no" 5531.25Sjmcneill.if ${USE_GPTMBR} != "no" 5541.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2 \ 5551.23Sjoerg -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin 5561.25Sjmcneill.endif 5571.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2 5581.23Sjoerg.endif # USE_GPT != "no" 5591.1Stsutsui.if ${USE_SUNLABEL} != "no" 5601.1Stsutsui @echo Creating sun disklabel... 5611.1Stsutsui printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \ 5621.1Stsutsui ${CYLINDERS} ${HEADS} ${SECTORS} \ 5631.1Stsutsui ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \ 5641.1Stsutsui ${TOOL_SUNLABEL} -nq ${WORKIMG} 5651.1Stsutsui.endif 5661.23Sjoerg.if ${USE_GPT} == "no" 5671.1Stsutsui ${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL} 5681.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no" 5691.11Sriastrad ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \ 5701.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} 5711.1Stsutsui.endif 5721.23Sjoerg.endif 5731.1Stsutsui mv ${WORKIMG} ${.TARGET} 5741.1Stsutsui 5751.1StsutsuiCLEANFILES+= ${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp 5761.1Stsutsui 5771.1Stsutsui${IMGBASE}.img.gz: ${IMGBASE}.img 5781.9Sapb ${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp 5791.1Stsutsui mv ${.TARGET}.tmp ${.TARGET} 5801.1Stsutsui 5811.1Stsutsuiclean: 5821.1Stsutsui @if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then \ 5831.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden; \ 5841.1Stsutsui fi # XXX 5851.1Stsutsui ${RM} -fr ${WORKDIR} 5861.23Sjoerg ${RM} -fr ${EFIWORKDIR} 5871.24Stsutsui ${RM} -fr ${WORKFATDIR} 5881.1Stsutsui 5891.1Stsutsuiprepare_md_post: .PHONY 5901.1Stsutsuiimage_md_post: .PHONY 5911.1Stsutsuiimage_md_pre: .PHONY 5921.1Stsutsui 5931.1Stsutsui.include <bsd.prog.mk> 594