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