1: #!/bin/sh
2: #
3: # U-boot cfg nand map load/save management script
4: #
5: # $Id: rc.cfg,v 1.3.2.2 2017/06/23 08:56:48 misho Exp $
6:
7: CFG_NAND_LIST="/etc/cfg.map"
8: CFG_NAND_MAP="/dev/map/cfg"
9: CFG_NAND_SIZE=65536
10:
11: UPGRADE_GPIO_PINS="8 6 7"
12:
13: ELWIX_CFG_BACKUP_NAME="elwix_cfg_$(hostname).bin"
14:
15: PKG2CF="/elwix/cf/pkg"
16:
17: die() { echo -n "EXIT: " >&2; echo "$@" >&2; exit 1; }
18:
19: cd ${2:-/etc}
20:
21: case "$1" in
22: load)
23: imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} | \
24: gunzip 2>&- | cpio -iud 2>&- || die "ERROR:: config load"
25: ;;
26: save)
27: if [ ! -r ${CFG_NAND_LIST} ]; then
28: echo "# Auto generated manifest file" >${CFG_NAND_LIST}
29: find . >>${CFG_NAND_LIST}
30: if [ $? -ne 0 -o ! -r ${CFG_NAND_LIST} ]; then
31: die "ERROR:: Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!"
32: fi
33: fi
34:
35: sed -nE -e 's/^ *([^ #]+) */\1/p' < ${CFG_NAND_LIST} | xargs find | \
36: cpio -o | gzip -9 | \
37: imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config save"
38: ;;
39: erase)
40: imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || die "ERROR:: config erase"
41: echo "Config NAND was erased!"
42: ;;
43: restore)
44: ELWIX_REMOTE_HOST=`cat /etc/myelwix`
45: ping -c1 $(echo ${ELWIX_REMOTE_HOST} | cut -f3 -d '/' | cut -f2 -d '@') >/dev/null 2>&1
46: if [ $? -ne 0 ]; then
47: die "ERROR:: ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!"
48: fi
49:
50: echo "ELWIX starting restore process from ${ELWIX_REMOTE_HOST}"
51: fetch -q -o- --user-agent=ELWIX_Restore --allow-sslv2 \
52: --no-verify-peer --no-verify-hostname \
53: ${ELWIX_REMOTE_HOST}/${ELWIX_CFG_BACKUP_NAME} | \
54: imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config restore"
55: echo "ELWIX restore process complete. Now rebooting system ..."
56: ;;
57: backup)
58: ELWIX_REMOTE_HOST="/tmp/${ELWIX_CFG_BACKUP_NAME}"
59:
60: echo "ELWIX starting backup process to ${ELWIX_REMOTE_HOST}"
61: imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || die "ERROR:: config backup"
62: echo "ELWIX backup process complete."
63: ;;
64: upgrade)
65: echo "ELWIX switch to upgrade mode. Starting TFTPd ..."
66: echo " You can upload now elwix_firmware.bin image to device with \"firmware\" name!!!"
67: echo " Example: put elwix_firmware.bin firmware"
68: for i in ${UPGRADE_GPIO_PINS}; do
69: gpioctl $i 1 >/dev/null 2>&1
70: done
71: TFTPd -wR
72: ;;
73: pkg_save)
74: echo "ELWIX syncing information about installed packages into storage"
75: cfexec tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save"
76: echo "ELWIX sync process complete."
77: ;;
78: pkg_load)
79: echo "ELWIX loading information about installed packages from storage"
80: tar -xzvpf /elwix/altroot/pkg/db/pkgz.tar.gz -C / || die "ERROR:: package load"
81: echo "ELWIX load process complete."
82: ;;
83: pkg2cf)
84: echo "ELWIX setup new pkg location on CF at $PKGCF"
85: if ! mount | grep "/elwix/cf"; then
86: echo "Skip pkg2cf setup, because CF partition isn't mounted ..."
87: exit 1
88: fi
89: if [ ! -L /elwix/local -a ! -L /elwix/altroot/pkg/db ]; then
90: mkdir -p ${PKG2CF}/db
91: mkdir -p ${PKG2CF}/local
92: cp -r /elwix/altroot/pkg/db/* ${PKG2CF}/db
93: cp -r /elwix/local/* ${PKG2CF}/local
94: rm -rf /elwix/local /elwix/altroot/pkg/db
95: ln -s ${PKG2CF}/db /elwix/altroot/pkg/db
96: ln -s ${PKG2CF}/local /elwix/local
97: fi
98: echo "ELWIX pkg2cf setup complete."
99: ;;
100: *)
101: echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade | pkg_load | pkg_save | pkg2cf)"
102: ;;
103: esac
104:
105: cd -
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>