File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_rootfs.sh
Revision 1.8.2.5: download - view: text, annotated - select for diffs - revision graph
Thu Jun 26 01:02:42 2014 UTC (9 years, 11 months ago) by misho
Branches: elwix2_2
Diff to: branchpoint 1.8: preferred, unified
fix rootfs script

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

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