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