3 # $FreeBSD: src/release/picobsd/build/picobsd,v 1.1.2.28 2002/12/02 22:33:50 luigi Exp $
4 # $DragonFly: src/release/picobsd/build/Attic/picobsd,v 1.2 2003/06/17 04:27:20 dillon Exp $
6 # The new PicoBSD build script. Invoked as
8 # picobsd [options] floppy_type site_name
10 # Where floppy_type is a directory where the picobsd config info
11 # is held, and ${floppy_type}/floppy.tree.${site_name} contains
12 # optional site-specific configuration.
14 # For Options, see the bottom of the file where the processing is
15 # done. The picobsd(8) manpage might be of some help, but code and docs
16 # tend to lose sync over time...
18 # This script depends on the following files:
21 # Makefile.conf Makefile used to build the kernel
22 # config shell variables, sourced here.
23 # mfs.mtree mtree config file
25 # floppy.tree/ files which go on the floppy
26 # mfs_tree/ files which go onto the mfs
29 # PICOBSD kernel config file
30 # config shell variables, sourced here.
31 # crunch.conf crunchgen configuration
32 # floppy.tree.exclude files from floppy.tree/ which we do not need here.
33 # floppy.tree/ local additions to the floppy.tree
34 # floppy.tree.${site}/ same as above, site specific.
37 #--- The main entry point is at the end.
40 # There are two set of initialization. The first one (set_defaults)
41 # is done on entry to the script, and is used to set default values
42 # for all variables which do not depend on floppy type and source tree.
44 # The second set is done after command line parsing, e.g.
45 # to resolve dependencies on the source tree.
48 # + variables that control operation (e.g. verbosity) and are generally
49 # set from the command line have o_ ("option") as a name prefix
51 # + variables which contain pathnames and values that should not change
52 # have c_ ("constant") as a name prefix
54 # + variables exported to Makefiles and subshells are CAPITAL
56 # + variables local to the script are lowercase, possibly with
57 # an l_ ("local") prefix
59 # SRC points to your FreeBSD source tree.
60 # l_usrtree points to the /usr subdir for the source tree.
61 # Normally /usr or ${SRC}/../usr
62 # l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico
63 # PICO_TREE is where standard picobsd stuff resides.
64 # Normally ${SRC}/release/picobsd
65 # You can set SRC with --src <directory>
66 # It is not recommended to override the other variables.
68 # MY_TREE (set later) is where this floppy type resides.
69 # BUILDDIR is the build directory
71 # set some default values for variables.
72 # needs to be done as the first thing in the script.
74 # log something on stdout if verbose.
75 o_verbose=0 # this needs to be here!
77 if [ ${o_verbose} -gt 0 ] ; then
78 printf "\n*** %s\n" "$*"
79 if [ ${o_verbose} -gt 1 ] ; then
80 read -p "=== Press enter to continue" foo
86 printf "\n*** %s\n" "$*"
87 read -p "=== Press enter to continue" foo
91 # no way to use logging in this function, variable not set yet.
93 # EDITOR is the editor you use
94 # fd_size floppy size in KB (default to 1440). You can use 1480,
95 # 1720, 2880, etc. but beware that only 1440 and 1480 will boot
96 # from 1.44M floppy drives (1480 will not work on vmware).
98 fd_size=${fd_size:-1440}
100 o_all_in_mfs="yes" # put all files in mfs so you can boot and run
101 # the image via diskless boot.
102 o_clean="" # do not clean
103 o_interactive="" # default is interactive
104 o_verbose=0 # verbose level, 0 is silent
105 o_tarv="" # tar verbose flag, "" or "v"
106 o_init_src="" # non "" if we need to init libs and includes.
107 o_makeopts=${MAKEOPTS:--s} # make options, be silent by default
108 o_no_devfs=yes # we do not want devfs
109 o_do_modules="" # do not build modules
111 SRC="/usr/src" # default location for sources
112 c_startdir=`pwd` # directory where we start
113 # used to lookup config and create BUILDDIR
115 c_boot1=/boot/boot1 # boot blocks (in case you want custom ones)
118 c_reply=${c_reply:-`mktemp "/tmp/reply.XXXXXXXXXX"`}
119 # file where User replies will be put
120 c_mnt=`mktemp -d "/tmp/picobsd.XXXXXXXXXX"`
121 # mountpoint used to build memory filesystems
122 c_fs=fs.PICOBSD # filename used for the memory filesystem
123 c_img=picobsd.bin # filename used for the picobsd image
125 # select the right memory disk name
129 l_makedev="${SRC}/etc/MAKEDEV"
133 l_makedev="/dev/MAKEDEV"
135 # Find a suitable vnode
136 l_vnum=`mount | awk "/${l_vn}/ { num++ } END { printf \"%d\", num }"`
137 l_vndev=${l_vn}${l_vnum}
145 free_vnode # cleanup old vnodes
148 create_includes_and_libraries2() {
149 log "create_includes_and_libraries2() for ${SRC}"
150 MAKEOBJDIRPREFIX=${l_objtree}
151 export MAKEOBJDIRPREFIX
153 make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
157 create_includes_and_libraries() {
158 log "create_includes_and_libraries() for ${SRC}"
159 # Optionally creates include directory and libraries.
160 mkdir -p ${l_usrtree}/include # the include directory...
161 mkdir -p ${l_usrtree}/share/misc # a few things go here
162 mkdir -p ${l_usrtree}/lib # libraries
163 mkdir -p ${l_usrtree}/sbin # some binaries
164 (cd ${SRC}; INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${l_usrtree}/.. \
165 make -m ${SRC}/share/mk includes ) || fail $? includes
166 # Pick up the correct headers for libraries.
167 CFLAGS="-nostdinc -I${l_usrtree}/include" ; export CFLAGS
170 # $e is the invocation of make with correct environment
171 e="MAKEOBJDIRPREFIX=${l_objtree}/picobsd/libraries \
172 INCOWN=`id -un` BINOWN=`id -un` DESTDIR=${l_usrtree}/.. \
173 make -m ${SRC}/share/mk \
174 -DNOHTML -DNOINFO -DNOMAN -DNOSHARE -DNOFSCHG "
175 log "do a 'make obj' in a few places."
176 # This is very version-specific... The following works for 5.0
177 for i in lib secure/lib gnu/lib usr.sbin/pcvt/keycap \
178 gnu/usr.bin/perl usr.bin/lex usr.sbin/config ; do
179 (cd ${i}; eval $e obj)
181 log "now make the static libraries"
182 eval $e -DNOPROFILE -DNOPIC libraries
183 (cd ${SRC}/usr.sbin/config
184 eval $e # build binary
185 eval $e install # install it
187 ) || fail $? "libraries"
191 # set_type <type> looks in user or system directories for the floppy type
192 # specified as first argument, and sets variables according to the config.
193 # file. Also sets MY_TREE and BUILDDIR and SITE
202 for i in ${c_startdir}/${a} ${PICO_TREE}/${a} ; do
203 log "set_type: checking $i"
204 if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ] ; then
205 set -- `cat $i/PICOBSD | \
206 awk '/^#PicoBSD/ {print $2, $3, $4, $5, $6}'`
207 if [ "$1" != "" ]; then
208 MFS_SIZE=$1 ; init_name=$2
209 mfs_inodes=$3 ; fd_inodes=$4
210 name=`(cd $i ; pwd) `
211 name=`basename $name`
213 BUILDDIR=${c_startdir}/build_dir-${name}
214 log "Matching file $name in $i"
219 echo "Type $a NOT FOUND"
224 if [ "${name}" = "" ] ; then
225 echo "---> Wrong floppy type"
231 # free as much as possible from the vnode
233 log "free_vnode() ${l_vndev} "
234 umount ${c_mnt} 2> /dev/null || true
235 umount /dev/${l_vndev} 2> /dev/null || true
236 if [ "${l_vn}" = "vn" ] ; then
237 vnconfig -u ${l_vndev} 2> /dev/null || true
239 mdconfig -d -u ${l_vnum} 2> /dev/null || true
243 # prepare a message to be printed in the dialog menus.
247 MSG1="Type: ${THETYPE} name $name"
249 MSG="PicoBSD build -- Current parameters:\n\n\t1. ${MSG1}\n\
250 \t2. MFS size: ${MFS_SIZE} kB\n\
251 \t3. Site-info: ${SITE}\n\t4. Full-path: ${MY_TREE}\n"
255 # Main build procedure.
257 log "build_image() <${name}>"
258 [ "${name}" != "" ] || fail $? bad_type
261 printf "${MSG}---> We'll use the sources living in ${SRC}\n\n"
263 # read config variables from a global and then a type-specific file
264 # basically STAND_LINKS and MY_DEVS, but can also override other
267 . ${PICO_TREE}/build/config
268 if [ -f ${MY_TREE}/config ] ; then
272 # location of the object directory
273 PICO_OBJ=${l_objtree}/picobsd/${THETYPE}
274 log "PICO_OBJ is ${PICO_OBJ}"
276 if [ ${OSVERSION} -ge 500035 ] ; then
277 MAKEOBJDIRPREFIX=${l_objtree}
278 export MAKEOBJDIRPREFIX
279 log `cd ${SRC}; make -f Makefile.inc1 -V WMAKEENV`
280 eval export `cd ${SRC}; make -f Makefile.inc1 -V WMAKEENV`
282 # create build directory and subtree
283 mkdir -p ${BUILDDIR}/crunch
284 # remove any old stuff
285 rm -f ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
286 # invoke commands to build a kernel
288 # fill a subdirectory with things that go into the floppy
289 # (mostly /etc and similar stuff)
291 # populate it and produce a file with the MFS image
292 populate_mfs_tree # things which go into mfs
293 # create, mount and fill a filesystem with floppy image
294 fill_floppy_image # copies everything into the floppy
300 log "build_package()"
302 echo "##############################################" >>build.status
303 echo "## `date` ">>build.status
304 echo "##############################################" >>build.status
305 for z in bridge dial router net isp ; do
307 echo "---------------------------------------------">>build.status
308 echo "Building TYPE=${z}, SIZE=${MFS_SIZE}" >>build.status
309 msg="(ok)" # error message
310 build_image || msg="** FAILED! **"
311 echo " ${msg}">>build.status
312 # where do i put things ?
318 # Set build parameters interactively
327 dialog --menu "PicoBSD build menu -- (29 sep 2001)" 19 70 12 \
328 N "--> READY, build it <---" \
330 K "edit Kernel config file" \
331 E "Edit crunch.conf file" \
332 S "MFS Size: ${MFS_SIZE}kB" \
333 I "Init type: ${init_name}" \
334 F "Floppy size: ${fd_size}kB" \
335 M "MFS bytes per inode: ${mfs_inodes}" \
336 U "UFS bytes per inode: ${fd_inodes}" \
337 $ "Site-info: ${SITE}" \
345 for i in ${c_startdir} ${c_startdir}/* ${PICO_TREE}/* ; do
346 if [ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ]; then
347 l="$l `basename $i` `basename $i`"
351 { dialog --menu "Setup the type of configuration" 12 70 5 $l \
352 2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ; } || true
355 { dialog --menu "Choose your init(8) program" \
356 10 70 2 init "Standard init (requires getty)" \
357 oinit "small init from TinyWare" 2> ${c_reply} \
358 && init_name=`cat ${c_reply}` ; } || true
361 K) ${EDITOR} ${MY_TREE}/PICOBSD ;;
363 E) ${EDITOR} ${MY_TREE}/crunch.conf ;;
366 { dialog --title "MFS Size setup" --inputbox \
367 "MFS size depends on what you need to put on the MFS image. Typically \
368 ranges between 820kB (for very small bridge/router images) to \
369 as much as 2500kB kB for a densely packed image. \
370 Keep in mind that this memory is \
371 totally lost to other programs. Usually you want to keep \
372 this as small as possible. " 10 70 2> ${c_reply} \
373 && MFS_SIZE=`cat ${c_reply}` ; } || true
377 { dialog --title "Site info setup" --inputbox \
378 "Please enter the full path to the directory \
379 containing site-specific setup. \
380 This directory tree must contain files that replace \
381 standard ones in floppy.tree/ and mfs.tree/ . " \
382 10 70 2> ${c_reply} && SITE=`cat ${c_reply}` ; } || true
386 { dialog --menu "Set floppy size" 15 70 4 \
387 1440 "1.44MB" 1720 "1.72MB" 2880 "2.88MB" 4096 "4MB" \
388 2> ${c_reply} && fd_size=`cat ${c_reply}` ; } || true
392 { dialog --title "MFS bytes per inode:" --inputbox \
393 "Enter MFS bytes per inode (typically 4096..65536). \
394 A larger value means fewer inodes but more space on MFS" \
395 10 70 2> ${c_reply} && mfs_inodes=`cat ${c_reply}` ; } || true
399 { dialog --title "Floppy bytes per inode:" --inputbox \
400 "Enter floppy bytes per inode (typically 3072..65536). \
401 A larger value means fewer inodes but more space on the floppy." \
402 10 70 2> ${c_reply} && fd_inodes=`cat ${c_reply}` ; } || true
410 *) echo "
\aUnknown option \"${ans}\". Try again."
418 # Call the build procedure
423 if [ "${o_interactive}" = "NO" ] ; then
424 echo "+++ Build completed +++"
428 dialog --title "Build ${THETYPE} completed" --inputbox \
429 "\nThe build process was completed successfuly.\n\
430 `cat .build.reply` \n\n\
431 Now we are going to install the image on the floppy.\n\
432 Please insert a blank floppy in /dev/fd0.\\n
433 WARNING: the contents of the floppy will be permanently erased!\n\
436 * ^C or [Cancel] to abort,\n\
437 * Enter to install ${c_img},\n\
438 " 20 80 2> ${c_reply}
439 if [ "$?" = "0" ]; then
440 echo "Writing ${c_img}..."
441 dd if=${BUILDDIR}/${c_img} of=/dev/fd0.${fd_size}
443 echo "Ok, the image is in ${c_img}"
449 #-------------------------------------------------------------------
451 # invoke the Makefile to compile the kernel.
453 log "do_kernel() Preparing kernel \"$name\" in $MY_TREE"
454 (cd $MY_TREE; export name SRC BUILDDIR # used in this makefile ;
456 if [ "${o_do_modules}" = "yes" ] ; then
460 make -m ${SRC}/share/mk -v -f ${PICO_TREE}/build/Makefile.conf ) || \
461 fail $? missing_kernel
464 # Populate the variable part of the floppy filesystem. Must be done before
465 # the MFS because its content might need to be copied there as well.
467 # This involves fetching files from three subtrees, in this order:
469 # 1. a standard one, from which type-specific files are excluded;
470 # 2. a type-specific one;
471 # 3. a site-specific one.
473 # Files are first copied to a local tree and then compressed.
475 populate_floppy_fs() { # OK
476 local dst excl srcdir
478 log "populate_floppy_fs()"
479 dst=${BUILDDIR}/floppy.tree
480 log "pwd=`pwd` Populating floppy filesystem..."
482 # clean relics from old compilations.
483 rm -rf ${dst} || true
486 excl=${MY_TREE}/floppy.tree.exclude
487 if [ -f ${excl} ] ; then
488 excl="--exclude-from ${excl}"
489 log "Files excluded from generic tree: `echo;cat ${excl}`"
493 (cd ${PICO_TREE}/floppy.tree ; tar -cf - --exclude CVS ${excl} . ) | \
494 (cd ${dst} ; tar x${o_tarv}f - )
495 log "Copied from generic floppy-tree `echo; ls -laR ${dst}`"
497 srcdir=${MY_TREE}/floppy.tree
498 if [ -d ${srcdir} ] ; then
499 log "update with type-specific files:"
500 (cd ${srcdir} ; tar -cf - --exclude CVS . ) | \
501 (cd ${dst} ; tar x${o_tarv}f - )
502 log "Copied from type floppy-tree `echo; ls -laR ${dst}`"
504 log "No type-specific floppy-tree"
506 if [ -d ${srcdir}.${SITE} ] ; then
507 log "Update with site-specific (${SITE}) files:"
508 (cd ${srcdir}.${SITE} ; tar -cf - --exclude CVS . ) | \
509 (cd ${dst} ; tar x${o_tarv}f - )
510 log "Copied from site floppy-tree `echo; ls -laR ${dst}`"
512 log "No site-specific floppy-tree"
515 # gzip returns an error if it fails to compress some file
516 (cd $dst ; gzip -9 etc/*
517 log "Compressed files in etc/ `echo; ls -l etc`"
522 log "create_mfs() Preparing MFS filesystem..."
526 # zero-fill the MFS image
527 init_fs_image ${BUILDDIR}/${c_fs} ${MFS_SIZE}
529 log "Labeling MFS image"
530 # Disklabel "auto" behaves strangely for sizes < 1024K. Basically
531 # it fails to install a label on the system. On the other hand,
532 # if you provide a specific disk type, the boot code is not
533 # installed so you have more space on the disk...
534 # For small image sizes, use std disktypes
535 if [ ${MFS_SIZE} -lt 1024 ] ; then
536 disklabel -rw ${l_vndev} fd${MFS_SIZE} || fail $? mfs_disklabel
538 disklabel -rw ${l_vndev} auto || fail $? mfs_disklabel
540 newfs -i ${mfs_inodes} -m 0 -o space -f 512 -b 4096 \
541 /dev/${l_vndev}c > /dev/null
542 mount /dev/${l_vndev}c ${c_mnt} || fail $? no_mount
543 log "`df /dev/${l_vndev}c`"
546 # Populate the memory filesystem with binaries and non-variable
547 # configuration files.
548 # First do an mtree pass, then create directory links and device entries,
549 # then run crunchgen etc. to build the binary and create links.
550 # Then copy the specific/generic mfs_tree.
551 # Finally, if required, make a copy of the floppy.tree onto /fd
553 populate_mfs_tree() {
556 log "populate_mfs_tree()"
558 if [ "${early_mfs_mount}" = "1" ] ; then
562 dst=${BUILDDIR}/mfs.tree
563 # clean relics from old compilations.
564 rm -rf ${dst} || true
568 log "pwd=`pwd`, Populating MFS tree..."
570 # use type-specific mfs.mtree, default to generic one.
571 a=${MY_TREE}/mfs.mtree
572 [ -f ${a} ] || a=${PICO_TREE}/build/mfs.mtree
573 log "Running mtree using $a..."
574 mtree -deU -f $a -p ${dst} > /dev/null || fail $? mtree
577 for i in ${STAND_LINKS}; do
578 ln -s /stand ${dst}/$i
580 ln -s /dev/null ${dst}/var/run/log
581 ln -s /etc/termcap ${dst}/usr/share/misc/termcap
585 cd ${BUILDDIR}/crunch
586 log "Making and installing crunch1 from `pwd` src ${SRC}..."
587 a=${BUILDDIR}/crunch1.conf
588 ( export BUILDDIR SRC MY_TREE PICO_OBJ ;
589 make -m ${SRC}/share/mk \
590 -v -f ${PICO_TREE}/build/Makefile.conf ${BUILDDIR}/crunch.mk )
591 log "Libs are ${LIBS} "
592 export SRC # used by crunch.mk
594 log "Now make -f crunch.mk"
595 make -m ${SRC}/share/mk ${o_makeopts} -f ${BUILDDIR}/crunch.mk
596 strip --remove-section=.note --remove-section=.comment crunch1
597 mv crunch1 ${dst}/stand/crunch
598 chmod 555 ${dst}/stand/crunch
599 log "Making links for binaries..."
600 for i in `crunchgen -l $a` ; do
601 ln ${dst}/stand/crunch ${dst}/stand/${i};
603 # rm $a # do not remove!
606 if [ -f ${dst}/stand/sshd ] ; then
607 log "Setting up host key for sshd:"
608 if [ -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key.gz ] ; then
609 log "Using existing host key"
611 log "Generating new host key"
612 ssh-keygen -t rsa1 -f ${BUILDDIR}/floppy.tree/etc/ssh_host_key \
613 -N "" -C "root@picobsd"
614 gzip -9 ${BUILDDIR}/floppy.tree/etc/ssh_host_key* || true
618 log "Copy generic and site-specific MFS tree..."
619 for MFS_TREE in ${PICO_TREE}/mfs_tree ${MY_TREE}/mfs_tree ; do
620 if [ -d ${MFS_TREE} ] ; then
621 log "Copy ${MFS_TREE} ..."
622 (cd ${MFS_TREE} ; tar -cf - --exclude CVS . ) | \
623 (cd ${dst} ; tar x${o_tarv}f - )
627 if [ "${o_all_in_mfs}" = "yes" ]; then
628 log "Copy generic floppy_tree into MFS..."
629 cp -Rp ${BUILDDIR}/floppy.tree/* ${dst}/fd
632 [ "`id -u`" = "0" ] || cat <<__EOF
634 ### -------------------------------------------------------------------
636 ### WARNING: You are not running with root permissions, so the next
637 ### stages are likely to fail because they call commands such as
638 ### chown, {vn|md}config, mount/umount which need adequate rights.
640 ### The results of the compilation so far is in directory
642 ### which has the following content:
647 ### -------------------------------------------------------------------
651 if [ "${o_no_devfs}" != "" ] ; then
652 # create device entries using MAKEDEV
654 ln -s ${l_makedev} ; chmod 555 MAKEDEV
659 log "Fixing permissions"
660 (cd ${dst}; chown -R root . )
662 if [ -n "${import_files}" ] ; then
663 log "importing ${import_files} into mfs"
664 # We do it in a chroot environment on the target so
665 # symlinks are followed correctly.
666 cp `which tar` ${dst}/my_copy_of_tar
667 (cd ${l_usrtree}/.. ; tar cf - ${import_files} ) | \
668 (chroot ${dst} /my_copy_of_tar xf - )
669 rm ${dst}/my_copy_of_tar
672 if [ "${early_mfs_mount}" != "1" ] ; then
674 log "Copy mfs tree into file"
675 (cd ${dst} ; tar cf - . ) | ( cd ${c_mnt} ; tar xf - )
677 # now umount and fsck the filesystem.
678 log "Status of mfs image"
681 fsck -p /dev/${l_vndev}c
686 log "final_cleanup()"
688 rm -rf ${c_mnt} ${c_reply} 2> /dev/null || true
693 # This function is used to trap errors and print msgs
696 local errno errocode where
701 echo "---> fail: Error <${errno}> error code <${errcode}> in <${where}>"
704 echo "Error in vnconfig on /dev/${l_vndev}..."
705 echo "Either you are not running as root or your running kernel"
706 echo "does not have the ${l_vn}(4) device."
709 echo "Error while labeling ${c_fs} size ${MFS_SIZE}"
712 echo "Error while mounting ${c_fs} (/dev/${l_vndev}c) on ${c_mnt}"
715 echo "Error while making hierarchy in ${c_mnt}"
718 echo "Error while building ${name}."
721 echo "Error while doing disklabel on of floppy.img size $fd_size"
724 echo "Error: you must build PICOBSD${suffix} kernel first"
727 echo "Error: failed while making includes"
730 echo "Error: failed while making libraries"
733 echo "Error: unknown floppy type ${name}"
736 echo "Error: no space left on device (${where})"
739 echo "Error: while writing MFS into the kernel."
746 echo "unknown error, maybe user break: $errno $errcode"
749 echo "---> Aborting $0"
750 # try to cleanup the vnode.
756 # Create a zero-filled disk image with a boot sector, and vnconfig it.
759 init_fs_image() { # filename size_in_kbytes
760 local imgname imgsize
762 log "init_fs_image() $1 $2"
763 imgname=$1 ; imgsize=$2
764 dd if=/dev/zero of=${imgname} count=${imgsize} bs=1k 2> /dev/null
765 dd if=${c_boot1} of=${imgname} conv=notrunc 2> /dev/null
767 if [ "${l_vn}" = "vn" ] ; then
768 vnconfig -c -s labels ${l_vndev} ${imgname} || fail $? no_vnconfig
770 mdconfig -a -t vnode -u ${l_vnum} -f ${imgname} || fail $? no_vnconfig
775 fill_floppy_image() {
776 local blocks sectors dst
778 log "fill_floppy_image()"
779 dst=${c_mnt} # where to create the image
781 log "Preparing ${fd_size}kB floppy filesystem..."
783 # correct block and number of sectors according to size.
784 blocks=${fd_size}; sectors=18
785 if [ "${blocks}" = "1720" ]; then
786 blocks=1722 ; sectors=21
787 elif [ "${blocks}" = "1480" ]; then
791 init_fs_image ${BUILDDIR}/${c_img} ${blocks}
793 log "Labeling floppy image"
794 b2=${BUILDDIR}/boot2 # modified boot2
797 set `strings -at d ${b2} | grep "/boot/loader"`
798 echo -e "/kernel\0\0\0\0\0" | dd of=${b2} obs=$1 oseek=1 conv=notrunc
801 # create a disklabel ...
802 disklabel -Brw -b ${c_boot1} -s ${b2} ${l_vndev} auto || \
803 fail $? floppy_disklabel
805 # and copy partition c: into partition a: using some sed magic
806 disklabel ${l_vndev} | sed -e '/ c:/{p;s/c:/a:/;}' | \
807 disklabel -R ${l_vndev} /dev/stdin
809 log "Newfs floppy image"
810 newfs -i ${fd_inodes} -m 0 -o space -f 512 -b 4096 \
811 /dev/${l_vndev}a > /dev/null
813 log "Mounting floppy image"
814 mount /dev/${l_vndev}a ${dst}
818 # $1 takes the offset of the MFS filesystem
819 set `strings -at d kernel | grep "MFS Filesystem goes here"`
820 mfs_ofs=$(($1 + 8192))
821 log "Preload kernel with file ${c_fs} at ${mfs_ofs}"
822 dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \
824 log "Compress with kgzip and copy to floppy image"
825 kgzip -o kernel.gz kernel
826 cp -p kernel.gz ${dst}/kernel || fail $? no_space "copying kernel"
828 log "now transfer floppy tree if needed"
829 # now transfer the floppy tree. If it is already in mfs, dont bother.
830 if [ "${o_all_in_mfs}" != "yes" ] ; then
831 cp -Rp floppy.tree/* ${dst} || \
832 fail $? no_space "copying floppy tree"
835 (log "Fixing permissions"; cd ${dst}; chown -R root *)
836 # rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
838 df -ik ${dst} | colrm 70 > .build.reply
841 rm ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
844 # This function creates variables which depend on the source tree in use:
845 # SRC, l_usrtree, l_objtree
846 # Optionally creates libraries, includes and the like (for cross compiles,
847 # needs to be done once).
849 set_build_parameters() {
850 log "set_build_parameters() SRC is ${SRC}"
851 if [ "${SRC}" = "/usr/src" ] ; then
852 l_usrtree=${USR:-/usr}
854 l_usrtree=${USR:-${SRC}/../usr}
856 l_objtree=${l_usrtree}/obj-pico
857 PICO_TREE=${PICO_TREE:-${SRC}/release/picobsd}
858 set `grep "#define[\t ]__FreeBSD_version" ${SRC}/sys/sys/param.h`
860 log "OSVERSION is ${OSVERSION}"
861 if [ "${o_init_src}" != "" ] ; then
862 if [ ${OSVERSION} -lt 500035 ] ; then
863 create_includes_and_libraries
865 create_includes_and_libraries2
868 if [ ${OSVERSION} -lt 500035 ] ; then
869 # Create the right LIBS and CFLAGS for further builds.
870 # and build the config program
871 LIBS="-L${l_usrtree}/lib"
872 CFLAGS="-nostdinc -I${l_usrtree}/include"
874 CONFIG=${l_usrtree}/sbin/config
879 #-------------------------------------------------------------------
880 # Main entry of the script. Initialize variables, parse command line
886 --src) # set the source path instead of /usr/src
907 --modules) # also build kernel modules
914 -clear|-clean|-c) # clean
919 -v) # need -v -v to wait for user input
920 o_verbose=$((${o_verbose}+1)) # verbose level
921 o_tarv="v" # tar verbose flag
922 o_makeopts="-d l" # be verbose
931 set_build_parameters # things that depend on ${SRC}
932 set_type $1 $2 # type and site, respectively
934 # If $1="package", it creates a neat set of floppies
936 if [ "$1" = "package" ] ; then
939 if [ "${o_interactive}" != "NO" ] ; then
942 if [ "${o_clean}" = "YES" ] ; then