File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_rootfs.sh
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Jul 5 23:43:00 2011 UTC (12 years, 10 months ago) by misho
Branches: MAIN
CVS tags: HEAD
Initial revision

    1: #!/bin/sh
    2: #
    3: # ELWIX build script for rootfs firmware
    4: #
    5: # (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
    6: #    by Michael Pounov <misho@elwix.org>
    7: #
    8: # $Id: build_rootfs.sh,v 1.1 2011/07/05 23:43:00 misho Exp $
    9: #
   10: 
   11: [ -r ./config/rc.elwix ] && . ./config/rc.elwix
   12: if [ X"${ELWIX_IS_CONFIGURED}" != X"YES" ]; then
   13: 	echo
   14: 	echo "ELWIX project is not configured !?!"
   15: 	echo
   16: 	exit 1
   17: fi
   18: 
   19: if [ ! -d ${BSDSRC} ]; then
   20: 	echo
   21: 	echo "ELWIX project is not configured - missing BSD sources !?!"
   22: 	echo
   23: 	exit 1
   24: fi
   25: 
   26: if [ "${USER}" != "root" ]; then
   27: 	echo
   28: 	echo "ELWIX project is not configured - RootFS must build under root !?!"
   29: 	echo
   30: 	exit 1
   31: fi
   32: 
   33: NEWKERN="${REL}/kernel"
   34: 
   35: clean_elwix()
   36: {
   37: 	echo "+++ Clean csh from ELWIX World ..."
   38: 	rm -rf ${BSDOBJ}/usr/src/bin/csh/*
   39: 
   40: 	echo "+++ Clean ELWIX RootFS firmware ..."
   41: 	rm -rf $MKDIR
   42: 	mkdir $MKDIR
   43: 
   44: 	echo "+++ Clean RootFS directory ..."
   45: 	rm -rf $ROOTFS
   46: 	mkdir $ROOTFS
   47: 
   48: 	echo "+++ Clean Release directory ..."
   49: 	rm -rf $REL/$ROOTFS_IMG ${NEWKERN}*
   50: }
   51: 
   52: prepare_elwix()
   53: {
   54: 	echo "+++ Prepair ELWIX RootFS firmware ..."
   55: 	cd $MKDIR
   56: 	cat >$MKH <<_EOF
   57: # Auto-generated Makefile include for crungegen
   58: # !!! Dont edit by hand !!!
   59: #
   60: #BUILDOPTS += TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
   61: CRUNCH_SUPPRESS_LINK_-sh= 1
   62: CRUNCH_SUPPRESS_LINK_-csh= 1
   63: CRUNCH_SUPPRESS_LINK_-tcsh= 1
   64: LIBS += -L${WORLD}/lib -L${WORLD}/usr/lib
   65: _EOF
   66: 	cat >$ROOTFS_CONF <<_EOF
   67: srcdirs ${BSDSRC}/bin ${BSDSRC}/sbin ${BSDSRC}/libexec ${BSDSRC}/cddl/sbin ${BSDSRC}/sbin/ggate
   68: #buildopts -DRESCUE CRUNCH_CFLAGS=-DRESCUE TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
   69: buildopts TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
   70: _EOF
   71: 	cat $CFGDIR/$ROOTFS_CONF >>$ROOTFS_CONF
   72: 
   73: 	crunchgen -f -p $BSDOBJ -h $MKDIR/$MKH -m $MKF -c elwix.c -e elwix $ROOTFS_CONF
   74: 	cd -
   75: }
   76: 
   77: build_elwix()
   78: {
   79: 	echo "+++ Build ELWIX RootFS firmware ..."
   80: 	cd $MKDIR
   81: 	make -f $MKF clean
   82: 	make -f $MKF
   83: 	cd -
   84: }
   85: 
   86: build_rootdir()
   87: {
   88: 	echo "+++ Build RootFS directory ..."
   89: 	cd $ROOTFS
   90: 
   91: 	install -d bin;
   92: 	install -d dev;
   93: 	install -d elwix;
   94: 	install -d elwix/etc;
   95: 	install -d mnt;
   96: 	install -d -m 0555 proc;
   97: 	install -d sbin;
   98: 	install -d system;
   99: 	install -d -m 1777 tmp;
  100: 	install -d usr;
  101: 	install -d var;
  102: 
  103: 	ln -fs /usr/lib lib;
  104: 	ln -fs /usr/libexec libexec;
  105: 
  106: 	ln -fs /elwix/etc etc;
  107: 	ln -fs /elwix/exports exports;
  108: 	ln -fs /elwix/home home;
  109: 	ln -fs /elwix/root root;
  110: 	ln -fs /elwix/tftpboot tftpboot;
  111: 
  112: 	cd -
  113: }
  114: 
  115: install_rootfs()
  116: {
  117: 	PRG="/sbin/elwix"
  118: 	BIN="${ROOTFS}/bin"
  119: 	SBIN="${ROOTFS}/sbin"
  120: 	ETC="${ROOTFS}/elwix/etc"
  121: 
  122: 	echo "+++ Install ELWIX into RootFS directory ..."
  123: 	install $MKDIR/elwix $SBIN
  124: 
  125: 	InstallList ${ELWIX_ROOTFS} ${WORLD} ${ROOTFS}
  126: 
  127: 	InstallFiles ${ROOTFS_ETC} $ETC
  128: 
  129: 	ln -s /usr/sbin/nologin $SBIN
  130: 
  131: 	ln -s $PRG $BIN/test
  132: 	ln -s $PRG $BIN/\[
  133: 	ln -s $PRG $BIN/cat
  134: 	ln -s $PRG $BIN/chflags
  135: 	ln -s $PRG $BIN/chio
  136: 	ln -s $PRG $BIN/chmod
  137: 	ln -s $PRG $BIN/cp
  138: 	ln -s $PRG $BIN/csh
  139: 	ln -s $PRG $BIN/tcsh
  140: 	ln -s $PRG $BIN/date
  141: 	ln -s $PRG $BIN/dd
  142: 	ln -s $PRG $BIN/df
  143: 	ln -s $PRG $BIN/domainname
  144: 	ln -s $PRG $BIN/echo
  145: 	ln -s $PRG $BIN/expr
  146: 	ln -s $PRG $BIN/getfacl
  147: 	ln -s $PRG $BIN/hostname
  148: 	ln -s $PRG $BIN/kenv
  149: 	ln -s $PRG $BIN/kill
  150: 	ln -s $PRG $BIN/ln
  151: 	ln -s $PRG $BIN/link
  152: 	ln -s $PRG $BIN/ls
  153: 	ln -s $PRG $BIN/mkdir
  154: 	ln -s $PRG $BIN/mv
  155: 	ln -s $PRG $BIN/pax
  156: 	ln -s $PRG $BIN/pkill
  157: 	ln -s $PRG $BIN/pgrep
  158: 	ln -s $PRG $BIN/sh
  159: 	ln -s $PRG $BIN/-sh
  160: 	ln -s $PRG $BIN/-tcsh
  161: 	ln -s $PRG $BIN/ps
  162: 	ln -s $PRG $BIN/pwait
  163: 	ln -s $PRG $BIN/pwd
  164: 	ln -s $PRG $BIN/realpath
  165: 	ln -s $PRG $BIN/rm
  166: 	ln -s $PRG $BIN/unlink
  167: 	ln -s $PRG $BIN/rmdir
  168: 	ln -s $PRG $BIN/setfacl
  169: 	ln -s $PRG $BIN/sleep
  170: 	ln -s $PRG $BIN/stty
  171: 	ln -s $PRG $BIN/sync
  172: 	ln -s $PRG $BIN/uuidgen
  173: 
  174: 	ln -s $PRG $SBIN/adjkerntz
  175: 	ln -s $PRG $SBIN/atacontrol
  176: 	ln -s $PRG $SBIN/badsect
  177: 	ln -s $PRG $SBIN/bsdlabel
  178: 	ln -s $PRG $SBIN/disklabel
  179: 	ln -s $PRG $SBIN/camcontrol
  180: 	ln -s $PRG $SBIN/ccdconfig
  181: 	ln -s $PRG $SBIN/comcontrol
  182: 	ln -s $PRG $SBIN/conscontrol
  183: 	ln -s $PRG $SBIN/devfs
  184: 	ln -s $PRG $SBIN/dhclient
  185: 	ln -s $PRG $SBIN/dmesg
  186: 	ln -s $PRG $SBIN/dump
  187: 	ln -s $PRG $SBIN/rdump
  188: 	ln -s $PRG $SBIN/dumpfs
  189: 	ln -s $PRG $SBIN/dumpon
  190: 	ln -s $PRG $SBIN/fdisk
  191: 	ln -s $PRG $SBIN/ffsinfo
  192: 	ln -s $PRG $SBIN/fsck
  193: 	ln -s $PRG $SBIN/fsck_ffs
  194: 	ln -s $PRG $SBIN/fsck_ufs
  195: 	ln -s $PRG $SBIN/fsck_4.2bsd
  196: 	ln -s $PRG $SBIN/fsck_msdosfs
  197: 	ln -s $PRG $SBIN/gbde
  198: 	ln -s $PRG $SBIN/ggatec
  199: 	ln -s $PRG $SBIN/ggated
  200: 	ln -s $PRG $SBIN/ggatel
  201: 	ln -s $PRG $SBIN/-geom
  202: 	ln -s $PRG $SBIN/glabel
  203: 	ln -s $PRG $SBIN/gpart
  204: 	ln -s $PRG $SBIN/growfs
  205: 	ln -s $PRG $SBIN/hastctl
  206: 	ln -s $PRG $SBIN/hastd
  207: 	ln -s $PRG $SBIN/ifconfig
  208: 	ln -s $PRG $SBIN/init
  209: 	ln -s $PRG $SBIN/ipfw
  210: 	ln -s $PRG $SBIN/iscontrol
  211: 	ln -s $PRG $SBIN/kldconfig
  212: 	ln -s $PRG $SBIN/kldload
  213: 	ln -s $PRG $SBIN/kldstat
  214: 	ln -s $PRG $SBIN/kldunload
  215: 	ln -s $PRG $SBIN/ldconfig
  216: 	ln -s $PRG $SBIN/md5
  217: 	ln -s $PRG $SBIN/sha1
  218: 	ln -s $PRG $SBIN/sha256
  219: 	ln -s $PRG $SBIN/rmd160
  220: 	ln -s $PRG $SBIN/mdconfig
  221: 	ln -s $PRG $SBIN/mdmfs
  222: 	ln -s $PRG $SBIN/mount_mfs
  223: 	ln -s $PRG $SBIN/mknod
  224: 	ln -s $PRG $SBIN/mksnap_ffs
  225: 	ln -s $PRG $SBIN/mount
  226: 	ln -s $PRG $SBIN/mount_cd9660
  227: 	ln -s $PRG $SBIN/mount_msdosfs
  228: 	ln -s $PRG $SBIN/mount_nfs
  229: 	ln -s $PRG $SBIN/mount_newnfs
  230: 	ln -s $PRG $SBIN/mount_ntfs
  231: 	ln -s $PRG $SBIN/mount_nullfs
  232: 	ln -s $PRG $SBIN/mount_udf
  233: 	ln -s $PRG $SBIN/mount_unionfs
  234: 	ln -s $PRG $SBIN/natd
  235: 	ln -s $PRG $SBIN/newfs
  236: 	ln -s $PRG $SBIN/newfs_msdos
  237: 	ln -s $PRG $SBIN/nfsiod
  238: 	ln -s $PRG $SBIN/nos-tun
  239: 	ln -s $PRG $SBIN/pfctl
  240: 	ln -s $PRG $SBIN/pflogd
  241: 	ln -s $PRG $SBIN/ping
  242: 	ln -s $PRG $SBIN/ping6
  243: 	ln -s $PRG $SBIN/quotacheck
  244: 	ln -s $PRG $SBIN/reboot
  245: 	ln -s $PRG $SBIN/halt
  246: 	ln -s $PRG $SBIN/fastboot
  247: 	ln -s $PRG $SBIN/fasthalt
  248: 	ln -s $PRG $SBIN/recoverdisk
  249: 	ln -s $PRG $SBIN/restore
  250: 	ln -s $PRG $SBIN/rrestore
  251: 	ln -s $PRG $SBIN/route
  252: 	ln -s $PRG $SBIN/rtsol
  253: 	ln -s $PRG $SBIN/savecore
  254: 	ln -s $PRG $SBIN/setkey
  255: 	ln -s $PRG $SBIN/shutdown
  256: 	ln -s $PRG $SBIN/spppcontrol
  257: 	ln -s $PRG $SBIN/swapon
  258: 	ln -s $PRG $SBIN/swapoff
  259: 	ln -s $PRG $SBIN/swapctl
  260: 	ln -s $PRG $SBIN/sysctl
  261: 	ln -s $PRG $SBIN/tunefs
  262: 	ln -s $PRG $SBIN/umount
  263: 	ln -s $PRG $SBIN/zfs
  264: 	ln -s $PRG $SBIN/zpool
  265: 
  266: 	chown -hR root:wheel $ROOTFS
  267: }
  268: 
  269: build_image()
  270: {
  271: 	echo "+++ Build ELWIX RootFS image ..."
  272: 	makefs -s ${ROOTFS_SIZE} -o minfree=0 $REL/$ROOTFS_IMG $ROOTFS
  273: }
  274: 
  275: install_image()
  276: {
  277: 	echo "+++ Install ELWIX RootFS Image into kernel ..."
  278: 	START=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | head -1`
  279: 	STOP=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | tail -1`
  280: 	STOP=$(($STOP + 1))
  281: 
  282: 	head -c $START $KERNEL >$NEWKERN
  283: 	cat $REL/$ROOTFS_IMG >>$NEWKERN
  284: 	tail -c +$STOP $KERNEL >>$NEWKERN
  285: 
  286: 	cd $REL
  287: 	gzip -9 kernel
  288: 	cd -
  289: }
  290: 
  291: ### main()
  292: if SnitVer ${WORLD}/elwix.ver; then
  293: 	clean_elwix
  294: 	prepare_elwix
  295: 	build_elwix
  296: 
  297: 	build_rootdir
  298: 	install_rootfs
  299: 
  300: 	build_image
  301: 	install_image
  302: else
  303: 	echo "Skipped ELWIX RootFS build ..."
  304: fi
  305: 
  306: echo "+++ Complete build ELWIX RootFS"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>