Makefile.bootimage revision 1.29
11.29Smaya# $NetBSD: Makefile.bootimage,v 1.29 2021/09/25 08:54:29 maya 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.29Smaya# (default: modules base etc comp games gpufw man misc 751.29Smaya# rescue tests 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.29SmayaSETS_DEFAULT= modules base etc comp games gpufw 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.28Sjmcneill.if defined(RC_CONF_EXTRA) 3701.28Sjmcneill @echo Adding contents of ${RC_CONF_EXTRA} to /etc/rc.conf ... 3711.28Sjmcneill cat ${RC_CONF_EXTRA} >> ${WORKRCCONF} 3721.28Sjmcneill.endif 3731.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf 3741.1Stsutsui.if defined(IMGDIR_EXTRA) 3751.1Stsutsui @echo Copying extra dirs... 3761.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA} 3771.1Stsutsui @if [ ! -d ${_SRCDIR} ]; then \ 3781.1Stsutsui echo "${_SRCDIR} is not directory, aborting"; \ 3791.1Stsutsui false; \ 3801.1Stsutsui fi 3811.14Schristos ${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET} 3821.1Stsutsui (cd ${_SRCDIR} ; \ 3831.21Stsutsui ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v \ 3841.1Stsutsui ${IMGDIR_EXCLUDE} \ 3851.1Stsutsui . ${.OBJDIR}/${WORKDIR}/${_TARGET} ) 3861.1Stsutsui.endfor 3871.1Stsutsui.endif 3881.1Stsutsui.if defined(IMGFILE_EXTRA) 3891.1Stsutsui @echo Copying extra files... 3901.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA} 3911.1Stsutsui @if [ ! -f ${_SRC} ]; then \ 3921.1Stsutsui echo "${_SRC} in IMGFILE_EXTRA not found, aborting"; \ 3931.1Stsutsui false; \ 3941.1Stsutsui fi 3951.1Stsutsui @if [ -f ${_SRC} ]; then \ 3961.21Stsutsui echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3971.21Stsutsui ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3981.1Stsutsui fi 3991.1Stsutsui.endfor 4001.1Stsutsui.endif 4011.1Stsutsui @echo Preparing spec files for makefs... 4021.1Stsutsui ${RM} -f ${WORKSPEC} 4031.1Stsutsui cat ${WORKDIR}/etc/mtree/* | \ 4041.1Stsutsui ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC} 4051.10Ssnj ${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty | \ 4061.1Stsutsui ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC} 4071.1Stsutsui cat ${SPEC_IN} >> ${WORKSPEC} 4081.1Stsutsui.if defined(SECONDARY_BOOT) 4091.1Stsutsui echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \ 4101.1Stsutsui >> ${WORKSPEC} 4111.1Stsutsui.endif 4121.1Stsutsui.if defined(SPEC_EXTRA) 4131.1Stsutsui cat ${SPEC_EXTRA} >> ${WORKSPEC} 4141.1Stsutsui.endif 4151.4Sriz @echo Creating rootfs... 4161.1Stsutsui # XXX /var/spool/ftp/hidden is unreadable 4171.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden 4181.1Stsutsui ${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE} \ 4191.1Stsutsui -B ${TARGET_ENDIANNESS} \ 4201.1Stsutsui -F ${WORKSPEC} -N ${WORKDIR}/etc \ 4211.13Schristos ${MAKEFS_TIMESTAMP} \ 4221.1Stsutsui ${IMGMAKEFSOPTIONS} \ 4231.1Stsutsui ${WORKFS} ${WORKDIR} 4241.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no" 4251.5Stsutsui ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \ 4261.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG} 4271.1Stsutsui.endif 4281.1Stsutsui @echo done. 4291.1Stsutsui mv ${WORKFS} ${.TARGET} 4301.1Stsutsui 4311.23SjoergTARGET_BLOCKS= 4321.23Sjoerg.if ${USE_MBR} != "no" || ${USE_GPT} != "no" 4331.23SjoergTARGET_BLOCKS+= ${WORKMBRTRUNC} 4341.23Sjoerg.endif 4351.23Sjoerg.if ${USE_GPT} != "no" 4361.23SjoergTARGET_BLOCKS+= ${WORKEFI} 4371.23Sjoerg.endif 4381.24Stsutsui.if ${FATSECTORS} != 0 4391.24StsutsuiTARGET_BLOCKS+= ${WORKFAT} 4401.24Stsutsui.endif 4411.23SjoergTARGET_BLOCKS+= ${TARGETFS} 4421.23Sjoerg.if ${SWAPSECTORS} != 0 4431.23SjoergTARGET_BLOCKS+= ${WORKSWAP} 4441.23Sjoerg.endif 4451.23Sjoerg.if ${USE_GPT} != "no" 4461.23SjoergTARGET_BLOCKS+= ${WORKGPT} 4471.1Stsutsui.endif 4481.1Stsutsui 4491.23SjoergCLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP} 4501.23SjoergCLEANFILES+= ${WORKEFI} ${WORKGPT} 4511.24StsutsuiCLEANFILES+= ${WORKFAT} 4521.23SjoergCLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL} 4531.23SjoergCLEANFILES+= ${WORKIMG} ${IMGBASE}.img 4541.5Stsutsui 4551.23Sjoerg${WORKSWAP}: 4561.23Sjoerg.if ${SWAPSECTORS} == 0 4571.23Sjoerg printf "" > ${WORKSWAP} 4581.23Sjoerg.else 4591.23Sjoerg ${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1 4601.23Sjoerg.endif 4611.1Stsutsui 4621.23Sjoerg${WORKMBRTRUNC}: ${WORKMBR} 4631.23Sjoerg ${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC} 4641.1Stsutsui 4651.1Stsutsui${WORKLABEL}: 4661.1Stsutsui ${TOOL_SED} \ 4671.1Stsutsui -e "s/@@SECTORS@@/${SECTORS}/" \ 4681.1Stsutsui -e "s/@@HEADS@@/${HEADS}/" \ 4691.1Stsutsui -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/" \ 4701.1Stsutsui -e "s/@@CYLINDERS@@/${CYLINDERS}/" \ 4711.1Stsutsui -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/" \ 4721.1Stsutsui -e "s/@@FSSECTORS@@/${FSSECTORS}/" \ 4731.1Stsutsui -e "s/@@FSOFFSET@@/${FSOFFSET}/" \ 4741.1Stsutsui -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/" \ 4751.1Stsutsui -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/" \ 4761.1Stsutsui -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/" \ 4771.24Stsutsui -e "s/@@FATSECTORS@@/${FATSECTORS}/" \ 4781.24Stsutsui -e "s/@@FATOFFSET@@/${FATOFFSET}/" \ 4791.1Stsutsui < ${DISKPROTO_IN} > ${WORKLABEL}.tmp 4801.1Stsutsui mv ${WORKLABEL}.tmp ${WORKLABEL} 4811.1Stsutsui 4821.23Sjoerg${WORKEFI}: ${TARGETFS} 4831.23Sjoerg @echo create EFI system partition... 4841.23Sjoerg @${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot 4851.23Sjoerg.for f in ${EFIBOOT} 4861.23Sjoerg ${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}` 4871.23Sjoerg.endfor 4881.23Sjoerg ${RM} -f ${WORKEFI} 4891.23Sjoerg ${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m \ 4901.23Sjoerg -B ${TARGET_ENDIANNESS} \ 4911.23Sjoerg ${MAKEFS_TIMESTAMP} \ 4921.23Sjoerg -t msdos -o F=32,c=1 \ 4931.23Sjoerg ${WORKEFI} ${EFIWORKDIR} 4941.23Sjoerg 4951.24Stsutsui${WORKFAT}: ${TARGETFS} ${FATFILES} 4961.24Stsutsui @echo create FAT partition for bootstrap files... 4971.24Stsutsui @${MKDIR} ${MKDIRPERM} ${WORKFATDIR} 4981.24Stsutsui.if defined(FATFILES) 4991.24Stsutsui @echo Copying files for FAT partition... 5001.24Stsutsui.for f in ${FATFILES} 5011.24Stsutsui @if [ ! -f ${f} ]; then \ 5021.24Stsutsui echo "${f} in FATFILES not found, aborting"; \ 5031.24Stsutsui false; \ 5041.24Stsutsui fi 5051.24Stsutsui ${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR} 5061.24Stsutsui.endfor 5071.24Stsutsui.endif 5081.24Stsutsui ${RM} -f ${WORKFAT} 5091.24Stsutsui ${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m \ 5101.24Stsutsui ${MAKEFS_TIMESTAMP} \ 5111.24Stsutsui -t msdos \ 5121.24Stsutsui ${FATMAKEFSOPTIONS} \ 5131.24Stsutsui ${WORKFAT} ${WORKFATDIR} 5141.24Stsutsui 5151.23Sjoerg${WORKMBR}: 5161.23Sjoerg.if ${USE_GPT} != "no" 5171.23Sjoerg @echo creating GPT header and partition entries... 5181.23Sjoerg ${RM} -f ${WORKMBR} 5191.23Sjoerg ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5201.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create 5211.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system" 5221.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs 5231.23Sjoerg. if ${SWAPSECTORS} != 0 5241.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap 5251.23Sjoerg. endif 5261.23Sjoerg.elif ${USE_MBR} != "no" 5271.1Stsutsui @echo creating MBR labels... 5281.1Stsutsui ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5291.24Stsutsui. if ${FATSECTORS} != 0 5301.24Stsutsui # create BSD partition 5311.24Stsutsui ${TOOL_FDISK} -f -i -u \ 5321.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5331.24Stsutsui -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5341.24Stsutsui -F ${WORKMBR} 5351.24Stsutsui # create FAT partition 5361.24Stsutsui ${TOOL_FDISK} -f -u \ 5371.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5381.24Stsutsui -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS} \ 5391.24Stsutsui -F ${WORKMBR} 5401.24Stsutsui. else 5411.24Stsutsui # create BSD partition 5421.5Stsutsui ${TOOL_FDISK} -f -i -u \ 5431.1Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5441.1Stsutsui -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5451.1Stsutsui -F ${WORKMBR} 5461.24Stsutsui. endif 5471.23Sjoerg. if empty(MBR_BOOTCODE) 5481.5Stsutsui @if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then \ 5491.5Stsutsui echo ${TOOL_FDISK} -f \ 5501.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5511.5Stsutsui -F ${WORKMBR}; \ 5521.5Stsutsui ${TOOL_FDISK} -f \ 5531.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5541.5Stsutsui -F ${WORKMBR}; \ 5551.5Stsutsui fi 5561.23Sjoerg. else 5571.5Stsutsui @if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then \ 5581.5Stsutsui echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \ 5591.5Stsutsui false; \ 5601.5Stsutsui fi 5611.5Stsutsui ${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} \ 5621.5Stsutsui -F ${WORKMBR} 5631.23Sjoerg. endif 5641.5Stsutsui.endif 5651.23Sjoerg 5661.23Sjoerg${WORKGPT}: ${WORKMBR} 5671.23Sjoerg @echo create GPT image... 5681.23Sjoerg ${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \ 5691.23Sjoerg count=2048 5701.23Sjoerg 5711.23Sjoerg.if ${USE_GPT} == "no" 5721.23Sjoerg${IMGBASE}.img: ${WORKLABEL} 5731.1Stsutsui.endif 5741.23Sjoerg 5751.23Sjoerg${IMGBASE}.img: ${TARGET_BLOCKS} 5761.23Sjoerg ${CAT} ${TARGET_BLOCKS} > ${WORKIMG} 5771.23Sjoerg.if ${USE_GPT} != "no" 5781.25Sjmcneill.if ${USE_GPTMBR} != "no" 5791.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2 \ 5801.23Sjoerg -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin 5811.25Sjmcneill.endif 5821.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2 5831.23Sjoerg.endif # USE_GPT != "no" 5841.1Stsutsui.if ${USE_SUNLABEL} != "no" 5851.1Stsutsui @echo Creating sun disklabel... 5861.1Stsutsui printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \ 5871.1Stsutsui ${CYLINDERS} ${HEADS} ${SECTORS} \ 5881.1Stsutsui ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \ 5891.1Stsutsui ${TOOL_SUNLABEL} -nq ${WORKIMG} 5901.1Stsutsui.endif 5911.23Sjoerg.if ${USE_GPT} == "no" 5921.1Stsutsui ${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL} 5931.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no" 5941.11Sriastrad ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \ 5951.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} 5961.1Stsutsui.endif 5971.23Sjoerg.endif 5981.1Stsutsui mv ${WORKIMG} ${.TARGET} 5991.1Stsutsui 6001.1StsutsuiCLEANFILES+= ${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp 6011.1Stsutsui 6021.1Stsutsui${IMGBASE}.img.gz: ${IMGBASE}.img 6031.9Sapb ${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp 6041.1Stsutsui mv ${.TARGET}.tmp ${.TARGET} 6051.1Stsutsui 6061.1Stsutsuiclean: 6071.1Stsutsui @if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then \ 6081.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden; \ 6091.1Stsutsui fi # XXX 6101.1Stsutsui ${RM} -fr ${WORKDIR} 6111.23Sjoerg ${RM} -fr ${EFIWORKDIR} 6121.24Stsutsui ${RM} -fr ${WORKFATDIR} 6131.1Stsutsui 6141.1Stsutsuiprepare_md_post: .PHONY 6151.1Stsutsuiimage_md_post: .PHONY 6161.1Stsutsuiimage_md_pre: .PHONY 6171.1Stsutsui 6181.1Stsutsui.include <bsd.prog.mk> 619