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