Makefile.bootimage revision 1.23
11.23Sjoerg# $NetBSD: Makefile.bootimage,v 1.23 2019/11/21 22:29:03 joerg 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.1Stsutsui# KERN_SET 671.1Stsutsui# kernel set name which should be extracted into image 681.1Stsutsui# (default: kern-GENERIC) 691.1Stsutsui# SETS 701.1Stsutsui# binary sets that should be extracted into image 711.22Smaya# (default: modules base etc comp games man misc rescue tests 721.22Smaya# text xbase xcomp xetc xfont xserver) 731.1Stsutsui# SETS_DIR 741.1Stsutsui# directory path where binary sets are stored 751.1Stsutsui# (default: ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets) 761.1Stsutsui# IMGFILE_EXTRA 771.1Stsutsui# list of additional files to be copied into images, 781.1Stsutsui# containing one or more tuples of the form: 791.1Stsutsui# FILE TARGETPATH 801.1Stsutsui# for installation image etc. 811.1Stsutsui# (default: empty) 821.1Stsutsui# IMGDIR_EXTRA 831.1Stsutsui# list of additional directories to be copied into images, 841.1Stsutsui# containing one or more tuples of the form: 851.1Stsutsui# DIR TARGETPATH 861.1Stsutsui# for installation image etc. 871.1Stsutsui# (default: empty) 881.6Stsutsui# XXX: currently permissions in IMGDIR_EXTRA are not handled 891.1Stsutsui# IMGDIR_EXCLUDE 901.1Stsutsui# pax(1) options to exclude files which should not copied 911.1Stsutsui# into TARGETPATH in IMGDIR_EXTRA 921.1Stsutsui# (default: empty) 931.1Stsutsui# FSTAB_IN 941.1Stsutsui# template file of /etc/fstab 951.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/fstab.in) 961.1Stsutsui# SPEC_IN 971.1Stsutsui# default files of spec file for makefs(8) 981.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/spec.in) 991.1Stsutsui# SPEC_EXTRA 1001.1Stsutsui# additional files of spec file for makefs(8) 1011.1Stsutsui# (default: empty) 1021.1Stsutsui# IMGMAKEFSOPTIONS 1031.1Stsutsui# options passed to makefs(8) to create root file system 1041.1Stsutsui# (default: -o bsize=16384,fsize=2048,density=8192) 1051.5Stsutsui# INSTALLBOOTOPTIONS 1061.5Stsutsui# options passed to installboot(8), e.g., -o console=com0 1071.5Stsutsui# (default: empty) 1081.1Stsutsui# PRIMARY_BOOT 1091.1Stsutsui# primary boot loader that should be installed into 1101.1Stsutsui# the target image via installboot(8) 1111.1Stsutsui# (default: empty) 1121.1Stsutsui# SECONDARY_BOOT 1131.1Stsutsui# secondary bootloader that should be put into the target image 1141.1Stsutsui# (default: empty) 1151.1Stsutsui# SECONDARY_BOOT_ARG 1161.1Stsutsui# extra arguments that should be passed to installboot(8) 1171.1Stsutsui# to specify the secondary bootloader 1181.1Stsutsui# (default: empty) 1191.1Stsutsui# DISKPROTO_IN 1201.1Stsutsui# template file of disklabel -R 1211.1Stsutsui# (default: ${DISTRIBDIR}/common/bootimage/diskproto.in 1221.1Stsutsui# or ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in) 1231.23Sjoerg# EFIBOOT 1241.23Sjoerg# EFI bootloader 1251.23Sjoerg# (default: empty) 1261.1Stsutsui# 1271.1Stsutsui 1281.1Stsutsui.include <bsd.own.mk> # 1291.1Stsutsui.include <bsd.endian.mk> # for TARGET_ENDIANNESS 1301.1Stsutsui 1311.1Stsutsui.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib" 1321.1Stsutsui 1331.13Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no" 1341.13SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1351.23SjoergGPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1361.15SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}" 1371.15Schristos.endif 1381.12Schristos 1391.1Stsutsui.if empty(IMGBASE) 1401.1Stsutsui.BEGIN: 1411.1Stsutsui @echo "Error: IMGBASE is not set" 1421.1Stsutsui @false 1431.1Stsutsui.endif 1441.1Stsutsui 1451.1Stsutsui# should be defined elsewhere? 1461.1StsutsuiCAT?= cat 1471.1StsutsuiCHMOD?= chmod 1481.1StsutsuiDD?= dd 1491.1StsutsuiMKDIR?= mkdir -p 1501.1StsutsuiRM?= rm 1511.1Stsutsui 1521.1Stsutsui# 1531.1Stsutsui# common definitions for image 1541.1Stsutsui# 1551.1StsutsuiUSE_MBR?= no 1561.23SjoergUSE_GPT?= no 1571.1StsutsuiUSE_SUNLABEL?= no 1581.1StsutsuiINSTALLBOOT_AFTER_DISKLABEL?= no 1591.1Stsutsui 1601.1Stsutsui# 1611.1Stsutsui# size parameters for image 1621.1Stsutsui# 1631.1StsutsuiIMAGEMB?= 2048 # 2048MB 1641.1StsutsuiSWAPMB?= 128 # 128MB 1651.23Sjoerg.if ${USE_GPT} == "no" 1661.23SjoergEFIMB?= 0 1671.23SjoergGPTSECTORS= 0 1681.23Sjoerg.else 1691.23SjoergEFIMB?= 128 # 128MB 1701.23SjoergGPTSECTORS= 2048 1711.23Sjoerg.endif 1721.1Stsutsui 1731.3Stsutsui# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case 1741.1StsutsuiIMAGESECTORS!= expr ${IMAGEMB} \* 1024 \* 1024 / 512 1751.3StsutsuiSWAPSECTORS!= expr ${SWAPMB} \* 1024 \* 1024 / 512 || true 1761.23SjoergEFISECTORS!= expr ${EFIMB} \* 1024 \* 1024 / 512 || true 1771.1Stsutsui 1781.23Sjoerg.if ${USE_MBR} == "no" && ${USE_GPT} == "no" 1791.1StsutsuiLABELSECTORS?= 0 1801.1Stsutsui.else 1811.1Stsutsui#LABELSECTORS?= 63 # historical 1821.1Stsutsui#LABELSECTORS?= 32 # 16KB aligned 1831.1StsutsuiLABELSECTORS?= 2048 # 1MB aligned for modern flash devices 1841.1Stsutsui.endif 1851.1Stsutsui 1861.23SjoergFSSECTORS!= expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \ 1871.23Sjoerg - ${EFISECTORS} - ${GPTSECTORS} 1881.1StsutsuiFSSIZE!= expr ${FSSECTORS} \* 512 1891.1Stsutsui 1901.1Stsutsui# parameters for disklabel and MBR 1911.1StsutsuiHEADS= 64 1921.1StsutsuiSECTORS= 32 1931.1StsutsuiCYLINDERS!= expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \) 1941.1StsutsuiSECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS} 1951.1StsutsuiMBRHEADS= 255 1961.1StsutsuiMBRSECTORS= 63 1971.1StsutsuiMBRCYLINDERS!= expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \) 1981.1StsutsuiMBRNETBSD= 169 1991.1Stsutsui 2001.23SjoergBSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} - ${EFISECTORS} - ${GPTSECTORS} 2011.23SjoergFSOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} 2021.23SjoergSWAPOFFSET!= expr ${LABELSECTORS} + ${FSSECTORS} + ${EFISECTORS} 2031.1Stsutsui 2041.1Stsutsui# parameters for sunlabel 2051.1StsutsuiFSCYLINDERS!= expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \) 2061.3StsutsuiSWAPCYLINDERS!= expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true 2071.1Stsutsui 2081.23Sjoerg.if ${USE_GPT} != "no" 2091.23SjoergBOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2101.23SjoergSWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2111.23Sjoerg.endif 2121.1Stsutsui 2131.1Stsutsui# 2141.1Stsutsui# definitions to create root fs 2151.1Stsutsui# 2161.22SmayaSETS_DEFAULT= modules base etc comp games man misc rescue tests text 2171.1Stsutsui.if ${MKX11} != "no" 2181.1StsutsuiSETS_DEFAULT+= xbase xcomp xetc xfont xserver 2191.1Stsutsui.endif 2201.1Stsutsui 2211.1StsutsuiKERN_SET?= kern-GENERIC 2221.1StsutsuiSETS?= ${SETS_DEFAULT} 2231.1StsutsuiIMG_SETS= ${KERN_SET} ${SETS} 2241.1StsutsuiSETS_DIR?= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 2251.1Stsutsui 2261.1StsutsuiFSTAB_IN?= ${DISTRIBDIR}/common/bootimage/fstab.in 2271.1StsutsuiSPEC_IN?= ${DISTRIBDIR}/common/bootimage/spec.in 2281.1Stsutsui 2291.1StsutsuiIMGMAKEFSOPTIONS?= -o bsize=16384,fsize=2048,density=8192 2301.1Stsutsui 2311.1StsutsuiWORKDIR?= work 2321.1StsutsuiWORKSPEC?= work.spec 2331.1StsutsuiWORKFSTAB?= work.fstab 2341.1StsutsuiWORKRCCONF?= work.rc.conf 2351.1StsutsuiWORKFS?= work.rootfs 2361.1StsutsuiTARGETFS?= imgroot.fs 2371.19SaymericCOMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}} 2381.18SmartinTAR_SUFF= ${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz} 2391.1Stsutsui 2401.1StsutsuiCLEANFILES+= ${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS} 2411.1StsutsuiCLEANFILES+= ${TARGETFS} 2421.1Stsutsui 2431.1Stsutsui# 2441.23Sjoerg# definitions to create image 2451.23Sjoerg# 2461.23Sjoerg.if ${SWAPSECTORS} == 0 2471.23Sjoerg. if ${USE_MBR} != "no" 2481.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in 2491.23Sjoerg. else 2501.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.in 2511.23Sjoerg. endif 2521.23Sjoerg.else 2531.23Sjoerg. if ${USE_MBR} != "no" 2541.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in 2551.23Sjoerg. else 2561.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.in 2571.23Sjoerg. endif 2581.23Sjoerg.endif 2591.23Sjoerg 2601.23SjoergMBR_DEFAULT_BOOTCODE?= mbr 2611.23Sjoerg 2621.23SjoergWORKMBR?= work.mbr 2631.23SjoergWORKMBRTRUNC?= work.mbr.truncated 2641.23SjoergWORKSWAP?= work.swap 2651.23SjoergWORKEFI?= work.efi 2661.23SjoergWORKGPT?= work.gpt 2671.23SjoergWORKLABEL?= work.diskproto 2681.23SjoergWORKIMG?= work.img 2691.23SjoergEFIWORKDIR?= work.efidir 2701.23Sjoerg 2711.23Sjoerg.if ${USE_GPT} != "no" 2721.23Sjoerg${WORKFSTAB}: ${WORKMBR} 2731.23Sjoerg.endif 2741.23Sjoerg 2751.23Sjoerg${WORKFSTAB}: 2761.23Sjoerg @echo Preparing /etc/fstab ... 2771.23Sjoerg.if ${USE_GPT} != "no" 2781.23Sjoerg. if ${SWAPSECTORS} != 0 2791.23Sjoerg ${TOOL_SED} \ 2801.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 2811.23Sjoerg -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/" \ 2821.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 2831.23Sjoerg. else 2841.23Sjoerg ${TOOL_SED} \ 2851.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 2861.23Sjoerg -e "/ROOT.b/d" \ 2871.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 2881.23Sjoerg. endif 2891.23Sjoerg.else 2901.23Sjoerg. if ${SWAPSECTORS} != 0 2911.23Sjoerg ${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB} 2921.23Sjoerg. else 2931.23Sjoerg ${TOOL_SED} \ 2941.23Sjoerg -e "/ROOT.b/d" \ 2951.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 2961.23Sjoerg. endif 2971.23Sjoerg.endif 2981.23Sjoerg 2991.23Sjoerg# 3001.1Stsutsui# create root file system for the image 3011.1Stsutsui# 3021.23Sjoerg${TARGETFS}: prepare_md_post ${WORKFSTAB} 3031.1Stsutsui @if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then \ 3041.1Stsutsui echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \ 3051.1Stsutsui false; \ 3061.1Stsutsui fi; 3071.14Schristos @${MKDIR} ${MKDIRPERM} ${WORKDIR} 3081.1Stsutsui.for set in ${IMG_SETS} 3091.18Smartin @if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then \ 3101.18Smartin echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\ 3111.1Stsutsui false; \ 3121.1Stsutsui fi 3131.18Smartin @echo Extracting ${set}.${TAR_SUFF} ... 3141.19Saymeric @(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \ 3151.19Saymeric --use-compress-program=${COMPRESS_PROGRAM:Q} \ 3161.19Saymeric -f ${SETS_DIR}/${set}.${TAR_SUFF} .) 3171.1Stsutsui.endfor 3181.1Stsutsui.if defined(SECONDARY_BOOT) 3191.1Stsutsui @echo Copying secondary boot... 3201.21Stsutsui ${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR} 3211.1Stsutsui.endif 3221.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab 3231.1Stsutsui @echo Setting rc_configured=YES in /etc/rc.conf ... 3241.1Stsutsui ${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/" \ 3251.1Stsutsui < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF} 3261.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf 3271.1Stsutsui.if defined(IMGDIR_EXTRA) 3281.1Stsutsui @echo Copying extra dirs... 3291.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA} 3301.1Stsutsui @if [ ! -d ${_SRCDIR} ]; then \ 3311.1Stsutsui echo "${_SRCDIR} is not directory, aborting"; \ 3321.1Stsutsui false; \ 3331.1Stsutsui fi 3341.14Schristos ${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET} 3351.1Stsutsui (cd ${_SRCDIR} ; \ 3361.21Stsutsui ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v \ 3371.1Stsutsui ${IMGDIR_EXCLUDE} \ 3381.1Stsutsui . ${.OBJDIR}/${WORKDIR}/${_TARGET} ) 3391.1Stsutsui.endfor 3401.1Stsutsui.endif 3411.1Stsutsui.if defined(IMGFILE_EXTRA) 3421.1Stsutsui @echo Copying extra files... 3431.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA} 3441.1Stsutsui @if [ ! -f ${_SRC} ]; then \ 3451.1Stsutsui echo "${_SRC} in IMGFILE_EXTRA not found, aborting"; \ 3461.1Stsutsui false; \ 3471.1Stsutsui fi 3481.1Stsutsui @if [ -f ${_SRC} ]; then \ 3491.21Stsutsui echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3501.21Stsutsui ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3511.1Stsutsui fi 3521.1Stsutsui.endfor 3531.1Stsutsui.endif 3541.1Stsutsui @echo Preparing spec files for makefs... 3551.1Stsutsui ${RM} -f ${WORKSPEC} 3561.1Stsutsui cat ${WORKDIR}/etc/mtree/* | \ 3571.1Stsutsui ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC} 3581.10Ssnj ${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty | \ 3591.1Stsutsui ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC} 3601.1Stsutsui cat ${SPEC_IN} >> ${WORKSPEC} 3611.1Stsutsui.if defined(SECONDARY_BOOT) 3621.1Stsutsui echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \ 3631.1Stsutsui >> ${WORKSPEC} 3641.1Stsutsui.endif 3651.1Stsutsui.if defined(SPEC_EXTRA) 3661.1Stsutsui cat ${SPEC_EXTRA} >> ${WORKSPEC} 3671.1Stsutsui.endif 3681.4Sriz @echo Creating rootfs... 3691.1Stsutsui # XXX /var/spool/ftp/hidden is unreadable 3701.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden 3711.1Stsutsui ${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE} \ 3721.1Stsutsui -B ${TARGET_ENDIANNESS} \ 3731.1Stsutsui -F ${WORKSPEC} -N ${WORKDIR}/etc \ 3741.13Schristos ${MAKEFS_TIMESTAMP} \ 3751.1Stsutsui ${IMGMAKEFSOPTIONS} \ 3761.1Stsutsui ${WORKFS} ${WORKDIR} 3771.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no" 3781.5Stsutsui ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \ 3791.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG} 3801.1Stsutsui.endif 3811.1Stsutsui @echo done. 3821.1Stsutsui mv ${WORKFS} ${.TARGET} 3831.1Stsutsui 3841.23SjoergTARGET_BLOCKS= 3851.23Sjoerg.if ${USE_MBR} != "no" || ${USE_GPT} != "no" 3861.23SjoergTARGET_BLOCKS+= ${WORKMBRTRUNC} 3871.23Sjoerg.endif 3881.23Sjoerg.if ${USE_GPT} != "no" 3891.23SjoergTARGET_BLOCKS+= ${WORKEFI} 3901.23Sjoerg.endif 3911.23SjoergTARGET_BLOCKS+= ${TARGETFS} 3921.23Sjoerg.if ${SWAPSECTORS} != 0 3931.23SjoergTARGET_BLOCKS+= ${WORKSWAP} 3941.23Sjoerg.endif 3951.23Sjoerg.if ${USE_GPT} != "no" 3961.23SjoergTARGET_BLOCKS+= ${WORKGPT} 3971.1Stsutsui.endif 3981.1Stsutsui 3991.23SjoergCLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP} 4001.23SjoergCLEANFILES+= ${WORKEFI} ${WORKGPT} 4011.23SjoergCLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL} 4021.23SjoergCLEANFILES+= ${WORKIMG} ${IMGBASE}.img 4031.5Stsutsui 4041.23Sjoerg${WORKSWAP}: 4051.23Sjoerg.if ${SWAPSECTORS} == 0 4061.23Sjoerg printf "" > ${WORKSWAP} 4071.23Sjoerg.else 4081.23Sjoerg ${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1 4091.23Sjoerg.endif 4101.1Stsutsui 4111.23Sjoerg${WORKMBRTRUNC}: ${WORKMBR} 4121.23Sjoerg ${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC} 4131.1Stsutsui 4141.1Stsutsui${WORKLABEL}: 4151.1Stsutsui ${TOOL_SED} \ 4161.1Stsutsui -e "s/@@SECTORS@@/${SECTORS}/" \ 4171.1Stsutsui -e "s/@@HEADS@@/${HEADS}/" \ 4181.1Stsutsui -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/" \ 4191.1Stsutsui -e "s/@@CYLINDERS@@/${CYLINDERS}/" \ 4201.1Stsutsui -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/" \ 4211.1Stsutsui -e "s/@@FSSECTORS@@/${FSSECTORS}/" \ 4221.1Stsutsui -e "s/@@FSOFFSET@@/${FSOFFSET}/" \ 4231.1Stsutsui -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/" \ 4241.1Stsutsui -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/" \ 4251.1Stsutsui -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/" \ 4261.1Stsutsui < ${DISKPROTO_IN} > ${WORKLABEL}.tmp 4271.1Stsutsui mv ${WORKLABEL}.tmp ${WORKLABEL} 4281.1Stsutsui 4291.23Sjoerg${WORKEFI}: ${TARGETFS} 4301.23Sjoerg @echo create EFI system partition... 4311.23Sjoerg @${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot 4321.23Sjoerg.for f in ${EFIBOOT} 4331.23Sjoerg ${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}` 4341.23Sjoerg.endfor 4351.23Sjoerg ${RM} -f ${WORKEFI} 4361.23Sjoerg ${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m \ 4371.23Sjoerg -B ${TARGET_ENDIANNESS} \ 4381.23Sjoerg ${MAKEFS_TIMESTAMP} \ 4391.23Sjoerg -t msdos -o F=32,c=1 \ 4401.23Sjoerg ${WORKEFI} ${EFIWORKDIR} 4411.23Sjoerg 4421.23Sjoerg${WORKMBR}: 4431.23Sjoerg.if ${USE_GPT} != "no" 4441.23Sjoerg @echo creating GPT header and partition entries... 4451.23Sjoerg ${RM} -f ${WORKMBR} 4461.23Sjoerg ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 4471.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create 4481.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system" 4491.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs 4501.23Sjoerg. if ${SWAPSECTORS} != 0 4511.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap 4521.23Sjoerg. endif 4531.23Sjoerg.elif ${USE_MBR} != "no" 4541.1Stsutsui @echo creating MBR labels... 4551.1Stsutsui ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 4561.5Stsutsui ${TOOL_FDISK} -f -i -u \ 4571.1Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 4581.1Stsutsui -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 4591.1Stsutsui -F ${WORKMBR} 4601.23Sjoerg. if empty(MBR_BOOTCODE) 4611.5Stsutsui @if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then \ 4621.5Stsutsui echo ${TOOL_FDISK} -f \ 4631.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 4641.5Stsutsui -F ${WORKMBR}; \ 4651.5Stsutsui ${TOOL_FDISK} -f \ 4661.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 4671.5Stsutsui -F ${WORKMBR}; \ 4681.5Stsutsui fi 4691.23Sjoerg. else 4701.5Stsutsui @if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then \ 4711.5Stsutsui echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \ 4721.5Stsutsui false; \ 4731.5Stsutsui fi 4741.5Stsutsui ${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} \ 4751.5Stsutsui -F ${WORKMBR} 4761.23Sjoerg. endif 4771.5Stsutsui.endif 4781.23Sjoerg 4791.23Sjoerg${WORKGPT}: ${WORKMBR} 4801.23Sjoerg @echo create GPT image... 4811.23Sjoerg ${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \ 4821.23Sjoerg count=2048 4831.23Sjoerg 4841.23Sjoerg.if ${USE_GPT} == "no" 4851.23Sjoerg${IMGBASE}.img: ${WORKLABEL} 4861.1Stsutsui.endif 4871.23Sjoerg 4881.23Sjoerg${IMGBASE}.img: ${TARGET_BLOCKS} 4891.23Sjoerg ${CAT} ${TARGET_BLOCKS} > ${WORKIMG} 4901.23Sjoerg.if ${USE_GPT} != "no" 4911.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2 \ 4921.23Sjoerg -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin 4931.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2 4941.23Sjoerg.endif # USE_GPT != "no" 4951.1Stsutsui.if ${USE_SUNLABEL} != "no" 4961.1Stsutsui @echo Creating sun disklabel... 4971.1Stsutsui printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \ 4981.1Stsutsui ${CYLINDERS} ${HEADS} ${SECTORS} \ 4991.1Stsutsui ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \ 5001.1Stsutsui ${TOOL_SUNLABEL} -nq ${WORKIMG} 5011.1Stsutsui.endif 5021.23Sjoerg.if ${USE_GPT} == "no" 5031.1Stsutsui ${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL} 5041.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no" 5051.11Sriastrad ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \ 5061.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} 5071.1Stsutsui.endif 5081.23Sjoerg.endif 5091.1Stsutsui mv ${WORKIMG} ${.TARGET} 5101.1Stsutsui 5111.1StsutsuiCLEANFILES+= ${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp 5121.1Stsutsui 5131.1Stsutsui${IMGBASE}.img.gz: ${IMGBASE}.img 5141.9Sapb ${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp 5151.1Stsutsui mv ${.TARGET}.tmp ${.TARGET} 5161.1Stsutsui 5171.1Stsutsuiclean: 5181.1Stsutsui @if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then \ 5191.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden; \ 5201.1Stsutsui fi # XXX 5211.1Stsutsui ${RM} -fr ${WORKDIR} 5221.23Sjoerg ${RM} -fr ${EFIWORKDIR} 5231.1Stsutsui 5241.1Stsutsuiprepare_md_post: .PHONY 5251.1Stsutsuiimage_md_post: .PHONY 5261.1Stsutsuiimage_md_pre: .PHONY 5271.1Stsutsui 5281.1Stsutsui.include <bsd.prog.mk> 529