1*6b8c8deeSWill Andrews#!/bin/sh 2*6b8c8deeSWill Andrews# 3*6b8c8deeSWill Andrews# Copyright (c) 2005 Poul-Henning Kamp. 4*6b8c8deeSWill Andrews# All rights reserved. 5*6b8c8deeSWill Andrews# 6*6b8c8deeSWill Andrews# Redistribution and use in source and binary forms, with or without 7*6b8c8deeSWill Andrews# modification, are permitted provided that the following conditions 8*6b8c8deeSWill Andrews# are met: 9*6b8c8deeSWill Andrews# 1. Redistributions of source code must retain the above copyright 10*6b8c8deeSWill Andrews# notice, this list of conditions and the following disclaimer. 11*6b8c8deeSWill Andrews# 2. Redistributions in binary form must reproduce the above copyright 12*6b8c8deeSWill Andrews# notice, this list of conditions and the following disclaimer in the 13*6b8c8deeSWill Andrews# documentation and/or other materials provided with the distribution. 14*6b8c8deeSWill Andrews# 15*6b8c8deeSWill Andrews# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*6b8c8deeSWill Andrews# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*6b8c8deeSWill Andrews# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*6b8c8deeSWill Andrews# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*6b8c8deeSWill Andrews# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*6b8c8deeSWill Andrews# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*6b8c8deeSWill Andrews# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*6b8c8deeSWill Andrews# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*6b8c8deeSWill Andrews# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*6b8c8deeSWill Andrews# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*6b8c8deeSWill Andrews# SUCH DAMAGE. 26*6b8c8deeSWill Andrews# 27*6b8c8deeSWill Andrews# $FreeBSD$ 28*6b8c8deeSWill Andrews# 29*6b8c8deeSWill Andrews 30*6b8c8deeSWill Andrewsset -e 31*6b8c8deeSWill Andrews 32*6b8c8deeSWill Andrews####################################################################### 33*6b8c8deeSWill Andrews# 34*6b8c8deeSWill Andrews# Setup default values for all controlling variables. 35*6b8c8deeSWill Andrews# These values can be overridden from the config file(s) 36*6b8c8deeSWill Andrews# 37*6b8c8deeSWill Andrews####################################################################### 38*6b8c8deeSWill Andrews 39*6b8c8deeSWill Andrews# Name of this NanoBSD build. (Used to construct workdir names) 40*6b8c8deeSWill AndrewsNANO_NAME=full 41*6b8c8deeSWill Andrews 42*6b8c8deeSWill Andrews# Source tree directory 43*6b8c8deeSWill AndrewsNANO_SRC=/usr/src 44*6b8c8deeSWill Andrews 45*6b8c8deeSWill Andrews# Where nanobsd additional files live under the source tree 46*6b8c8deeSWill AndrewsNANO_TOOLS=tools/tools/nanobsd 47*6b8c8deeSWill Andrews 48*6b8c8deeSWill Andrews# Where cust_pkg() finds packages to install 49*6b8c8deeSWill AndrewsNANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg 50*6b8c8deeSWill AndrewsNANO_PACKAGE_LIST="*" 51*6b8c8deeSWill Andrews 52*6b8c8deeSWill Andrews# where package metadata gets placed 53*6b8c8deeSWill AndrewsNANO_PKG_META_BASE=/var/db 54*6b8c8deeSWill Andrews 55*6b8c8deeSWill Andrews# Object tree directory 56*6b8c8deeSWill Andrews# default is subdir of /usr/obj 57*6b8c8deeSWill Andrews#NANO_OBJ="" 58*6b8c8deeSWill Andrews 59*6b8c8deeSWill Andrews# The directory to put the final images 60*6b8c8deeSWill Andrews# default is ${NANO_OBJ} 61*6b8c8deeSWill Andrews#NANO_DISKIMGDIR="" 62*6b8c8deeSWill Andrews 63*6b8c8deeSWill Andrews# Make & parallel Make 64*6b8c8deeSWill AndrewsNANO_MAKE="make" 65*6b8c8deeSWill AndrewsNANO_PMAKE="make -j 3" 66*6b8c8deeSWill Andrews 67*6b8c8deeSWill Andrews# The default name for any image we create. 68*6b8c8deeSWill AndrewsNANO_IMGNAME="_.disk.full" 69*6b8c8deeSWill Andrews 70*6b8c8deeSWill Andrews# Options to put in make.conf during buildworld only 71*6b8c8deeSWill AndrewsCONF_BUILD=' ' 72*6b8c8deeSWill Andrews 73*6b8c8deeSWill Andrews# Options to put in make.conf during installworld only 74*6b8c8deeSWill AndrewsCONF_INSTALL=' ' 75*6b8c8deeSWill Andrews 76*6b8c8deeSWill Andrews# Options to put in make.conf during both build- & installworld. 77*6b8c8deeSWill AndrewsCONF_WORLD=' ' 78*6b8c8deeSWill Andrews 79*6b8c8deeSWill Andrews# Kernel config file to use 80*6b8c8deeSWill AndrewsNANO_KERNEL=GENERIC 81*6b8c8deeSWill Andrews 82*6b8c8deeSWill Andrews# Kernel modules to install. If empty, no modules are installed. 83*6b8c8deeSWill Andrews# Use "default" to install all built modules. 84*6b8c8deeSWill AndrewsNANO_MODULES= 85*6b8c8deeSWill Andrews 86*6b8c8deeSWill Andrews# Customize commands. 87*6b8c8deeSWill AndrewsNANO_CUSTOMIZE="" 88*6b8c8deeSWill Andrews 89*6b8c8deeSWill Andrews# Late customize commands. 90*6b8c8deeSWill AndrewsNANO_LATE_CUSTOMIZE="" 91*6b8c8deeSWill Andrews 92*6b8c8deeSWill Andrews# Newfs paramters to use 93*6b8c8deeSWill AndrewsNANO_NEWFS="-b 4096 -f 512 -i 8192 -U" 94*6b8c8deeSWill Andrews 95*6b8c8deeSWill Andrews# The drive name of the media at runtime 96*6b8c8deeSWill AndrewsNANO_DRIVE=ad0 97*6b8c8deeSWill Andrews 98*6b8c8deeSWill Andrews# Target media size in 512 bytes sectors 99*6b8c8deeSWill AndrewsNANO_MEDIASIZE=2000000 100*6b8c8deeSWill Andrews 101*6b8c8deeSWill Andrews# Number of code images on media (1 or 2) 102*6b8c8deeSWill AndrewsNANO_IMAGES=2 103*6b8c8deeSWill Andrews 104*6b8c8deeSWill Andrews# 0 -> Leave second image all zeroes so it compresses better. 105*6b8c8deeSWill Andrews# 1 -> Initialize second image with a copy of the first 106*6b8c8deeSWill AndrewsNANO_INIT_IMG2=1 107*6b8c8deeSWill Andrews 108*6b8c8deeSWill Andrews# Size of code file system in 512 bytes sectors 109*6b8c8deeSWill Andrews# If zero, size will be as large as possible. 110*6b8c8deeSWill AndrewsNANO_CODESIZE=0 111*6b8c8deeSWill Andrews 112*6b8c8deeSWill Andrews# Size of configuration file system in 512 bytes sectors 113*6b8c8deeSWill Andrews# Cannot be zero. 114*6b8c8deeSWill AndrewsNANO_CONFSIZE=2048 115*6b8c8deeSWill Andrews 116*6b8c8deeSWill Andrews# Size of data file system in 512 bytes sectors 117*6b8c8deeSWill Andrews# If zero: no partition configured. 118*6b8c8deeSWill Andrews# If negative: max size possible 119*6b8c8deeSWill AndrewsNANO_DATASIZE=0 120*6b8c8deeSWill Andrews 121*6b8c8deeSWill Andrews# Size of the /etc ramdisk in 512 bytes sectors 122*6b8c8deeSWill AndrewsNANO_RAM_ETCSIZE=10240 123*6b8c8deeSWill Andrews 124*6b8c8deeSWill Andrews# Size of the /tmp+/var ramdisk in 512 bytes sectors 125*6b8c8deeSWill AndrewsNANO_RAM_TMPVARSIZE=10240 126*6b8c8deeSWill Andrews 127*6b8c8deeSWill Andrews# Media geometry, only relevant if bios doesn't understand LBA. 128*6b8c8deeSWill AndrewsNANO_SECTS=63 129*6b8c8deeSWill AndrewsNANO_HEADS=16 130*6b8c8deeSWill Andrews 131*6b8c8deeSWill Andrews# boot0 flags/options and configuration 132*6b8c8deeSWill AndrewsNANO_BOOT0CFG="-o packet -s 1 -m 3" 133*6b8c8deeSWill AndrewsNANO_BOOTLOADER="boot/boot0sio" 134*6b8c8deeSWill Andrews 135*6b8c8deeSWill Andrews# boot2 flags/options 136*6b8c8deeSWill Andrews# default force serial console 137*6b8c8deeSWill AndrewsNANO_BOOT2CFG="-h" 138*6b8c8deeSWill Andrews 139*6b8c8deeSWill Andrews# Backing type of md(4) device 140*6b8c8deeSWill Andrews# Can be "file" or "swap" 141*6b8c8deeSWill AndrewsNANO_MD_BACKING="file" 142*6b8c8deeSWill Andrews 143*6b8c8deeSWill Andrews# for swap type md(4) backing, write out the mbr only 144*6b8c8deeSWill AndrewsNANO_IMAGE_MBRONLY=true 145*6b8c8deeSWill Andrews 146*6b8c8deeSWill Andrews# Progress Print level 147*6b8c8deeSWill AndrewsPPLEVEL=3 148*6b8c8deeSWill Andrews 149*6b8c8deeSWill Andrews# Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label 150*6b8c8deeSWill Andrews# in preference to /dev/${NANO_DRIVE} 151*6b8c8deeSWill Andrews# Root partition will be ${NANO_LABEL}s{1,2} 152*6b8c8deeSWill Andrews# /cfg partition will be ${NANO_LABEL}s3 153*6b8c8deeSWill Andrews# /data partition will be ${NANO_LABEL}s4 154*6b8c8deeSWill AndrewsNANO_LABEL="" 155*6b8c8deeSWill Andrews 156*6b8c8deeSWill Andrews####################################################################### 157*6b8c8deeSWill Andrews# Architecture to build. Corresponds to TARGET_ARCH in a buildworld. 158*6b8c8deeSWill Andrews# Unfortunately, there's no way to set TARGET at this time, and it 159*6b8c8deeSWill Andrews# conflates the two, so architectures where TARGET != TARGET_ARCH do 160*6b8c8deeSWill Andrews# not work. This defaults to the arch of the current machine. 161*6b8c8deeSWill Andrews 162*6b8c8deeSWill AndrewsNANO_ARCH=`uname -p` 163*6b8c8deeSWill Andrews 164*6b8c8deeSWill Andrews# Directory to populate /cfg from 165*6b8c8deeSWill AndrewsNANO_CFGDIR="" 166*6b8c8deeSWill Andrews 167*6b8c8deeSWill Andrews# Directory to populate /data from 168*6b8c8deeSWill AndrewsNANO_DATADIR="" 169*6b8c8deeSWill Andrews 170*6b8c8deeSWill Andrews# src.conf to use when building the image. Defaults to /dev/null for the sake 171*6b8c8deeSWill Andrews# of determinism. 172*6b8c8deeSWill AndrewsSRCCONF=${SRCCONF:=/dev/null} 173*6b8c8deeSWill Andrews 174*6b8c8deeSWill Andrews####################################################################### 175*6b8c8deeSWill Andrews# 176*6b8c8deeSWill Andrews# The functions which do the real work. 177*6b8c8deeSWill Andrews# Can be overridden from the config file(s) 178*6b8c8deeSWill Andrews# 179*6b8c8deeSWill Andrews####################################################################### 180*6b8c8deeSWill Andrews 181*6b8c8deeSWill Andrews# rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build 182*6b8c8deeSWill Andrews# hosts for now. 183*6b8c8deeSWill Andrewsnano_rm ( ) { 184*6b8c8deeSWill Andrews case $(uname -r) in 185*6b8c8deeSWill Andrews 7*|8*|9*) rm $* ;; 186*6b8c8deeSWill Andrews *) rm -x $* ;; 187*6b8c8deeSWill Andrews esac 188*6b8c8deeSWill Andrews} 189*6b8c8deeSWill Andrews 190*6b8c8deeSWill Andrews# run in the world chroot, errors fatal 191*6b8c8deeSWill AndrewsCR() 192*6b8c8deeSWill Andrews{ 193*6b8c8deeSWill Andrews chroot ${NANO_WORLDDIR} /bin/sh -exc "$*" 194*6b8c8deeSWill Andrews} 195*6b8c8deeSWill Andrews 196*6b8c8deeSWill Andrews# run in the world chroot, errors not fatal 197*6b8c8deeSWill AndrewsCR0() 198*6b8c8deeSWill Andrews{ 199*6b8c8deeSWill Andrews chroot ${NANO_WORLDDIR} /bin/sh -c "$*" || true 200*6b8c8deeSWill Andrews} 201*6b8c8deeSWill Andrews 202*6b8c8deeSWill Andrewsnano_cleanup ( ) ( 203*6b8c8deeSWill Andrews if [ $? -ne 0 ]; then 204*6b8c8deeSWill Andrews echo "Error encountered. Check for errors in last log file." 1>&2 205*6b8c8deeSWill Andrews fi 206*6b8c8deeSWill Andrews exit $? 207*6b8c8deeSWill Andrews) 208*6b8c8deeSWill Andrews 209*6b8c8deeSWill Andrewsclean_build ( ) ( 210*6b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" 211*6b8c8deeSWill Andrews 212*6b8c8deeSWill Andrews if ! nano_rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then 213*6b8c8deeSWill Andrews chflags -R noschg ${MAKEOBJDIRPREFIX}/ 214*6b8c8deeSWill Andrews nano_rm -r ${MAKEOBJDIRPREFIX}/ 215*6b8c8deeSWill Andrews fi 216*6b8c8deeSWill Andrews) 217*6b8c8deeSWill Andrews 218*6b8c8deeSWill Andrewsmake_conf_build ( ) ( 219*6b8c8deeSWill Andrews pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)" 220*6b8c8deeSWill Andrews 221*6b8c8deeSWill Andrews mkdir -p ${MAKEOBJDIRPREFIX} 222*6b8c8deeSWill Andrews printenv > ${MAKEOBJDIRPREFIX}/_.env 223*6b8c8deeSWill Andrews 224*6b8c8deeSWill Andrews echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD} 225*6b8c8deeSWill Andrews echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD} 226*6b8c8deeSWill Andrews) 227*6b8c8deeSWill Andrews 228*6b8c8deeSWill Andrewsbuild_world ( ) ( 229*6b8c8deeSWill Andrews pprint 2 "run buildworld" 230*6b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw" 231*6b8c8deeSWill Andrews 232*6b8c8deeSWill Andrews cd ${NANO_SRC} 233*6b8c8deeSWill Andrews env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \ 234*6b8c8deeSWill Andrews SRCCONF=${SRCCONF} \ 235*6b8c8deeSWill Andrews __MAKE_CONF=${NANO_MAKE_CONF_BUILD} buildworld \ 236*6b8c8deeSWill Andrews > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 237*6b8c8deeSWill Andrews) 238*6b8c8deeSWill Andrews 239*6b8c8deeSWill Andrewsbuild_kernel ( ) ( 240*6b8c8deeSWill Andrews local extra 241*6b8c8deeSWill Andrews 242*6b8c8deeSWill Andrews pprint 2 "build kernel ($NANO_KERNEL)" 243*6b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk" 244*6b8c8deeSWill Andrews 245*6b8c8deeSWill Andrews ( 246*6b8c8deeSWill Andrews if [ -f ${NANO_KERNEL} ] ; then 247*6b8c8deeSWill Andrews kernconfdir_arg="KERNCONFDIR='$(realpath $(dirname ${NANO_KERNEL}))'" 248*6b8c8deeSWill Andrews kernconf=$(basename ${NANO_KERNEL}) 249*6b8c8deeSWill Andrews else 250*6b8c8deeSWill Andrews kernconf=${NANO_KERNEL} 251*6b8c8deeSWill Andrews fi 252*6b8c8deeSWill Andrews 253*6b8c8deeSWill Andrews cd ${NANO_SRC}; 254*6b8c8deeSWill Andrews # unset these just in case to avoid compiler complaints 255*6b8c8deeSWill Andrews # when cross-building 256*6b8c8deeSWill Andrews unset TARGET_CPUTYPE 257*6b8c8deeSWill Andrews # Note: We intentionally build all modules, not only the ones in 258*6b8c8deeSWill Andrews # NANO_MODULES so the built world can be reused by multiple images. 259*6b8c8deeSWill Andrews eval "TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \ 260*6b8c8deeSWill Andrews SRCCONF='${SRCCONF}' \ 261*6b8c8deeSWill Andrews __MAKE_CONF='${NANO_MAKE_CONF_BUILD}' \ 262*6b8c8deeSWill Andrews ${kernconfdir_arg} KERNCONF=${kernconf}" 263*6b8c8deeSWill Andrews ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 264*6b8c8deeSWill Andrews) 265*6b8c8deeSWill Andrews 266*6b8c8deeSWill Andrewsclean_world ( ) ( 267*6b8c8deeSWill Andrews if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then 268*6b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${NANO_OBJ})" 269*6b8c8deeSWill Andrews if ! nano_rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then 270*6b8c8deeSWill Andrews chflags -R noschg ${NANO_OBJ} 271*6b8c8deeSWill Andrews nano_rm -r ${NANO_OBJ}/ 272*6b8c8deeSWill Andrews fi 273*6b8c8deeSWill Andrews mkdir -p ${NANO_OBJ} ${NANO_WORLDDIR} 274*6b8c8deeSWill Andrews printenv > ${NANO_OBJ}/_.env 275*6b8c8deeSWill Andrews else 276*6b8c8deeSWill Andrews pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" 277*6b8c8deeSWill Andrews if ! nano_rm -rf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then 278*6b8c8deeSWill Andrews chflags -R noschg ${NANO_WORLDDIR} 279*6b8c8deeSWill Andrews nano_rm -rf ${NANO_WORLDDIR}/ 280*6b8c8deeSWill Andrews fi 281*6b8c8deeSWill Andrews mkdir -p ${NANO_WORLDDIR} 282*6b8c8deeSWill Andrews fi 283*6b8c8deeSWill Andrews) 284*6b8c8deeSWill Andrews 285*6b8c8deeSWill Andrewsmake_conf_install ( ) ( 286*6b8c8deeSWill Andrews pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)" 287*6b8c8deeSWill Andrews 288*6b8c8deeSWill Andrews echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL} 289*6b8c8deeSWill Andrews echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL} 290*6b8c8deeSWill Andrews) 291*6b8c8deeSWill Andrews 292*6b8c8deeSWill Andrewsinstall_world ( ) ( 293*6b8c8deeSWill Andrews pprint 2 "installworld" 294*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.iw" 295*6b8c8deeSWill Andrews 296*6b8c8deeSWill Andrews cd ${NANO_SRC} 297*6b8c8deeSWill Andrews env TARGET_ARCH=${NANO_ARCH} \ 298*6b8c8deeSWill Andrews ${NANO_MAKE} SRCCONF=${SRCCONF} \ 299*6b8c8deeSWill Andrews __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \ 300*6b8c8deeSWill Andrews DESTDIR=${NANO_WORLDDIR} \ 301*6b8c8deeSWill Andrews > ${NANO_OBJ}/_.iw 2>&1 302*6b8c8deeSWill Andrews chflags -R noschg ${NANO_WORLDDIR} 303*6b8c8deeSWill Andrews) 304*6b8c8deeSWill Andrews 305*6b8c8deeSWill Andrewsinstall_etc ( ) ( 306*6b8c8deeSWill Andrews 307*6b8c8deeSWill Andrews pprint 2 "install /etc" 308*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.etc" 309*6b8c8deeSWill Andrews 310*6b8c8deeSWill Andrews cd ${NANO_SRC} 311*6b8c8deeSWill Andrews env TARGET_ARCH=${NANO_ARCH} \ 312*6b8c8deeSWill Andrews ${NANO_MAKE} SRCCONF=${SRCCONF} \ 313*6b8c8deeSWill Andrews __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \ 314*6b8c8deeSWill Andrews DESTDIR=${NANO_WORLDDIR} \ 315*6b8c8deeSWill Andrews > ${NANO_OBJ}/_.etc 2>&1 316*6b8c8deeSWill Andrews # make.conf doesn't get created by default, but some ports need it 317*6b8c8deeSWill Andrews # so they can spam it. 318*6b8c8deeSWill Andrews cp /dev/null ${NANO_WORLDDIR}/etc/make.conf 319*6b8c8deeSWill Andrews) 320*6b8c8deeSWill Andrews 321*6b8c8deeSWill Andrewsinstall_kernel ( ) ( 322*6b8c8deeSWill Andrews local extra 323*6b8c8deeSWill Andrews 324*6b8c8deeSWill Andrews pprint 2 "install kernel ($NANO_KERNEL)" 325*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.ik" 326*6b8c8deeSWill Andrews 327*6b8c8deeSWill Andrews ( 328*6b8c8deeSWill Andrews if [ -f ${NANO_KERNEL} ] ; then 329*6b8c8deeSWill Andrews kernconfdir_arg="KERNCONFDIR='$(realpath $(dirname ${NANO_KERNEL}))'" 330*6b8c8deeSWill Andrews kernconf=$(basename ${NANO_KERNEL}) 331*6b8c8deeSWill Andrews else 332*6b8c8deeSWill Andrews kernconf=${NANO_KERNEL} 333*6b8c8deeSWill Andrews fi 334*6b8c8deeSWill Andrews 335*6b8c8deeSWill Andrews # Install all built modules if NANO_MODULES=default, 336*6b8c8deeSWill Andrews # else install only listed modules (none if NANO_MODULES is empty). 337*6b8c8deeSWill Andrews if [ "${NANO_MODULES}" != "default" ]; then 338*6b8c8deeSWill Andrews modules_override_arg="MODULES_OVERRIDE='${NANO_MODULES}'" 339*6b8c8deeSWill Andrews fi 340*6b8c8deeSWill Andrews 341*6b8c8deeSWill Andrews cd ${NANO_SRC} 342*6b8c8deeSWill Andrews eval "TARGET_ARCH=${NANO_ARCH} ${NANO_MAKE} installkernel \ 343*6b8c8deeSWill Andrews DESTDIR='${NANO_WORLDDIR}' \ 344*6b8c8deeSWill Andrews SRCCONF='${SRCCONF}' \ 345*6b8c8deeSWill Andrews __MAKE_CONF='${NANO_MAKE_CONF_INSTALL}' \ 346*6b8c8deeSWill Andrews ${kernconfdir_arg} KERNCONF=${kernconf} \ 347*6b8c8deeSWill Andrews ${modules_override_arg}" 348*6b8c8deeSWill Andrews ) > ${NANO_OBJ}/_.ik 2>&1 349*6b8c8deeSWill Andrews) 350*6b8c8deeSWill Andrews 351*6b8c8deeSWill Andrewsnative_xtools ( ) ( 352*6b8c8deeSWill Andrews print 2 "Installing the optimized native build tools for cross env" 353*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.native_xtools" 354*6b8c8deeSWill Andrews 355*6b8c8deeSWill Andrews cd ${NANO_SRC} 356*6b8c8deeSWill Andrews env TARGET_ARCH=${NANO_ARCH} \ 357*6b8c8deeSWill Andrews ${NANO_MAKE} SRCCONF=${SRCCONF} \ 358*6b8c8deeSWill Andrews __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} native-xtools \ 359*6b8c8deeSWill Andrews DESTDIR=${NANO_WORLDDIR} \ 360*6b8c8deeSWill Andrews > ${NANO_OBJ}/_.native_xtools 2>&1 361*6b8c8deeSWill Andrews) 362*6b8c8deeSWill Andrews 363*6b8c8deeSWill Andrewsrun_customize() ( 364*6b8c8deeSWill Andrews 365*6b8c8deeSWill Andrews pprint 2 "run customize scripts" 366*6b8c8deeSWill Andrews for c in $NANO_CUSTOMIZE 367*6b8c8deeSWill Andrews do 368*6b8c8deeSWill Andrews pprint 2 "customize \"$c\"" 369*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.cust.$c" 370*6b8c8deeSWill Andrews pprint 4 "`type $c`" 371*6b8c8deeSWill Andrews ( set -x ; $c ) > ${NANO_OBJ}/_.cust.$c 2>&1 372*6b8c8deeSWill Andrews done 373*6b8c8deeSWill Andrews) 374*6b8c8deeSWill Andrews 375*6b8c8deeSWill Andrewsrun_late_customize() ( 376*6b8c8deeSWill Andrews 377*6b8c8deeSWill Andrews pprint 2 "run late customize scripts" 378*6b8c8deeSWill Andrews for c in $NANO_LATE_CUSTOMIZE 379*6b8c8deeSWill Andrews do 380*6b8c8deeSWill Andrews pprint 2 "late customize \"$c\"" 381*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c" 382*6b8c8deeSWill Andrews pprint 4 "`type $c`" 383*6b8c8deeSWill Andrews ( set -x ; $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1 384*6b8c8deeSWill Andrews done 385*6b8c8deeSWill Andrews) 386*6b8c8deeSWill Andrews 387*6b8c8deeSWill Andrewssetup_nanobsd ( ) ( 388*6b8c8deeSWill Andrews pprint 2 "configure nanobsd setup" 389*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.dl" 390*6b8c8deeSWill Andrews 391*6b8c8deeSWill Andrews ( 392*6b8c8deeSWill Andrews cd ${NANO_WORLDDIR} 393*6b8c8deeSWill Andrews 394*6b8c8deeSWill Andrews # Move /usr/local/etc to /etc/local so that the /cfg stuff 395*6b8c8deeSWill Andrews # can stomp on it. Otherwise packages like ipsec-tools which 396*6b8c8deeSWill Andrews # have hardcoded paths under ${prefix}/etc are not tweakable. 397*6b8c8deeSWill Andrews if [ -d usr/local/etc ] ; then 398*6b8c8deeSWill Andrews ( 399*6b8c8deeSWill Andrews mkdir -p etc/local 400*6b8c8deeSWill Andrews cd usr/local/etc 401*6b8c8deeSWill Andrews find . -print | cpio -dumpl ../../../etc/local 402*6b8c8deeSWill Andrews cd .. 403*6b8c8deeSWill Andrews nano_rm -rf etc 404*6b8c8deeSWill Andrews ln -s ../../etc/local etc 405*6b8c8deeSWill Andrews ) 406*6b8c8deeSWill Andrews fi 407*6b8c8deeSWill Andrews 408*6b8c8deeSWill Andrews for d in var etc 409*6b8c8deeSWill Andrews do 410*6b8c8deeSWill Andrews # link /$d under /conf 411*6b8c8deeSWill Andrews # we use hard links so we have them both places. 412*6b8c8deeSWill Andrews # the files in /$d will be hidden by the mount. 413*6b8c8deeSWill Andrews # XXX: configure /$d ramdisk size 414*6b8c8deeSWill Andrews mkdir -p conf/base/$d conf/default/$d 415*6b8c8deeSWill Andrews find $d -print | cpio -dumpl conf/base/ 416*6b8c8deeSWill Andrews done 417*6b8c8deeSWill Andrews 418*6b8c8deeSWill Andrews echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size 419*6b8c8deeSWill Andrews echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size 420*6b8c8deeSWill Andrews 421*6b8c8deeSWill Andrews # pick up config files from the special partition 422*6b8c8deeSWill Andrews echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount 423*6b8c8deeSWill Andrews 424*6b8c8deeSWill Andrews # Put /tmp on the /var ramdisk (could be symlink already) 425*6b8c8deeSWill Andrews nano_rm -rf tmp 426*6b8c8deeSWill Andrews ln -s var/tmp tmp 427*6b8c8deeSWill Andrews 428*6b8c8deeSWill Andrews ) > ${NANO_OBJ}/_.dl 2>&1 429*6b8c8deeSWill Andrews) 430*6b8c8deeSWill Andrews 431*6b8c8deeSWill Andrewssetup_nanobsd_etc ( ) ( 432*6b8c8deeSWill Andrews pprint 2 "configure nanobsd /etc" 433*6b8c8deeSWill Andrews 434*6b8c8deeSWill Andrews ( 435*6b8c8deeSWill Andrews cd ${NANO_WORLDDIR} 436*6b8c8deeSWill Andrews 437*6b8c8deeSWill Andrews # create diskless marker file 438*6b8c8deeSWill Andrews touch etc/diskless 439*6b8c8deeSWill Andrews 440*6b8c8deeSWill Andrews # Make root filesystem R/O by default 441*6b8c8deeSWill Andrews echo "root_rw_mount=NO" >> etc/defaults/rc.conf 442*6b8c8deeSWill Andrews 443*6b8c8deeSWill Andrews # save config file for scripts 444*6b8c8deeSWill Andrews echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf 445*6b8c8deeSWill Andrews 446*6b8c8deeSWill Andrews echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab 447*6b8c8deeSWill Andrews echo "/dev/${NANO_DRIVE}s3 /cfg ufs rw,noauto 2 2" >> etc/fstab 448*6b8c8deeSWill Andrews mkdir -p cfg 449*6b8c8deeSWill Andrews ) 450*6b8c8deeSWill Andrews) 451*6b8c8deeSWill Andrews 452*6b8c8deeSWill Andrewsprune_usr() ( 453*6b8c8deeSWill Andrews 454*6b8c8deeSWill Andrews # Remove all empty directories in /usr 455*6b8c8deeSWill Andrews find ${NANO_WORLDDIR}/usr -type d -depth -print | 456*6b8c8deeSWill Andrews while read d 457*6b8c8deeSWill Andrews do 458*6b8c8deeSWill Andrews rmdir $d > /dev/null 2>&1 || true 459*6b8c8deeSWill Andrews done 460*6b8c8deeSWill Andrews) 461*6b8c8deeSWill Andrews 462*6b8c8deeSWill Andrewsnewfs_part ( ) ( 463*6b8c8deeSWill Andrews local dev mnt lbl 464*6b8c8deeSWill Andrews dev=$1 465*6b8c8deeSWill Andrews mnt=$2 466*6b8c8deeSWill Andrews lbl=$3 467*6b8c8deeSWill Andrews echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev} 468*6b8c8deeSWill Andrews newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev} 469*6b8c8deeSWill Andrews mount -o async ${dev} ${mnt} 470*6b8c8deeSWill Andrews) 471*6b8c8deeSWill Andrews 472*6b8c8deeSWill Andrews# Convenient spot to work around any umount issues that your build environment 473*6b8c8deeSWill Andrews# hits by overriding this method. 474*6b8c8deeSWill Andrewsnano_umount () ( 475*6b8c8deeSWill Andrews umount ${1} 476*6b8c8deeSWill Andrews) 477*6b8c8deeSWill Andrews 478*6b8c8deeSWill Andrewspopulate_slice ( ) ( 479*6b8c8deeSWill Andrews local dev dir mnt lbl 480*6b8c8deeSWill Andrews dev=$1 481*6b8c8deeSWill Andrews dir=$2 482*6b8c8deeSWill Andrews mnt=$3 483*6b8c8deeSWill Andrews lbl=$4 484*6b8c8deeSWill Andrews echo "Creating ${dev} (mounting on ${mnt})" 485*6b8c8deeSWill Andrews newfs_part ${dev} ${mnt} ${lbl} 486*6b8c8deeSWill Andrews if [ -n "${dir}" -a -d "${dir}" ]; then 487*6b8c8deeSWill Andrews echo "Populating ${lbl} from ${dir}" 488*6b8c8deeSWill Andrews cd ${dir} 489*6b8c8deeSWill Andrews find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -dumpv ${mnt} 490*6b8c8deeSWill Andrews fi 491*6b8c8deeSWill Andrews df -i ${mnt} 492*6b8c8deeSWill Andrews nano_umount ${mnt} 493*6b8c8deeSWill Andrews) 494*6b8c8deeSWill Andrews 495*6b8c8deeSWill Andrewspopulate_cfg_slice ( ) ( 496*6b8c8deeSWill Andrews populate_slice "$1" "$2" "$3" "$4" 497*6b8c8deeSWill Andrews) 498*6b8c8deeSWill Andrews 499*6b8c8deeSWill Andrewspopulate_data_slice ( ) ( 500*6b8c8deeSWill Andrews populate_slice "$1" "$2" "$3" "$4" 501*6b8c8deeSWill Andrews) 502*6b8c8deeSWill Andrews 503*6b8c8deeSWill Andrewscreate_diskimage ( ) ( 504*6b8c8deeSWill Andrews pprint 2 "build diskimage" 505*6b8c8deeSWill Andrews pprint 3 "log: ${NANO_OBJ}/_.di" 506*6b8c8deeSWill Andrews 507*6b8c8deeSWill Andrews ( 508*6b8c8deeSWill Andrews echo $NANO_MEDIASIZE $NANO_IMAGES \ 509*6b8c8deeSWill Andrews $NANO_SECTS $NANO_HEADS \ 510*6b8c8deeSWill Andrews $NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE | 511*6b8c8deeSWill Andrews awk ' 512*6b8c8deeSWill Andrews { 513*6b8c8deeSWill Andrews printf "# %s\n", $0 514*6b8c8deeSWill Andrews 515*6b8c8deeSWill Andrews # size of cylinder in sectors 516*6b8c8deeSWill Andrews cs = $3 * $4 517*6b8c8deeSWill Andrews 518*6b8c8deeSWill Andrews # number of full cylinders on media 519*6b8c8deeSWill Andrews cyl = int ($1 / cs) 520*6b8c8deeSWill Andrews 521*6b8c8deeSWill Andrews # output fdisk geometry spec, truncate cyls to 1023 522*6b8c8deeSWill Andrews if (cyl <= 1023) 523*6b8c8deeSWill Andrews print "g c" cyl " h" $4 " s" $3 524*6b8c8deeSWill Andrews else 525*6b8c8deeSWill Andrews print "g c" 1023 " h" $4 " s" $3 526*6b8c8deeSWill Andrews 527*6b8c8deeSWill Andrews if ($7 > 0) { 528*6b8c8deeSWill Andrews # size of data partition in full cylinders 529*6b8c8deeSWill Andrews dsl = int (($7 + cs - 1) / cs) 530*6b8c8deeSWill Andrews } else { 531*6b8c8deeSWill Andrews dsl = 0; 532*6b8c8deeSWill Andrews } 533*6b8c8deeSWill Andrews 534*6b8c8deeSWill Andrews # size of config partition in full cylinders 535*6b8c8deeSWill Andrews csl = int (($6 + cs - 1) / cs) 536*6b8c8deeSWill Andrews 537*6b8c8deeSWill Andrews if ($5 == 0) { 538*6b8c8deeSWill Andrews # size of image partition(s) in full cylinders 539*6b8c8deeSWill Andrews isl = int ((cyl - dsl - csl) / $2) 540*6b8c8deeSWill Andrews } else { 541*6b8c8deeSWill Andrews isl = int (($5 + cs - 1) / cs) 542*6b8c8deeSWill Andrews } 543*6b8c8deeSWill Andrews 544*6b8c8deeSWill Andrews # First image partition start at second track 545*6b8c8deeSWill Andrews print "p 1 165 " $3, isl * cs - $3 546*6b8c8deeSWill Andrews c = isl * cs; 547*6b8c8deeSWill Andrews 548*6b8c8deeSWill Andrews # Second image partition (if any) also starts offset one 549*6b8c8deeSWill Andrews # track to keep them identical. 550*6b8c8deeSWill Andrews if ($2 > 1) { 551*6b8c8deeSWill Andrews print "p 2 165 " $3 + c, isl * cs - $3 552*6b8c8deeSWill Andrews c += isl * cs; 553*6b8c8deeSWill Andrews } 554*6b8c8deeSWill Andrews 555*6b8c8deeSWill Andrews # Config partition starts at cylinder boundary. 556*6b8c8deeSWill Andrews print "p 3 165 " c, csl * cs 557*6b8c8deeSWill Andrews c += csl * cs 558*6b8c8deeSWill Andrews 559*6b8c8deeSWill Andrews # Data partition (if any) starts at cylinder boundary. 560*6b8c8deeSWill Andrews if ($7 > 0) { 561*6b8c8deeSWill Andrews print "p 4 165 " c, dsl * cs 562*6b8c8deeSWill Andrews } else if ($7 < 0 && $1 > c) { 563*6b8c8deeSWill Andrews print "p 4 165 " c, $1 - c 564*6b8c8deeSWill Andrews } else if ($1 < c) { 565*6b8c8deeSWill Andrews print "Disk space overcommitted by", \ 566*6b8c8deeSWill Andrews c - $1, "sectors" > "/dev/stderr" 567*6b8c8deeSWill Andrews exit 2 568*6b8c8deeSWill Andrews } 569*6b8c8deeSWill Andrews 570*6b8c8deeSWill Andrews # Force slice 1 to be marked active. This is necessary 571*6b8c8deeSWill Andrews # for booting the image from a USB device to work. 572*6b8c8deeSWill Andrews print "a 1" 573*6b8c8deeSWill Andrews } 574*6b8c8deeSWill Andrews ' > ${NANO_OBJ}/_.fdisk 575*6b8c8deeSWill Andrews 576*6b8c8deeSWill Andrews IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} 577*6b8c8deeSWill Andrews MNT=${NANO_OBJ}/_.mnt 578*6b8c8deeSWill Andrews mkdir -p ${MNT} 579*6b8c8deeSWill Andrews 580*6b8c8deeSWill Andrews if [ "${NANO_MD_BACKING}" = "swap" ] ; then 581*6b8c8deeSWill Andrews MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \ 582*6b8c8deeSWill Andrews -y ${NANO_HEADS}` 583*6b8c8deeSWill Andrews else 584*6b8c8deeSWill Andrews echo "Creating md backing file..." 585*6b8c8deeSWill Andrews nano_rm -f ${IMG} 586*6b8c8deeSWill Andrews dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0 587*6b8c8deeSWill Andrews MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \ 588*6b8c8deeSWill Andrews -y ${NANO_HEADS}` 589*6b8c8deeSWill Andrews fi 590*6b8c8deeSWill Andrews 591*6b8c8deeSWill Andrews trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT 592*6b8c8deeSWill Andrews 593*6b8c8deeSWill Andrews fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD} 594*6b8c8deeSWill Andrews fdisk ${MD} 595*6b8c8deeSWill Andrews # XXX: params 596*6b8c8deeSWill Andrews # XXX: pick up cached boot* files, they may not be in image anymore. 597*6b8c8deeSWill Andrews if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then 598*6b8c8deeSWill Andrews boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD} 599*6b8c8deeSWill Andrews fi 600*6b8c8deeSWill Andrews if [ -f ${NANO_WORLDDIR}/boot/boot ]; then 601*6b8c8deeSWill Andrews bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1 602*6b8c8deeSWill Andrews else 603*6b8c8deeSWill Andrews bsdlabel -w ${MD}s1 604*6b8c8deeSWill Andrews fi 605*6b8c8deeSWill Andrews bsdlabel ${MD}s1 606*6b8c8deeSWill Andrews 607*6b8c8deeSWill Andrews # Create first image 608*6b8c8deeSWill Andrews populate_slice /dev/${MD}s1a ${NANO_WORLDDIR} ${MNT} "s1a" 609*6b8c8deeSWill Andrews mount /dev/${MD}s1a ${MNT} 610*6b8c8deeSWill Andrews echo "Generating mtree..." 611*6b8c8deeSWill Andrews ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree 612*6b8c8deeSWill Andrews ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du 613*6b8c8deeSWill Andrews nano_umount ${MNT} 614*6b8c8deeSWill Andrews 615*6b8c8deeSWill Andrews if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then 616*6b8c8deeSWill Andrews # Duplicate to second image (if present) 617*6b8c8deeSWill Andrews echo "Duplicating to second image..." 618*6b8c8deeSWill Andrews dd conv=sparse if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k 619*6b8c8deeSWill Andrews mount /dev/${MD}s2a ${MNT} 620*6b8c8deeSWill Andrews for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab 621*6b8c8deeSWill Andrews do 622*6b8c8deeSWill Andrews sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f 623*6b8c8deeSWill Andrews done 624*6b8c8deeSWill Andrews nano_umount ${MNT} 625*6b8c8deeSWill Andrews # Override the label from the first partition so we 626*6b8c8deeSWill Andrews # don't confuse glabel with duplicates. 627*6b8c8deeSWill Andrews if [ ! -z ${NANO_LABEL} ]; then 628*6b8c8deeSWill Andrews tunefs -L ${NANO_LABEL}"s2a" /dev/${MD}s2a 629*6b8c8deeSWill Andrews fi 630*6b8c8deeSWill Andrews fi 631*6b8c8deeSWill Andrews 632*6b8c8deeSWill Andrews # Create Config slice 633*6b8c8deeSWill Andrews populate_cfg_slice /dev/${MD}s3 "${NANO_CFGDIR}" ${MNT} "s3" 634*6b8c8deeSWill Andrews 635*6b8c8deeSWill Andrews # Create Data slice, if any. 636*6b8c8deeSWill Andrews if [ $NANO_DATASIZE -ne 0 ] ; then 637*6b8c8deeSWill Andrews populate_data_slice /dev/${MD}s4 "${NANO_DATADIR}" ${MNT} "s4" 638*6b8c8deeSWill Andrews fi 639*6b8c8deeSWill Andrews 640*6b8c8deeSWill Andrews if [ "${NANO_MD_BACKING}" = "swap" ] ; then 641*6b8c8deeSWill Andrews if [ ${NANO_IMAGE_MBRONLY} ]; then 642*6b8c8deeSWill Andrews echo "Writing out _.disk.mbr..." 643*6b8c8deeSWill Andrews dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1 644*6b8c8deeSWill Andrews else 645*6b8c8deeSWill Andrews echo "Writing out ${NANO_IMGNAME}..." 646*6b8c8deeSWill Andrews dd if=/dev/${MD} of=${IMG} bs=64k 647*6b8c8deeSWill Andrews fi 648*6b8c8deeSWill Andrews 649*6b8c8deeSWill Andrews echo "Writing out ${NANO_IMGNAME}..." 650*6b8c8deeSWill Andrews dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k 651*6b8c8deeSWill Andrews fi 652*6b8c8deeSWill Andrews 653*6b8c8deeSWill Andrews if ${do_copyout_partition} ; then 654*6b8c8deeSWill Andrews echo "Writing out _.disk.image..." 655*6b8c8deeSWill Andrews dd conv=sparse if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k 656*6b8c8deeSWill Andrews fi 657*6b8c8deeSWill Andrews mdconfig -d -u $MD 658*6b8c8deeSWill Andrews 659*6b8c8deeSWill Andrews trap - 1 2 15 660*6b8c8deeSWill Andrews trap nano_cleanup EXIT 661*6b8c8deeSWill Andrews 662*6b8c8deeSWill Andrews ) > ${NANO_OBJ}/_.di 2>&1 663*6b8c8deeSWill Andrews) 664*6b8c8deeSWill Andrews 665*6b8c8deeSWill Andrewslast_orders () ( 666*6b8c8deeSWill Andrews # Redefine this function with any last orders you may have 667*6b8c8deeSWill Andrews # after the build completed, for instance to copy the finished 668*6b8c8deeSWill Andrews # image to a more convenient place: 669*6b8c8deeSWill Andrews # cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk 670*6b8c8deeSWill Andrews true 671*6b8c8deeSWill Andrews) 672*6b8c8deeSWill Andrews 673*6b8c8deeSWill Andrews####################################################################### 674*6b8c8deeSWill Andrews# 675*6b8c8deeSWill Andrews# Optional convenience functions. 676*6b8c8deeSWill Andrews# 677*6b8c8deeSWill Andrews####################################################################### 678*6b8c8deeSWill Andrews 679*6b8c8deeSWill Andrews####################################################################### 680*6b8c8deeSWill Andrews# Common Flash device geometries 681*6b8c8deeSWill Andrews# 682*6b8c8deeSWill Andrews 683*6b8c8deeSWill AndrewsFlashDevice () { 684*6b8c8deeSWill Andrews if [ -d ${NANO_TOOLS} ] ; then 685*6b8c8deeSWill Andrews . ${NANO_TOOLS}/FlashDevice.sub 686*6b8c8deeSWill Andrews else 687*6b8c8deeSWill Andrews . ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub 688*6b8c8deeSWill Andrews fi 689*6b8c8deeSWill Andrews sub_FlashDevice $1 $2 690*6b8c8deeSWill Andrews} 691*6b8c8deeSWill Andrews 692*6b8c8deeSWill Andrews####################################################################### 693*6b8c8deeSWill Andrews# USB device geometries 694*6b8c8deeSWill Andrews# 695*6b8c8deeSWill Andrews# Usage: 696*6b8c8deeSWill Andrews# UsbDevice Generic 1000 # a generic flash key sold as having 1GB 697*6b8c8deeSWill Andrews# 698*6b8c8deeSWill Andrews# This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you. 699*6b8c8deeSWill Andrews# 700*6b8c8deeSWill Andrews# Note that the capacity of a flash key is usually advertised in MB or 701*6b8c8deeSWill Andrews# GB, *not* MiB/GiB. As such, the precise number of cylinders available 702*6b8c8deeSWill Andrews# for C/H/S geometry may vary depending on the actual flash geometry. 703*6b8c8deeSWill Andrews# 704*6b8c8deeSWill Andrews# The following generic device layouts are understood: 705*6b8c8deeSWill Andrews# generic An alias for generic-hdd. 706*6b8c8deeSWill Andrews# generic-hdd 255H 63S/T xxxxC with no MBR restrictions. 707*6b8c8deeSWill Andrews# generic-fdd 64H 32S/T xxxxC with no MBR restrictions. 708*6b8c8deeSWill Andrews# 709*6b8c8deeSWill Andrews# The generic-hdd device is preferred for flash devices larger than 1GB. 710*6b8c8deeSWill Andrews# 711*6b8c8deeSWill Andrews 712*6b8c8deeSWill AndrewsUsbDevice () { 713*6b8c8deeSWill Andrews a1=`echo $1 | tr '[:upper:]' '[:lower:]'` 714*6b8c8deeSWill Andrews case $a1 in 715*6b8c8deeSWill Andrews generic-fdd) 716*6b8c8deeSWill Andrews NANO_HEADS=64 717*6b8c8deeSWill Andrews NANO_SECTS=32 718*6b8c8deeSWill Andrews NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 719*6b8c8deeSWill Andrews ;; 720*6b8c8deeSWill Andrews generic|generic-hdd) 721*6b8c8deeSWill Andrews NANO_HEADS=255 722*6b8c8deeSWill Andrews NANO_SECTS=63 723*6b8c8deeSWill Andrews NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 724*6b8c8deeSWill Andrews ;; 725*6b8c8deeSWill Andrews *) 726*6b8c8deeSWill Andrews echo "Unknown USB flash device" 727*6b8c8deeSWill Andrews exit 2 728*6b8c8deeSWill Andrews ;; 729*6b8c8deeSWill Andrews esac 730*6b8c8deeSWill Andrews} 731*6b8c8deeSWill Andrews 732*6b8c8deeSWill Andrews####################################################################### 733*6b8c8deeSWill Andrews# Setup serial console 734*6b8c8deeSWill Andrews 735*6b8c8deeSWill Andrewscust_comconsole () ( 736*6b8c8deeSWill Andrews # Enable getty on console 737*6b8c8deeSWill Andrews sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys 738*6b8c8deeSWill Andrews 739*6b8c8deeSWill Andrews # Disable getty on syscons devices 740*6b8c8deeSWill Andrews sed -i "" -e '/^ttyv[0-8]/s/ on/ off/' ${NANO_WORLDDIR}/etc/ttys 741*6b8c8deeSWill Andrews 742*6b8c8deeSWill Andrews # Tell loader to use serial console early. 743*6b8c8deeSWill Andrews echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config 744*6b8c8deeSWill Andrews) 745*6b8c8deeSWill Andrews 746*6b8c8deeSWill Andrews####################################################################### 747*6b8c8deeSWill Andrews# Allow root login via ssh 748*6b8c8deeSWill Andrews 749*6b8c8deeSWill Andrewscust_allow_ssh_root () ( 750*6b8c8deeSWill Andrews sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \ 751*6b8c8deeSWill Andrews ${NANO_WORLDDIR}/etc/ssh/sshd_config 752*6b8c8deeSWill Andrews) 753*6b8c8deeSWill Andrews 754*6b8c8deeSWill Andrews####################################################################### 755*6b8c8deeSWill Andrews# Install the stuff under ./Files 756*6b8c8deeSWill Andrews 757*6b8c8deeSWill Andrewscust_install_files () ( 758*6b8c8deeSWill Andrews cd ${NANO_TOOLS}/Files 759*6b8c8deeSWill Andrews find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -Ldumpv ${NANO_WORLDDIR} 760*6b8c8deeSWill Andrews) 761*6b8c8deeSWill Andrews 762*6b8c8deeSWill Andrews####################################################################### 763*6b8c8deeSWill Andrews# Install packages from ${NANO_PACKAGE_DIR} 764*6b8c8deeSWill Andrews 765*6b8c8deeSWill Andrewscust_pkg () ( 766*6b8c8deeSWill Andrews 767*6b8c8deeSWill Andrews # If the package directory doesn't exist, we're done. 768*6b8c8deeSWill Andrews if [ ! -d ${NANO_PACKAGE_DIR} ]; then 769*6b8c8deeSWill Andrews echo "DONE 0 packages" 770*6b8c8deeSWill Andrews return 0 771*6b8c8deeSWill Andrews fi 772*6b8c8deeSWill Andrews 773*6b8c8deeSWill Andrews # Copy packages into chroot 774*6b8c8deeSWill Andrews mkdir -p ${NANO_WORLDDIR}/Pkg ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg 775*6b8c8deeSWill Andrews ( 776*6b8c8deeSWill Andrews cd ${NANO_PACKAGE_DIR} 777*6b8c8deeSWill Andrews find ${NANO_PACKAGE_LIST} -print | 778*6b8c8deeSWill Andrews cpio -Ldumpv ${NANO_WORLDDIR}/Pkg 779*6b8c8deeSWill Andrews ) 780*6b8c8deeSWill Andrews 781*6b8c8deeSWill Andrews # Count & report how many we have to install 782*6b8c8deeSWill Andrews todo=`ls ${NANO_WORLDDIR}/Pkg | wc -l` 783*6b8c8deeSWill Andrews echo "=== TODO: $todo" 784*6b8c8deeSWill Andrews ls ${NANO_WORLDDIR}/Pkg 785*6b8c8deeSWill Andrews echo "===" 786*6b8c8deeSWill Andrews while true 787*6b8c8deeSWill Andrews do 788*6b8c8deeSWill Andrews # Record how many we have now 789*6b8c8deeSWill Andrews have=`ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg | wc -l` 790*6b8c8deeSWill Andrews 791*6b8c8deeSWill Andrews # Attempt to install more packages 792*6b8c8deeSWill Andrews # ...but no more than 200 at a time due to pkg_add's internal 793*6b8c8deeSWill Andrews # limitations. 794*6b8c8deeSWill Andrews CR0 'ls Pkg/*tbz | xargs -n 200 env PKG_DBDIR='${NANO_PKG_META_BASE}'/pkg pkg_add -v -F' 795*6b8c8deeSWill Andrews 796*6b8c8deeSWill Andrews # See what that got us 797*6b8c8deeSWill Andrews now=`ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg | wc -l` 798*6b8c8deeSWill Andrews echo "=== NOW $now" 799*6b8c8deeSWill Andrews ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg 800*6b8c8deeSWill Andrews echo "===" 801*6b8c8deeSWill Andrews 802*6b8c8deeSWill Andrews 803*6b8c8deeSWill Andrews if [ $now -eq $todo ] ; then 804*6b8c8deeSWill Andrews echo "DONE $now packages" 805*6b8c8deeSWill Andrews break 806*6b8c8deeSWill Andrews elif [ $now -eq $have ] ; then 807*6b8c8deeSWill Andrews echo "FAILED: Nothing happened on this pass" 808*6b8c8deeSWill Andrews exit 2 809*6b8c8deeSWill Andrews fi 810*6b8c8deeSWill Andrews done 811*6b8c8deeSWill Andrews nano_rm -rf ${NANO_WORLDDIR}/Pkg 812*6b8c8deeSWill Andrews) 813*6b8c8deeSWill Andrews 814*6b8c8deeSWill Andrewscust_pkgng () ( 815*6b8c8deeSWill Andrews 816*6b8c8deeSWill Andrews # If the package directory doesn't exist, we're done. 817*6b8c8deeSWill Andrews if [ ! -d ${NANO_PACKAGE_DIR} ]; then 818*6b8c8deeSWill Andrews echo "DONE 0 packages" 819*6b8c8deeSWill Andrews return 0 820*6b8c8deeSWill Andrews fi 821*6b8c8deeSWill Andrews 822*6b8c8deeSWill Andrews # Find a pkg-* package 823*6b8c8deeSWill Andrews for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do 824*6b8c8deeSWill Andrews _NANO_PKG_PACKAGE=`basename "$x"` 825*6b8c8deeSWill Andrews done 826*6b8c8deeSWill Andrews if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then 827*6b8c8deeSWill Andrews echo "FAILED: need a pkg/ package for bootstrapping" 828*6b8c8deeSWill Andrews exit 2 829*6b8c8deeSWill Andrews fi 830*6b8c8deeSWill Andrews 831*6b8c8deeSWill Andrews # Copy packages into chroot 832*6b8c8deeSWill Andrews mkdir -p ${NANO_WORLDDIR}/Pkg 833*6b8c8deeSWill Andrews ( 834*6b8c8deeSWill Andrews cd ${NANO_PACKAGE_DIR} 835*6b8c8deeSWill Andrews find ${NANO_PACKAGE_LIST} -print | 836*6b8c8deeSWill Andrews cpio -Ldumpv ${NANO_WORLDDIR}/Pkg 837*6b8c8deeSWill Andrews ) 838*6b8c8deeSWill Andrews 839*6b8c8deeSWill Andrews #Bootstrap pkg 840*6b8c8deeSWill Andrews CR env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /Pkg/${_NANO_PKG_PACKAGE} 841*6b8c8deeSWill Andrews CR pkg -N >/dev/null 2>&1 842*6b8c8deeSWill Andrews if [ "$?" -ne "0" ]; then 843*6b8c8deeSWill Andrews echo "FAILED: pkg bootstrapping faied" 844*6b8c8deeSWill Andrews exit 2 845*6b8c8deeSWill Andrews fi 846*6b8c8deeSWill Andrews nano_rm -f ${NANO_WORLDDIR}/Pkg/pkg-* 847*6b8c8deeSWill Andrews 848*6b8c8deeSWill Andrews # Count & report how many we have to install 849*6b8c8deeSWill Andrews todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l` 850*6b8c8deeSWill Andrews todo=$(expr $todo + 1) # add one for pkg since it is installed already 851*6b8c8deeSWill Andrews echo "=== TODO: $todo" 852*6b8c8deeSWill Andrews ls ${NANO_WORLDDIR}/Pkg 853*6b8c8deeSWill Andrews echo "===" 854*6b8c8deeSWill Andrews while true 855*6b8c8deeSWill Andrews do 856*6b8c8deeSWill Andrews # Record how many we have now 857*6b8c8deeSWill Andrews have=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l) 858*6b8c8deeSWill Andrews 859*6b8c8deeSWill Andrews # Attempt to install more packages 860*6b8c8deeSWill Andrews CR0 'ls 'Pkg/*txz' | xargs env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg add' 861*6b8c8deeSWill Andrews 862*6b8c8deeSWill Andrews # See what that got us 863*6b8c8deeSWill Andrews now=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l) 864*6b8c8deeSWill Andrews echo "=== NOW $now" 865*6b8c8deeSWill Andrews CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info 866*6b8c8deeSWill Andrews echo "===" 867*6b8c8deeSWill Andrews if [ $now -eq $todo ] ; then 868*6b8c8deeSWill Andrews echo "DONE $now packages" 869*6b8c8deeSWill Andrews break 870*6b8c8deeSWill Andrews elif [ $now -eq $have ] ; then 871*6b8c8deeSWill Andrews echo "FAILED: Nothing happened on this pass" 872*6b8c8deeSWill Andrews exit 2 873*6b8c8deeSWill Andrews fi 874*6b8c8deeSWill Andrews done 875*6b8c8deeSWill Andrews nano_rm -rf ${NANO_WORLDDIR}/Pkg 876*6b8c8deeSWill Andrews) 877*6b8c8deeSWill Andrews 878*6b8c8deeSWill Andrews####################################################################### 879*6b8c8deeSWill Andrews# Convenience function: 880*6b8c8deeSWill Andrews# Register all args as customize function. 881*6b8c8deeSWill Andrews 882*6b8c8deeSWill Andrewscustomize_cmd () { 883*6b8c8deeSWill Andrews NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*" 884*6b8c8deeSWill Andrews} 885*6b8c8deeSWill Andrews 886*6b8c8deeSWill Andrews####################################################################### 887*6b8c8deeSWill Andrews# Convenience function: 888*6b8c8deeSWill Andrews# Register all args as late customize function to run just before 889*6b8c8deeSWill Andrews# image creation. 890*6b8c8deeSWill Andrews 891*6b8c8deeSWill Andrewslate_customize_cmd () { 892*6b8c8deeSWill Andrews NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*" 893*6b8c8deeSWill Andrews} 894*6b8c8deeSWill Andrews 895*6b8c8deeSWill Andrews####################################################################### 896*6b8c8deeSWill Andrews# 897*6b8c8deeSWill Andrews# All set up to go... 898*6b8c8deeSWill Andrews# 899*6b8c8deeSWill Andrews####################################################################### 900*6b8c8deeSWill Andrews 901*6b8c8deeSWill Andrews# Progress Print 902*6b8c8deeSWill Andrews# Print $2 at level $1. 903*6b8c8deeSWill Andrewspprint() ( 904*6b8c8deeSWill Andrews if [ "$1" -le $PPLEVEL ]; then 905*6b8c8deeSWill Andrews runtime=$(( `date +%s` - $NANO_STARTTIME )) 906*6b8c8deeSWill Andrews printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3 907*6b8c8deeSWill Andrews fi 908*6b8c8deeSWill Andrews) 909*6b8c8deeSWill Andrews 910*6b8c8deeSWill Andrewsusage () { 911*6b8c8deeSWill Andrews ( 912*6b8c8deeSWill Andrews echo "Usage: $0 [-bfiKknqvw] [-c config_file]" 913*6b8c8deeSWill Andrews echo " -b suppress builds (both kernel and world)" 914*6b8c8deeSWill Andrews echo " -c specify config file" 915*6b8c8deeSWill Andrews echo " -f suppress code slice extraction" 916*6b8c8deeSWill Andrews echo " -i suppress disk image build" 917*6b8c8deeSWill Andrews echo " -K suppress installkernel" 918*6b8c8deeSWill Andrews echo " -k suppress buildkernel" 919*6b8c8deeSWill Andrews echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc" 920*6b8c8deeSWill Andrews echo " -q make output more quiet" 921*6b8c8deeSWill Andrews echo " -v make output more verbose" 922*6b8c8deeSWill Andrews echo " -w suppress buildworld" 923*6b8c8deeSWill Andrews ) 1>&2 924*6b8c8deeSWill Andrews exit 2 925*6b8c8deeSWill Andrews} 926*6b8c8deeSWill Andrews 927*6b8c8deeSWill Andrews####################################################################### 928*6b8c8deeSWill Andrews# Setup and Export Internal variables 929*6b8c8deeSWill Andrews# 930*6b8c8deeSWill Andrews 931*6b8c8deeSWill Andrewsexport_var() { 932*6b8c8deeSWill Andrews var=$1 933*6b8c8deeSWill Andrews # Lookup value of the variable. 934*6b8c8deeSWill Andrews eval val=\$$var 935*6b8c8deeSWill Andrews pprint 3 "Setting variable: $var=\"$val\"" 936*6b8c8deeSWill Andrews export $1 937*6b8c8deeSWill Andrews} 938*6b8c8deeSWill Andrews 939*6b8c8deeSWill Andrews# Call this function to set defaults _after_ parsing options. 940*6b8c8deeSWill Andrewsset_defaults_and_export() { 941*6b8c8deeSWill Andrews test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME} 942*6b8c8deeSWill Andrews test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ} 943*6b8c8deeSWill Andrews test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ} 944*6b8c8deeSWill Andrews NANO_WORLDDIR=${NANO_OBJ}/_.w 945*6b8c8deeSWill Andrews NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build 946*6b8c8deeSWill Andrews NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install 947*6b8c8deeSWill Andrews 948*6b8c8deeSWill Andrews # Override user's NANO_DRIVE if they specified a NANO_LABEL 949*6b8c8deeSWill Andrews [ ! -z "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" 950*6b8c8deeSWill Andrews 951*6b8c8deeSWill Andrews # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. 952*6b8c8deeSWill Andrews [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ 953*6b8c8deeSWill Andrews NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" 954*6b8c8deeSWill Andrews 955*6b8c8deeSWill Andrews NANO_STARTTIME=`date +%s` 956*6b8c8deeSWill Andrews pprint 3 "Exporting NanoBSD variables" 957*6b8c8deeSWill Andrews export_var MAKEOBJDIRPREFIX 958*6b8c8deeSWill Andrews export_var NANO_ARCH 959*6b8c8deeSWill Andrews export_var NANO_CODESIZE 960*6b8c8deeSWill Andrews export_var NANO_CONFSIZE 961*6b8c8deeSWill Andrews export_var NANO_CUSTOMIZE 962*6b8c8deeSWill Andrews export_var NANO_DATASIZE 963*6b8c8deeSWill Andrews export_var NANO_DRIVE 964*6b8c8deeSWill Andrews export_var NANO_HEADS 965*6b8c8deeSWill Andrews export_var NANO_IMAGES 966*6b8c8deeSWill Andrews export_var NANO_IMGNAME 967*6b8c8deeSWill Andrews export_var NANO_MAKE 968*6b8c8deeSWill Andrews export_var NANO_MAKE_CONF_BUILD 969*6b8c8deeSWill Andrews export_var NANO_MAKE_CONF_INSTALL 970*6b8c8deeSWill Andrews export_var NANO_MEDIASIZE 971*6b8c8deeSWill Andrews export_var NANO_NAME 972*6b8c8deeSWill Andrews export_var NANO_NEWFS 973*6b8c8deeSWill Andrews export_var NANO_OBJ 974*6b8c8deeSWill Andrews export_var NANO_PMAKE 975*6b8c8deeSWill Andrews export_var NANO_SECTS 976*6b8c8deeSWill Andrews export_var NANO_SRC 977*6b8c8deeSWill Andrews export_var NANO_TOOLS 978*6b8c8deeSWill Andrews export_var NANO_WORLDDIR 979*6b8c8deeSWill Andrews export_var NANO_BOOT0CFG 980*6b8c8deeSWill Andrews export_var NANO_BOOTLOADER 981*6b8c8deeSWill Andrews export_var NANO_LABEL 982*6b8c8deeSWill Andrews export_var NANO_MODULES 983*6b8c8deeSWill Andrews} 984