From 29481b994e5787c1896700a12ff1e8b709688391 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Wed, 16 Nov 2016 16:49:21 +0000 Subject: [PATCH] Start to move the old interface into a legacy file. --- tools/tools/nanobsd/defaults.sh | 171 ------------------ tools/tools/nanobsd/legacy.sh | 203 ++++++++++++++++++++++ tools/tools/nanobsd/nanobsd.sh | 12 ++ tools/tools/nanobsd/pcengines/common.conf | 2 +- 4 files changed, 216 insertions(+), 172 deletions(-) create mode 100644 tools/tools/nanobsd/legacy.sh diff --git a/tools/tools/nanobsd/defaults.sh b/tools/tools/nanobsd/defaults.sh index a5984b784f5c..362e5aa8d340 100755 --- a/tools/tools/nanobsd/defaults.sh +++ b/tools/tools/nanobsd/defaults.sh @@ -132,10 +132,6 @@ NANO_RAM_ETCSIZE=10240 # Size of the /tmp+/var ramdisk in 512 bytes sectors NANO_RAM_TMPVARSIZE=10240 -# Media geometry, only relevant if bios doesn't understand LBA. -NANO_SECTS=63 -NANO_HEADS=16 - # boot0 flags/options and configuration NANO_BOOT0CFG="-o packet -s 1 -m 3" NANO_BOOTLOADER="boot/boot0sio" @@ -652,173 +648,6 @@ populate_data_slice ( ) ( populate_slice "$1" "$2" "$3" "$4" ) -create_diskimage ( ) ( - pprint 2 "build diskimage" - pprint 3 "log: ${NANO_LOG}/_.di" - - ( - echo $NANO_MEDIASIZE $NANO_IMAGES \ - $NANO_SECTS $NANO_HEADS \ - $NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE | - awk ' - { - printf "# %s\n", $0 - - # size of cylinder in sectors - cs = $3 * $4 - - # number of full cylinders on media - cyl = int ($1 / cs) - - # output fdisk geometry spec, truncate cyls to 1023 - if (cyl <= 1023) - print "g c" cyl " h" $4 " s" $3 - else - print "g c" 1023 " h" $4 " s" $3 - - if ($7 > 0) { - # size of data partition in full cylinders - dsl = int (($7 + cs - 1) / cs) - } else { - dsl = 0; - } - - # size of config partition in full cylinders - csl = int (($6 + cs - 1) / cs) - - if ($5 == 0) { - # size of image partition(s) in full cylinders - isl = int ((cyl - dsl - csl) / $2) - } else { - isl = int (($5 + cs - 1) / cs) - } - - # First image partition start at second track - print "p 1 165 " $3, isl * cs - $3 - c = isl * cs; - - # Second image partition (if any) also starts offset one - # track to keep them identical. - if ($2 > 1) { - print "p 2 165 " $3 + c, isl * cs - $3 - c += isl * cs; - } - - # Config partition starts at cylinder boundary. - print "p 3 165 " c, csl * cs - c += csl * cs - - # Data partition (if any) starts at cylinder boundary. - if ($7 > 0) { - print "p 4 165 " c, dsl * cs - } else if ($7 < 0 && $1 > c) { - print "p 4 165 " c, $1 - c - } else if ($1 < c) { - print "Disk space overcommitted by", \ - c - $1, "sectors" > "/dev/stderr" - exit 2 - } - - # Force slice 1 to be marked active. This is necessary - # for booting the image from a USB device to work. - print "a 1" - } - ' > ${NANO_LOG}/_.fdisk - - IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} - MNT=${NANO_OBJ}/_.mnt - mkdir -p ${MNT} - - if [ "${NANO_MD_BACKING}" = "swap" ] ; then - MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \ - -y ${NANO_HEADS}` - else - echo "Creating md backing file..." - rm -f ${IMG} - dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0 - MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \ - -y ${NANO_HEADS}` - fi - - trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT - - fdisk -i -f ${NANO_LOG}/_.fdisk ${MD} - fdisk ${MD} - # XXX: params - # XXX: pick up cached boot* files, they may not be in image anymore. - if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then - boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD} - fi - if [ -f ${NANO_WORLDDIR}/boot/boot ]; then - bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}${NANO_SLICE_ROOT} - else - bsdlabel -w ${MD}${NANO_SLICE_ROOT} - fi - bsdlabel ${MD}${NANO_SLICE_ROOT} - - # Create first image - populate_slice /dev/${MD}${NANO_ROOT} ${NANO_WORLDDIR} ${MNT} "${NANO_ROOT}" - mount /dev/${MD}${NANO_ROOT} ${MNT} - echo "Generating mtree..." - ( cd "${MNT}" && mtree -c ) > ${NANO_LOG}/_.mtree - ( cd "${MNT}" && du -k ) > ${NANO_LOG}/_.du - nano_umount "${MNT}" - - if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then - # Duplicate to second image (if present) - echo "Duplicating to second image..." - dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=/dev/${MD}${NANO_SLICE_ALTROOT} bs=64k - mount /dev/${MD}${NANO_ALTROOT} ${MNT} - for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab - do - sed -i "" "s=${NANO_DRIVE}${NANO_SLICE_ROOT}=${NANO_DRIVE}${NANO_SLICE_ALTROOT}=g" $f - done - nano_umount ${MNT} - # Override the label from the first partition so we - # don't confuse glabel with duplicates. - if [ -n "${NANO_LABEL}" ]; then - tunefs -L ${NANO_LABEL}"${NANO_ALTROOT}" /dev/${MD}${NANO_ALTROOT} - fi - fi - - # Create Config slice - populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" ${MNT} "${NANO_SLICE_CFG}" - - # Create Data slice, if any. - if [ -n "$NANO_SLICE_DATA" -a "$NANO_SLICE_CFG" = "$NANO_SLICE_DATA" -a \ - "$NANO_DATASIZE" -ne 0 ]; then - pprint 2 "NANO_SLICE_DATA is the same as NANO_SLICE_CFG, fix." - exit 2 - fi - if [ $NANO_DATASIZE -ne 0 -a -n "$NANO_SLICE_DATA" ] ; then - populate_data_slice /dev/${MD}${NANO_SLICE_DATA} "${NANO_DATADIR}" ${MNT} "${NANO_SLICE_DATA}" - fi - - if [ "${NANO_MD_BACKING}" = "swap" ] ; then - if [ ${NANO_IMAGE_MBRONLY} ]; then - echo "Writing out _.disk.mbr..." - dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1 - else - echo "Writing out ${NANO_IMGNAME}..." - dd if=/dev/${MD} of=${IMG} bs=64k - fi - - echo "Writing out ${NANO_IMGNAME}..." - dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k - fi - - if ${do_copyout_partition} ; then - echo "Writing out _.disk.image..." - dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=${NANO_DISKIMGDIR}/_.disk.image bs=64k - fi - mdconfig -d -u $MD - - trap - 1 2 15 - trap nano_cleanup EXIT - - ) > ${NANO_LOG}/_.di 2>&1 -) - last_orders ( ) ( # Redefine this function with any last orders you may have # after the build completed, for instance to copy the finished diff --git a/tools/tools/nanobsd/legacy.sh b/tools/tools/nanobsd/legacy.sh new file mode 100644 index 000000000000..f0d79fab2fa9 --- /dev/null +++ b/tools/tools/nanobsd/legacy.sh @@ -0,0 +1,203 @@ +#!/bin/sh +# +# Copyright (c) 2005 Poul-Henning Kamp. +# Copyright (c) 2016 M. Warner Losh. +# 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$ +# + +# Media geometry, only relevant if bios doesn't understand LBA. +[ -z "$NANO_SECTS" ] || NANO_SECTS=63 +[ -z "$NANO_HEADS" ] || NANO_HEADS=16 + +# Functions and variable definitions used by the legacy nanobsd +# image building system. + +create_diskimage ( ) ( + pprint 2 "build diskimage" + pprint 3 "log: ${NANO_LOG}/_.di" + + ( + echo $NANO_MEDIASIZE $NANO_IMAGES \ + $NANO_SECTS $NANO_HEADS \ + $NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE | + awk ' + { + printf "# %s\n", $0 + + # size of cylinder in sectors + cs = $3 * $4 + + # number of full cylinders on media + cyl = int ($1 / cs) + + # output fdisk geometry spec, truncate cyls to 1023 + if (cyl <= 1023) + print "g c" cyl " h" $4 " s" $3 + else + print "g c" 1023 " h" $4 " s" $3 + + if ($7 > 0) { + # size of data partition in full cylinders + dsl = int (($7 + cs - 1) / cs) + } else { + dsl = 0; + } + + # size of config partition in full cylinders + csl = int (($6 + cs - 1) / cs) + + if ($5 == 0) { + # size of image partition(s) in full cylinders + isl = int ((cyl - dsl - csl) / $2) + } else { + isl = int (($5 + cs - 1) / cs) + } + + # First image partition start at second track + print "p 1 165 " $3, isl * cs - $3 + c = isl * cs; + + # Second image partition (if any) also starts offset one + # track to keep them identical. + if ($2 > 1) { + print "p 2 165 " $3 + c, isl * cs - $3 + c += isl * cs; + } + + # Config partition starts at cylinder boundary. + print "p 3 165 " c, csl * cs + c += csl * cs + + # Data partition (if any) starts at cylinder boundary. + if ($7 > 0) { + print "p 4 165 " c, dsl * cs + } else if ($7 < 0 && $1 > c) { + print "p 4 165 " c, $1 - c + } else if ($1 < c) { + print "Disk space overcommitted by", \ + c - $1, "sectors" > "/dev/stderr" + exit 2 + } + + # Force slice 1 to be marked active. This is necessary + # for booting the image from a USB device to work. + print "a 1" + } + ' > ${NANO_LOG}/_.fdisk + + IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} + MNT=${NANO_OBJ}/_.mnt + mkdir -p ${MNT} + + if [ "${NANO_MD_BACKING}" = "swap" ] ; then + MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \ + -y ${NANO_HEADS}` + else + echo "Creating md backing file..." + rm -f ${IMG} + dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0 + MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \ + -y ${NANO_HEADS}` + fi + + trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT + + fdisk -i -f ${NANO_LOG}/_.fdisk ${MD} + fdisk ${MD} + # XXX: params + # XXX: pick up cached boot* files, they may not be in image anymore. + if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then + boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD} + fi + if [ -f ${NANO_WORLDDIR}/boot/boot ]; then + bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}${NANO_SLICE_ROOT} + else + bsdlabel -w ${MD}${NANO_SLICE_ROOT} + fi + bsdlabel ${MD}${NANO_SLICE_ROOT} + + # Create first image + populate_slice /dev/${MD}${NANO_ROOT} ${NANO_WORLDDIR} ${MNT} "${NANO_ROOT}" + mount /dev/${MD}${NANO_ROOT} ${MNT} + echo "Generating mtree..." + ( cd "${MNT}" && mtree -c ) > ${NANO_LOG}/_.mtree + ( cd "${MNT}" && du -k ) > ${NANO_LOG}/_.du + nano_umount "${MNT}" + + if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then + # Duplicate to second image (if present) + echo "Duplicating to second image..." + dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=/dev/${MD}${NANO_SLICE_ALTROOT} bs=64k + mount /dev/${MD}${NANO_ALTROOT} ${MNT} + for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab + do + sed -i "" "s=${NANO_DRIVE}${NANO_SLICE_ROOT}=${NANO_DRIVE}${NANO_SLICE_ALTROOT}=g" $f + done + nano_umount ${MNT} + # Override the label from the first partition so we + # don't confuse glabel with duplicates. + if [ -n "${NANO_LABEL}" ]; then + tunefs -L ${NANO_LABEL}"${NANO_ALTROOT}" /dev/${MD}${NANO_ALTROOT} + fi + fi + + # Create Config slice + populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" ${MNT} "${NANO_SLICE_CFG}" + + # Create Data slice, if any. + if [ -n "$NANO_SLICE_DATA" -a "$NANO_SLICE_CFG" = "$NANO_SLICE_DATA" -a \ + "$NANO_DATASIZE" -ne 0 ]; then + pprint 2 "NANO_SLICE_DATA is the same as NANO_SLICE_CFG, fix." + exit 2 + fi + if [ $NANO_DATASIZE -ne 0 -a -n "$NANO_SLICE_DATA" ] ; then + populate_data_slice /dev/${MD}${NANO_SLICE_DATA} "${NANO_DATADIR}" ${MNT} "${NANO_SLICE_DATA}" + fi + + if [ "${NANO_MD_BACKING}" = "swap" ] ; then + if [ ${NANO_IMAGE_MBRONLY} ]; then + echo "Writing out _.disk.mbr..." + dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1 + else + echo "Writing out ${NANO_IMGNAME}..." + dd if=/dev/${MD} of=${IMG} bs=64k + fi + + echo "Writing out ${NANO_IMGNAME}..." + dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k + fi + + if ${do_copyout_partition} ; then + echo "Writing out _.disk.image..." + dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=${NANO_DISKIMGDIR}/_.disk.image bs=64k + fi + mdconfig -d -u $MD + + trap - 1 2 15 + trap nano_cleanup EXIT + + ) > ${NANO_LOG}/_.di 2>&1 +) diff --git a/tools/tools/nanobsd/nanobsd.sh b/tools/tools/nanobsd/nanobsd.sh index 02c84cd1afb6..c2bd74b46758 100755 --- a/tools/tools/nanobsd/nanobsd.sh +++ b/tools/tools/nanobsd/nanobsd.sh @@ -43,6 +43,9 @@ do_world=true do_image=true do_copyout_partition=true do_native_xtools=false +# Don't do the legacy build unless we detect 'old' variables being +# set. +do_legacy=false set +e args=`getopt KXbc:fhiknqvw $*` @@ -121,6 +124,15 @@ if [ $# -gt 0 ] ; then usage fi +if [ -n "$NANO_HEADS" -o -n "$NANO_SECTS" ]; then + do_legacy=true +fi + +# If this uses the old, legacy image system, pull that in as well +if $do_legacy ; then + . "${topdir}/legacy.sh" +fi + ####################################################################### # And then it is as simple as that... diff --git a/tools/tools/nanobsd/pcengines/common.conf b/tools/tools/nanobsd/pcengines/common.conf index 687fd74eec9e..c23293d8fd81 100644 --- a/tools/tools/nanobsd/pcengines/common.conf +++ b/tools/tools/nanobsd/pcengines/common.conf @@ -21,7 +21,7 @@ NO_CLEAN=YES # Options to put in make.conf during installworld only CONF_INSTALL=' ' -# Options to put in make.conf during both build- & installworld. +# Options to put in make.conf during both build- & installworld. CONF_WORLD=' CFLAGS=-O -pipe WITHOUT_ACPI=