Index: UsbDevice.sub =================================================================== --- UsbDevice.sub (revision 0) +++ UsbDevice.sub (revision 0) @@ -0,0 +1,86 @@ +#!/bin/sh +# +# Copyright (c) 2008 Bruce M. Simpson. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +# Convenience function for USB devices. +# +# There is a hook over in nanobsd.sh which allows you to call into +# this function simply with a line like: +# +# UsbDevice Generic 1000 # a generic flash key sold as having 1GB +# +# This file will then set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you. +# +# Note that the capacity of a flash key is usually advertised in MB or +# GB, *not* MiB/GiB. As such, the precise number of cylinders available +# for C/H/S geometry may vary depending on the actual flash geometry. +# +# The following generic device layouts are understood: +# generic An alias for generic-hdd. +# generic-hdd 255H 63S/T xxxxC with no MBR restrictions. +# generic-fdd 64H 32S/T xxxxC with no MBR restrictions. +# generic-zip 64H 32S/T xxxxC, with a single active slice da0s4. +# +# The generic-hdd device is preferred for flash devices larger than 1GB. +# +# The generic-zip device is intended for use with platform BIOS which +# only supports booting USB media in the 'USB-ZIP' mode (e.g. certain +# versions of the Award BIOS). This mode has the restriction that there +# can only be a single primary active MBR partition in the 4th slot. +# TODO: Currently not implemented. +# +# TODO: Hardcode sector sizes/geometries for these cases, if someone +# is using real ZIP disks. +# A 100MB ZIP disk has 96 cylinders +# A 250MB ZIP disk has 239 cylinders. +# + +sub_UsbDevice () { + + a1=`echo $1 | tr '[:upper:]' '[:lower:]'` + case $a1 in + generic-fdd) + NANO_HEADS=64 + NANO_SECTS=32 + NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) + ;; + generic|generic-hdd) + NANO_HEADS=255 + NANO_SECTS=63 + NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) + ;; + generic-zip) + echo "USB-ZIP is not yet supported" + exit 2 + ;; + *) + echo "Unknown USB flash manufacturer" + exit 2 + ;; + esac +} + Index: CdromDevice.sub =================================================================== --- CdromDevice.sub (revision 0) +++ CdromDevice.sub (revision 0) @@ -0,0 +1,75 @@ +#!/bin/sh +# +# Copyright (c) 2008 Bruce M. Simpson. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +# Convenience function for CDROM and DVD devices. +# +# There is a hook over in nanobsd.sh which allows you to call into +# this function simply with a line like: +# +# CdromDevice CD [sizeMB] +# +# This file will then set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you. +# NANO_HEADS and NANO_SECTS generally have no meaning for UDF and ISO, +# however, so they are set to default values. +# NANO_MEDIASIZE is currently always expressed in terms of 512-byte sectors, +# CDROM devices have a 2048 byte sector size. +# One head, one spiral track. +# + +sub_CdromDevice () { + a1=`echo $1 | tr '[:upper:]' '[:lower:]'` + case $a1 in + cd) + if [ $# -eq 2 ]; then + NANO_MEDIASIZE=$(( $2 * 1024 * 1024 / 512 )) + else + # default 650MB ISO image + NANO_MEDIASIZE=1332000 + fi + NANO_HEADS=1 + NANO_SECTS=${NANO_MEDIASIZE} + NANO_CDROM=true + ;; + *) + echo "Unknown CDROM device type" + exit 2 + ;; + esac + + # Set NANO_DRIVE in case the user forgot to set it, + # or set it to something which is not a CDROM/DVD device. + NANO_DRIVE=${NANO_DRIVE:-"acd0"} + case $NANO_DRIVE in + acd*|cd*) + ;; + *) + echo "Forcing NANO_DRIVE to acd0". + NANO_DRIVE=acd0 + ;; + esac +} Index: nanobsd.sh =================================================================== --- nanobsd.sh (revision 183279) +++ nanobsd.sh (working copy) @@ -40,7 +40,7 @@ NANO_NAME=full # Source tree directory -NANO_SRC=/usr/src +NANO_SRC=${NANO_SRC:-"/usr/src"} # Where nanobsd additional files live under the source tree NANO_TOOLS=tools/tools/nanobsd @@ -60,6 +60,18 @@ # Parallel Make NANO_PMAKE="make -j 3" +# The default name for any image we create. +NANO_IMGNAME=${NANO_IMGNAME:-"_.disk.full"} + +# Are we making a CDROM? If so, many assumptions change. +NANO_CDROM=false + +# mkisofs (for CDROM image generation) +NANO_MKISOFS=${NANO_MKISOFS:="$(which mkisofs)"} + +# The default ISO volume ID. +NANO_VOLID=${NANO_VOLID:-"NanoBSD"} + # Options to put in make.conf during buildworld only CONF_BUILD=' ' @@ -82,8 +94,18 @@ NANO_NEWFS="-b 4096 -f 512 -i 8192 -O1 -U" # The drive name of the media at runtime -NANO_DRIVE=ad0 +NANO_DRIVE=${NANO_DRIVE:-"ad0"} +# The name of the configuration slice (must override if using cdrom) +NANO_CONF_DRIVE=${NANO_CONF_DRIVE:-"${NANO_DRIVE}s3"} + +# The type of the config file system. +NANO_CONF_FSTYPE=${NANO_CONF_FSTYPE:-"ufs"} + +# Whether or not the config slice is optional. +# XXX It seems this clobbers the CD build. +#NANO_CONF_OPTIONAL=${NANO_CONF_OPTIONAL:-"false"} + # Target media size in 512 bytes sectors NANO_MEDIASIZE=1000000 @@ -162,7 +184,8 @@ echo "### log: ${MAKEOBJDIRPREFIX}/_.bw" cd ${NANO_SRC} - ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} buildworld \ + env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \ + __MAKE_CONF=${NANO_MAKE_CONF} buildworld \ > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 ) @@ -179,7 +202,7 @@ # when cross-building unset TARGET_CPUTYPE unset TARGET_BIG_ENDIAN - ${NANO_PMAKE} buildkernel \ + env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \ __MAKE_CONF=${NANO_MAKE_CONF} KERNCONF=`basename ${NANO_KERNEL}` \ > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 ) @@ -208,6 +231,7 @@ echo "### log: ${MAKEOBJDIRPREFIX}/_.iw" cd ${NANO_SRC} + env TARGET_ARCH=${NANO_ARCH} \ ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} installworld \ DESTDIR=${NANO_WORLDDIR} \ > ${MAKEOBJDIRPREFIX}/_.iw 2>&1 @@ -220,6 +244,7 @@ echo "### log: ${MAKEOBJDIRPREFIX}/_.etc" cd ${NANO_SRC} + env TARGET_ARCH=${NANO_ARCH} \ ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} distribution \ DESTDIR=${NANO_WORLDDIR} \ > ${MAKEOBJDIRPREFIX}/_.etc 2>&1 @@ -230,7 +255,7 @@ echo "### log: ${MAKEOBJDIRPREFIX}/_.ik" cd ${NANO_SRC} - ${NANO_PMAKE} installkernel \ + env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} installkernel \ DESTDIR=${NANO_WORLDDIR} \ __MAKE_CONF=${NANO_MAKE_CONF} KERNCONF=`basename ${NANO_KERNEL}` \ > ${MAKEOBJDIRPREFIX}/_.ik 2>&1 @@ -294,9 +319,35 @@ echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size - # pick up config files from the special partition - echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount + # Pick up FS-specific boot time mount options. + mountopts="-o ro" + if [ "x$NANO_CONF_FSOPTS" != "x" ]; then + mountopts="${mountopts},$NANO_CONF_FSOPTS" + fi + echo "mount -t $NANO_CONF_FSTYPE $mountopts /dev/${NANO_CONF_DRIVE}" > conf/default/etc/remount + if [ "$NANO_CONF_OPTIONAL" = "true" ]; then + touch conf/default/etc/remount_optional + fi + + # If NANO_CONF_SUBDIR is set, then the configuration data + # is in fact in a subdirectory of the NANO_CONF_DRIVE. + # We need to trick rc.initdiskless into using a tempoary + # mount point. We can't use /tmp to do this as it may NOT yet + # be mounted at that point in the boot process, so we need to + # mkdir and hardcode the temporary mount point. + # If the cfg mount is optional then we must also deal with + # that here. + if [ "x$NANO_CONF_SUBDIR" != "x" ]; then + # XXX enable subdir mode for main mountpoint + touch conf/default/etc/remount_subdir + echo $NANO_CONF_SUBDIR >> conf/default/etc/remount_subdir + mkdir -p conf.tmp/default/etc + if [ "$NANO_CONF_OPTIONAL" = "true" ]; then + touch conf.tmp/default/etc/remount_optional + fi + fi + # Put /tmp on the /var ramdisk (could be symlink already) rmdir tmp || true rm tmp || true @@ -320,8 +371,23 @@ # save config file for scripts echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf - echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab - echo "/dev/${NANO_DRIVE}s3 /cfg ufs rw,noauto 2 2" >> etc/fstab + if $NANO_CDROM ; then + echo "/dev/${NANO_DRIVE} / cd9660 ro 0 0" > etc/fstab + else + echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab + fi + + if [ "$NANO_CONF_OPTIONAL" = "true" ]; then + preen=0 + else + preen=2 + fi + mountopts="rw,noauto" + if [ "x$NANO_CONF_FSOPTS" != "x" ]; then + mountopts="${mountopts},$NANO_CONF_FSOPTS" + fi + echo "/dev/${NANO_CONF_DRIVE} /cfg ${NANO_CONF_FSTYPE} $mountopts 2 $preen" >> etc/fstab + mkdir -p cfg ) ) @@ -409,7 +475,7 @@ } ' > ${MAKEOBJDIRPREFIX}/_.fdisk - IMG=${NANO_DISKIMGDIR}/_.disk.full + IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} MNT=${MAKEOBJDIRPREFIX}/_.mnt mkdir -p ${MNT} @@ -461,6 +527,16 @@ # Create Config slice newfs ${NANO_NEWFS} /dev/${MD}s3 + + # If subdir mode enabled for config slice, assume that the + # boot time remount is non-optional, and force the subdir to + # be created so that the nullfs mount will succeed. + if [ "x$NANO_CONF_SUBDIR" != "x" ]; then + mount /dev/${MD}s3 ${MNT} + mkdir -p ${MNT}/${NANO_CONF_SUBDIR} + umount ${MNT} + fi + # XXX: fill from where ? # Create Data slice, if any. @@ -480,6 +556,43 @@ ) > ${MAKEOBJDIRPREFIX}/_.di 2>&1 ) +create_i386_cdimage ( ) ( + echo "## build cdimage" + echo "### log: ${MAKEOBJDIRPREFIX}/_.ci" + + ( + if [ "x${NANO_MKISOFS}" = "x" ]; then + echo "can't find mkisofs" + exit 20 + fi + + if [ $NANO_IMAGES -gt 1 ] ; then + echo "Ignoring NANO_IMAGES=${NANO_IMAGES}" + fi + + IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} + MNT=${MAKEOBJDIRPREFIX}/_.mnt + mkdir -p ${MNT} + + dd if=/dev/zero of=${IMG} bs=${NANO_SECTS}b \ + count=`expr ${NANO_MEDIASIZE} / ${NANO_SECTS}` + + MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} -y ${NANO_HEADS}` + + trap "df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT + + ( cd ${NANO_WORLDDIR} && ${NANO_MKISOFS} -b boot/cdboot -no-emul-boot -c boot/boot.catalog -l -R -V "${NANO_VOLID}" -o /dev/$MD . ) + + mount -t cd9660 /dev/$MD ${MNT} + df -i ${MNT} + ( cd ${MNT} && mtree -c ) > ${MAKEOBJDIRPREFIX}/_.mtree + ( cd ${MNT} && du -k ) > ${MAKEOBJDIRPREFIX}/_.du + umount ${MNT} + + mdconfig -d -u $MD + ) > ${MAKEOBJDIRPREFIX}/_.ci 2>&1 +) + last_orders () ( # Redefine this function with any last orders you may have # after the build completed, for instance to copy the finished @@ -506,8 +619,33 @@ sub_FlashDevice $1 $2 } +####################################################################### +# USB device geometries +# +UsbDevice () { + if [ -d ${NANO_TOOLS} ] ; then + . ${NANO_TOOLS}/UsbDevice.sub + else + . ${NANO_SRC}/${NANO_TOOLS}/UsbDevice.sub + fi + sub_UsbDevice $1 $2 +} + ####################################################################### +# CDROM and DVD device geometries +# + +CdromDevice () { + if [ -d ${NANO_TOOLS} ] ; then + . ${NANO_TOOLS}/CdromDevice.sub + else + . ${NANO_SRC}/${NANO_TOOLS}/CdromDevice.sub + fi + sub_CdromDevice $1 $2 +} + +####################################################################### # Setup serial console cust_comconsole () ( @@ -706,6 +844,7 @@ export NANO_DRIVE export NANO_HEADS export NANO_IMAGES +export NANO_IMGNAME export NANO_MAKE_CONF export NANO_MEDIASIZE export NANO_NAME @@ -748,7 +887,13 @@ prune_usr run_late_customize if $do_image ; then - create_${NANO_ARCH}_diskimage + if $NANO_CDROM ; then + create_${NANO_ARCH}_cdimage + echo "# Created NanoBSD ISO image: ${MAKEOBJDIRPREFIX}/${NANO_IMGNAME}" + else + create_${NANO_ARCH}_diskimage + echo "# Created NanoBSD disk image: ${MAKEOBJDIRPREFIX}/${NANO_IMGNAME}" + fi else echo "## Skipping image build (as instructed)" fi