File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_rootfs.sh
Revision 1.8.2.2: download - view: text, annotated - select for diffs - revision graph
Fri Jan 17 00:48:28 2014 UTC (10 years, 5 months ago) by misho
Branches: elwix2_2
Diff to: branchpoint 1.8: preferred, unified
initial mips shrink rootfs

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

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