File:  [ELWIX - Embedded LightWeight unIX -] / elwix / build_rootfs.sh
Revision 1.8.2.3: download - view: text, annotated - select for diffs - revision graph
Fri Jan 17 01:11:52 2014 UTC (10 years, 5 months ago) by misho
Branches: elwix2_2
Diff to: branchpoint 1.8: preferred, unified

ut the shits and fix cross compiling

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

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