picobsd revision 255313
172770Sluigi#!/bin/sh - 272770Sluigi# 372770Sluigi# $FreeBSD: head/release/picobsd/build/picobsd 255313 2013-09-06 17:16:33Z luigi $ 4155136Sluigi# This file requires sysutils/makefs to run 572770Sluigi# 6190378Sluigi# The PicoBSD build script. Invoked as 772770Sluigi# 8190378Sluigi# picobsd [options] image_type [site_name] 972770Sluigi# 10239738Sluigi# CWARNFLAGS can be used to pass -Wall or similar options 11239738Sluigi# 12190378Sluigi# Where image_type is a directory with the picobsd config info, 13190378Sluigi# and ${image_type}/floppy.tree.${site_name} contains 1472770Sluigi# optional site-specific configuration. 1572770Sluigi# 1672770Sluigi# For Options, see the bottom of the file where the processing is 1778494Sluigi# done. The picobsd(8) manpage might be of some help, but code and docs 18190378Sluigi# tend to lose sync over time. 1972770Sluigi# 2072770Sluigi# This script depends on the following files: 2172770Sluigi# 2272770Sluigi# in ${PICO_TREE} : 2372770Sluigi# Makefile.conf Makefile used to build the kernel 2472770Sluigi# config shell variables, sourced here. 2572770Sluigi# mfs.mtree mtree config file 2672770Sluigi# floppy.tree/ files which go on the floppy 2772770Sluigi# mfs_tree/ files which go onto the mfs 2872770Sluigi# 2972770Sluigi# in ${MY_TREE} : 3072770Sluigi# PICOBSD kernel config file 3172770Sluigi# config shell variables, sourced here. 3272770Sluigi# crunch.conf crunchgen configuration 33188835Sluigi# mfs.mtree overrides ${PICO_TREE}/mfs.mtree 3472770Sluigi# floppy.tree.exclude files from floppy.tree/ which we do not need here. 35188835Sluigi# floppy.tree/ local additions to ${PICO_TREE}/mfs_free 3672770Sluigi# floppy.tree.${site}/ same as above, site specific. 37122229Ssimokawa# mfs_tree/ local additions to the mfs_free 38190378Sluigi# buildtree.mk optional Makefile to build an extension for floppy tree 39188835Sluigi# (generated in buildtree/ ) 4072770Sluigi 4172770Sluigi# 4272770Sluigi#--- The main entry point is at the end. 4372770Sluigi# 4472770Sluigi 45190378Sluigi# There are two initialization functions: 4684377Sluigi# 47190378Sluigi# + set_defaults 48190378Sluigi# is run on entry to the script, and is used to set default values 49190378Sluigi# for all variables that do not depend on image type and source tree. 5084377Sluigi# 51190378Sluigi# + set_build_parameters 52190378Sluigi# is run after command line parsing 53190378Sluigi# 54190378Sluigi# VARIABLE NAMES: 5584377Sluigi# + variables that control operation (e.g. verbosity) and are generally 5684377Sluigi# set from the command line have o_ ("option") as a name prefix 5784377Sluigi# 58190378Sluigi# + variables that contain pathnames and values that should not change 5984377Sluigi# have c_ ("constant") as a name prefix 6084377Sluigi# 6184377Sluigi# + variables exported to Makefiles and subshells are CAPITAL 6284377Sluigi# 6384377Sluigi# + variables local to the script are lowercase, possibly with 64190378Sluigi# an l_ ("local") prefix. 65190378Sluigi# 66190378Sluigi# There are unfortunately exceptions: 67190378Sluigi# name, l_usrtree, l_objtree 6872770Sluigi 6984377Sluigi# SRC points to your FreeBSD source tree. 7084377Sluigi# l_usrtree points to the /usr subdir for the source tree. 7184377Sluigi# Normally /usr or ${SRC}/../usr 72227878Sluigi# l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico-${o_arch} 73190378Sluigi# c_label is either bsdlabel or disklabel 7484377Sluigi# PICO_TREE is where standard picobsd stuff resides. 7584377Sluigi# Normally ${SRC}/release/picobsd 7684377Sluigi# You can set SRC with --src <directory> 7784377Sluigi# It is not recommended to override the other variables. 7872770Sluigi 7984377Sluigi# MY_TREE (set later) is where this floppy type resides. 8084377Sluigi# BUILDDIR is the build directory 8172770Sluigi 8284377Sluigi# log something on stdout if verbose. 8384377Sluigio_verbose=0 # this needs to be here! 84190378Sluigilog() { # message 85173602Sluigi local foo 86173602Sluigi [ ${o_verbose} -gt 0 ] && printf "\n*** %s\n" "$*" 87173602Sluigi [ ${o_verbose} -gt 1 ] && read -p "=== Press enter to continue" foo 88173602Sluigi return 0 8984377Sluigi} 9083723Sjoe 91190378Sluigi# unconditionally log and wait for input 92190378Sluigilogverbose() { # message 93127266Sluigi local foo 9491846Sluigi printf "\n*** %s\n" "$*" 9591846Sluigi read -p "=== Press enter to continue" foo 96173602Sluigi return 0 9791846Sluigi} 9891846Sluigi 99190378Sluigi# set some default values for variables. 100190378Sluigi# needs to be done as the first thing in the script. 10172770Sluigi 102190378Sluigiset_defaults() { # no arguments 10372770Sluigi # EDITOR is the editor you use 10484377Sluigi # fd_size floppy size in KB (default to 1440). You can use 1480, 10572770Sluigi # 1720, 2880, etc. but beware that only 1440 and 1480 will boot 10672770Sluigi # from 1.44M floppy drives (1480 will not work on vmware). 10772770Sluigi EDITOR=${EDITOR:-vi} 10884377Sluigi fd_size=${fd_size:-1440} 10972770Sluigi 110190378Sluigi o_all_in_mfs="yes" # put all files in mfs so you can boot 111190378Sluigi # and run the image via diskless boot. 112190378Sluigi o_clean="" # set if you want to clean prev.builds. 11384377Sluigi o_interactive="" # default is interactive 11484377Sluigi o_verbose=0 # verbose level, 0 is silent 11584377Sluigi o_tarv="" # tar verbose flag, "" or "v" 116190378Sluigi o_init_src="" # set to build libs and includes. 11784377Sluigi o_makeopts=${MAKEOPTS:--s} # make options, be silent by default 118190378Sluigi o_no_devfs= # default is use devfs. 119190378Sluigi # You should only set it when building 4.x images 12085833Sluigi o_do_modules="" # do not build modules 121227878Sluigi o_arch=`uname -m` # default to amd64 or i386 ... 12272770Sluigi 12384377Sluigi SRC="/usr/src" # default location for sources 124155136Sluigi c_startdir=`pwd` # directory where we start 125155136Sluigi # used to lookup config and create BUILDDIR 12684377Sluigi 127155136Sluigi # XXX 6.x/7.x have a single /boot/boot block, which is the concatenation 128155136Sluigi # of the old two. For the time being, we keep these, but this should 129155136Sluigi # be fixed at some point. 130155136Sluigi 131155136Sluigi # blocks 132127266Sluigi c_boot1=/boot/boot1 # boot blocks (in case you want custom ones) 13384377Sluigi c_boot2=/boot/boot2 13484377Sluigi 13584377Sluigi c_reply=${c_reply:-`mktemp "/tmp/reply.XXXXXXXXXX"`} 136155136Sluigi # file where User replies will be put 13784377Sluigi c_mnt=`mktemp -d "/tmp/picobsd.XXXXXXXXXX"` 138155136Sluigi # mountpoint used to build memory filesystems 139155136Sluigi c_fs=fs.PICOBSD # filename used for the memory filesystem 140155136Sluigi c_img=picobsd.bin # filename used for the picobsd image 141194635Sluigi c_iso=picobsd.iso # filename used for the ISO image 142188835Sluigi generate_iso="NO" # don't generate the iso image 14384377Sluigi 144190378Sluigi # select the right disklabel program 14584377Sluigi case `uname -r` in 146190378Sluigi 4.*) 147190378Sluigi c_label="disklabel" 14884377Sluigi ;; 14984377Sluigi *) 150190378Sluigi c_label="bsdlabel" 151127266Sluigi ;; 15284377Sluigi esac 15372770Sluigi 15472770Sluigi set -e 15572770Sluigi 15684377Sluigi trap fail 2 15784377Sluigi #trap fail 3 15884377Sluigi #trap fail 6 15984377Sluigi trap fail 15 16072770Sluigi} 16172770Sluigi 162190411Sluigi# use the new build infrastructure to create libraries 163190411Sluigi# and also to build a specific target 164190411Sluigicreate_includes_and_libraries2() { # opt_dir opt_target 165155136Sluigi local no 166229532Sluigi log "create_includes_and_libraries2() for ${SRC} $1" 167155136Sluigi if [ ${OSVERSION} -ge 600000 ] ; then 168201059Sluigi no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITHOUT_CDDL=1" 169239738Sluigi no="$no -DWITHOUT_CLANG -DMALLOC_PRODUCTION" 170155136Sluigi else 171155136Sluigi no="-DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R" 172155136Sluigi fi 17399946Sluigi ( cd ${SRC}; 174155136Sluigi # make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld 175190411Sluigi if [ -d "$1" ] ; then 176218359Sluigi cd $1 ; ${BINMAKE} ${o_par} $2 # specific target, e.g. ld-elf.so 177190411Sluigi else 178250289Sluigi export MAKEOBJDIRPREFIX=${l_objtree} 179250289Sluigi make ${o_par} $no toolchain 180250289Sluigi # XXX do we need any of these ? 181229511Sluigi eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV` 182229511Sluigi [ ${o_arch} != `uname -m` ] && \ 183229511Sluigi (cd ${l_objtree}; ln -s . ${o_arch}.${o_arch} || true ) 184190411Sluigi fi 18599946Sluigi ) 18699946Sluigi} 18799946Sluigi 188173602Sluigi# entry for 4.x and earlier trees 18984377Sluigicreate_includes_and_libraries() { 190127266Sluigi local e i 191127266Sluigi 19284377Sluigi log "create_includes_and_libraries() for ${SRC}" 19384377Sluigi # Optionally creates include directory and libraries. 194190378Sluigi mkdir -p ${l_usrtree}/include # the include directory... 19584377Sluigi mkdir -p ${l_usrtree}/share/misc # a few things go here 19684377Sluigi mkdir -p ${l_usrtree}/lib # libraries 19784377Sluigi mkdir -p ${l_usrtree}/sbin # some binaries 198127266Sluigi # override variables for ownershiip and destinations 199127266Sluigi # BINOWN:BINGRP are also used for include files 200127266Sluigi (cd ${SRC}; \ 201127266Sluigi BINOWN=`id -un` BINGRP=`id -gn` \ 202127266Sluigi DESTDIR=${l_usrtree}/.. \ 203127266Sluigi make -m ${SRC}/share/mk includes ) || fail $? includes 20492964Sru # Pick up the correct headers for libraries. 20592964Sru CFLAGS="-nostdinc -I${l_usrtree}/include" ; export CFLAGS 20684377Sluigi 20784377Sluigi (cd ${SRC} 20884377Sluigi # $e is the invocation of make with correct environment 209155136Sluigi # XXX check the NO* options below, maybe system dependent. 21084377Sluigi e="MAKEOBJDIRPREFIX=${l_objtree}/picobsd/libraries \ 211127266Sluigi BINOWN=`id -un` BINGRP=`id -gn` \ 212127266Sluigi DESTDIR=${l_usrtree}/.. \ 21386876Sluigi make -m ${SRC}/share/mk \ 214155136Sluigi -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG " 21592063Sluigi log "do a 'make obj' in a few places." 21692063Sluigi # This is very version-specific... The following works for 5.0 217158687Sphk for i in lib secure/lib gnu/lib \ 21884377Sluigi gnu/usr.bin/perl usr.bin/lex usr.sbin/config ; do 21984377Sluigi (cd ${i}; eval $e obj) 22084377Sluigi done 22192063Sluigi log "now make the static libraries" 222155136Sluigi eval $e -DNOPROFILE -DNOPIC libraries 22384377Sluigi (cd ${SRC}/usr.sbin/config 22484377Sluigi eval $e # build binary 22584377Sluigi eval $e install # install it 22684377Sluigi ) 22784377Sluigi ) || fail $? "libraries" 22884377Sluigi log "Libraries done" 22972770Sluigi} 23072770Sluigi 231190378Sluigi# set_type <the_type> [the_site] looks in user or system directories 232190378Sluigi# for the directory named as the first argument, reads the configuration 233190378Sluigi# files and sets variables according to the config. 234190378Sluigi# Also sets MY_TREE and BUILDDIR and SITE 23572770Sluigi 236190378Sluigiset_type() { # the_type the_site 237127266Sluigi local a i 23884377Sluigi 239173602Sluigi log "set_type() : Type '$1' site '$2'" 24084377Sluigi THETYPE=$1 24184377Sluigi SITE=$2 24272770Sluigi a=$1 243173602Sluigi name="" # clear in case of errors 24484377Sluigi for i in ${c_startdir}/${a} ${PICO_TREE}/${a} ; do 24578494Sluigi log "set_type: checking $i" 246229511Sluigi [ -d $i -a -f $i/crunch.conf ] || continue 247229511Sluigi # look for a kernel config file, privilege arch-specific 248229511Sluigi l_kernconf=$i/PICOBSD.${o_arch} 249229511Sluigi [ -f $l_kernconf ] || l_kernconf=$i/PICOBSD 250229511Sluigi [ -f $l_kernconf ] || continue 251229511Sluigi set -- `cat $l_kernconf | \ 25272770Sluigi awk '/^#PicoBSD/ {print $2, $3, $4, $5, $6}'` 253173602Sluigi [ x"$1" != "x" ] || continue 254229511Sluigi MFS_SIZE=$1 255173602Sluigi name=`(cd $i ; pwd) ` 256173602Sluigi name=`basename $name` 257173602Sluigi MY_TREE=$i 258229511Sluigi BUILDDIR=${c_startdir}/build_dir-${name}-${o_arch} 259173602Sluigi log "Matching file $name in $i" 260173602Sluigi return ; 26172770Sluigi done 262173602Sluigi logverbose "Type $a NOT FOUND" 26372770Sluigi} 26472770Sluigi 26572770Sluigiclean_tree() { 26684377Sluigi log "clean_tree()" 267190411Sluigi if [ -z "${name}" ] ; then 26884377Sluigi echo "---> Wrong floppy type" 26972770Sluigi exit 3 27072770Sluigi fi 27172770Sluigi rm -rf ${BUILDDIR} 27272770Sluigi} 27372770Sluigi 27472770Sluigi# prepare a message to be printed in the dialog menus. 27572770Sluigiset_msgs() { # OK 27684377Sluigi log "set_msgs()" 27784377Sluigi 27872770Sluigi MSG1="Type: ${THETYPE} name $name" 27972770Sluigi 28072770Sluigi MSG="PicoBSD build -- Current parameters:\n\n\t1. ${MSG1}\n\ 28172770Sluigi\t2. MFS size: ${MFS_SIZE} kB\n\ 28272770Sluigi\t3. Site-info: ${SITE}\n\t4. Full-path: ${MY_TREE}\n" 28372770Sluigi} 28472770Sluigi 285194631Sluigi# Main build procedure. Builds both the disk image and the ISO 28672770Sluigibuild_image() { 28784377Sluigi log "build_image() <${name}>" 288190411Sluigi [ -n "${name}" ] || fail $? bad_type 28972770Sluigi clear 29072770Sluigi set_msgs 29184377Sluigi printf "${MSG}---> We'll use the sources living in ${SRC}\n\n" 29272770Sluigi 29384377Sluigi # read config variables from a global and then a type-specific file 29484377Sluigi # basically STAND_LINKS and MY_DEVS, but can also override other 29584377Sluigi # variables. 29684377Sluigi # 29784377Sluigi . ${PICO_TREE}/build/config 298190411Sluigi [ -f "${MY_TREE}/config" ] && . ${MY_TREE}/config 299190411Sluigi [ -f "${o_additional_config}" ] && . ${o_additional_config} 30084377Sluigi 30184377Sluigi # location of the object directory 30284377Sluigi PICO_OBJ=${l_objtree}/picobsd/${THETYPE} 30384377Sluigi log "PICO_OBJ is ${PICO_OBJ}" 30484377Sluigi 30584377Sluigi # create build directory and subtree 30684377Sluigi mkdir -p ${BUILDDIR}/crunch 30784377Sluigi # remove any old stuff 30884377Sluigi rm -f ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs} 30984377Sluigi # invoke commands to build a kernel 31072770Sluigi do_kernel 31184377Sluigi # fill a subdirectory with things that go into the floppy 31284377Sluigi # (mostly /etc and similar stuff) 31384377Sluigi populate_floppy_fs 31484377Sluigi # populate it and produce a file with the MFS image 31584377Sluigi populate_mfs_tree # things which go into mfs 31684377Sluigi # create, mount and fill a filesystem with floppy image 31772770Sluigi fill_floppy_image # copies everything into the floppy 31872770Sluigi} 31972770Sluigi 32072770Sluigi# Set build parameters interactively 32172770Sluigi 32272770Sluigimain_dialog() { 32384377Sluigi local ans i l 32484377Sluigi 32584377Sluigi log "main_dialog()" 326190411Sluigi while true ; do 32772770Sluigi set_msgs 32884377Sluigi rm ${c_reply} 32984377Sluigi dialog --menu "PicoBSD build menu -- (29 sep 2001)" 19 70 12 \ 33072770Sluigi N "--> READY, build it <---" \ 33172770Sluigi T "${MSG1}" \ 33272770Sluigi K "edit Kernel config file" \ 33372770Sluigi E "Edit crunch.conf file" \ 33472770Sluigi S "MFS Size: ${MFS_SIZE}kB" \ 33584377Sluigi F "Floppy size: ${fd_size}kB" \ 33672770Sluigi $ "Site-info: ${SITE}" \ 33772770Sluigi Q "Quit" \ 33884377Sluigi 2> ${c_reply} 33984377Sluigi ans=`cat ${c_reply}` 34084377Sluigi rm ${c_reply} 34172770Sluigi case ${ans} in 34272770Sluigi T) 34372770Sluigi l="" 34484377Sluigi for i in ${c_startdir} ${c_startdir}/* ${PICO_TREE}/* ; do 34572770Sluigi if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ]; then 34672770Sluigi l="$l `basename $i` `basename $i`" 34772770Sluigi fi 34872770Sluigi done 34972770Sluigi log $l 35090659Sluigi { dialog --menu "Setup the type of configuration" 12 70 5 $l \ 35190659Sluigi 2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ; } || true 35272770Sluigi ;; 35372770Sluigi 35472770Sluigi K) ${EDITOR} ${MY_TREE}/PICOBSD ;; 35572770Sluigi 35672770Sluigi E) ${EDITOR} ${MY_TREE}/crunch.conf ;; 35772770Sluigi 35872770Sluigi S) 35990659Sluigi { dialog --title "MFS Size setup" --inputbox \ 36072770Sluigi"MFS size depends on what you need to put on the MFS image. Typically \ 36172770Sluigiranges between 820kB (for very small bridge/router images) to \ 36272770Sluigias much as 2500kB kB for a densely packed image. \ 36372770SluigiKeep in mind that this memory is \ 36472770Sluigitotally lost to other programs. Usually you want to keep \ 36584377Sluigithis as small as possible. " 10 70 2> ${c_reply} \ 36690659Sluigi && MFS_SIZE=`cat ${c_reply}` ; } || true 36772770Sluigi ;; 36872770Sluigi 36972770Sluigi \$) 37090659Sluigi { dialog --title "Site info setup" --inputbox \ 37172770Sluigi "Please enter the full path to the directory \ 37272770Sluigi containing site-specific setup. \ 37372770Sluigi This directory tree must contain files that replace \ 37472770Sluigi standard ones in floppy.tree/ and mfs.tree/ . " \ 37590659Sluigi 10 70 2> ${c_reply} && SITE=`cat ${c_reply}` ; } || true 37672770Sluigi ;; 37772770Sluigi 37872770Sluigi F) 37991846Sluigi { dialog --menu "Set floppy size" 15 70 4 \ 38084377Sluigi 1440 "1.44MB" 1720 "1.72MB" 2880 "2.88MB" 4096 "4MB" \ 38191846Sluigi 2> ${c_reply} && fd_size=`cat ${c_reply}` ; } || true 38272770Sluigi ;; 38372770Sluigi 38472770Sluigi N) break 2 38572770Sluigi ;; 38672770Sluigi 38772770Sluigi Q) exit 0 ;; 38872770Sluigi 38972770Sluigi *) echo "Unknown option \"${ans}\". Try again." 39072770Sluigi sleep 2 39172770Sluigi clear 39272770Sluigi ;; 39372770Sluigi esac 39472770Sluigi done 39572770Sluigi} 39672770Sluigi 39772770Sluigi# Call the build procedure 39872770Sluigi# Install image 39972770Sluigido_install() { 40084377Sluigi log "do_install()" 40184377Sluigi 40285833Sluigi if [ "${o_interactive}" = "NO" ] ; then 40385833Sluigi echo "+++ Build completed +++" 404155136Sluigi cat .build.reply || true 40585833Sluigi return 40685833Sluigi fi 40782747Sluigi dialog --title "Build ${THETYPE} completed" --inputbox \ 40872770Sluigi"\nThe build process was completed successfuly.\n\ 40972770Sluigi`cat .build.reply` \n\n\ 41072770SluigiNow we are going to install the image on the floppy.\n\ 41172770SluigiPlease insert a blank floppy in /dev/fd0.\\n 41272770SluigiWARNING: the contents of the floppy will be permanently erased!\n\ 41372770Sluigi\n\ 41472770SluigiYour options:\n\ 41572770Sluigi * ^C or [Cancel] to abort,\n\ 41684377Sluigi * Enter to install ${c_img},\n\ 41784377Sluigi" 20 80 2> ${c_reply} 41872770Sluigi if [ "$?" = "0" ]; then 41984377Sluigi echo "Writing ${c_img}..." 42084377Sluigi dd if=${BUILDDIR}/${c_img} of=/dev/fd0.${fd_size} 42172770Sluigi else 42284377Sluigi echo "Ok, the image is in ${c_img}" 42372770Sluigi fi 42472770Sluigi echo "Done." 42572770Sluigi} 42672770Sluigi 42772770Sluigi 42872770Sluigi#------------------------------------------------------------------- 42972770Sluigi 430173602Sluigi# invoke the picobsd Makefile to compile the kernel. 431173602Sluigi# if MODULES is set (value is irrelevant) the makefile will build modules. 43272770Sluigido_kernel() { # OK 43384377Sluigi log "do_kernel() Preparing kernel \"$name\" in $MY_TREE" 43499946Sluigi (cd $MY_TREE; export name SRC BUILDDIR # used in this makefile ; 43599946Sluigi # export CONFIG 436227878Sluigi export WARNS CWARNFLAGS 437173602Sluigi [ "${o_do_modules}" = "yes" ] && export MODULES="" 438250289Sluigi # kernel build not parallelizable yet 439250289Sluigi ${BINMAKE} KERNCONF=${l_kernconf} \ 440229511Sluigi -v -f ${PICO_TREE}/build/Makefile.conf ) || \ 441229511Sluigi fail $? missing_kernel 44272770Sluigi} 44372770Sluigi 44484377Sluigi# Populate the variable part of the floppy filesystem. Must be done before 44584377Sluigi# the MFS because its content might need to be copied there as well. 44672770Sluigi# 44784377Sluigi# This involves fetching files from three subtrees, in this order: 44872770Sluigi# 44984377Sluigi# 1. a standard one, from which type-specific files are excluded; 45072770Sluigi# 2. a type-specific one; 45172770Sluigi# 3. a site-specific one. 45272770Sluigi# 45372770Sluigi# Files are first copied to a local tree and then compressed. 45472770Sluigi 45572770Sluigipopulate_floppy_fs() { # OK 45683692Sluigi local dst excl srcdir 45772770Sluigi 45884377Sluigi log "populate_floppy_fs()" 45972770Sluigi dst=${BUILDDIR}/floppy.tree 46084377Sluigi log "pwd=`pwd` Populating floppy filesystem..." 46172770Sluigi 462188835Sluigi rm -rf ${dst} || true # clean relics from old compilations. 463188835Sluigi mkdir ${dst} # create a clean tree 46472770Sluigi 465188835Sluigi # compute exclude list for generic tree 46672770Sluigi excl=${MY_TREE}/floppy.tree.exclude 46772770Sluigi if [ -f ${excl} ] ; then 468173597Sluigi log "Files excluded from generic tree: `echo;cat ${excl}`" 46972770Sluigi excl="--exclude-from ${excl}" 47072770Sluigi else 47172770Sluigi excl="" 47272770Sluigi fi 473188835Sluigi # copy from the floppy trees into the destination 474188835Sluigi for FLOPPY_TREE in ${PICO_TREE}/floppy.tree ${MY_TREE}/floppy.tree \ 475188835Sluigi ${MY_TREE}/floppy.tree.${SITE} ; do 476188835Sluigi if [ -d ${FLOPPY_TREE} ] ; then 477188835Sluigi (cd ${FLOPPY_TREE} ; tar -cf - --exclude CVS \ 478188835Sluigi --exclude .svn ${excl} . ) | \ 47984377Sluigi (cd ${dst} ; tar x${o_tarv}f - ) 480188835Sluigi log "Copied from ${FLOPPY_TREE}" 481188835Sluigi fi 482188835Sluigi excl="" # reset the exclude list. 483188835Sluigi done 48472770Sluigi 485188835Sluigi # add local manipulation 486188835Sluigi if [ -f ${MY_TREE}/buildtree.mk ] ; then 487188835Sluigi log "building local floppy tree" 488188835Sluigi ${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk floppy.tree 48972770Sluigi fi 490188835Sluigi 491188835Sluigi # compress the files in etc/, just in case 492188835Sluigi # XXX this should be done in the makefile. 49372770Sluigi # gzip returns an error if it fails to compress some file 49484377Sluigi (cd $dst ; gzip -9 etc/* 49584377Sluigi log "Compressed files in etc/ `echo; ls -l etc`" 49672770Sluigi ) || true 49772770Sluigi} 49872770Sluigi 499189978Sluigi# Copy the specified files to the destination filesystem. 500189978Sluigi# Each file is specified as a pair "src dst", dst is assumed to be 501189978Sluigi# a directory (and created with mkdir -p) if it has a trailing / 502189978Sluigi# Be careful to escape metacharacters. 503189978Sluigi# You can use ${CROSS} to point to the root of the cross build 504189978Sluigi# (remember that it might be incomplete) 505189978Sluigi 506189978Sluigido_copyfiles() { # rootdir varname 507189978Sluigi log Copy files to $1 508189978Sluigi local root=$1 509189978Sluigi local srcs dst 510189978Sluigi local CROSS=${_SHLIBDIRPREFIX} 511189978Sluigi eval set "\${${2}}" 512189978Sluigi srcs="" 513189978Sluigi for dst in $* ; do 514190411Sluigi [ -z "$srcs" ] && srcs=$dst && continue 515189978Sluigi eval srcs="$srcs" # expand wildcard and vars 516189978Sluigi case x"$dst" in 517189978Sluigi */ ) mkdir -p ${root}/${dst} ;; 518189978Sluigi # * ) mkdir -p `dirname ${root}/${dst}` ;; 519189978Sluigi esac 520189978Sluigi cp -p ${srcs} ${root}/${dst} || true 521189978Sluigi srcs="" 522189978Sluigi done 523189978Sluigi} 524189978Sluigi 525190411Sluigi# do_links is a helper function to create links between programs 526190411Sluigi# in stand/ 527190411Sluigi# This is done reading the names and destination from variable 528190411Sluigi# links in a config file, in the format 529190411Sluigi# : dst names 530190411Sluigi 531190411Sluigido_links() { # rootdir varname 532190411Sluigi local root=$1 533190411Sluigi local l i dst 534190411Sluigi eval l="\${${2}}" 535190411Sluigi dst="" 536190411Sluigi log "Create links for ${l}" 537190411Sluigi (cd ${root}/stand 538190411Sluigi for i in $l ; do 539190411Sluigi if [ "$dst" = ":" -o "$i" = ":" ] ; then 540190411Sluigi dst=$i 541190411Sluigi elif [ -n "${dst}" ] ; then 542190411Sluigi ln -s ${dst} ${i} 543190411Sluigi fi 544190411Sluigi done 545190411Sluigi ) 546190411Sluigi} 547190411Sluigi 548190383Sluigi# find_progs is a helper function to locate the named programs 549190411Sluigi# or libraries in ${o_objdir} or ${_SHLIBDIRPREFIX}, 550190411Sluigi# and return the full pathnames. 551229532Sluigi# Called as "find_progs [[-L libpath] [-P binpath]] prog1 prog2 ... " 552201072Sluigi# On return it sets ${u_progs} to the list of programs, and ${u_libs} 553190383Sluigi# to the list of shared libraries used. 554201072Sluigi# 555201072Sluigi# '-L path' can be used to specify a search path for libraries 556201072Sluigi# (which searches in $path/lib:$path/usr/lib:$path/usr/local/lib 557201072Sluigi# '-P binpath' can be used to specify a search path for programs 558201072Sluigi# (which searches in a lot of places in the subtree) 559201072Sluigi# -L must be the first, followed by -P 560190383Sluigi# 561201072Sluigi# You can use it e.g. in a local confign file by writing 562190383Sluigi# 563190383Sluigi# do_copyfiles_user() { 564190383Sluigi# local dst=$1 565190383Sluigi# find_progs nvi sed less grep 566190383Sluigi# cp -p ${u_progs} ${dst}/bin 567190383Sluigi# cp -p ${u_libs} ${dst}/lib 568190383Sluigi# mkdir -p ${dst}/libexec 569190383Sluigi# find_progs ld-elf.so.1 570201072Sluigi# cp -p ${u_progs} ${dst}/libexec # ignore errors 571190383Sluigi# } 572190383Sluigi 573190383Sluigifind_progs() { # programs 574229532Sluigi local pass i old_libs="" tmp o="" 575201072Sluigi if [ x"$1" = "x-L" -a -d "$2" ] ; then # set lib search path 576229532Sluigi o="-P $2"; shift; shift 577201072Sluigi fi 578229532Sluigi # Result returned in global variables 579229532Sluigi u_libs="" ; u_progs="`find_progs_helper $*`" 580190383Sluigi [ -z "${u_progs}" ] && return 1 # not found, error 581229532Sluigi # use objdump to find libraries. Iterate to fetch recursive 582229532Sluigi # dependencies. 583229532Sluigi tmp="${u_progs}" ; pass=1 584229532Sluigi while [ $pass -lt 10 ] ; do 585229532Sluigi pass=$(($pass + 1)) 586229532Sluigi i="`objdump -x ${tmp} | \ 587229532Sluigi awk '$1 == "NEEDED" { print $2 }' | sort | uniq`" 588229532Sluigi if [ "$old_libs" = "$i" ] ; then 589229532Sluigi log "libraries for: $my_progs ($u_progs) are ($i) $u_libs" 590229532Sluigi log "--- done find_progs ---" 591229532Sluigi return 0 592229532Sluigi else 593229532Sluigi # logverbose "old--- $old_libs --- new +++ $i +++" 594229532Sluigi fi 595229532Sluigi u_libs="`find_progs_helper $o $i`" 596229532Sluigi old_libs="$i" 597229532Sluigi tmp="$tmp $u_libs" 598229532Sluigi done 599229532Sluigi log "WARNING: Too many passes, giving up" 600190383Sluigi} 601190383Sluigi 602190383Sluigifind_progs_helper() { # programs 603201072Sluigi local dir=${o_objdir:-${_SHLIBDIRPREFIX}/..} 604201072Sluigi local ldir="" 605201072Sluigi if [ x"$1" = "x-P" -a -d "$2" ] ; then # set path 606201072Sluigi ldir=$2; shift; shift 607201072Sluigi fi 608190383Sluigi local progs="$*" 609201072Sluigi local subdirs=". local/bin local/sbin local/lib local/libexec \ 610201072Sluigi bin sbin usr.bin usr.sbin libexec lib \ 611190383Sluigi gnu/usr.bin gnu/lib \ 612190383Sluigi secure/usr.bin secure/usr.sbin secure/libexec secure/lib" 613201072Sluigi local names="" # files to search 614201072Sluigi local o="" 615201072Sluigi local i 616190383Sluigi for i in $progs ; do 617201072Sluigi # full pathnames are just listed 618190411Sluigi [ -f "$i" ] && echo $i && continue 619190383Sluigi names="${names} ${o} -name $i" 620190383Sluigi o="-o" 621190383Sluigi done 622190411Sluigi [ -z "${names}" ] && return 0 623201072Sluigi local places="" # places to search 624190383Sluigi for i in $subdirs ; do 625201072Sluigi [ -d "${dir}/${i}" ] && places="${places} ${dir}/${i}" 626190383Sluigi done 627201072Sluigi if [ -n "${ldir}" ] ; then 628201072Sluigi for i in $subdirs ; do 629201072Sluigi [ -d "${ldir}/${i}" ] && places="${places} ${ldir}/${i}" 630201072Sluigi done 631201072Sluigi fi 632229511Sluigi for i in $progs ; do 633229511Sluigi # full pathnames are just listed 634229511Sluigi [ -f "$i" ] && echo $i && continue 635229511Sluigi find ${places} -maxdepth 3 -type f -name ${i} | head -1 636229511Sluigi done 637201072Sluigi # use maxdepth 3 because some libs are way down 638190383Sluigi} 639190411Sluigi 64072770Sluigi# Populate the memory filesystem with binaries and non-variable 64172770Sluigi# configuration files. 64272770Sluigi# First do an mtree pass, then create directory links and device entries, 64372770Sluigi# then run crunchgen etc. to build the binary and create links. 64472770Sluigi# Then copy the specific/generic mfs_tree. 64572770Sluigi# Finally, if required, make a copy of the floppy.tree onto /fd 64672770Sluigi 64784377Sluigipopulate_mfs_tree() { 648189978Sluigi local i j a dst MFS_TREE 64972770Sluigi 65084377Sluigi log "populate_mfs_tree()" 651155136Sluigi dst=${BUILDDIR}/mfs.tree 652188835Sluigi rm -rf ${dst} || true # clean relics from old compilations. 653188835Sluigi mkdir ${dst} # create a fresh tree 65472770Sluigi 65584377Sluigi log "pwd=`pwd`, Populating MFS tree..." 65684377Sluigi 65784377Sluigi # use type-specific mfs.mtree, default to generic one. 65884377Sluigi a=${MY_TREE}/mfs.mtree 65984377Sluigi [ -f ${a} ] || a=${PICO_TREE}/build/mfs.mtree 66084377Sluigi log "Running mtree using $a..." 66184377Sluigi mtree -deU -f $a -p ${dst} > /dev/null || fail $? mtree 66284377Sluigi 663189978Sluigi # Create symlinks using relative pathnames, so it is possible 664189978Sluigi # to follow them also when building the image. 665189978Sluigi # Note that names in STAND_LINKS should not have a leading / 66672770Sluigi for i in ${STAND_LINKS}; do 667189978Sluigi j=`echo $i | sed -E 's:^[^/]+::;s:/[^/]+:../:g'` 668189978Sluigi ln -s ${j}stand ${dst}/$i 66972770Sluigi done 670189978Sluigi ln -s ../../dev/null ${dst}/var/run/log 671189978Sluigi ln -s ../../../etc/termcap ${dst}/usr/share/misc/termcap 67272770Sluigi 673188835Sluigi ### now build the crunched binaries ### 67472770Sluigi ( 67572770Sluigi cd ${BUILDDIR}/crunch 67684377Sluigi log "Making and installing crunch1 from `pwd` src ${SRC}..." 67772770Sluigi a=${BUILDDIR}/crunch1.conf 67878541Sluigi ( export BUILDDIR SRC MY_TREE PICO_OBJ ; 679173597Sluigi ${BINMAKE} \ 68086876Sluigi -v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk ) 68184377Sluigi log "Libs are ${LIBS} " 68299946Sluigi export SRC # used by crunch.mk 68399946Sluigi # export LIBS CFLAGS 68472770Sluigi log "Now make -f crunch.mk" 685173597Sluigi ${BINMAKE} ${o_makeopts} -f ${BUILDDIR}/crunch.mk 68672770Sluigi strip --remove-section=.note --remove-section=.comment crunch1 68784377Sluigi mv crunch1 ${dst}/stand/crunch 68884377Sluigi chmod 555 ${dst}/stand/crunch 68984377Sluigi log "Making links for binaries..." 69072770Sluigi for i in `crunchgen -l $a` ; do 69184377Sluigi ln ${dst}/stand/crunch ${dst}/stand/${i}; 69272770Sluigi done 69378541Sluigi # rm $a # do not remove! 69472770Sluigi ) || fail $? crunch 69572770Sluigi 69684377Sluigi if [ -f ${dst}/stand/sshd ] ; then 69792063Sluigi log "Setting up host key for sshd:" 69892063Sluigi if [ -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key.gz ] ; then 69984627Sluigi log "Using existing host key" 70084627Sluigi else 70192063Sluigi log "Generating new host key" 702127266Sluigi ssh-keygen -t rsa1 -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key \ 70392063Sluigi -N "" -C "root@picobsd" 70492063Sluigi gzip -9 ${BUILDDIR}/floppy.tree/etc/ssh_host_key* || true 70584627Sluigi fi 70672770Sluigi fi 70772770Sluigi 70891846Sluigi log "Copy generic and site-specific MFS tree..." 70991846Sluigi for MFS_TREE in ${PICO_TREE}/mfs_tree ${MY_TREE}/mfs_tree ; do 71091846Sluigi if [ -d ${MFS_TREE} ] ; then 71191846Sluigi log "Copy ${MFS_TREE} ..." 712180012Sru (cd ${MFS_TREE} ; tar -cf - --exclude CVS --exclude .svn . ) | \ 71392063Sluigi (cd ${dst} ; tar x${o_tarv}f - ) 71491846Sluigi fi 71591846Sluigi done 71672770Sluigi 717188835Sluigi if [ -f ${MY_TREE}/buildtree.mk ] ; then 718188835Sluigi log "building local floppy tree" 719188835Sluigi ${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk mfs.tree 720188835Sluigi fi 721188835Sluigi 72284377Sluigi if [ "${o_all_in_mfs}" = "yes" ]; then 72384377Sluigi log "Copy generic floppy_tree into MFS..." 724188835Sluigi # ignore failure in case the floppy is empty 725155136Sluigi cp -Rp ${BUILDDIR}/floppy.tree/* ${dst}/fd || true 72672770Sluigi fi 72784377Sluigi 728188835Sluigi # 4.x compatibility - create device nodes 729190411Sluigi if [ -n "${o_no_devfs}" ] ; then 73084377Sluigi # create device entries using MAKEDEV 73184377Sluigi (cd ${dst}/dev 732155136Sluigi ln -s ${SRC}/etc/MAKEDEV ; chmod 555 MAKEDEV 733155136Sluigi # log `pwd` 734155136Sluigi sh ./MAKEDEV ${MY_DEVS} 73584377Sluigi rm MAKEDEV 73684377Sluigi ) 73784377Sluigi fi 738155136Sluigi if [ "`id -u`" = "0" ] ; then 739155136Sluigi log "Fixing permissions" 740155136Sluigi (cd ${dst}; chown -R root . ) 741155136Sluigi fi 74284377Sluigi 743200301Sluigi log "for a shared 'crunch' take libraries and dynamic loader as well" 744190411Sluigi find_progs ${dst}/stand/crunch 745190411Sluigi if [ -n "${u_libs}" ] ; then 746190411Sluigi mkdir -p ${dst}/lib && cp -p ${u_libs} ${dst}/lib 747190411Sluigi mkdir -p ${dst}/libexec 748190411Sluigi create_includes_and_libraries2 libexec/rtld-elf 749190411Sluigi find_progs ld-elf.so.1 && cp -p ${u_progs} ${dst}/libexec 750189978Sluigi fi 751190411Sluigi 752190411Sluigi [ -n "${copy_files}" ] && do_copyfiles ${dst} copy_files 753190378Sluigi do_copyfiles_user ${dst} || true 754190411Sluigi [ -n "${links}" ] && do_links ${dst} links 755190411Sluigi strip ${dst}/libexec/* ${dst}/lib/* ${dst}/stand/* 2> /dev/null || true 756189978Sluigi 757189978Sluigi # The 'import_files' mechanism is deprecated, as it requires 758189978Sluigi # root permissions to follow the symlinks, and also does 759189978Sluigi # not let you rename the entries. 76092853Sluigi if [ -n "${import_files}" ] ; then 76192853Sluigi log "importing ${import_files} into mfs" 76292853Sluigi # We do it in a chroot environment on the target so 76392853Sluigi # symlinks are followed correctly. 764188835Sluigi # Make sure we have a statically linked tar there. 765188835Sluigi mkdir -p ${dst}/rescue 766188835Sluigi cp /rescue/tar ${dst}/rescue 76792853Sluigi (cd ${l_usrtree}/.. ; tar cf - ${import_files} ) | \ 768188835Sluigi (chroot ${dst} /rescue/tar xPf - ) 769188835Sluigi rm -rf ${dst}/rescue 77092853Sluigi fi 77192853Sluigi 772189978Sluigi # final step -- build the mfs image 773155136Sluigi (cd ${BUILDDIR} 774155136Sluigi # override the owner 775155136Sluigi echo "/set uid=0 gid=0" > mtree.out 776188835Sluigi mtree -ic -p ${dst} -k "" >> mtree.out 777155136Sluigi log "mtre.out at ${BUILDDIR}/mtree.out" 778155136Sluigi makefs -t ffs -o bsize=4096 -o fsize=512 \ 779188835Sluigi -s ${MFS_SIZE}k -f 1000 -F mtree.out ${c_fs} ${dst} 780155136Sluigi ls -l ${c_fs} ) 781155136Sluigi log "done mfs image" 78272770Sluigi} 78372770Sluigi 78472770Sluigifinal_cleanup() { 78584377Sluigi log "final_cleanup()" 78684377Sluigi rm -rf ${c_mnt} ${c_reply} 2> /dev/null || true 78772770Sluigi} 78872770Sluigi 78972770Sluigi# fail errno errcode 79072770Sluigi# This function is used to trap errors and print msgs 79172770Sluigi# 79272770Sluigifail() { 79384377Sluigi local errno errocode where 79484377Sluigi 79572770Sluigi errno=$1 79672770Sluigi errcode=$2 79784377Sluigi where=$3 79884377Sluigi echo "---> fail: Error <${errno}> error code <${errcode}> in <${where}>" 79984377Sluigi case ${errcode} in 80072770Sluigi mtree) 80184377Sluigi echo "Error while making hierarchy in ${c_mnt}" 80272770Sluigi ;; 80372770Sluigi crunch) 80472770Sluigi echo "Error while building ${name}." 80572770Sluigi ;; 80672770Sluigi missing_kernel) 80775880Sjoe echo "Error: you must build PICOBSD${suffix} kernel first" 80872770Sluigi ;; 80982917Sluigi includes) 81082917Sluigi echo "Error: failed while making includes" 81182917Sluigi ;; 81282917Sluigi libraries) 81382917Sluigi echo "Error: failed while making libraries" 81482917Sluigi ;; 81584377Sluigi bad_type) 81684377Sluigi echo "Error: unknown floppy type ${name}" 81784377Sluigi ;; 81884377Sluigi no_space) 81984377Sluigi echo "Error: no space left on device (${where})" 82084377Sluigi ;; 82192853Sluigi no_mfs) 82292853Sluigi echo "Error: while writing MFS into the kernel." 82392853Sluigi ;; 82472770Sluigi "") 82572770Sluigi echo "User break" 82684377Sluigi errcode="userbreak" 82772770Sluigi ;; 82872770Sluigi *) 82972770Sluigi echo "unknown error, maybe user break: $errno $errcode" 83072770Sluigi ;; 83172770Sluigi esac 83272770Sluigi echo "---> Aborting $0" 83372770Sluigi # try to cleanup the vnode. 83472770Sluigi final_cleanup 83572770Sluigi exit 2 83672770Sluigi} 83772770Sluigi 83872770Sluigifill_floppy_image() { 839155136Sluigi local blocks dst mfs_start mfs_end mfs_size img_size 84072770Sluigi 84184377Sluigi log "fill_floppy_image()" 84284377Sluigi dst=${c_mnt} # where to create the image 84384377Sluigi 84484377Sluigi log "Preparing ${fd_size}kB floppy filesystem..." 84584377Sluigi 846155136Sluigi # correct blocks according to size. 847155136Sluigi blocks=${fd_size}; 84872770Sluigi if [ "${blocks}" = "1720" ]; then 849155136Sluigi blocks=1722 85072770Sluigi elif [ "${blocks}" = "1480" ]; then 851155136Sluigi blocks=1476 85272770Sluigi fi 85372770Sluigi 85484377Sluigi log "Labeling floppy image" 855155136Sluigi 856155136Sluigi dst=${BUILDDIR}/image.tree 857155136Sluigi rm -rf ${dst} 858155136Sluigi mkdir -p ${dst} 85972770Sluigi ( 86072770Sluigi cd ${BUILDDIR} 861155136Sluigi set 0 0 # reset variables 86299946Sluigi # $1 takes the offset of the MFS filesystem 86399946Sluigi set `strings -at d kernel | grep "MFS Filesystem goes here"` 864155136Sluigi mfs_start=$1 865155136Sluigi set 0 0 # reset variables 866155136Sluigi set `strings -at d kernel | grep "MFS Filesystem had better"` 867155136Sluigi mfs_end=$1 868155136Sluigi mfs_size="$((${mfs_end} - ${mfs_start}))" 869155136Sluigi set -- `ls -l ${c_fs}`; imgsize="$5" 870155136Sluigi if [ ${mfs_start} -gt 0 -a ${mfs_size} -ge ${imgsize} ] ; then 871155136Sluigi mfs_ofs=$((${mfs_start} + 8192)) 872155136Sluigi log "Preload kernel with file ${c_fs} at ${mfs_ofs}" 873203877Sluigi log "`ls -l ${c_fs}` to fit in ${mfs_size}" 874155136Sluigi dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \ 875188835Sluigi oseek=1 conv=notrunc # 2> /dev/null 876155136Sluigi else 877155136Sluigi log "not loading mfs, size ${mfs_size} img ${imgsize}" 878155136Sluigi fi 87984377Sluigi log "Compress with kgzip and copy to floppy image" 88072770Sluigi 881229511Sluigi mkdir -p ${dst}/boot/kernel 882234983Sluigi # XXX loader.conf does not work unless we also load the .4th files 883229511Sluigi echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf 884229511Sluigi echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf 885229511Sluigi cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader" 886229511Sluigi gzip -c kernel > ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel" 887229511Sluigi 88872770Sluigi # now transfer the floppy tree. If it is already in mfs, dont bother. 88984377Sluigi if [ "${o_all_in_mfs}" != "yes" ] ; then 890188835Sluigi log "Now transfer floppy tree if not already in MFS image" 89184377Sluigi cp -Rp floppy.tree/* ${dst} || \ 89284377Sluigi fail $? no_space "copying floppy tree" 89372770Sluigi fi 89472770Sluigi ) 895188835Sluigi 896188835Sluigi # add local manipulation to the image 897188835Sluigi if [ -f ${MY_TREE}/buildtree.mk ] ; then 898188835Sluigi ${BINMAKE} -C ${dst} -f ${MY_TREE}/buildtree.mk image.tree 899188835Sluigi fi 900188835Sluigi 901188835Sluigi log "image used `du -s ${dst}` of ${blocks}k" 902194631Sluigi if [ "${generate_iso}" = "YES" ]; then 903194631Sluigi logverbose "generate_iso ${generate_iso}" 904194631Sluigi # build_iso_image # XXX not implemented yet 905194631Sluigi (cd ${BUILDDIR} 906194631Sluigi cp -p /boot/cdboot ${dst}/boot || fail $? no_space "copying cdboot" 907194631Sluigi mkisofs -b boot/cdboot -no-emul-boot -J -r -ldots -l -L \ 908194631Sluigi -o ${c_iso} ${dst} 909194631Sluigi ) 910194631Sluigi fi 911194631Sluigi 912155136Sluigi (cd ${BUILDDIR} 913155136Sluigi makefs -t ffs -o bsize=4096 -o fsize=512 \ 914155136Sluigi -s ${blocks}k -f 50 ${c_img} ${dst} 915190378Sluigi 916190378Sluigi ${c_label} -w -f `pwd`/${c_img} auto # write in a label 917155136Sluigi # copy partition c: into a: with some sed magic 918190378Sluigi ${c_label} -f `pwd`/${c_img} | sed -e '/ c:/{p;s/c:/a:/;}' | \ 919190378Sluigi ${c_label} -R -f `pwd`/${c_img} /dev/stdin 920190378Sluigi ${c_label} -f `pwd`/${c_img} 921188835Sluigi 922155136Sluigi ls -l ${c_img} 923190378Sluigi ${c_label} -f `pwd`/${c_img} 924203877Sluigi log "after disklabel" 925188835Sluigi ) 926188835Sluigi 927188835Sluigi echo "BUILDDIR ${BUILDDIR}" 928188835Sluigi 929155136Sluigi # dump the primary and secondary boot 930155136Sluigi # XXX primary is 512 bytes 931155136Sluigi dd if=${c_boot1} of=${BUILDDIR}/${c_img} conv=notrunc 2>/dev/null 932155136Sluigi # XXX secondary starts after the 0x114 = dec 276 bytes of the label 933155136Sluigi # so we skip 276 from the source, and 276+512=788 from dst 934155136Sluigi # the old style blocks used 512 and 1024 respectively 93572770Sluigi 936229511Sluigi dd if=${c_boot2} iseek=1 ibs=276 2> /dev/null | \ 937155136Sluigi dd of=${BUILDDIR}/${c_img} oseek=1 obs=788 conv=notrunc 2>/dev/null 938203877Sluigi log "done disk image" 939155136Sluigi # XXX (log "Fixing permissions"; cd ${dst}; chown -R root *) 940229511Sluigi # leave build stuff if verbose 941229511Sluigi [ ${o_verbose} -gt 0 ] && return 942229511Sluigi 943155136Sluigi rm -rf ${BUILDDIR}/floppy.tree || true # cleanup 944155136Sluigi # df -ik ${dst} | colrm 70 > .build.reply 94584377Sluigi rm -rf ${dst} 946188835Sluigi rm ${BUILDDIR}/${c_fs} 947188835Sluigi # rm ${BUILDDIR}/kernel.gz 94872770Sluigi} 94972770Sluigi 95084377Sluigi# This function creates variables which depend on the source tree in use: 95199946Sluigi# SRC, l_usrtree, l_objtree 95284377Sluigi# Optionally creates libraries, includes and the like (for cross compiles, 95384377Sluigi# needs to be done once). 95484377Sluigi 95584377Sluigiset_build_parameters() { 95684377Sluigi if [ "${SRC}" = "/usr/src" ] ; then 95784377Sluigi l_usrtree=${USR:-/usr} 95884377Sluigi else 95984377Sluigi l_usrtree=${USR:-${SRC}/../usr} 96084093Sluigi fi 961227878Sluigi l_objtree=${l_usrtree}/obj-pico-${o_arch} 962215177Sluigi 96384377Sluigi PICO_TREE=${PICO_TREE:-${SRC}/release/picobsd} 96499946Sluigi set `grep "#define[\t ]__FreeBSD_version" ${SRC}/sys/sys/param.h` 96599946Sluigi OSVERSION=$3 96699951Sluigi log "OSVERSION is ${OSVERSION}" 967215177Sluigi if [ ${OSVERSION} -ge 500035 ] ; then 968215177Sluigi export MAKEOBJDIRPREFIX=${l_objtree} 969227878Sluigi export TARGET_ARCH=${o_arch} TARGET=${o_arch} 970244642Sluigi export WITHOUT_CLANG_IS_CC=1 971229511Sluigi # XXX why change machine_arch ? 972229511Sluigi #-- export MACHINE_ARCH=`uname -m` MACHINE=`uname -m` 973227878Sluigi # export CWARNFLAGS="-Wextra -Wno-sign-compare -Wno-missing-field-initializers" 974215177Sluigi eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V BINMAKE`\"" 975255313Sluigi [ "$BINMAKE" = "" ] && \ 976255313Sluigi eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V SUB_MAKE`\"" 977215177Sluigi fi 978215177Sluigi 97984377Sluigi if [ "${o_init_src}" != "" ] ; then 98099946Sluigi if [ ${OSVERSION} -lt 500035 ] ; then 98199946Sluigi create_includes_and_libraries 98299946Sluigi else 98399946Sluigi create_includes_and_libraries2 98499946Sluigi fi 985229511Sluigi else 986229511Sluigi eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV` 98784093Sluigi fi 98899946Sluigi if [ ${OSVERSION} -lt 500035 ] ; then 98999946Sluigi # Create the right LIBS and CFLAGS for further builds. 99099946Sluigi # and build the config program 99199946Sluigi LIBS="-L${l_usrtree}/lib" 99299946Sluigi CFLAGS="-nostdinc -I${l_usrtree}/include" 99399946Sluigi export LIBS CFLAGS 99499946Sluigi CONFIG=${l_usrtree}/sbin/config 99599946Sluigi export CONFIG 99699946Sluigi fi 997190383Sluigi 998190383Sluigi # if we have o_objdir, find where bin/ is 999190383Sluigi if [ ! -z "${o_objdir}" ] ; then 1000190383Sluigi if [ -d ${o_objdir}/bin ] ; then 1001190383Sluigi # fine 1002190383Sluigi elif [ -d "${o_objdir}${SRC}/bin" ] ; then 1003190383Sluigi o_objdir="${o_objdir}${SRC}" 1004190383Sluigi log "Changing objdir to ${o_objdir}" 1005190383Sluigi else 1006190383Sluigi log "Cannot find objdir in ${o_objdir}, sorry" 1007190383Sluigi o_objdir="" 1008190383Sluigi fi 1009190383Sluigi fi 101084093Sluigi} 101184093Sluigi 101284377Sluigi#------------------------------------------------------------------- 101384377Sluigi# Main entry of the script. Initialize variables, parse command line 101484377Sluigi# arguments. 101584093Sluigi 1016218359Sluigi# o_par="-j 8" # parallel make and other make options 1017218359Sluigi 101884377Sluigiset_defaults 1019188835Sluigiwhile [ true ]; do 1020190383Sluigi log "Parsing $1" 102172770Sluigi case $1 in 1022229511Sluigi --par) 1023229511Sluigi o_par="-j 8" 1024229511Sluigi ;; 1025229511Sluigi 102678494Sluigi --src) # set the source path instead of /usr/src 1027190383Sluigi SRC=`realpath $2` 102884093Sluigi shift 102978494Sluigi ;; 1030229511Sluigi 1031229511Sluigi --init) # run a partial buildworld on the source tree 103284377Sluigi o_init_src="YES" 103384377Sluigi ;; 103482917Sluigi 1035229511Sluigi --arch) # override the target architecture 1036227878Sluigi o_arch=$2 1037227878Sluigi shift 1038227878Sluigi ;; 1039227878Sluigi 1040229511Sluigi --floppy_size) # image size 104184377Sluigi fd_size=$2 104272770Sluigi shift 104372770Sluigi ;; 104484377Sluigi 104584377Sluigi --all_in_mfs) 104684377Sluigi o_all_in_mfs="yes" 104784377Sluigi ;; 104884377Sluigi 104984377Sluigi --no_all_in_mfs) 1050188835Sluigi o_all_in_mfs="no" 105184377Sluigi ;; 105284377Sluigi 105385833Sluigi --modules) # also build kernel modules 105485833Sluigi o_do_modules="yes" 105585833Sluigi ;; 1056229511Sluigi 105772770Sluigi -n) 105884377Sluigi o_interactive="NO" 105972770Sluigi ;; 106084377Sluigi 106184377Sluigi -clear|-clean|-c) # clean 106284377Sluigi o_clean="YES" 106384377Sluigi o_interactive="NO" 106472770Sluigi ;; 106584377Sluigi 106684377Sluigi -v) # need -v -v to wait for user input 106784377Sluigi o_verbose=$((${o_verbose}+1)) # verbose level 106884377Sluigi o_tarv="v" # tar verbose flag 106984377Sluigi o_makeopts="-d l" # be verbose 107072770Sluigi ;; 1071188835Sluigi 1072188835Sluigi --iso) # generate iso image 1073188835Sluigi generate_iso="YES" 1074188835Sluigi ;; 1075188835Sluigi 1076189978Sluigi --cfg) # read additional config from this file 1077189978Sluigi o_additional_config=`realpath $2` 1078189978Sluigi shift 1079189978Sluigi ;; 1080189978Sluigi 1081190383Sluigi --objdir) # Place with results of a previous buildworld 1082190383Sluigi # useful if you want to copy shared binaries and libs 1083190383Sluigi o_objdir=`realpath $2` 1084190383Sluigi shift 1085190383Sluigi ;; 1086190383Sluigi 108772770Sluigi *) 1088188835Sluigi break 108972770Sluigi ;; 109072770Sluigi 109172770Sluigi esac 109272770Sluigi shift 109372770Sluigidone 1094190378Sluigi 109584377Sluigiset_build_parameters # things that depend on ${SRC} 1096188835Sluigiset_type $1 $2 # type and site, respectively 109772770Sluigi 1098173602Sluigi[ "${o_interactive}" != "NO" ] && main_dialog 1099173602Sluigi 110084377Sluigiif [ "${o_clean}" = "YES" ] ; then 110172770Sluigi clean_tree 110272770Sluigielse 110372770Sluigi build_image 110472770Sluigi do_install 110572770Sluigifi 110672770Sluigifinal_cleanup 110772770Sluigiexit 0 1108