diff options
Diffstat (limited to 'tools')
20 files changed, 361 insertions, 287 deletions
diff --git a/tools/regression/mac/mac_portacl/misc.sh b/tools/regression/mac/mac_portacl/misc.sh index 0fabe15..a1f152b 100755 --- a/tools/regression/mac/mac_portacl/misc.sh +++ b/tools/regression/mac/mac_portacl/misc.sh @@ -3,8 +3,7 @@ sysctl security.mac.portacl >/dev/null 2>&1 if [ $? -ne 0 ]; then - echo "1..1" - echo "not ok 1 # MAC_PORTACL is unavailable." + echo "1..0 # SKIP MAC_PORTACL is unavailable." exit 0 fi diff --git a/tools/regression/tls/ttls2/ttls2.c b/tools/regression/tls/ttls2/ttls2.c index f528e3d..15eb640 100644 --- a/tools/regression/tls/ttls2/ttls2.c +++ b/tools/regression/tls/ttls2/ttls2.c @@ -1,7 +1,8 @@ /* $FreeBSD$ */ -#include <stdio.h> #include <pthread.h> +#include <stdio.h> +#include <unistd.h> int __thread i; @@ -13,6 +14,7 @@ foo1(void *arg) printf("thread %p, i = %d\n", pthread_self(), i); sleep(1); } + return (NULL); } void * @@ -23,9 +25,11 @@ foo2(void *arg) printf("thread %p, i = %d\n", pthread_self(), i); sleep(1); } + return (NULL); } -int main(int argc, char** argv) +int +main(int argc, char** argv) { pthread_t t1, t2; @@ -33,4 +37,6 @@ int main(int argc, char** argv) pthread_create(&t2, 0, foo2, 0); pthread_join(t1, 0); pthread_join(t2, 0); + + return (0); } diff --git a/tools/regression/tls/ttls4/ttls4.c b/tools/regression/tls/ttls4/ttls4.c index d55e51b..914b220 100644 --- a/tools/regression/tls/ttls4/ttls4.c +++ b/tools/regression/tls/ttls4/ttls4.c @@ -9,11 +9,13 @@ #include <stdio.h> #include <pthread.h> +#include <stdlib.h> #include <unistd.h> int __thread n; -void *f1(void *arg) +void +*f1(void *arg) { if (n != 0) { printf("bug, n == %d \n", n); @@ -23,7 +25,8 @@ void *f1(void *arg) return (0); } -int main() +int +main(void) { pthread_t td; int i; diff --git a/tools/tools/nanobsd/defaults.sh b/tools/tools/nanobsd/defaults.sh index 067d306..46608f4 100755 --- a/tools/tools/nanobsd/defaults.sh +++ b/tools/tools/nanobsd/defaults.sh @@ -134,7 +134,7 @@ NANO_BOOTLOADER="boot/boot0sio" # boot2 flags/options # default force serial console -NANO_BOOT2CFG="-h" +NANO_BOOT2CFG="-h -S115200" # Backing type of md(4) device # Can be "file" or "swap" @@ -157,6 +157,9 @@ NANO_SLICE_ALTROOT=s2 NANO_SLICE_CFG=s3 NANO_SLICE_DATA=s4 +# Default ownwership for nopriv build +NANO_DEF_UNAME=root +NANO_DEF_GNAME=wheel ####################################################################### # Architecture to build. Corresponds to TARGET_ARCH in a buildworld. @@ -226,19 +229,52 @@ nano_make_kernel_env ( ) { } nano_global_make_env ( ) ( - [ ! -z "${NANO_ARCH}" ] && echo TARGET_ARCH="${NANO_ARCH}" || true - [ ! -z "${NANO_CPUTYPE}" ] && echo TARGET_CPUTYPE="${NANO_CPUTYPE}" || true + # global settings for the make.conf file, if set + [ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}" + [ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}" ) # rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build -# hosts for now. -nano_rm ( ) { +# hosts for now. This will go away when support in the base goes away. +rm ( ) { + echo "NANO RM $*" case $(uname -r) in - 7*|8*|9*) rm $* ;; - *) rm -x $* ;; + 7*|8*|9*) command rm $* ;; + *) command rm -x $* ;; esac } +# +# Create empty files in the target tree, and record the fact. All paths +# are relative to NANO_WORLDDIR. +# +tgt_touch ( ) ( + + cd "${NANO_WORLDDIR}" + for i; do + touch $i + echo "./${i} type=file" >> ${NANO_METALOG} + done +) + +# +# Convert a directory into a symlink. Takes two arguments, the +# current directory and what it should become a symlink to. The +# directory is removed and a symlink is created. If we're doing +# a nopriv build, then append this fact to the metalog +# +tgt_dir2symlink () ( + dir=$1 + symlink=$2 + + cd "${NANO_WORLDDIR}" + rm -rf "$dir" + ln -s "$symlink" "$dir" + if [ -n "$NANO_METALOG" ]; then + echo "./${dir} type=link mode=0777 link=${symlink}" >> ${NANO_METALOG} + fi +) + # run in the world chroot, errors fatal CR ( ) { chroot "${NANO_WORLDDIR}" /bin/sh -exc "$*" @@ -250,18 +286,16 @@ CR0 ( ) { } nano_cleanup ( ) ( - if [ $? -ne 0 ]; then - echo "Error encountered. Check for errors in last log file." 1>&2 - fi + [ $? -eq 0 ] || echo "Error encountered. Check for errors in last log file." 1>&2 exit $? ) clean_build ( ) ( pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" - if ! nano_rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then + if ! rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then chflags -R noschg ${MAKEOBJDIRPREFIX}/ - nano_rm -r ${MAKEOBJDIRPREFIX}/ + rm -r ${MAKEOBJDIRPREFIX}/ fi ) @@ -315,17 +349,17 @@ build_kernel ( ) ( clean_world ( ) ( if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then pprint 2 "Clean and create object directory (${NANO_OBJ})" - if ! nano_rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then + if ! rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then chflags -R noschg ${NANO_OBJ} - nano_rm -r ${NANO_OBJ}/ + rm -r ${NANO_OBJ}/ fi mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}" printenv > ${NANO_OBJ}/_.env else pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" - if ! nano_rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then + if ! rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then chflags -R noschg "${NANO_WORLDDIR}" - nano_rm -rf "${NANO_WORLDDIR}/" + rm -rf "${NANO_WORLDDIR}/" fi mkdir -p "${NANO_WORLDDIR}" fi @@ -340,7 +374,7 @@ make_conf_install ( ) ( nano_global_make_env echo "${CONF_WORLD}" echo "${CONF_INSTALL}" - if [ ! -z "${NANO_NOPRIV_BUILD}" ]; then + if [ -n "${NANO_NOPRIV_BUILD}" ]; then echo NO_ROOT=t echo METALOG=${NANO_METALOG} fi @@ -413,6 +447,11 @@ native_xtools ( ) ( ) > ${NANO_OBJ}/_.native_xtools 2>&1 ) +# +# Run the requested set of customization scripts, run after we've +# done an installworld, installed the etc files, installed the kernel +# and tweaked them in the standard way. +# run_customize ( ) ( pprint 2 "run customize scripts" @@ -425,6 +464,10 @@ run_customize ( ) ( done ) +# +# Run any last-minute customization commands after we've had a chance to +# setup nanobsd, prune empty dirs from /usr, etc +# run_late_customize ( ) ( pprint 2 "run late customize scripts" @@ -437,6 +480,33 @@ run_late_customize ( ) ( done ) +# +# Hook called after we run all the late customize commands, but +# before we invoke the disk imager. The nopriv build uses it to +# read in the meta log, apply the changes other parts of nanobsd +# have been recording their actions. It's not anticipated that +# a user's cfg file would override this. +# +fixup_before_diskimage ( ) ( + + # Run the deduplication script that takes the matalog journal and + # combines multiple entries for the same file (see source for + # details). We take the extra step of removing the size keywords. This + # script, and many of the user scripts, copies, appeneds and otherwise + # modifies files in the build, changing their sizes. These actions are + # impossible to trap, so go ahead remove the size= keyword. For this + # narrow use, it doesn't buy us any protection and just gets in the way. + # The dedup tool's output must be sorted due to limitations in awk. + if [ -n "${NANO_METALOG}" ]; then + pprint 2 "Fixing metalog" + cp ${NANO_METALOG} ${NANO_METALOG}.pre + (echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" && + cat ${NANO_METALOG}.pre) | \ + ${NANO_TOOLS}/mtree-dedup.awk | \ + sed -e 's/ size=[0-9][0-9]*//' | sort > ${NANO_METALOG} + fi +) + setup_nanobsd ( ) ( pprint 2 "configure nanobsd setup" pprint 3 "log: ${NANO_OBJ}/_.dl" @@ -453,7 +523,7 @@ setup_nanobsd ( ) ( cd usr/local/etc find . -print | cpio -dumpl ../../../etc/local cd .. - nano_rm -rf etc + rm -rf etc ln -s ../../etc/local etc ) fi @@ -474,8 +544,7 @@ setup_nanobsd ( ) ( echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount # Put /tmp on the /var ramdisk (could be symlink already) - nano_rm -rf tmp - ln -s var/tmp tmp + tgt_dir2symlink tmp var/tmp ) > ${NANO_OBJ}/_.dl 2>&1 ) @@ -489,10 +558,14 @@ setup_nanobsd_etc ( ) ( # create diskless marker file touch etc/diskless + [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf + # Make root filesystem R/O by default - [ ! -z "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf echo "root_rw_mount=NO" >> etc/defaults/rc.conf - [ ! -z "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf + # Disable entropy file, since / is read-only /var/db/entropy should be enough? + echo "entropy_file=NO" >> etc/defaults/rc.conf + + [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf # save config file for scripts echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf @@ -636,7 +709,7 @@ create_diskimage ( ) ( -y ${NANO_HEADS}` else echo "Creating md backing file..." - nano_rm -f ${IMG} + 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}` @@ -678,7 +751,7 @@ create_diskimage ( ) ( nano_umount ${MNT} # Override the label from the first partition so we # don't confuse glabel with duplicates. - if [ ! -z ${NANO_LABEL} ]; then + if [ -n "${NANO_LABEL}" ]; then tunefs -L ${NANO_LABEL}"${NANO_SLICE_ALTROOT}a" /dev/${MD}${NANO_SLICE_ALTROOT}a fi fi @@ -687,12 +760,12 @@ create_diskimage ( ) ( populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" ${MNT} "${NANO_SLICE_CFG}" # Create Data slice, if any. - if [ ! -z $NANO_SLICE_DATA -a $NANO_SLICE_CFG = $NANO_SLICE_DATA -a \ - $NANO_DATASIZE -ne 0 ]; then + 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 ! -z $NANO_SLICE_DATA ] ; then + 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 @@ -853,7 +926,7 @@ cust_pkgng ( ) ( echo "FAILED: pkg bootstrapping faied" exit 2 fi - nano_rm -f ${NANO_WORLDDIR}/Pkg/pkg-* + rm -f ${NANO_WORLDDIR}/Pkg/pkg-* # Count & report how many we have to install todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l` @@ -882,7 +955,7 @@ cust_pkgng ( ) ( exit 2 fi done - nano_rm -rf ${NANO_WORLDDIR}/Pkg + rm -rf ${NANO_WORLDDIR}/Pkg ) ####################################################################### @@ -949,21 +1022,21 @@ export_var ( ) { # Don't wawnt a subshell # Call this function to set defaults _after_ parsing options. # dont want a subshell otherwise variable setting is thrown away. set_defaults_and_export ( ) { - test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME} - test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ} - test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ} + : ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}} + : ${MAKEOBJDIRPREFIX:=${NANO_OBJ}} + : ${NANO_DISKIMGDIR=:${NANO_OBJ}} NANO_WORLDDIR=${NANO_OBJ}/_.w NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install # Override user's NANO_DRIVE if they specified a NANO_LABEL - [ ! -z "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true + [ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true - [ ! -z "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \ + [ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \ NANO_METALOG=${NANO_OBJ}/_.metalog || true NANO_STARTTIME=`date +%s` diff --git a/tools/tools/nanobsd/embedded/README b/tools/tools/nanobsd/embedded/README index 7be7978..e8b1c8c 100644 --- a/tools/tools/nanobsd/embedded/README +++ b/tools/tools/nanobsd/embedded/README @@ -12,3 +12,40 @@ This is a work in progress. Generally, to build this you should sudo sh ../nanobsd.sh -c foo.cfg but do be careful if things are interrupted. There may still be bugs lurking that cause your entire FreeBSD tree to disappear. + +Some features: + +Image size is minimal, we grow the last partition on first boot to +fill the media. + +Images are both as easy as possible to construct, as well as easy as +possible to expand. + +Config Short description +beaglebone.cfg Create a bootable beaglebone image +qemu-amd64.cfg Create a bootable amd64 image for qemu (W) +qemu-i386.cfg Create a bootable i386 image for qemu (W) +qemu-mips.cfg Create a bootable mips malta board image for + qemu +qemu-mips64.cfg Create a bootable mips malta board (64-bit + mode) image for qemu +qemu-powerpc.cfg Create a bootable 32-bit powerpc image for + qemu +qemu-powerpc64.cfg Create a bootable 64-bit IBM-flavor image for + qemu +qemu-sparc64.cfg Create a bootable sparc64 image for qemu +rpi.cfg Create a bootable image for Raspberry Pi B +rpi2.cfg Create a bootable image for Raspberry Pi2 +sam9260ek.cfg Create a bootable image for an Atmel SAM9260-EK + evaluation board (still needs a kenrel loaded + into dataflash or NAND, so experimental). +sam9g20ek.cfg Create a bootable image for an Atmel SAM9G20-EK + evaluation board (still needs a kenrel loaded + into dataflash or NAND, so experimental). Also + works on many after-market boards that are somewhat + compatible with the refernce board. + +QEMU command lines for serial console access + +i386: qemu-system-i386 -m 512 -hda _.disk.image.qemu-i386.qcow2 -nographic +amd64: qemu-system-amd64 -m 512 -hda _.disk.image.qemu-amd64.qcow2 -nographic diff --git a/tools/tools/nanobsd/embedded/beaglebone.cfg b/tools/tools/nanobsd/embedded/beaglebone.cfg index 3f28feb..8defe5e 100644 --- a/tools/tools/nanobsd/embedded/beaglebone.cfg +++ b/tools/tools/nanobsd/embedded/beaglebone.cfg @@ -25,12 +25,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=armv6 NANO_KERNEL=BEAGLEBONE diff --git a/tools/tools/nanobsd/embedded/common b/tools/tools/nanobsd/embedded/common index a4635f0..c0bbae9 100644 --- a/tools/tools/nanobsd/embedded/common +++ b/tools/tools/nanobsd/embedded/common @@ -73,26 +73,6 @@ if [ -z $NANO_NAME ]; then echo "NANO_NAME not defined. Use foo.cfg instead." fi -# Slice 1: FAT for ROM loading bootstrap -# Slice 2: Config partition -# Slice 3: FreeBSD partition (sized exactly) -# Slice 4: FreeBSD partition (empty) -# on first boot, we resize slice 3 & 4 to be 1/2 of what's -# left over on the SD card after slice 1 and 2 are taken -# off the top. We also resize the 'a' partion on first boot -# to the size of the partition for the ping/pong upgrade. -if [ -z "$EMBED_OMIT_FAT" ]; then - NANO_SLICE_FAT=s1 - NANO_SLICE_CFG=s2 - NANO_SLICE_ROOT=s3 - NANO_SLICE_ALTROOT=s4 -else - NANO_SLICE_CFG=s1 - NANO_SLICE_ROOT=s2 - NANO_SLICE_ALTROOT=s3 -fi -NANO_SLICE_DATA= # Not included - NANO_SLICE_FAT_SIZE=32m NANO_SLICE_CFG_SIZE=32m @@ -138,16 +118,6 @@ cust_install_machine_files() customize_cmd cust_install_files customize_cmd cust_install_machine_files -buildenv() -{ - cd ${NANO_SRC} - env __MAKE_CONF=${NANO_MAKE_CONF_BUILD} DESTDIR=${NANO_WORLDDIR} make buildenv -} - -NANO_MAKEFS="makefs -B big \ - -o bsize=4096,fsize=512,density=8192,optimization=space" -export NANO_MAKEFS - # NB: leave c++ enabled so devd can be built CONF_BUILD=" WITHOUT_ACPI=true @@ -184,6 +154,7 @@ WITHOUT_SENDMAIL=true WITHOUT_SHAREDOCS=true WITHOUT_SYSCONS=true WITHOUT_LIB32=true +WITHOUT_TESTS=true " CONF_INSTALL="$CONF_BUILD INSTALL_NODEBUG=t @@ -305,61 +276,93 @@ add_port () { fi } -create_diskimage ( ) ( - local extra +# Creates images for all the formats that use MBR +create_diskimage_mbr ( ) ( pprint 2 "build diskimage ${NANO_NAME}" pprint 3 "log: ${NANO_OBJ}/_.di" ( - if [ ! -z ${NANO_NOPRIV_BUILD} ]; then - extra="-F ${NANO_OBJ}/_.metalog" - fi + local extra i sz fmt fmtarg bootmbr bootbsd skiparg + set -o xtrace + + [ -z ${NANO_DISKIMAGE_FORMAT} ] || fmtarg="-f ${NANO_DISKIMAGE_FORMAT}" + [ -z ${NANO_DISKIMAGE_FORMAT} ] || fmt=".${NANO_DISKIMAGE_FORMAT}" + bootmbr=${NANO_BOOT_MBR:+-b ${NANO_BOOT_MBR}} + bootbsd=${NANO_BOOT_BSD:+-b ${NANO_BOOT_BSD}} + skiparg=${NANO_MBR_FIRST_SKIP:+-S ${NANO_MBR_FIRST_SKIP}} for i in s1 s2 s3 s4 empty; do rm -fr ${NANO_OBJ}/_.${i}* done - if [ ! -z "${NANO_SLICE_FAT}" ]; then + # Populate the FAT partition + if [-n "${NANO_SLICE_FAT}" ]; then echo Creating MSDOS partition for kernel - newfs_msdos -C ${NANO_SLICE_FAT_SIZE:-100m} -F 16 -L ${NANO_NAME} \ + newfs_msdos -C ${NANO_SLICE_FAT_SIZE} -F 16 -L ${NANO_NAME} \ ${NANO_OBJ}/_.${NANO_SLICE_FAT} + # Need to copy files from ${NANO_FATDIR} with mtools, or use + # makefs -t msdos once that's supported fi - echo Creating main partition + + # Populate the / partition, and place it into a slice with a + # bsd label + [ -z ${NANO_NOPRIV_BUILD} ] || extra="-F ${NANO_METALOG}" sz=${NANO_SLICE_ROOT_SIZE:+-s ${NANO_SLICE_ROOT_SIZE}} - makefs ${extra} -B little $sz -t ffs ${NANO_OBJ}/_.${NANO_SLICE_ROOT}a "${NANO_WORLDDIR}" + eval "${NANO_MAKEFS_UFS}" ${extra} $sz "${NANO_OBJ}/_.${NANO_SLICE_ROOT}a" \ + "${NANO_WORLDDIR}" + mkimg -s bsd ${bootbsd} -p freebsd-ufs:=${NANO_OBJ}/_.${NANO_SLICE_ROOT}a \ + -o ${NANO_OBJ}/_.${NANO_SLICE_ROOT} + + # Populate the /cfg partition, empty if none given if [ -z "${NANO_CFGDIR}" ]; then echo "Faking cfg dir, it's empty" NANO_CFGDIR=${NANO_OBJ}/_.empty mkdir ${NANO_CFGDIR} fi - echo Creating cfg parittion -# XXX -F cfg-mtree - makefs -B little -t ffs -s ${NANO_SLICE_CFG_SIZE:-100m} \ - ${NANO_OBJ}/_.${NANO_SLICE_CFG} "${NANO_CFGDIR}" + # XXX -F cfg-mtree + eval "${NANO_MAKEFS_UFS}" -s ${NANO_SLICE_CFG_SIZE} \ + "${NANO_OBJ}/_.${NANO_SLICE_CFG}" "${NANO_CFGDIR}" + # data slice not supported since we need the part for FAT for # booting - echo Slicing up the main partition into a full bsd part - mkimg -s bsd -p freebsd-ufs:=${NANO_OBJ}/_.${NANO_SLICE_ROOT}a \ - -o ${NANO_OBJ}/_.${NANO_SLICE_ROOT} - echo Making the whole shooting match - if [ ! -z $NANO_SLICE_FAT ]; then + + # Now shuffle all the slices together into the proper layout + if [ -n "$NANO_SLICE_FAT" ]; then eval $NANO_SLICE_FAT=fat16b fi eval $NANO_SLICE_CFG=freebsd eval $NANO_SLICE_ROOT=freebsd - if [ ! -z "${NANO_SLICE_FAT}" ]; then - mkimg -s mbr -p ${s1}:=${NANO_OBJ}/_.s1 \ + # below depends on https://reviews.freebsd.org/D4403 not yet in the tree + # but there's problems: it marks all partitions as active, so you have to + # boot off parittion 3 or 2 by hand if you're playing around with this WIP + case ${NANO_LAYOUT} in + std-embedded) + mkimg -a 3 ${skiparg} ${fmtarg} ${bootmbr} -s mbr -p ${s1}:=${NANO_OBJ}/_.s1 \ -p ${s2}:=${NANO_OBJ}/_.s2 \ -p ${s3}:=${NANO_OBJ}/_.s3 \ - -o ${NANO_OBJ}/_.disk.image.${NANO_NAME} - else + -o ${NANO_OBJ}/_.disk.image.${NANO_NAME}${fmt} + ;; + std-x86) # s1 is cfg, s2 is /, not sure how to make that # boot (marked as active) with mkimg yet - mkimg -s mbr -p ${s1}:=${NANO_OBJ}/_.s1 \ + mkimg -a 2 ${fmtarg} ${bootmbr} -s mbr -p ${s1}:=${NANO_OBJ}/_.s1 \ -p ${s2}:=${NANO_OBJ}/_.s2 \ - -o ${NANO_OBJ}/_.disk.image.${NANO_NAME} - fi + -o ${NANO_OBJ}/_.disk.image.${NANO_NAME}${fmt} + ;; + powerpc64-ibm) + # A lie to make the boot loader work, it boots the first BSD partition + # it finds, regardless of the active flag. + s2=fat16b + # boot image is on a special partition, ala std-embedded, but that + # partition isn't FAT with special files, but a copy of the boot + # loader itself. + mkimg ${fmtarg} -s mbr -p ppcboot:=${NANO_WORLDDIR}/boot/boot1.elf \ + -p ${s2}:=${NANO_OBJ}/_.s2 \ + -p ${s3}:=${NANO_OBJ}/_.s3 \ + -o ${NANO_OBJ}/_.disk.image.${NANO_NAME}${fmt} + ;; + esac ) > ${NANO_OBJ}/_.di 2>&1 ) @@ -371,7 +374,9 @@ die() # Automatically include the packaging port here so it is always first so it # builds the port and adds the package so we can add other packages. -#XXX Not sure this works for cross build, so punting for the moment +#XXX Doesn't work for cross build, so punting until I can integreate qemu-static +#XXX or poudere, both of which require priv'd execution. Or qemu-system, which +#XXX is super, super slow. #add_port ports-mgmt/pkg #add_port security/sudo #add_port ftp/curl @@ -383,8 +388,6 @@ if [ -n "$__a" ]; then umount $__a fi -NANO_BOOTLOADER="boot/boot0" - if [ "$DEBUG" = 1 ]; then DEBUG_BUILD=" DEBUG_FLAGS= -g @@ -421,15 +424,6 @@ $var=$val" fi done -hack_nsswitch_conf ( ) -{ - # Remove all references to NIS in the nsswitch.conf file - # Not sure this is still needed, but FreeNAS has it... - sed -i.bak -es/nis/files/g ${NANO_WORLDDIR}/etc/nsswitch.conf - rm -f ${NANO_WORLDDIR}/etc/nsswitch.conf.bak -} -customize_cmd hack_nsswitch_conf - save_build ( ) { VERSION_FILE=${NANO_WORLDDIR}/etc/version @@ -441,12 +435,6 @@ save_build ( ) } customize_cmd save_build -remove_patch_divots ( ) -{ - find ${NANO_WORLDDIR} -name \*.orig -or -name \*.rej -delete -} -customize_cmd remove_patch_divots - shrink_md_fbsize() { # We have a lot of little files on our memory disks. Let's decrease @@ -459,21 +447,11 @@ shrink_md_fbsize() } customize_cmd shrink_md_fbsize -if [ "${DEBUG}" = 1 ]; then - -unmute_console_logging() -{ - # /var is small. Don't fill it up with messages from console.log - # because it's a chatty log. - sed -i '' -e 's/#console.info/console.info/' \ - "${NANO_WORLDDIR}/etc/syslog.conf" -} -customize_cmd unmute_console_logging - -fi +customize_cmd cust_comconsole product_custom() { + # not quie ready to tweak these in nopriv build if [ -z ${NANO_NOPRIV_BUILD} ]; then # Last second tweaks -- generally not needed chown -R root:wheel ${NANO_WORLDDIR}/root @@ -483,85 +461,133 @@ product_custom() chown -R root:wheel ${NANO_WORLDDIR}/boot chown root:wheel ${NANO_WORLDDIR}/ chown root:wheel ${NANO_WORLDDIR}/usr - else - # Construct an mtree after our messing around with the tree - # Trim out all the uid / gid stuff, since for new files it - # is likely wrong, and for other files it doesn't matter. - mtree -p ${NANO_WORLDDIR} -c | \ - mtree -C | \ - sed -e 's/ uid=[0-9][0-9]* / /g;s/ gid=[0-9][0-9]* / /' \ - > ${NANO_OBJ}/_.mtree.post - - # Sort the metalog, and save the original. Sadly, this - # seems to expand the uname= and gname= to uid= and gid= - # which is lame and likely a bug in mtree. The man page - # is just vague enough to be infuriating as to the proper - # behavior. Happily, it removes all the // that can confound - # things. - mtree -C -S -f ${NANO_OBJ}/_.metalog > ${NANO_OBJ}/_.mtree.pre - mv ${NANO_OBJ}/_.metalog ${NANO_OBJ}/_.metalog.install - - # mtree -f -f produces a comm-like output. The first column will - # be the files we deleted, so we ignore it. The second column is - # the same in both, so we pass it through. The third column is - # listed twice, so we ignore the second one. We also trim out - # the size, because size just doesn't matter as nanobsd and - # customizations often tweak files changing their size. We also - # add 'optional' to every file in case something slipped through - # that's gone from the tree, though maybe that's a real bug. - # - # To make matters worse, currently mtree in freebsd uses the - # old 'file' keyword rather than the newer type=file. Ditto - # dir and link. Also, nlinks is output, which is lame. And - # there's a bloatload of extra flags=none, which I remove too. - # - # Even worse is that all the uid / gid stuff is also tossed - # into the scrap heap. Hope they weren't important. - # - # And somewhere along the way, flags seem to have gone missing. - # - # Oh, and we have to add back in ./ to keep makefs happy. - # - # And then we have to sort the damn hing so directories come - # before subdirectories - # - # Note: For reasons unknown, all the directories are changing - # from 755 to 775, so that's why we ignore the second line. - # We also get repeats for all the files whose size changed. - # Perhaps we should filter those going into the pre/post files - # and not here. - mtree -f ${NANO_OBJ}/_.mtree.pre -f ${NANO_OBJ}/_.mtree.post | \ - awk ' - function frob_bogus_mtree_line(old) { - line = "./" old " gid=0 uid=0" - # XXX make this a damn function - sub(/^\.\/\./, ".", line); - sub(/ file /, " type=file ", line); - sub(/ dir /, " type=dir ", line); - sub(/ link /, " type=link ", line); - sub(/ size=[0-9][0-9]*/, "", line); - sub(/ nlinks=[0-9][0-9]*/, "", line); - sub(/ flags=none*/, "", line); - return line; - } - BEGIN { - x = 0; - FS="\t"; - print "#mtree 2.0"; - } - $1 != "" {} - $2 != "" { - print frob_bogus_mtree_line($2); - } - $3 != "" { - if (x == 0) { - print frob_bogus_mtree_line($3); - x = 1; - } else { - x = 0; - } - } - ' | sort > ${NANO_OBJ}/_.metalog fi } late_customize_cmd product_custom + +# +# Convenience routines to bring up many settings for standard environments +# + +# +# For each architecture, we have a standard set of settings to the extent +# it makes sense. For architectures that don't have a standard environment +# cfg files need to either define a lot of settings, provide their own disk +# imaging, or set which of the variants we support. +# + +std_aarch64 ( ) { +} + +std_amd64 ( ) { + std_i386 +} + +std_arm ( ) { +} + +std_armeb ( ) { + NANO_ENDIAN=big +} + +std_armv6 ( ) { +} + +std_i386 ( ) { + # Default values, if not overridden in .cfg file + : ${NANO_KERNEL:=GENERIC} + : ${NANO_DRIVE:=ada0} + : ${NANO_LAYOUT:=std-x86} + : ${NANO_BOOT_MBR:=${NANO_WORLDDIR}/boot/boot0sio} + : ${NANO_BOOT_BSD:=${NANO_WORLDDIR}/boot/boot} +} + +std_mips ( ) { + NANO_ENDIAN=big +} + +std_mipsel ( ) { +} + +std_mips64 ( ) { + NANO_ENDIAN=big +} + +std_mips64el ( ) { +} + +std_powerpc ( ) { + NANO_ENDIAN=big +} + +std_powerpc64 ( ) { + NANO_LAYOUT=powerpc64-ibm + NANO_ENDIAN=big +} + +std_sparc64 ( ) { + NANO_ENDIAN=big +} + +# +# QEMU settings for the standard environments +# +qemu_env ( ) { + + NANO_DISKIMAGE_FORMAT=qcow2 +} + +# other standard environments will go here + +eval std_${NANO_ARCH} + +# Slice 1: FAT for ROM loading bootstrap +# Slice 2: Config partition +# Slice 3: FreeBSD partition (sized exactly) +# Slice 4: FreeBSD partition (empty) +# on first boot, we resize slice 3 & 4 to be 1/2 of what's +# left over on the SD card after slice 1 and 2 are taken +# off the top. We also resize the 'a' partion on first boot +# to the size of the partition for the ping/pong upgrade. +# This feature needs support in the rc.d bootup script. + +: ${NANO_ENDIAN:=little} # make -V something to figure it out? +: ${NANO_LAYOUT:=std-embedded} +: ${NANO_MAKEFS_UFS:=makefs -t ffs -B ${NANO_ENDIAN}} +: ${NANO_DISK_SCHEME:=mbr} # No others really supported ATM +case ${NANO_LAYOUT} in +std-embedded) + NANO_SLICE_FAT=s1 + NANO_SLICE_CFG=s2 + NANO_SLICE_ROOT=s3 + NANO_SLICE_ALTROOT=s4 + ;; +std-x86) + NANO_SLICE_CFG=s1 + NANO_SLICE_ROOT=s2 + NANO_SLICE_ALTROOT=s3 + ;; +powerpc64-ibm) + NANO_SLICE_PPCBOOT=s1 + NANO_SLICE_CFG=s2 + NANO_SLICE_ROOT=s3 + NANO_SLICE_ALTROOT=s4 + ;; +powerpc64-apple) + echo Not yet + exit 1 + ;; +*) + echo Unknown Layout ${NANO_LAYOUT} + exit 1 + ;; +esac + +NANO_SLICE_DATA= # Not included + +# Each major disk scheme has its own routine. Generally +# this is for mbr, gpt, etc. These are generally are widely +# shared, but some specialized formats won't be shared. +create_diskimage ( ) ( + eval create_diskimage_${NANO_DISK_SCHEME} +) diff --git a/tools/tools/nanobsd/embedded/qemu-amd64.cfg b/tools/tools/nanobsd/embedded/qemu-amd64.cfg index 5ca6837..c405f04 100644 --- a/tools/tools/nanobsd/embedded/qemu-amd64.cfg +++ b/tools/tools/nanobsd/embedded/qemu-amd64.cfg @@ -25,18 +25,10 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=amd64 -NANO_KERNEL=GENERIC -NANO_DRIVE=ada0 NANO_NAME=qemu-amd64 -export EMBED_OMIT_FAT=t +qemu_env . common # Pull in common definitions, keep last diff --git a/tools/tools/nanobsd/embedded/qemu-i386.cfg b/tools/tools/nanobsd/embedded/qemu-i386.cfg index 856f61f..642f19a 100644 --- a/tools/tools/nanobsd/embedded/qemu-i386.cfg +++ b/tools/tools/nanobsd/embedded/qemu-i386.cfg @@ -25,18 +25,10 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=i386 -NANO_KERNEL=GENERIC -NANO_DRIVE=ada0 NANO_NAME=qemu-i386 -export EMBED_OMIT_FAT=t +qemu_env . common # Pull in common definitions, keep last diff --git a/tools/tools/nanobsd/embedded/qemu-mips.cfg b/tools/tools/nanobsd/embedded/qemu-mips.cfg index 9b9581d..1582fdf 100644 --- a/tools/tools/nanobsd/embedded/qemu-mips.cfg +++ b/tools/tools/nanobsd/embedded/qemu-mips.cfg @@ -25,18 +25,12 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=mips NANO_KERNEL=MALTA NANO_DRIVE=ada0 NANO_NAME=qemu-mips -export EMBED_OMIT_FAT=t +qemu_env . common # Pull in common definitions, keep last diff --git a/tools/tools/nanobsd/embedded/qemu-mips64.cfg b/tools/tools/nanobsd/embedded/qemu-mips64.cfg index 9ac22cd..a6ad39e 100644 --- a/tools/tools/nanobsd/embedded/qemu-mips64.cfg +++ b/tools/tools/nanobsd/embedded/qemu-mips64.cfg @@ -25,18 +25,12 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=mips NANO_KERNEL=MALTA64 NANO_DRIVE=ada0 NANO_NAME=qemu-mips64 -export EMBED_OMIT_FAT=t +qemu_env . common # Pull in common definitions, keep last diff --git a/tools/tools/nanobsd/embedded/qemu-powerpc.cfg b/tools/tools/nanobsd/embedded/qemu-powerpc.cfg index 8c588b1..ac1efa1 100644 --- a/tools/tools/nanobsd/embedded/qemu-powerpc.cfg +++ b/tools/tools/nanobsd/embedded/qemu-powerpc.cfg @@ -25,12 +25,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# # Open question: do we have one for MAC G4 and one for Book-E? NANO_ARCH=powerpc @@ -38,6 +32,6 @@ NANO_KERNEL=GENERIC NANO_DRIVE=ada0 NANO_NAME=qemu-powerpc -export EMBED_OMIT_FAT=t +qemu_env . common # Pull in common definitions, keep last diff --git a/tools/tools/nanobsd/embedded/qemu-powerpc64.cfg b/tools/tools/nanobsd/embedded/qemu-powerpc64.cfg index 1563472..00f177a 100644 --- a/tools/tools/nanobsd/embedded/qemu-powerpc64.cfg +++ b/tools/tools/nanobsd/embedded/qemu-powerpc64.cfg @@ -25,18 +25,12 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=powerpc64 NANO_KERNEL=GENERIC64 NANO_DRIVE=ada0 NANO_NAME=qemu-powerpc64 -export EMBED_OMIT_FAT=t +qemu_env . common # Pull in common definitions, keep last diff --git a/tools/tools/nanobsd/embedded/qemu-sparc64.cfg b/tools/tools/nanobsd/embedded/qemu-sparc64.cfg index 656fcef..d497dd4 100644 --- a/tools/tools/nanobsd/embedded/qemu-sparc64.cfg +++ b/tools/tools/nanobsd/embedded/qemu-sparc64.cfg @@ -25,18 +25,12 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=sparc64 NANO_KERNEL=GENERIC NANO_DRIVE=ada0 NANO_NAME=qemu-sparc64 -export EMBED_OMIT_FAT=t +qemu_env . common # Pull in common definitions, keep last diff --git a/tools/tools/nanobsd/embedded/rpi.cfg b/tools/tools/nanobsd/embedded/rpi.cfg index 598de19..25304e4 100644 --- a/tools/tools/nanobsd/embedded/rpi.cfg +++ b/tools/tools/nanobsd/embedded/rpi.cfg @@ -25,12 +25,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=armv6 NANO_KERNEL=RPI-B diff --git a/tools/tools/nanobsd/embedded/rpi2.cfg b/tools/tools/nanobsd/embedded/rpi2.cfg index 043874c..8415e35 100644 --- a/tools/tools/nanobsd/embedded/rpi2.cfg +++ b/tools/tools/nanobsd/embedded/rpi2.cfg @@ -25,12 +25,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=armv6 NANO_KERNEL=RPI2 diff --git a/tools/tools/nanobsd/embedded/sam9260ek.cfg b/tools/tools/nanobsd/embedded/sam9260ek.cfg index fec892a..50bbf1d 100644 --- a/tools/tools/nanobsd/embedded/sam9260ek.cfg +++ b/tools/tools/nanobsd/embedded/sam9260ek.cfg @@ -25,12 +25,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=arm NANO_KERNEL=SAM9260EK diff --git a/tools/tools/nanobsd/embedded/sam9g20ek.cfg b/tools/tools/nanobsd/embedded/sam9g20ek.cfg index 8fe67d4..6964e3f 100644 --- a/tools/tools/nanobsd/embedded/sam9g20ek.cfg +++ b/tools/tools/nanobsd/embedded/sam9g20ek.cfg @@ -25,12 +25,6 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# This file is heavily derived from both Sam Leffler's Avilia config, -# as well as the BSDRP project's config file. Neither of these have -# an explicit copyright/license statement, but are implicitly BSDL. This -# example has been taken from the FreeNAS project and simplified to meet -# the needs of the example. -# NANO_ARCH=arm NANO_KERNEL=SAM9G20EK diff --git a/tools/tools/nanobsd/mtree-dedup.awk b/tools/tools/nanobsd/mtree-dedup.awk index 17aa5e2..ca0f186 100755 --- a/tools/tools/nanobsd/mtree-dedup.awk +++ b/tools/tools/nanobsd/mtree-dedup.awk @@ -178,6 +178,8 @@ BEGIN { nv = "___NO__VALUE___"; while ((getline < "/dev/stdin") > 0) { + if ($1 ~ "^#") + continue; if ($1 == "/set") { for (i = 2; i <= NF; i++) { kv($i); @@ -192,6 +194,9 @@ BEGIN { process_line($1, $0); } + # Print the last set of defaults. This will carry + # over, I think, to makefs' defaults + print mtree_from_kvs("/set", defaults) for (x in tree) print tree[x]; } diff --git a/tools/tools/nanobsd/nanobsd.sh b/tools/tools/nanobsd/nanobsd.sh index 776b246..a17db7a 100755 --- a/tools/tools/nanobsd/nanobsd.sh +++ b/tools/tools/nanobsd/nanobsd.sh @@ -178,6 +178,7 @@ run_customize setup_nanobsd prune_usr run_late_customize +fixup_before_diskimage if $do_image ; then create_diskimage else |