File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_rootfs.sh
Revision 1.9: download - view: text, annotated - select for diffs - revision graph
Mon Sep 15 19:06:42 2014 UTC (10 years, 1 month ago) by misho
Branches: MAIN
CVS tags: elwix2_3, HEAD, ELWIX2_2p0
elwix 2.2

    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.9 2014/09/15 19:06: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/csh
  170: 	ln -s $PRG $BIN/-csh
  171: 	ln -s $PRG $BIN/tcsh
  172: 	ln -s $PRG $BIN/-tcsh
  173: 	ln -s $PRG $BIN/date
  174: 	ln -s $PRG $BIN/dd
  175: 	ln -s $PRG $BIN/df
  176: 	ln -s $PRG $BIN/domainname
  177: 	ln -s $PRG $BIN/echo
  178: 	ln -s $PRG $BIN/expr
  179: 	ln -s $PRG $BIN/hostname
  180: 	ln -s $PRG $BIN/kenv
  181: 	ln -s $PRG $BIN/kill
  182: 	ln -s $PRG $BIN/ln
  183: 	ln -s $PRG $BIN/link
  184: 	ln -s $PRG $BIN/ls
  185: 	ln -s $PRG $BIN/mkdir
  186: 	ln -s $PRG $BIN/mv
  187: 	ln -s $PRG $BIN/pax
  188: 	ln -s $PRG $BIN/pkill
  189: 	ln -s $PRG $BIN/pgrep
  190: 	ln -s $PRG $BIN/sh
  191: 	ln -s $PRG $BIN/-sh
  192: 	ln -s $PRG $BIN/ps
  193: 	ln -s $PRG $BIN/pwait
  194: 	ln -s $PRG $BIN/pwd
  195: 	ln -s $PRG $BIN/realpath
  196: 	ln -s $PRG $BIN/rm
  197: 	ln -s $PRG $BIN/unlink
  198: 	ln -s $PRG $BIN/rmdir
  199: 	ln -s $PRG $BIN/sleep
  200: 	ln -s $PRG $BIN/stty
  201: 	ln -s $PRG $BIN/sync
  202: 	ln -s $PRG $BIN/uuidgen
  203: 
  204: 	ln -s $PRG $BIN/true
  205: 	ln -s $PRG $BIN/false
  206: 	ln -s $PRG $BIN/basename
  207: 	ln -s $PRG $BIN/tail
  208: 	ln -s $PRG $BIN/nc
  209: 	ln -s $PRG $BIN/w
  210: 	ln -s $PRG $BIN/head
  211: 	ln -s $PRG $BIN/uname
  212: 	ln -s $PRG $BIN/tset
  213: 	ln -s $PRG $BIN/vmstat
  214: 	ln -s $PRG $BIN/systat
  215: 	ln -s $PRG $BIN/tput
  216: 	ln -s $PRG $BIN/grep
  217: 	ln -s $PRG $BIN/awk
  218: 	ln -s $PRG $BIN/less
  219: 	ln -s $PRG $BIN/gzip
  220: 	ln -s $PRG $BIN/cap_mkdb
  221: 	ln -s $PRG $BIN/sed
  222: 	ln -s $PRG $BIN/vi
  223: 	ln -s $PRG $BIN/du
  224: 	ln -s $PRG $BIN/getopt
  225: 	ln -s $PRG $BIN/logger
  226: 	ln -s $PRG $BIN/nice
  227: 	ln -s $PRG $BIN/nohup
  228: 	ln -s $PRG $BIN/seq
  229: 	ln -s $PRG $BIN/sockstat
  230: 	ln -s $PRG $BIN/stat
  231: 	ln -s $PRG $BIN/tee
  232: 	ln -s $PRG $BIN/tftp
  233: 	ln -s $PRG $BIN/touch
  234: 	ln -s $PRG $BIN/wc
  235: 	ln -s $PRG $BIN/xargs
  236: 	ln -s $PRG $BIN/printenv
  237: 	ln -s $PRG $BIN/egrep
  238: 	ln -s $PRG $BIN/fgrep
  239: 	ln -s $PRG $BIN/tar
  240: 	ln -s $PRG $BIN/cpio
  241: 	ln -s $PRG $BIN/nawk
  242: 	ln -s $PRG $BIN/gunzip
  243: 	ln -s $PRG $BIN/gzcat
  244: 	ln -s $PRG $BIN/zcat
  245: 	ln -s $PRG $BIN/more
  246: 	ln -s $PRG $BIN/reset
  247: 	ln -s $PRG $BIN/readlink
  248: 	ln -s $PRG $BIN/uptime
  249: 	ln -s $PRG $BIN/bzip2
  250: 	ln -s $PRG $BIN/bunzip2
  251: 	ln -s $PRG $BIN/bzcat
  252: 
  253: 	ln -s $PRG $SBIN/bsdlabel
  254: 	ln -s $PRG $SBIN/disklabel
  255: 	ln -s $PRG $SBIN/camcontrol
  256: 	ln -s $PRG $SBIN/comcontrol
  257: 	ln -s $PRG $SBIN/conscontrol
  258: 	ln -s $PRG $SBIN/devfs
  259: 	ln -s $PRG $SBIN/dhclient
  260: 	ln -s $PRG $SBIN/dmesg
  261: 	ln -s $PRG $SBIN/dump
  262: 	ln -s $PRG $SBIN/rdump
  263: 	ln -s $PRG $SBIN/dumpon
  264: 	ln -s $PRG $SBIN/fdisk
  265: 	ln -s $PRG $SBIN/fsck
  266: 	ln -s $PRG $SBIN/fsck_ffs
  267: 	ln -s $PRG $SBIN/fsck_ufs
  268: 	ln -s $PRG $SBIN/fsck_4.2bsd
  269: 	ln -s $PRG $SBIN/fsck_msdosfs
  270: 	ln -s $PRG $SBIN/etherswitchcfg
  271: 	ln -s $PRG $SBIN/-geom
  272: 	ln -s $PRG $SBIN/glabel
  273: 	ln -s $PRG $SBIN/gpart
  274: 	ln -s $PRG $SBIN/graid
  275: 	ln -s $PRG $SBIN/growfs
  276: 	ln -s $PRG $SBIN/hastctl
  277: 	ln -s $PRG $SBIN/hastd
  278: 	ln -s $PRG $SBIN/ifconfig
  279: 	ln -s $PRG $SBIN/init
  280: 	ln -s $PRG $SBIN/ipfw
  281: 	ln -s $PRG $SBIN/iscontrol
  282: 	ln -s $PRG $SBIN/kldconfig
  283: 	ln -s $PRG $SBIN/kldload
  284: 	ln -s $PRG $SBIN/kldstat
  285: 	ln -s $PRG $SBIN/kldunload
  286: 	ln -s $PRG $SBIN/ldconfig
  287: 	ln -s $PRG $SBIN/md5
  288: 	ln -s $PRG $SBIN/sha1
  289: 	ln -s $PRG $SBIN/sha256
  290: 	ln -s $PRG $SBIN/rmd160
  291: 	ln -s $PRG $SBIN/mdconfig
  292: 	ln -s $PRG $SBIN/mdmfs
  293: 	ln -s $PRG $SBIN/mount_mfs
  294: 	ln -s $PRG $SBIN/mknod
  295: 	ln -s $PRG $SBIN/mksnap_ffs
  296: 	ln -s $PRG $SBIN/mount
  297: 	ln -s $PRG $SBIN/mount_cd9660
  298: 	ln -s $PRG $SBIN/mount_msdosfs
  299: 	ln -s $PRG $SBIN/mount_nfs
  300: #	ln -s $PRG $SBIN/mount_ntfs
  301: 	ln -s $PRG $SBIN/mount_nullfs
  302: 	ln -s $PRG $SBIN/mount_udf
  303: 	ln -s $PRG $SBIN/mount_unionfs
  304: 	ln -s $PRG $SBIN/newfs
  305: 	ln -s $PRG $SBIN/newfs_msdos
  306: 	ln -s $PRG $SBIN/nfsiod
  307: 	ln -s $PRG $SBIN/nos-tun
  308: 	ln -s $PRG $SBIN/nvmecontrol
  309: 	ln -s $PRG $SBIN/pfctl
  310: 	ln -s $PRG $SBIN/pflogd
  311: 	ln -s $PRG $SBIN/quotacheck
  312: 	ln -s $PRG $SBIN/reboot
  313: 	ln -s $PRG $SBIN/halt
  314: 	ln -s $PRG $SBIN/fastboot
  315: 	ln -s $PRG $SBIN/fasthalt
  316: 	ln -s $PRG $SBIN/recoverdisk
  317: 	ln -s $PRG $SBIN/restore
  318: 	ln -s $PRG $SBIN/rrestore
  319: 	ln -s $PRG $SBIN/route
  320: 	ln -s $PRG $SBIN/rtsol
  321: 	ln -s $PRG $SBIN/shutdown
  322: 	ln -s $PRG $SBIN/savecore
  323: 	ln -s $PRG $SBIN/swapon
  324: 	ln -s $PRG $SBIN/swapoff
  325: 	ln -s $PRG $SBIN/swapctl
  326: 	ln -s $PRG $SBIN/sysctl
  327: 	ln -s $PRG $SBIN/tunefs
  328: 	ln -s $PRG $SBIN/umount
  329: 	ln -s $PRG $SBIN/zfs
  330: 	ln -s $PRG $SBIN/zpool
  331: 
  332: 	ln -s $PRG $SBIN/ping
  333: 	ln -s $PRG $SBIN/ping6
  334: 	ln -s $PRG $SBIN/traceroute
  335: 	ln -s $PRG $SBIN/traceroute6
  336: 
  337: 	ln -s $PRG $SBIN/chown
  338: 	ln -s $PRG $SBIN/pwd_mkdb
  339: 	ln -s $PRG $SBIN/arp
  340: 	ln -s $PRG $SBIN/gpioctl
  341: 	ln -s $PRG $SBIN/hostapd
  342: 	ln -s $PRG $SBIN/hostapd_cli
  343: 	ln -s $PRG $SBIN/wpa_supplicant
  344: 	ln -s $PRG $SBIN/wpa_cli
  345: 	ln -s $PRG $SBIN/wpa_passphrase
  346: 	ln -s $PRG $SBIN/wake
  347: 	ln -s $PRG $SBIN/watchdog
  348: 	ln -s $PRG $SBIN/watchdogd
  349: 	ln -s $PRG $SBIN/inetd
  350: 	ln -s $PRG $SBIN/wlandebug
  351: 	ln -s $PRG $SBIN/chroot
  352: 	ln -s $PRG $SBIN/i2c
  353: 	ln -s $PRG $SBIN/iostat
  354: 	ln -s $PRG $SBIN/jail
  355: 	ln -s $PRG $SBIN/jexec
  356: 	ln -s $PRG $SBIN/jls
  357: 	ln -s $PRG $SBIN/ndp
  358: 	ln -s $PRG $SBIN/newsyslog
  359: 	ln -s $PRG $SBIN/nologin
  360: 	ln -s $PRG $SBIN/pstat
  361: 	ln -s $PRG $SBIN/rtadvctl
  362: 	ln -s $PRG $SBIN/rtadvd
  363: 	ln -s $PRG $SBIN/rtsold
  364: 	ln -s $PRG $SBIN/syslogd
  365: 	ln -s $PRG $SBIN/setfib
  366: 	ln -s $PRG $SBIN/swapinfo
  367: 	ln -s $PRG $SBIN/chgrp
  368: 
  369: 	ln -s $PRG $UBIN/login
  370: 	ln -s $PRG $UBIN/passwd
  371: 
  372: 	ln -s $PRG $LIBEXEC/getty
  373: 	ln -s $PRG $LIBEXEC/tftpd
  374: 
  375: 	strip -s $LNPRG
  376: 
  377: 	chown -hR root:wheel $ROOTFS
  378: 
  379: 	echo "+++ ELWIX clean CVS tags ..."
  380: 	CleanCVS $ETC
  381: 	CleanCVS $ETC/etc
  382: 	echo
  383: }
  384: 
  385: build_image()
  386: {
  387: 	echo "+++ Build ELWIX RootFS image ..."
  388: 	makefs -s ${ROOTFS_SIZE} -o minfree=0 $REL/$ROOTFS_IMG $ROOTFS
  389: }
  390: 
  391: install_image()
  392: {
  393: 	echo "+++ Install ELWIX RootFS Image into kernel ..."
  394: 	START=`strings -td $KERNEL_ROOTFS | grep "MFS Filesystem" | cut -d ' ' -f 1 | head -1`
  395: 	STOP=`strings -td $KERNEL_ROOTFS | grep "MFS Filesystem" | cut -d ' ' -f 1 | tail -1`
  396: 	STOP=$(($STOP + 1))
  397: 
  398: 	head -c $START $KERNEL_ROOTFS >$NEWKERN
  399: 	cat $REL/$ROOTFS_IMG >>$NEWKERN
  400: 	tail -c +$STOP $KERNEL_ROOTFS >>$NEWKERN
  401: 
  402: 	cd $REL
  403: 	gzip -9 $KRNNAME
  404: 	cd -
  405: }
  406: 
  407: ### main()
  408: if SnitVer ${WORLD}/elwix.ver; then
  409: 	clean_elwix
  410: 	prepare_elwix || exit 1
  411: 	build_elwix || exit 1
  412: 
  413: 	build_rootdir || exit 1
  414: 	install_rootfs || exit 1
  415: 
  416: 	build_image || exit 1
  417: 	install_image || exit 1
  418: else
  419: 	echo "$? Skipped ELWIX RootFS build ..."
  420: fi
  421: 
  422: echo "+++ Complete build ELWIX RootFS"

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