#!/bin/sh
#
# U-boot cfg nand map load/save management script
#
# $Id: rc.cfg,v 1.2.2.3 2014/09/23 14:18:19 misho Exp $
CFG_NAND_LIST="/etc/cfg.map"
CFG_NAND_MAP="/dev/ada0g"
CFG_NAND_SIZE=262144
UPGRADE_GPIO_PINS="1 2 3"
cd ${2:-/etc}
case "$1" in
load)
imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} | \
gunzip 2>&- | cpio -iud 2>&- || exit 1
;;
save)
if [ ! -r ${CFG_NAND_LIST} ];then
echo "# Auto generated manifest file" >${CFG_NAND_LIST}
find . >>${CFG_NAND_LIST}
if [ $? -ne 0 -o ! -r ${CFG_NAND_LIST} ]; then
echo "Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!"
exit 1
fi
fi
sed -nE -e 's/^ *([^ #]+) */\1/p' < ${CFG_NAND_LIST} | xargs find | \
cpio -o | gzip -9 | \
imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || exit 1
;;
erase)
imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || exit 1
echo "Config NAND was erased!"
;;
restore)
ELWIX_REMOTE_HOST=`cat /etc/myelwix`
ping -c1 $(echo ${ELWIX_REMOTE_HOST} | cut -f3 -d '/' | cut -f2 -d '@') >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!"
exit 1
fi
echo "ELWIX starting restore process from ${ELWIX_REMOTE_HOST}"
fetch -q -o- --user-agent=ELWIX_Restore --allow-sslv2 \
--no-verify-peer --no-verify-hostname ${ELWIX_REMOTE_HOST} | \
imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || exit 1
echo "ELWIX restore process complete. Now rebooting system ..."
;;
backup)
ELWIX_REMOTE_HOST="/tmp/elwix_cfg_$(hostname).bin"
echo "ELWIX starting backup process to ${ELWIX_REMOTE_HOST}"
imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || exit 1
echo "ELWIX backup process complete."
;;
upgrade)
echo "ELWIX switch to upgrade mode. Starting TFTPd ..."
echo " You can upload now elwix_firmware.bin image to device with \"firmware\" name!!!"
echo " Example: put elwix_firmware.bin firmware"
for i in ${UPGRADE_GPIO_PINS}; do
gpioctl $i 1 >/dev/null 2>&1 || pceng "$i=0" >/dev/null 2>&1
done
TFTPd -wR
;;
*)
echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade)"
;;
esac
cd -
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>