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