Makefile.bootimage revision 1.24
11.24Stsutsui# $NetBSD: Makefile.bootimage,v 1.24 2020/03/21 14:19:26 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.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.1StsutsuiUSE_SUNLABEL?= no 1701.1StsutsuiINSTALLBOOT_AFTER_DISKLABEL?= no 1711.1Stsutsui 1721.1Stsutsui# 1731.1Stsutsui# size parameters for image 1741.1Stsutsui# 1751.1StsutsuiIMAGEMB?= 2048 # 2048MB 1761.1StsutsuiSWAPMB?= 128 # 128MB 1771.23Sjoerg.if ${USE_GPT} == "no" 1781.23SjoergEFIMB?= 0 1791.23SjoergGPTSECTORS= 0 1801.23Sjoerg.else 1811.23SjoergEFIMB?= 128 # 128MB 1821.23SjoergGPTSECTORS= 2048 1831.23Sjoerg.endif 1841.24StsutsuiFATMB?= 0 1851.1Stsutsui 1861.3Stsutsui# XXX: SWAPMB could be zero and expr(1) returns exit status 1 in that case 1871.1StsutsuiIMAGESECTORS!= expr ${IMAGEMB} \* 1024 \* 1024 / 512 1881.3StsutsuiSWAPSECTORS!= expr ${SWAPMB} \* 1024 \* 1024 / 512 || true 1891.23SjoergEFISECTORS!= expr ${EFIMB} \* 1024 \* 1024 / 512 || true 1901.24StsutsuiFATSECTORS!= expr ${FATMB} \* 1024 \* 1024 / 512 || true 1911.1Stsutsui 1921.23Sjoerg.if ${USE_MBR} == "no" && ${USE_GPT} == "no" 1931.1StsutsuiLABELSECTORS?= 0 1941.1Stsutsui.else 1951.1Stsutsui#LABELSECTORS?= 63 # historical 1961.1Stsutsui#LABELSECTORS?= 32 # 16KB aligned 1971.1StsutsuiLABELSECTORS?= 2048 # 1MB aligned for modern flash devices 1981.1Stsutsui.endif 1991.1Stsutsui 2001.23SjoergFSSECTORS!= expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS} \ 2011.24Stsutsui - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} 2021.1StsutsuiFSSIZE!= expr ${FSSECTORS} \* 512 2031.1Stsutsui 2041.1Stsutsui# parameters for disklabel and MBR 2051.1StsutsuiHEADS= 64 2061.1StsutsuiSECTORS= 32 2071.1StsutsuiCYLINDERS!= expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \) 2081.1StsutsuiSECPERCYLINDERS!= expr ${HEADS} \* ${SECTORS} 2091.1StsutsuiMBRHEADS= 255 2101.1StsutsuiMBRSECTORS= 63 2111.1StsutsuiMBRCYLINDERS!= expr ${IMAGESECTORS} / \( ${MBRHEADS} \* ${MBRSECTORS} \) 2121.1StsutsuiMBRNETBSD= 169 2131.24StsutsuiMBRFAT?= 6 # 16-bit FAT, more than 32M 2141.1Stsutsui 2151.24StsutsuiBSDPARTSECTORS!= expr ${IMAGESECTORS} - ${LABELSECTORS} \ 2161.24Stsutsui - ${EFISECTORS} - ${GPTSECTORS} - ${FATSECTORS} 2171.24StsutsuiFSOFFSET!= expr ${LABELSECTORS} + ${EFISECTORS} + ${FATSECTORS} 2181.24StsutsuiSWAPOFFSET!= expr ${LABELSECTORS} + ${FSSECTORS} \ 2191.24Stsutsui + ${EFISECTORS} + ${FATSECTORS} 2201.24StsutsuiFATOFFSET= ${LABELSECTORS} 2211.1Stsutsui 2221.1Stsutsui# parameters for sunlabel 2231.1StsutsuiFSCYLINDERS!= expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \) 2241.3StsutsuiSWAPCYLINDERS!= expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \) || true 2251.1Stsutsui 2261.23Sjoerg.if ${USE_GPT} != "no" 2271.23SjoergBOOTDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 2 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2281.23SjoergSWAPDISK_UUID=`${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} show -i 3 | ${TOOL_AWK} '/^GUID/ {print $$2}'` 2291.23Sjoerg.endif 2301.1Stsutsui 2311.1Stsutsui# 2321.1Stsutsui# definitions to create root fs 2331.1Stsutsui# 2341.22SmayaSETS_DEFAULT= modules base etc comp games man misc rescue tests text 2351.1Stsutsui.if ${MKX11} != "no" 2361.1StsutsuiSETS_DEFAULT+= xbase xcomp xetc xfont xserver 2371.1Stsutsui.endif 2381.1Stsutsui 2391.1StsutsuiKERN_SET?= kern-GENERIC 2401.1StsutsuiSETS?= ${SETS_DEFAULT} 2411.1StsutsuiIMG_SETS= ${KERN_SET} ${SETS} 2421.1StsutsuiSETS_DIR?= ${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets 2431.1Stsutsui 2441.1StsutsuiFSTAB_IN?= ${DISTRIBDIR}/common/bootimage/fstab.in 2451.1StsutsuiSPEC_IN?= ${DISTRIBDIR}/common/bootimage/spec.in 2461.1Stsutsui 2471.1StsutsuiIMGMAKEFSOPTIONS?= -o bsize=16384,fsize=2048,density=8192 2481.24StsutsuiFATMAKEFSOPTIONS?= -o fat_type=16 2491.1Stsutsui 2501.1StsutsuiWORKDIR?= work 2511.1StsutsuiWORKSPEC?= work.spec 2521.1StsutsuiWORKFSTAB?= work.fstab 2531.1StsutsuiWORKRCCONF?= work.rc.conf 2541.1StsutsuiWORKFS?= work.rootfs 2551.1StsutsuiTARGETFS?= imgroot.fs 2561.19SaymericCOMPRESS_PROGRAM=${"${USE_XZ_SETS:Uno}"!="no":?${TOOL_XZ}:${TOOL_GZIP}} 2571.18SmartinTAR_SUFF= ${"${USE_XZ_SETS:Uno}"!="no":?tar.xz:tgz} 2581.1Stsutsui 2591.1StsutsuiCLEANFILES+= ${WORKSPEC} ${WORKFSTAB} ${WORKRCCONF} ${WORKFS} 2601.1StsutsuiCLEANFILES+= ${TARGETFS} 2611.1Stsutsui 2621.1Stsutsui# 2631.23Sjoerg# definitions to create image 2641.23Sjoerg# 2651.23Sjoerg.if ${SWAPSECTORS} == 0 2661.23Sjoerg. if ${USE_MBR} != "no" 2671.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.mbr.in 2681.23Sjoerg. else 2691.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.noswap.in 2701.23Sjoerg. endif 2711.23Sjoerg.else 2721.23Sjoerg. if ${USE_MBR} != "no" 2731.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.mbr.in 2741.23Sjoerg. else 2751.23SjoergDISKPROTO_IN?= ${DISTRIBDIR}/common/bootimage/diskproto.in 2761.23Sjoerg. endif 2771.23Sjoerg.endif 2781.23Sjoerg 2791.23SjoergMBR_DEFAULT_BOOTCODE?= mbr 2801.23Sjoerg 2811.23SjoergWORKMBR?= work.mbr 2821.23SjoergWORKMBRTRUNC?= work.mbr.truncated 2831.23SjoergWORKSWAP?= work.swap 2841.23SjoergWORKEFI?= work.efi 2851.23SjoergWORKGPT?= work.gpt 2861.23SjoergWORKLABEL?= work.diskproto 2871.23SjoergWORKIMG?= work.img 2881.23SjoergEFIWORKDIR?= work.efidir 2891.24StsutsuiWORKFAT?= work.fat 2901.24StsutsuiWORKFATDIR?= work.fatdir 2911.23Sjoerg 2921.23Sjoerg.if ${USE_GPT} != "no" 2931.23Sjoerg${WORKFSTAB}: ${WORKMBR} 2941.23Sjoerg.endif 2951.23Sjoerg 2961.23Sjoerg${WORKFSTAB}: 2971.23Sjoerg @echo Preparing /etc/fstab ... 2981.23Sjoerg.if ${USE_GPT} != "no" 2991.23Sjoerg. if ${SWAPSECTORS} != 0 3001.23Sjoerg ${TOOL_SED} \ 3011.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 3021.23Sjoerg -e "s/ROOT.b/NAME=${SWAPDISK_UUID}/" \ 3031.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3041.23Sjoerg. else 3051.23Sjoerg ${TOOL_SED} \ 3061.23Sjoerg -e "s/ROOT.a/NAME=${BOOTDISK_UUID}/" \ 3071.23Sjoerg -e "/ROOT.b/d" \ 3081.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3091.23Sjoerg. endif 3101.23Sjoerg.else 3111.23Sjoerg. if ${SWAPSECTORS} != 0 3121.23Sjoerg ${TOOL_SED} < ${FSTAB_IN} > ${WORKFSTAB} 3131.23Sjoerg. else 3141.23Sjoerg ${TOOL_SED} \ 3151.23Sjoerg -e "/ROOT.b/d" \ 3161.23Sjoerg < ${FSTAB_IN} > ${WORKFSTAB} 3171.23Sjoerg. endif 3181.23Sjoerg.endif 3191.23Sjoerg 3201.23Sjoerg# 3211.1Stsutsui# create root file system for the image 3221.1Stsutsui# 3231.23Sjoerg${TARGETFS}: prepare_md_post ${WORKFSTAB} 3241.1Stsutsui @if [ ! -d ${RELEASEDIR}/${RELEASEMACHINEDIR} ]; then \ 3251.1Stsutsui echo "Missing ${RELEASEDIR}/${RELEASEMACHINEDIR}, aborting"; \ 3261.1Stsutsui false; \ 3271.1Stsutsui fi; 3281.14Schristos @${MKDIR} ${MKDIRPERM} ${WORKDIR} 3291.1Stsutsui.for set in ${IMG_SETS} 3301.18Smartin @if [ ! -f ${SETS_DIR}/${set}.${TAR_SUFF} ]; then \ 3311.18Smartin echo "Missing ${SETS_DIR}/${set}.${TAR_SUFF}, aborting";\ 3321.1Stsutsui false; \ 3331.1Stsutsui fi 3341.18Smartin @echo Extracting ${set}.${TAR_SUFF} ... 3351.19Saymeric @(cd ${WORKDIR}; ${TOOL_PAX} ${PAX_TIMESTAMP} -rn \ 3361.19Saymeric --use-compress-program=${COMPRESS_PROGRAM:Q} \ 3371.19Saymeric -f ${SETS_DIR}/${set}.${TAR_SUFF} .) 3381.1Stsutsui.endfor 3391.1Stsutsui.if defined(SECONDARY_BOOT) 3401.1Stsutsui @echo Copying secondary boot... 3411.21Stsutsui ${INSTALL} ${COPY} -m 0444 ${WORKDIR}/usr/mdec/${SECONDARY_BOOT} ${WORKDIR} 3421.1Stsutsui.endif 3431.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKFSTAB} ${WORKDIR}/etc/fstab 3441.1Stsutsui @echo Setting rc_configured=YES in /etc/rc.conf ... 3451.1Stsutsui ${TOOL_SED} "s/rc_configured=NO/rc_configured=YES/" \ 3461.1Stsutsui < ${WORKDIR}/etc/rc.conf > ${WORKRCCONF} 3471.14Schristos ${INSTALL} ${COPY} -m 0644 ${WORKRCCONF} ${WORKDIR}/etc/rc.conf 3481.1Stsutsui.if defined(IMGDIR_EXTRA) 3491.1Stsutsui @echo Copying extra dirs... 3501.1Stsutsui.for _SRCDIR _TARGET in ${IMGDIR_EXTRA} 3511.1Stsutsui @if [ ! -d ${_SRCDIR} ]; then \ 3521.1Stsutsui echo "${_SRCDIR} is not directory, aborting"; \ 3531.1Stsutsui false; \ 3541.1Stsutsui fi 3551.14Schristos ${MKDIR} ${MKDIRPERM} ${WORKDIR}/${_TARGET} 3561.1Stsutsui (cd ${_SRCDIR} ; \ 3571.21Stsutsui ${TOOL_PAX} ${PAX_TIMESTAMP} -rw -pe -v \ 3581.1Stsutsui ${IMGDIR_EXCLUDE} \ 3591.1Stsutsui . ${.OBJDIR}/${WORKDIR}/${_TARGET} ) 3601.1Stsutsui.endfor 3611.1Stsutsui.endif 3621.1Stsutsui.if defined(IMGFILE_EXTRA) 3631.1Stsutsui @echo Copying extra files... 3641.1Stsutsui.for _SRC _TARGET in ${IMGFILE_EXTRA} 3651.1Stsutsui @if [ ! -f ${_SRC} ]; then \ 3661.1Stsutsui echo "${_SRC} in IMGFILE_EXTRA not found, aborting"; \ 3671.1Stsutsui false; \ 3681.1Stsutsui fi 3691.1Stsutsui @if [ -f ${_SRC} ]; then \ 3701.21Stsutsui echo ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3711.21Stsutsui ${INSTALL} ${COPY} -m 0644 ${_SRC} ${WORKDIR}/${_TARGET}; \ 3721.1Stsutsui fi 3731.1Stsutsui.endfor 3741.1Stsutsui.endif 3751.1Stsutsui @echo Preparing spec files for makefs... 3761.1Stsutsui ${RM} -f ${WORKSPEC} 3771.1Stsutsui cat ${WORKDIR}/etc/mtree/* | \ 3781.1Stsutsui ${TOOL_SED} -e 's/ size=[0-9]*//' > ${WORKSPEC} 3791.10Ssnj ${HOST_SH} ${WORKDIR}/dev/MAKEDEV -s all ipty | \ 3801.1Stsutsui ${TOOL_SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKSPEC} 3811.1Stsutsui cat ${SPEC_IN} >> ${WORKSPEC} 3821.1Stsutsui.if defined(SECONDARY_BOOT) 3831.1Stsutsui echo "./${SECONDARY_BOOT} type=file uname=root gname=wheel mode=0444" \ 3841.1Stsutsui >> ${WORKSPEC} 3851.1Stsutsui.endif 3861.1Stsutsui.if defined(SPEC_EXTRA) 3871.1Stsutsui cat ${SPEC_EXTRA} >> ${WORKSPEC} 3881.1Stsutsui.endif 3891.4Sriz @echo Creating rootfs... 3901.1Stsutsui # XXX /var/spool/ftp/hidden is unreadable 3911.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden 3921.1Stsutsui ${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE} \ 3931.1Stsutsui -B ${TARGET_ENDIANNESS} \ 3941.1Stsutsui -F ${WORKSPEC} -N ${WORKDIR}/etc \ 3951.13Schristos ${MAKEFS_TIMESTAMP} \ 3961.1Stsutsui ${IMGMAKEFSOPTIONS} \ 3971.1Stsutsui ${WORKFS} ${WORKDIR} 3981.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} == "no" 3991.5Stsutsui ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKFS} \ 4001.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG} 4011.1Stsutsui.endif 4021.1Stsutsui @echo done. 4031.1Stsutsui mv ${WORKFS} ${.TARGET} 4041.1Stsutsui 4051.23SjoergTARGET_BLOCKS= 4061.23Sjoerg.if ${USE_MBR} != "no" || ${USE_GPT} != "no" 4071.23SjoergTARGET_BLOCKS+= ${WORKMBRTRUNC} 4081.23Sjoerg.endif 4091.23Sjoerg.if ${USE_GPT} != "no" 4101.23SjoergTARGET_BLOCKS+= ${WORKEFI} 4111.23Sjoerg.endif 4121.24Stsutsui.if ${FATSECTORS} != 0 4131.24StsutsuiTARGET_BLOCKS+= ${WORKFAT} 4141.24Stsutsui.endif 4151.23SjoergTARGET_BLOCKS+= ${TARGETFS} 4161.23Sjoerg.if ${SWAPSECTORS} != 0 4171.23SjoergTARGET_BLOCKS+= ${WORKSWAP} 4181.23Sjoerg.endif 4191.23Sjoerg.if ${USE_GPT} != "no" 4201.23SjoergTARGET_BLOCKS+= ${WORKGPT} 4211.1Stsutsui.endif 4221.1Stsutsui 4231.23SjoergCLEANFILES+= ${WORKMBR} ${WORKMBRTRUNC} ${WORKSWAP} 4241.23SjoergCLEANFILES+= ${WORKEFI} ${WORKGPT} 4251.24StsutsuiCLEANFILES+= ${WORKFAT} 4261.23SjoergCLEANFILES+= ${WORKLABEL}.tmp ${WORKLABEL} 4271.23SjoergCLEANFILES+= ${WORKIMG} ${IMGBASE}.img 4281.5Stsutsui 4291.23Sjoerg${WORKSWAP}: 4301.23Sjoerg.if ${SWAPSECTORS} == 0 4311.23Sjoerg printf "" > ${WORKSWAP} 4321.23Sjoerg.else 4331.23Sjoerg ${DD} if=/dev/zero of=${WORKSWAP} seek=$$((${SWAPSECTORS} - 1)) count=1 4341.23Sjoerg.endif 4351.1Stsutsui 4361.23Sjoerg${WORKMBRTRUNC}: ${WORKMBR} 4371.23Sjoerg ${DD} if=${WORKMBR} count=${LABELSECTORS} of=${WORKMBRTRUNC} 4381.1Stsutsui 4391.1Stsutsui${WORKLABEL}: 4401.1Stsutsui ${TOOL_SED} \ 4411.1Stsutsui -e "s/@@SECTORS@@/${SECTORS}/" \ 4421.1Stsutsui -e "s/@@HEADS@@/${HEADS}/" \ 4431.1Stsutsui -e "s/@@SECPERCYLINDERS@@/${SECPERCYLINDERS}/" \ 4441.1Stsutsui -e "s/@@CYLINDERS@@/${CYLINDERS}/" \ 4451.1Stsutsui -e "s/@@IMAGESECTORS@@/${IMAGESECTORS}/" \ 4461.1Stsutsui -e "s/@@FSSECTORS@@/${FSSECTORS}/" \ 4471.1Stsutsui -e "s/@@FSOFFSET@@/${FSOFFSET}/" \ 4481.1Stsutsui -e "s/@@SWAPSECTORS@@/${SWAPSECTORS}/" \ 4491.1Stsutsui -e "s/@@SWAPOFFSET@@/${SWAPOFFSET}/" \ 4501.1Stsutsui -e "s/@@BSDPARTSECTORS@@/${BSDPARTSECTORS}/" \ 4511.24Stsutsui -e "s/@@FATSECTORS@@/${FATSECTORS}/" \ 4521.24Stsutsui -e "s/@@FATOFFSET@@/${FATOFFSET}/" \ 4531.1Stsutsui < ${DISKPROTO_IN} > ${WORKLABEL}.tmp 4541.1Stsutsui mv ${WORKLABEL}.tmp ${WORKLABEL} 4551.1Stsutsui 4561.23Sjoerg${WORKEFI}: ${TARGETFS} 4571.23Sjoerg @echo create EFI system partition... 4581.23Sjoerg @${MKDIR} ${MKDIRPERM} ${EFIWORKDIR}/EFI/boot 4591.23Sjoerg.for f in ${EFIBOOT} 4601.23Sjoerg ${INSTALL} ${COPY} -m 0644 ${f} ${EFIWORKDIR}/EFI/boot/`basename ${f}` 4611.23Sjoerg.endfor 4621.23Sjoerg ${RM} -f ${WORKEFI} 4631.23Sjoerg ${TOOL_MAKEFS} -M ${EFIMB}m -m ${EFIMB}m \ 4641.23Sjoerg -B ${TARGET_ENDIANNESS} \ 4651.23Sjoerg ${MAKEFS_TIMESTAMP} \ 4661.23Sjoerg -t msdos -o F=32,c=1 \ 4671.23Sjoerg ${WORKEFI} ${EFIWORKDIR} 4681.23Sjoerg 4691.24Stsutsui${WORKFAT}: ${TARGETFS} ${FATFILES} 4701.24Stsutsui @echo create FAT partition for bootstrap files... 4711.24Stsutsui @${MKDIR} ${MKDIRPERM} ${WORKFATDIR} 4721.24Stsutsui.if defined(FATFILES) 4731.24Stsutsui @echo Copying files for FAT partition... 4741.24Stsutsui.for f in ${FATFILES} 4751.24Stsutsui @if [ ! -f ${f} ]; then \ 4761.24Stsutsui echo "${f} in FATFILES not found, aborting"; \ 4771.24Stsutsui false; \ 4781.24Stsutsui fi 4791.24Stsutsui ${INSTALL} ${COPY} -m 0644 ${f} ${WORKFATDIR} 4801.24Stsutsui.endfor 4811.24Stsutsui.endif 4821.24Stsutsui ${RM} -f ${WORKFAT} 4831.24Stsutsui ${TOOL_MAKEFS} -M ${FATMB}m -m ${FATMB}m \ 4841.24Stsutsui ${MAKEFS_TIMESTAMP} \ 4851.24Stsutsui -t msdos \ 4861.24Stsutsui ${FATMAKEFSOPTIONS} \ 4871.24Stsutsui ${WORKFAT} ${WORKFATDIR} 4881.24Stsutsui 4891.23Sjoerg${WORKMBR}: 4901.23Sjoerg.if ${USE_GPT} != "no" 4911.23Sjoerg @echo creating GPT header and partition entries... 4921.23Sjoerg ${RM} -f ${WORKMBR} 4931.23Sjoerg ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 4941.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} create 4951.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${EFISECTORS} -t efi -l "EFI system" 4961.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${FSSECTORS} -t ffs 4971.23Sjoerg. if ${SWAPSECTORS} != 0 4981.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKMBR} add -a 1m -s ${SWAPSECTORS} -t swap 4991.23Sjoerg. endif 5001.23Sjoerg.elif ${USE_MBR} != "no" 5011.1Stsutsui @echo creating MBR labels... 5021.1Stsutsui ${DD} if=/dev/zero of=${WORKMBR} seek=$$((${IMAGESECTORS} - 1)) count=1 5031.24Stsutsui. if ${FATSECTORS} != 0 5041.24Stsutsui # create BSD partition 5051.24Stsutsui ${TOOL_FDISK} -f -i -u \ 5061.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5071.24Stsutsui -1 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5081.24Stsutsui -F ${WORKMBR} 5091.24Stsutsui # create FAT partition 5101.24Stsutsui ${TOOL_FDISK} -f -u \ 5111.24Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5121.24Stsutsui -0 -s ${MBRFAT}/${FATOFFSET}/${FATSECTORS} \ 5131.24Stsutsui -F ${WORKMBR} 5141.24Stsutsui. else 5151.24Stsutsui # create BSD partition 5161.5Stsutsui ${TOOL_FDISK} -f -i -u \ 5171.1Stsutsui -b ${MBRCYLINDERS}/${MBRHEADS}/${MBRSECTORS} \ 5181.1Stsutsui -0 -a -s ${MBRNETBSD}/${FSOFFSET}/${BSDPARTSECTORS} \ 5191.1Stsutsui -F ${WORKMBR} 5201.24Stsutsui. endif 5211.23Sjoerg. if empty(MBR_BOOTCODE) 5221.5Stsutsui @if [ -f ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} ]; then \ 5231.5Stsutsui echo ${TOOL_FDISK} -f \ 5241.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5251.5Stsutsui -F ${WORKMBR}; \ 5261.5Stsutsui ${TOOL_FDISK} -f \ 5271.5Stsutsui -i -c ${WORKDIR}/usr/mdec/${MBR_DEFAULT_BOOTCODE} \ 5281.5Stsutsui -F ${WORKMBR}; \ 5291.5Stsutsui fi 5301.23Sjoerg. else 5311.5Stsutsui @if [ ! -f ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} ]; then \ 5321.5Stsutsui echo "${MBR_BOOTCODE} is not found in DESTDIR/usr/mdec, aborting"; \ 5331.5Stsutsui false; \ 5341.5Stsutsui fi 5351.5Stsutsui ${TOOL_FDISK} -f -i -c ${WORKDIR}/usr/mdec/${MBR_BOOTCODE} \ 5361.5Stsutsui -F ${WORKMBR} 5371.23Sjoerg. endif 5381.5Stsutsui.endif 5391.23Sjoerg 5401.23Sjoerg${WORKGPT}: ${WORKMBR} 5411.23Sjoerg @echo create GPT image... 5421.23Sjoerg ${DD} if=${WORKMBR} of=${WORKGPT} skip=$$((${IMAGESECTORS} - 2048)) \ 5431.23Sjoerg count=2048 5441.23Sjoerg 5451.23Sjoerg.if ${USE_GPT} == "no" 5461.23Sjoerg${IMGBASE}.img: ${WORKLABEL} 5471.1Stsutsui.endif 5481.23Sjoerg 5491.23Sjoerg${IMGBASE}.img: ${TARGET_BLOCKS} 5501.23Sjoerg ${CAT} ${TARGET_BLOCKS} > ${WORKIMG} 5511.23Sjoerg.if ${USE_GPT} != "no" 5521.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} biosboot -i 2 \ 5531.23Sjoerg -c ${.OBJDIR}/${WORKDIR}/usr/mdec/gptmbr.bin 5541.23Sjoerg ${TOOL_GPT} ${GPT_TIMESSTAMP} ${WORKIMG} set -a bootme -i 2 5551.23Sjoerg.endif # USE_GPT != "no" 5561.1Stsutsui.if ${USE_SUNLABEL} != "no" 5571.1Stsutsui @echo Creating sun disklabel... 5581.1Stsutsui printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d %d/0/0\nW\n' \ 5591.1Stsutsui ${CYLINDERS} ${HEADS} ${SECTORS} \ 5601.1Stsutsui ${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCYLINDERS} | \ 5611.1Stsutsui ${TOOL_SUNLABEL} -nq ${WORKIMG} 5621.1Stsutsui.endif 5631.23Sjoerg.if ${USE_GPT} == "no" 5641.1Stsutsui ${TOOL_DISKLABEL} -R -F ${WORKIMG} ${WORKLABEL} 5651.1Stsutsui.if !empty(PRIMARY_BOOT) && ${INSTALLBOOT_AFTER_DISKLABEL} != "no" 5661.11Sriastrad ${TOOL_INSTALLBOOT} -v -m ${MACHINE} ${INSTALLBOOTOPTIONS} ${WORKIMG} \ 5671.1Stsutsui ${WORKDIR}/usr/mdec/${PRIMARY_BOOT} 5681.1Stsutsui.endif 5691.23Sjoerg.endif 5701.1Stsutsui mv ${WORKIMG} ${.TARGET} 5711.1Stsutsui 5721.1StsutsuiCLEANFILES+= ${IMGBASE}.img.gz ${IMGBASE}.img.gz.tmp 5731.1Stsutsui 5741.1Stsutsui${IMGBASE}.img.gz: ${IMGBASE}.img 5751.9Sapb ${TOOL_GZIP_N} -9c ${IMGBASE}.img > ${.TARGET}.tmp 5761.1Stsutsui mv ${.TARGET}.tmp ${.TARGET} 5771.1Stsutsui 5781.1Stsutsuiclean: 5791.1Stsutsui @if [ -d ${WORKDIR}/var/spool/ftp/hidden ]; then \ 5801.1Stsutsui ${CHMOD} +r ${WORKDIR}/var/spool/ftp/hidden; \ 5811.1Stsutsui fi # XXX 5821.1Stsutsui ${RM} -fr ${WORKDIR} 5831.23Sjoerg ${RM} -fr ${EFIWORKDIR} 5841.24Stsutsui ${RM} -fr ${WORKFATDIR} 5851.1Stsutsui 5861.1Stsutsuiprepare_md_post: .PHONY 5871.1Stsutsuiimage_md_post: .PHONY 5881.1Stsutsuiimage_md_pre: .PHONY 5891.1Stsutsui 5901.1Stsutsui.include <bsd.prog.mk> 591