File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_rootfs.sh
Revision 1.2.4.5: download - view: text, annotated - select for diffs - revision graph
Thu Feb 16 10:05:34 2012 UTC (12 years, 4 months ago) by misho
Branches: elwix1_6
Diff to: branchpoint 1.2: preferred, unified
patch elwix related to emergency boot system without second stage firmware

    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.2.4.5 2012/02/16 10:05:34 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: srcdirs ${BSDSRC}/usr.bin ${BSDSRC}/usr.sbin ${BSDSRC}/usr.sbin/wpa
   69: 
   70: #buildopts -DRESCUE CRUNCH_CFLAGS=-DRESCUE TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
   71: buildopts TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
   72: _EOF
   73: 	cat $CFGDIR/$ROOTFS_CONF >>$ROOTFS_CONF
   74: 
   75: 	crunchgen -f -p $BSDOBJ -h $MKDIR/$MKH -m $MKF -c elwix.c -e elwix $ROOTFS_CONF
   76: 	cd -
   77: }
   78: 
   79: build_elwix()
   80: {
   81: 	echo "+++ Build ELWIX RootFS firmware ..."
   82: 	cd $MKDIR
   83: 	make -f $MKF clean
   84: 	make -f $MKF
   85: 	cd -
   86: }
   87: 
   88: build_rootdir()
   89: {
   90: 	echo "+++ Build RootFS directory ..."
   91: 	cd $ROOTFS
   92: 
   93: 	install -d bin;
   94: 	install -d dev;
   95: 	install -d elwix;
   96: 	install -d elwix/etc;
   97: 	install -d mnt;
   98: 	install -d -m 0555 proc;
   99: 	install -d sbin;
  100: 	install -d system;
  101: 	install -d -m 1777 tmp;
  102: 	install -d usr;
  103: 	install -d usr/bin;
  104: 	install -d usr/lib;
  105: 	install -d usr/libexec;
  106: 	install -d usr/sbin;
  107: 	install -d var;
  108: 
  109: 	ln -fs /usr/lib lib;
  110: 	ln -fs /usr/libexec libexec;
  111: 
  112: 	ln -fs /elwix/etc etc;
  113: 	ln -fs /elwix/exports exports;
  114: 	ln -fs /elwix/home home;
  115: 	ln -fs /elwix/root root;
  116: 	ln -fs /elwix/tftpboot tftpboot;
  117: 
  118: 	cd -
  119: }
  120: 
  121: install_rootfs()
  122: {
  123: 	PRG="/sbin/elwix"
  124: 	BIN="${ROOTFS}/bin"
  125: 	SBIN="${ROOTFS}/sbin"
  126: 	UBIN="${ROOTFS}/usr/bin"
  127: 	LIBEXEC="${ROOTFS}/usr/libexec"
  128: 	USBIN="${ROOTFS}/usr/sbin"
  129: 	ETC="${ROOTFS}/elwix/etc"
  130: 
  131: 	echo "+++ Install ELWIX into RootFS directory ..."
  132: 	install $MKDIR/elwix $SBIN
  133: 
  134: 	InstallList ${ELWIX_ROOTFS} ${WORLD} ${ROOTFS}
  135: 
  136: 	InstallDir ${ROOTFS_ETC} $ETC
  137: 
  138: #	ln -s /usr/sbin/nologin $SBIN
  139: 
  140: 	ln -s $PRG $BIN/test
  141: 	ln -s $PRG $BIN/\[
  142: 	ln -s $PRG $BIN/cat
  143: 	ln -s $PRG $BIN/chflags
  144: 	ln -s $PRG $BIN/chio
  145: 	ln -s $PRG $BIN/chmod
  146: 	ln -s $PRG $BIN/cp
  147: #	ln -s $PRG $BIN/csh
  148: #	ln -s $PRG $BIN/tcsh
  149: 	ln -s /bin/tcsh $BIN/-tcsh
  150: 	ln -s /bin/csh $BIN/-csh
  151: 	ln -s $PRG $BIN/date
  152: 	ln -s $PRG $BIN/dd
  153: 	ln -s $PRG $BIN/df
  154: 	ln -s $PRG $BIN/domainname
  155: 	ln -s $PRG $BIN/echo
  156: 	ln -s $PRG $BIN/expr
  157: 	ln -s $PRG $BIN/getfacl
  158: 	ln -s $PRG $BIN/hostname
  159: 	ln -s $PRG $BIN/kenv
  160: 	ln -s $PRG $BIN/kill
  161: 	ln -s $PRG $BIN/ln
  162: 	ln -s $PRG $BIN/link
  163: 	ln -s $PRG $BIN/ls
  164: 	ln -s $PRG $BIN/mkdir
  165: 	ln -s $PRG $BIN/mv
  166: 	ln -s $PRG $BIN/pax
  167: 	ln -s $PRG $BIN/pkill
  168: 	ln -s $PRG $BIN/pgrep
  169: 	ln -s $PRG $BIN/sh
  170: 	ln -s $PRG $BIN/-sh
  171: 	ln -s $PRG $BIN/ps
  172: 	ln -s $PRG $BIN/pwait
  173: 	ln -s $PRG $BIN/pwd
  174: 	ln -s $PRG $BIN/realpath
  175: 	ln -s $PRG $BIN/rm
  176: 	ln -s $PRG $BIN/unlink
  177: 	ln -s $PRG $BIN/rmdir
  178: 	ln -s $PRG $BIN/setfacl
  179: 	ln -s $PRG $BIN/sleep
  180: 	ln -s $PRG $BIN/stty
  181: 	ln -s $PRG $BIN/sync
  182: 	ln -s $PRG $BIN/uuidgen
  183: 
  184: 	ln -s $PRG $BIN/true
  185: 	ln -s $PRG $BIN/false
  186: 	ln -s $PRG $BIN/basename
  187: 	ln -s $PRG $BIN/tail
  188: 	ln -s $PRG $BIN/nc
  189: 	ln -s $PRG $BIN/w
  190: 	ln -s $PRG $BIN/head
  191: 	ln -s $PRG $BIN/uname
  192: 	ln -s $PRG $BIN/tset
  193: 	ln -s $PRG $BIN/vmstat
  194: 	ln -s $PRG $BIN/systat
  195: 	ln -s $PRG $BIN/tput
  196: 	ln -s $PRG $BIN/grep
  197: 	ln -s $PRG $BIN/awk
  198: 	ln -s $PRG $BIN/less
  199: 	ln -s $PRG $BIN/gzip
  200: 	ln -s $PRG $BIN/cap_mkdb
  201: 	ln -s $PRG $BIN/sed
  202: 	ln -s $PRG $BIN/vi
  203: 	ln -s $PRG $BIN/du
  204: 	ln -s $PRG $BIN/getopt
  205: 	ln -s $PRG $BIN/logger
  206: 	ln -s $PRG $BIN/nice
  207: 	ln -s $PRG $BIN/nohup
  208: 	ln -s $PRG $BIN/seq
  209: 	ln -s $PRG $BIN/sockstat
  210: 	ln -s $PRG $BIN/stat
  211: 	ln -s $PRG $BIN/tee
  212: 	ln -s $PRG $BIN/tftp
  213: 	ln -s $PRG $BIN/touch
  214: 	ln -s $PRG $BIN/wc
  215: 	ln -s $PRG $BIN/xargs
  216: 	ln -s $PRG $BIN/printenv
  217: 	ln -s $PRG $BIN/egrep
  218: 	ln -s $PRG $BIN/fgrep
  219: 	ln -s $PRG $BIN/tar
  220: 	ln -s $PRG $BIN/cpio
  221: 	ln -s $PRG $BIN/nawk
  222: 	ln -s $PRG $BIN/gunzip
  223: 	ln -s $PRG $BIN/more
  224: 	ln -s $PRG $BIN/reset
  225: 	ln -s $PRG $BIN/readlink
  226: 	ln -s $PRG $BIN/uptime
  227: 
  228: 	ln -s $PRG $SBIN/adjkerntz
  229: 	ln -s $PRG $SBIN/atacontrol
  230: 	ln -s $PRG $SBIN/badsect
  231: 	ln -s $PRG $SBIN/bsdlabel
  232: 	ln -s $PRG $SBIN/disklabel
  233: 	ln -s $PRG $SBIN/camcontrol
  234: 	ln -s $PRG $SBIN/ccdconfig
  235: 	ln -s $PRG $SBIN/comcontrol
  236: 	ln -s $PRG $SBIN/conscontrol
  237: 	ln -s $PRG $SBIN/devfs
  238: 	ln -s $PRG $SBIN/dhclient
  239: 	ln -s $PRG $SBIN/dmesg
  240: 	ln -s $PRG $SBIN/dump
  241: 	ln -s $PRG $SBIN/rdump
  242: 	ln -s $PRG $SBIN/dumpfs
  243: 	ln -s $PRG $SBIN/dumpon
  244: 	ln -s $PRG $SBIN/fdisk
  245: 	ln -s $PRG $SBIN/ffsinfo
  246: 	ln -s $PRG $SBIN/fsck
  247: 	ln -s $PRG $SBIN/fsck_ffs
  248: 	ln -s $PRG $SBIN/fsck_ufs
  249: 	ln -s $PRG $SBIN/fsck_4.2bsd
  250: 	ln -s $PRG $SBIN/fsck_msdosfs
  251: 	ln -s $PRG $SBIN/gbde
  252: 	ln -s $PRG $SBIN/ggatec
  253: 	ln -s $PRG $SBIN/ggated
  254: 	ln -s $PRG $SBIN/ggatel
  255: 	ln -s $PRG $SBIN/-geom
  256: 	ln -s $PRG $SBIN/glabel
  257: 	ln -s $PRG $SBIN/gpart
  258: 	ln -s $PRG $SBIN/growfs
  259: 	ln -s $PRG $SBIN/hastctl
  260: 	ln -s $PRG $SBIN/hastd
  261: 	ln -s $PRG $SBIN/ifconfig
  262: 	ln -s $PRG $SBIN/init
  263: 	ln -s $PRG $SBIN/ipfw
  264: 	ln -s $PRG $SBIN/iscontrol
  265: 	ln -s $PRG $SBIN/kldconfig
  266: 	ln -s $PRG $SBIN/kldload
  267: 	ln -s $PRG $SBIN/kldstat
  268: 	ln -s $PRG $SBIN/kldunload
  269: 	ln -s $PRG $SBIN/ldconfig
  270: 	ln -s $PRG $SBIN/md5
  271: 	ln -s $PRG $SBIN/sha1
  272: 	ln -s $PRG $SBIN/sha256
  273: 	ln -s $PRG $SBIN/rmd160
  274: 	ln -s $PRG $SBIN/mdconfig
  275: 	ln -s $PRG $SBIN/mdmfs
  276: 	ln -s $PRG $SBIN/mount_mfs
  277: 	ln -s $PRG $SBIN/mknod
  278: 	ln -s $PRG $SBIN/mksnap_ffs
  279: 	ln -s $PRG $SBIN/mount
  280: 	ln -s $PRG $SBIN/mount_cd9660
  281: 	ln -s $PRG $SBIN/mount_msdosfs
  282: 	ln -s $PRG $SBIN/mount_nfs
  283: 	ln -s $PRG $SBIN/mount_ntfs
  284: 	ln -s $PRG $SBIN/mount_nullfs
  285: 	ln -s $PRG $SBIN/mount_udf
  286: 	ln -s $PRG $SBIN/mount_unionfs
  287: 	ln -s $PRG $SBIN/natd
  288: 	ln -s $PRG $SBIN/newfs
  289: 	ln -s $PRG $SBIN/newfs_msdos
  290: 	ln -s $PRG $SBIN/nfsiod
  291: 	ln -s $PRG $SBIN/nos-tun
  292: 	ln -s $PRG $SBIN/pfctl
  293: 	ln -s $PRG $SBIN/ping
  294: 	ln -s $PRG $SBIN/ping6
  295: 	ln -s $PRG $SBIN/pflogd
  296: 	ln -s $PRG $SBIN/quotacheck
  297: 	ln -s $PRG $SBIN/reboot
  298: 	ln -s $PRG $SBIN/halt
  299: 	ln -s $PRG $SBIN/fastboot
  300: 	ln -s $PRG $SBIN/fasthalt
  301: 	ln -s $PRG $SBIN/recoverdisk
  302: 	ln -s $PRG $SBIN/restore
  303: 	ln -s $PRG $SBIN/rrestore
  304: 	ln -s $PRG $SBIN/route
  305: 	ln -s $PRG $SBIN/rtsol
  306: 	ln -s $PRG $SBIN/shutdown
  307: 	ln -s $PRG $SBIN/savecore
  308: 	ln -s $PRG $SBIN/setkey
  309: 	ln -s $PRG $SBIN/spppcontrol
  310: 	ln -s $PRG $SBIN/swapon
  311: 	ln -s $PRG $SBIN/swapoff
  312: 	ln -s $PRG $SBIN/swapctl
  313: 	ln -s $PRG $SBIN/sysctl
  314: 	ln -s $PRG $SBIN/tunefs
  315: 	ln -s $PRG $SBIN/umount
  316: 	ln -s $PRG $SBIN/zfs
  317: 	ln -s $PRG $SBIN/zpool
  318: 
  319: 	ln -s $PRG $SBIN/traceroute
  320: 	ln -s $PRG $SBIN/traceroute6
  321: 	ln -s $PRG $SBIN/chown
  322: 	ln -s $PRG $SBIN/pwd_mkdb
  323: 	ln -s $PRG $SBIN/arp
  324: 	ln -s $PRG $SBIN/gpioctl
  325: 	ln -s $PRG $SBIN/hostapd
  326: 	ln -s $PRG $SBIN/hostapd_cli
  327: 	ln -s $PRG $SBIN/wpa_supplicant
  328: 	ln -s $PRG $SBIN/wpa_cli
  329: 	ln -s $PRG $SBIN/wpa_passphrase
  330: 	ln -s $PRG $SBIN/wake
  331: 	ln -s $PRG $SBIN/watchdog
  332: 	ln -s $PRG $SBIN/watchdogd
  333: 	ln -s $PRG $SBIN/inetd
  334: 	ln -s $PRG $SBIN/wlandebug
  335: 	ln -s $PRG $SBIN/chroot
  336: 	ln -s $PRG $SBIN/i2c
  337: 	ln -s $PRG $SBIN/iostat
  338: 	ln -s $PRG $SBIN/jail
  339: 	ln -s $PRG $SBIN/jexec
  340: 	ln -s $PRG $SBIN/jls
  341: 	ln -s $PRG $SBIN/ndp
  342: 	ln -s $PRG $SBIN/newsyslog
  343: 	ln -s $PRG $SBIN/nologin
  344: 	ln -s $PRG $SBIN/pstat
  345: 	ln -s $PRG $SBIN/rtadvctl
  346: 	ln -s $PRG $SBIN/rtadvd
  347: 	ln -s $PRG $SBIN/rtsold
  348: 	ln -s $PRG $SBIN/syslogd
  349: 	ln -s $PRG $SBIN/setfib
  350: 	ln -s $PRG $SBIN/swapinfo
  351: 	ln -s $PRG $SBIN/chgrp
  352: 
  353: 	ln -s $PRG $LIBEXEC/getty
  354: 	ln -s $PRG $LIBEXEC/tftpd
  355: 
  356: 	chown -hR root:wheel $ROOTFS
  357: 
  358: 	echo "+++ ELWIX clean CVS tags ..."
  359: 	CleanCVS $ETC
  360: 	CleanCVS $ETC/etc
  361: }
  362: 
  363: build_image()
  364: {
  365: 	echo "+++ Build ELWIX RootFS image ..."
  366: 	makefs -s ${ROOTFS_SIZE} -o minfree=0 $REL/$ROOTFS_IMG $ROOTFS
  367: }
  368: 
  369: install_image()
  370: {
  371: 	echo "+++ Install ELWIX RootFS Image into kernel ..."
  372: 	START=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | head -1`
  373: 	STOP=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | tail -1`
  374: 	STOP=$(($STOP + 1))
  375: 
  376: 	head -c $START $KERNEL >$NEWKERN
  377: 	cat $REL/$ROOTFS_IMG >>$NEWKERN
  378: 	tail -c +$STOP $KERNEL >>$NEWKERN
  379: 
  380: 	cd $REL
  381: 	gzip -9 kernel
  382: 	cd -
  383: }
  384: 
  385: ### main()
  386: if SnitVer ${WORLD}/elwix.ver; then
  387: 	clean_elwix
  388: 	prepare_elwix
  389: 	build_elwix
  390: 
  391: 	build_rootdir
  392: 	install_rootfs
  393: 
  394: 	build_image && install_image
  395: else
  396: 	echo "Skipped ELWIX RootFS build ..."
  397: fi
  398: 
  399: echo "+++ Complete build ELWIX RootFS"

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