File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_rootfs.sh
Revision 1.8: download - view: text, annotated - select for diffs - revision graph
Sun Jan 5 23:14:22 2014 UTC (10 years, 4 months ago) by misho
Branches: MAIN
CVS tags: elwix2_2, HEAD, ELWIX2_1
version 2.1

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

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