Makefile.bootimage revision 1.27
11.27Stsutsui# $NetBSD: Makefile.bootimage,v 1.27 2021/06/04 17:09:36 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.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.26Sjmcneill# IMAGEHOSTNAME 1391.26Sjmcneill# if set, sets the default hostname in rc.conf (default: empty) 1401.1Stsutsui# 1411.1Stsutsui 1421.1Stsutsui.include <bsd.own.mk> # 1431.1Stsutsui.include <bsd.endian.mk> # for TARGET_ENDIANNESS 1441.1Stsutsui 1451.1Stsutsui.include "${NETBSDSRCDIR}/distrib/common/Makefile.distrib" 1461.1Stsutsui 1471.13Schristos.if ${MKREPRO_TIMESTAMP:Uno} != "no" 1481.13SchristosMAKEFS_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1491.23SjoergGPT_TIMESTAMP=-T "${MKREPRO_TIMESTAMP}" 1501.15SchristosPAX_TIMESTAMP=--timestamp "${MKREPRO_TIMESTAMP}" 1511.15Schristos.endif 1521.12Schristos 1531.1Stsutsui.if empty(IMGBASE) 1541.1Stsutsui.BEGIN: 1551.1Stsutsui @echo "Error: IMGBASE is not set" 1561.1Stsutsui @false 1571.1Stsutsui.endif 1581.1Stsutsui 1591.1Stsutsui# should be defined elsewhere? 1601.1StsutsuiCAT?= cat 1611.1StsutsuiCHMOD?= chmod 1621.1StsutsuiDD?= dd 1631.1StsutsuiMKDIR?= mkdir -p 1641.1StsutsuiRM?= rm 1651.1Stsutsui 1661.1Stsutsui# 1671.1Stsutsui# common definitions for image 1681.1Stsutsui# 1691.1StsutsuiUSE_MBR?= no 1701.23SjoergUSE_GPT?= no 1711.25SjmcneillUSE_GPTMBR?= no 1721.1StsutsuiUSE_SUNLABEL?= no 1731.1StsutsuiINSTALLBOOT_AFTER_DISKLABEL?= no 1741.1Stsutsui 1751.1Stsutsui# 1761.1Stsutsui# size parameters for image 1771.1Stsutsui# 1781.1StsutsuiIMAGEMB?= 2048 # 2048MB 1791.1StsutsuiSWAPMB?= 128 # 128MB 1801.23Sjoerg.if ${USE_GPT} == "no" 1811.23SjoergEFIMB?= 0 1821.23SjoergGPTSECTORS= 0 1831.23Sjoerg.else 1841.23SjoergEFIMB?= 128 # 128MB 1851.23SjoergGPTSECTORS= 2048 1861.23Sjoerg.endif 1871.24StsutsuiFATMB?= 0 1881.1Stsutsui 1891.3Stsutsui# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case 1901.1StsutsuiIMAGESECTORS!= expr ${IMAGEMB} \* 1024 \* 1024 / 512 1911.3StsutsuiSWAPSECTORS!= expr ${SWAPMB} \* 1024 \* 1024 / 512 || true 1921.23SjoergEFISECTORS!= expr ${EFIMB} \* 1024 \* 1024 / 512 || true 1931.24StsutsuiFATSECTORS!= expr ${FATMB} \* 1024 \* 1024 / 512 || true 1941.1Stsutsui 1951.23Sjoerg.if ${USE_MBR} == "no" && ${USE_GPT} == "no" 1961.1StsutsuiLABELSECTORS?= 0 1971.1Stsutsui.else 1981.1Stsutsui#LABELSECTORS?= 63 # historical 1991.1Stsutsui#LABELSECTORS?= 32 # 16KB aligned 2001.1StsutsuiLABELSECTORS?= 2048 # 1MB aligned for modern flash devices 2011.1Stsutsui.endif 2021.1Stsutsui 2031.23SjoergFSSECTORS!= expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \ 2041.24Stsutsui - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} 2051.1StsutsuiFSSIZE!= expr ${FSSECTORS} \* 512 2061.1Stsutsui 2071.1Stsutsui# parameters for disklabel and MBR 2081.1StsutsuiHEADS= 64 2091.1StsutsuiSECTORS= 32 2101.1StsutsuiCYLINDERS!= expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \) 2111.1StsutsuiSECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS} 2121.1StsutsuiMBRHEADS= 255 2131.1StsutsuiMBRSECTORS= 63 2141.1StsutsuiMBRCYLINDERS!= expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \) 2151.1StsutsuiMBRNETBSD= 169 2161.24StsutsuiMBRFAT?= 6 # 16-bit FAT, more than 32M 2171.1Stsutsui 2181.24StsutsuiBSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \ 2191.24Stsutsui - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} 2201.24StsutsuiFSOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} 2211.24StsutsuiSWAPOFFSET!= expr ${LABELSECTORS} + ${FSSECTORS} \ 2221.24Stsutsui + ${EFISECTORS} + ${FATSECTORS} 2231.24StsutsuiFATOFFSET= ${LABELSECTORS} 2241.1Stsutsui 2251.1Stsutsui# parameters for sunlabel 2261.1StsutsuiFSCYLINDERS!= expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \) 2271.3StsutsuiSWAPCYLINDERS!= expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true 2281.1Stsutsui 2291.23Sjoerg.if ${USE_GPT} != "no" 2301.23SjoergBOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2311.23SjoergSWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2321.23Sjoerg.endif 2331.1Stsutsui 2341.1Stsutsui# 2351.1Stsutsui# definitions to create root fs 2361.1Stsutsui# 2371.22SmayaSETS_DEFAULT= modules base etc comp games man misc rescue tests text 2381.1Stsutsui.if ${MKX11} != "no" 2391.1StsutsuiSETS_DEFAULT+= xbase xcomp xetc xfont xserver 2401.1Stsutsui.endif 2411.1Stsutsui 2421.1StsutsuiKERN_SET?= kern-GENERIC 2431.1StsutsuiSETS?= ${SETS_DEFAULT} 2441.1StsutsuiIMG_SETS= ${KERN_SET} ${SETS} 2451.1StsutsuiSETS_DIR?= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 2461.1Stsutsui 2471.1StsutsuiFSTAB_IN?= ${DISTRIBDIR}/common/bootimage/fstab.in 2481.1StsutsuiSPEC_IN?= ${DISTRIBDIR}/common/bootimage/spec.in 2491.1Stsutsui 2501.1StsutsuiIMGMAKEFSOPTIONS?= -o bsize=16384,fsize=2048,density=8192 2511.24StsutsuiFATMAKEFSOPTIONS?= -o fat_type=16 2521.1Stsutsui 2531.1StsutsuiWORKDIR?= work 2541.1StsutsuiWORKSPEC?= work.spec 2551.1StsutsuiWORKFSTAB?= work.fstab 2561.1StsutsuiWORKRCCONF?= work.rc.conf 2571.1StsutsuiWORKFS?= work.rootfs 2581.1StsutsuiTARGETFS?= imgroot.fs 2591.19SaymericCOMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}} 2601.18SmartinTAR_SUFF= ${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz} 2611.1Stsutsui 2621.1StsutsuiCLEANFILES+= ${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS} 2631.1StsutsuiCLEANFILES+= ${TARGETFS} 2641.1Stsutsui 2651.1Stsutsui# 2661.23Sjoerg# definitions to create image 2671.23Sjoerg# 2681.23Sjoerg.if ${SWAPSECTORS} == 0 2691.23Sjoerg. if ${USE_MBR} != "no" 2701.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in 2711.23Sjoerg. else 2721.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.in 2731.23Sjoerg. endif 2741.23Sjoerg.else 2751.23Sjoerg. if ${USE_MBR} != "no" 2761.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in 2771.23Sjoerg. else 2781.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.in 2791.23Sjoerg. endif 2801.23Sjoerg.endif 2811.23Sjoerg 2821.23SjoergMBR_DEFAULT_BOOTCODE?= mbr 2831.23Sjoerg 2841.23SjoergWORKMBR?= work.mbr 2851.23SjoergWORKMBRTRUNC?= work.mbr.truncated 2861.23SjoergWORKSWAP?= work.swap 2871.23SjoergWORKEFI?= work.efi 2881.23SjoergWORKGPT?= work.gpt 2891.23SjoergWORKLABEL?= work.diskproto 2901.23SjoergWORKIMG?= work.img 2911.23SjoergEFIWORKDIR?= work.efidir 2921.24StsutsuiWORKFAT?= work.fat 2931.24StsutsuiWORKFATDIR?= work.fatdir 2941.23Sjoerg 2951.23Sjoerg.if ${USE_GPT} != "no" 2961.23Sjoerg${WORKFSTAB}: ${WORKMBR} 2971.27Stsutsui 2981.27Stsutsui.BEGIN: 2991.27Stsutsui @if [ -f ${WORKMBR} ]; then \ 3001.27Stsutsui st_size=`${TOOL_STAT} -f %z ${WORKMBR}`; \ 3011.27Stsutsui if [ "$$st_size" -ne "$$((${IMAGESECTORS} * 512))" ]; then \ 3021.27Stsutsui echo Removing stale ${WORKMBR} ...; \ 3031.27Stsutsui rm -f ${WORKMBR}; \ 3041.27Stsutsui fi \ 3051.27Stsutsui fi 3061.23Sjoerg.endif 3071.23Sjoerg 3081.23Sjoerg${WORKFSTAB}: 3091.23Sjoerg @echo Preparing /etc/fstab ... 3101.23Sjoerg.if ${USE_GPT} != "no" 3111.23Sjoerg. if ${SWAPSECTORS} != 0 3121.23Sjoerg ${TOOL_SED} \ 3131.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 3141.23Sjoerg -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/" \ 3151.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3161.23Sjoerg. else 3171.23Sjoerg ${TOOL_SED} \ 3181.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 3191.23Sjoerg -e "/ROOT.b/d" \ 3201.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3211.23Sjoerg. endif 3221.23Sjoerg.else 3231.23Sjoerg. if ${SWAPSECTORS} != 0 3241.23Sjoerg ${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB} 3251.23Sjoerg. else 3261.23Sjoerg ${TOOL_SED} \ 3271.23Sjoerg -e "/ROOT.b/d" \ 3281.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3291.23Sjoerg. endif 3301.23Sjoerg.endif 3311.23Sjoerg 3321.23Sjoerg# 3331.1Stsutsui# create root file system for the image 3341.1Stsutsui# 3351.23Sjoerg${TARGETFS}: prepare_md_post ${WORKFSTAB} 3361.1Stsutsui @if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then \ 3371.1Stsutsui echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \ 3381.1Stsutsui false; \ 3391.1Stsutsui fi; 3401.14Schristos @${MKDIR} ${MKDIRPERM} ${WORKDIR} 3411.1Stsutsui.for set in ${IMG_SETS} 3421.18Smartin @if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then \ 3431.18Smartin echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\ 3441.1Stsutsui false; \ 3451.1Stsutsui fi 3461.18Smartin @echo Extracting ${set}.${TAR_SUFF} ... 3471.19Saymeric @(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \ 3481.19Saymeric --use-compress-program=${COMPRESS_PROGRAM:Q} \ 3491.19Saymeric -f ${SETS_DIR}/${set}.${TAR_SUFF} .) 3501.1Stsutsui.endfor 3511.1Stsutsui.if defined(SECONDARY_BOOT) 3521.1Stsutsui @echo Copying secondary boot... 3531.21Stsutsui ${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR} 3541.1Stsutsui.endif 3551.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab 3561.1Stsutsui @echo Setting rc_configured=YES in /etc/rc.conf ... 3571.1Stsutsui ${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/" \ 3581.1Stsutsui < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF} 3591.26Sjmcneill.if defined(IMAGEHOSTNAME) 3601.26Sjmcneill @echo Setting hostname=${IMAGEHOSTNAME} in /etc/rc.conf ... 3611.26Sjmcneill echo "hostname=${IMAGEHOSTNAME}" >> ${WORKRCCONF} 3621.26Sjmcneill.endif 3631.26Sjmcneill.if ${SWAPSECTORS} == 0 3641.26Sjmcneill @echo Setting no_swap=YES in /etc/rc.conf ... 3651.26Sjmcneill echo "no_swap=YES" >> ${WORKRCCONF} 3661.26Sjmcneill @echo Setting savecore=NO in /etc/rc.conf ... 3671.26Sjmcneill echo "savecore=NO" >> ${WORKRCCONF} 3681.26Sjmcneill.endif 3691.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf 3701.1Stsutsui.if defined(IMGDIR_EXTRA) 3711.1Stsutsui @echo Copying extra dirs... 3721.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA} 3731.1Stsutsui @if [ ! -d ${_SRCDIR} ]; then \ 3741.1Stsutsui echo "${_SRCDIR} is not directory, aborting"; \ 3751.1Stsutsui false; \ 3761.1Stsutsui fi 3771.14Schristos ${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET} 3781.1Stsutsui (cd ${_SRCDIR} ; \ 3791.21Stsutsui ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v \ 3801.1Stsutsui ${IMGDIR_EXCLUDE} \ 3811.1Stsutsui . ${.OBJDIR}/${WORKDIR}/${_TARGET} ) 3821.1Stsutsui.endfor 3831.1Stsutsui.endif 3841.1Stsutsui.if defined(IMGFILE_EXTRA) 3851.1Stsutsui @echo Copying extra files... 3861.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA} 3871.1Stsutsui @if [ ! -f ${_SRC} ]; then \ 3881.1Stsutsui echo "${_SRC} in IMGFILE_EXTRA not found, aborting"; \ 3891.1Stsutsui false; \ 3901.1Stsutsui fi 3911.1Stsutsui @if [ -f ${_SRC} ]; then \ 3921.21Stsutsui echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3931.21Stsutsui ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3941.1Stsutsui fi 3951.1Stsutsui.endfor 3961.1Stsutsui.endif 3971.1Stsutsui @echo Preparing spec files for makefs... 3981.1Stsutsui ${RM} -f ${WORKSPEC} 3991.1Stsutsui cat ${WORKDIR}/etc/mtree/* | \ 4001.1Stsutsui ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC} 4011.10Ssnj ${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty | \ 4021.1Stsutsui ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC} 4031.1Stsutsui cat ${SPEC_IN} >> ${WORKSPEC} 4041.1Stsutsui.if defined(SECONDARY_BOOT) 4051.1Stsutsui echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \ 4061.1Stsutsui >> ${WORKSPEC} 4071.1Stsutsui.endif 4081.1Stsutsui.if defined(SPEC_EXTRA) 4091.1Stsutsui cat ${SPEC_EXTRA} >> ${WORKSPEC} 4101.1Stsutsui.endif 4111.4Sriz @echo Creating rootfs... 4121.1Stsutsui # XXX /var/spool/ftp/hidden is unreadable 4131.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden 4141.1Stsutsui ${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE} \ 4151.1Stsutsui -B ${TARGET_ENDIANNESS} \ 4161.1Stsutsui -F ${WORKSPEC} -N ${WORKDIR}/etc \ 4171.13Schristos ${MAKEFS_TIMESTAMP} \ 4181.1Stsutsui ${IMGMAKEFSOPTIONS} \ 4191.1Stsutsui ${WORKFS} ${WORKDIR} 4201.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no" 4211.5Stsutsui ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \ 4221.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG} 4231.1Stsutsui.endif 4241.1Stsutsui @echo done. 4251.1Stsutsui mv ${WORKFS} ${.TARGET} 4261.1Stsutsui 4271.23SjoergTARGET_BLOCKS= 4281.23Sjoerg.if ${USE_MBR} != "no" || ${USE_GPT} != "no" 4291.23SjoergTARGET_BLOCKS+= ${WORKMBRTRUNC} 4301.23Sjoerg.endif 4311.23Sjoerg.if ${USE_GPT} != "no" 4321.23SjoergTARGET_BLOCKS+= ${WORKEFI} 4331.23Sjoerg.endif 4341.24Stsutsui.if ${FATSECTORS} != 0 4351.24StsutsuiTARGET_BLOCKS+= ${WORKFAT} 4361.24Stsutsui.endif 4371.23SjoergTARGET_BLOCKS+= ${TARGETFS} 4381.23Sjoerg.if ${SWAPSECTORS} != 0 4391.23SjoergTARGET_BLOCKS+= ${WORKSWAP} 4401.23Sjoerg.endif 4411.23Sjoerg.if ${USE_GPT} != "no" 4421.23SjoergTARGET_BLOCKS+= ${WORKGPT} 4431.1Stsutsui.endif 4441.1Stsutsui 4451.23SjoergCLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP} 4461.23SjoergCLEANFILES+= ${WORKEFI} ${WORKGPT} 4471.24StsutsuiCLEANFILES+= ${WORKFAT} 4481.23SjoergCLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL} 4491.23SjoergCLEANFILES+= ${WORKIMG} ${IMGBASE}.img 4501.5Stsutsui 4511.23Sjoerg${WORKSWAP}: 4521.23Sjoerg.if ${SWAPSECTORS} == 0 4531.23Sjoerg printf "" > ${WORKSWAP} 4541.23Sjoerg.else 4551.23Sjoerg ${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1 4561.23Sjoerg.endif 4571.1Stsutsui 4581.23Sjoerg${WORKMBRTRUNC}: ${WORKMBR} 4591.23Sjoerg ${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC} 4601.1Stsutsui 4611.1Stsutsui${WORKLABEL}: 4621.1Stsutsui ${TOOL_SED} \ 4631.1Stsutsui -e "s/@@SECTORS@@/${SECTORS}/" \ 4641.1Stsutsui -e "s/@@HEADS@@/${HEADS}/" \ 4651.1Stsutsui -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/" \ 4661.1Stsutsui -e "s/@@CYLINDERS@@/${CYLINDERS}/" \ 4671.1Stsutsui -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/" \ 4681.1Stsutsui -e "s/@@FSSECTORS@@/${FSSECTORS}/" \ 4691.1Stsutsui -e "s/@@FSOFFSET@@/${FSOFFSET}/" \ 4701.1Stsutsui -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/" \ 4711.1Stsutsui -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/" \ 4721.1Stsutsui -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/" \ 4731.24Stsutsui -e "s/@@FATSECTORS@@/${FATSECTORS}/" \ 4741.24Stsutsui -e "s/@@FATOFFSET@@/${FATOFFSET}/" \ 4751.1Stsutsui < ${DISKPROTO_IN} > ${WORKLABEL}.tmp 4761.1Stsutsui mv ${WORKLABEL}.tmp ${WORKLABEL} 4771.1Stsutsui 4781.23Sjoerg${WORKEFI}: ${TARGETFS} 4791.23Sjoerg @echo create EFI system partition... 4801.23Sjoerg @${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot 4811.23Sjoerg.for f in ${EFIBOOT} 4821.23Sjoerg ${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}` 4831.23Sjoerg.endfor 4841.23Sjoerg ${RM} -f ${WORKEFI} 4851.23Sjoerg ${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m \ 4861.23Sjoerg -B ${TARGET_ENDIANNESS} \ 4871.23Sjoerg ${MAKEFS_TIMESTAMP} \ 4881.23Sjoerg -t msdos -o F=32,c=1 \ 4891.23Sjoerg ${WORKEFI} ${EFIWORKDIR} 4901.23Sjoerg 4911.24Stsutsui${WORKFAT}: ${TARGETFS} ${FATFILES} 4921.24Stsutsui @echo create FAT partition for bootstrap files... 4931.24Stsutsui @${MKDIR} ${MKDIRPERM} ${WORKFATDIR} 4941.24Stsutsui.if defined(FATFILES) 4951.24Stsutsui @echo Copying files for FAT partition... 4961.24Stsutsui.for f in ${FATFILES} 4971.24Stsutsui @if [ ! -f ${f} ]; then \ 4981.24Stsutsui echo "${f} in FATFILES not found, aborting"; \ 4991.24Stsutsui false; \ 5001.24Stsutsui fi 5011.24Stsutsui ${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR} 5021.24Stsutsui.endfor 5031.24Stsutsui.endif 5041.24Stsutsui ${RM} -f ${WORKFAT} 5051.24Stsutsui ${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m \ 5061.24Stsutsui ${MAKEFS_TIMESTAMP} \ 5071.24Stsutsui -t msdos \ 5081.24Stsutsui ${FATMAKEFSOPTIONS} \ 5091.24Stsutsui ${WORKFAT} ${WORKFATDIR} 5101.24Stsutsui 5111.23Sjoerg${WORKMBR}: 5121.23Sjoerg.if ${USE_GPT} != "no" 5131.23Sjoerg @echo creating GPT header and partition entries... 5141.23Sjoerg ${RM} -f ${WORKMBR} 5151.23Sjoerg ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5161.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create 5171.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system" 5181.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs 5191.23Sjoerg. if ${SWAPSECTORS} != 0 5201.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap 5211.23Sjoerg. endif 5221.23Sjoerg.elif ${USE_MBR} != "no" 5231.1Stsutsui @echo creating MBR labels... 5241.1Stsutsui ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5251.24Stsutsui. if ${FATSECTORS} != 0 5261.24Stsutsui # create BSD partition 5271.24Stsutsui ${TOOL_FDISK} -f -i -u \ 5281.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5291.24Stsutsui -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5301.24Stsutsui -F ${WORKMBR} 5311.24Stsutsui # create FAT partition 5321.24Stsutsui ${TOOL_FDISK} -f -u \ 5331.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5341.24Stsutsui -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS} \ 5351.24Stsutsui -F ${WORKMBR} 5361.24Stsutsui. else 5371.24Stsutsui # create BSD partition 5381.5Stsutsui ${TOOL_FDISK} -f -i -u \ 5391.1Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5401.1Stsutsui -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5411.1Stsutsui -F ${WORKMBR} 5421.24Stsutsui. endif 5431.23Sjoerg. if empty(MBR_BOOTCODE) 5441.5Stsutsui @if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then \ 5451.5Stsutsui echo ${TOOL_FDISK} -f \ 5461.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5471.5Stsutsui -F ${WORKMBR}; \ 5481.5Stsutsui ${TOOL_FDISK} -f \ 5491.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5501.5Stsutsui -F ${WORKMBR}; \ 5511.5Stsutsui fi 5521.23Sjoerg. else 5531.5Stsutsui @if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then \ 5541.5Stsutsui echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \ 5551.5Stsutsui false; \ 5561.5Stsutsui fi 5571.5Stsutsui ${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} \ 5581.5Stsutsui -F ${WORKMBR} 5591.23Sjoerg. endif 5601.5Stsutsui.endif 5611.23Sjoerg 5621.23Sjoerg${WORKGPT}: ${WORKMBR} 5631.23Sjoerg @echo create GPT image... 5641.23Sjoerg ${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \ 5651.23Sjoerg count=2048 5661.23Sjoerg 5671.23Sjoerg.if ${USE_GPT} == "no" 5681.23Sjoerg${IMGBASE}.img: ${WORKLABEL} 5691.1Stsutsui.endif 5701.23Sjoerg 5711.23Sjoerg${IMGBASE}.img: ${TARGET_BLOCKS} 5721.23Sjoerg ${CAT} ${TARGET_BLOCKS} > ${WORKIMG} 5731.23Sjoerg.if ${USE_GPT} != "no" 5741.25Sjmcneill.if ${USE_GPTMBR} != "no" 5751.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2 \ 5761.23Sjoerg -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin 5771.25Sjmcneill.endif 5781.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2 5791.23Sjoerg.endif # USE_GPT != "no" 5801.1Stsutsui.if ${USE_SUNLABEL} != "no" 5811.1Stsutsui @echo Creating sun disklabel... 5821.1Stsutsui printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \ 5831.1Stsutsui ${CYLINDERS} ${HEADS} ${SECTORS} \ 5841.1Stsutsui ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \ 5851.1Stsutsui ${TOOL_SUNLABEL} -nq ${WORKIMG} 5861.1Stsutsui.endif 5871.23Sjoerg.if ${USE_GPT} == "no" 5881.1Stsutsui ${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL} 5891.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no" 5901.11Sriastrad ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \ 5911.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} 5921.1Stsutsui.endif 5931.23Sjoerg.endif 5941.1Stsutsui mv ${WORKIMG} ${.TARGET} 5951.1Stsutsui 5961.1StsutsuiCLEANFILES+= ${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp 5971.1Stsutsui 5981.1Stsutsui${IMGBASE}.img.gz: ${IMGBASE}.img 5991.9Sapb ${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp 6001.1Stsutsui mv ${.TARGET}.tmp ${.TARGET} 6011.1Stsutsui 6021.1Stsutsuiclean: 6031.1Stsutsui @if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then \ 6041.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden; \ 6051.1Stsutsui fi # XXX 6061.1Stsutsui ${RM} -fr ${WORKDIR} 6071.23Sjoerg ${RM} -fr ${EFIWORKDIR} 6081.24Stsutsui ${RM} -fr ${WORKFATDIR} 6091.1Stsutsui 6101.1Stsutsuiprepare_md_post: .PHONY 6111.1Stsutsuiimage_md_post: .PHONY 6121.1Stsutsuiimage_md_pre: .PHONY 6131.1Stsutsui 6141.1Stsutsui.include <bsd.prog.mk> 615