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