--- elwix/install2img.sh 2014/09/12 00:29:27 1.7.6.2 +++ elwix/install2img.sh 2017/06/21 13:00:48 1.8.4.2 @@ -5,7 +5,7 @@ # (C) AITNET ltd - Sofia/Bulgaria # by Michael Pounov # -# $Id: install2img.sh,v 1.7.6.2 2014/09/12 00:29:27 misho Exp $ +# $Id: install2img.sh,v 1.8.4.2 2017/06/21 13:00:48 misho Exp $ # [ -r ./config/rc.elwix ] && . ./config/rc.elwix @@ -52,22 +52,33 @@ initdev() exit 3 fi - disklabel $1 2>&- | awk -vcfgsize=${CFG_NAND_SIZE:-65536} '($1 == "a:") { - cfgsize /= 512; - for (i = 1; i <= NF; i++) { - if (i == 2) - printf("%s ", $i - cfgsize); - else if (i == 3) { - offset = $i; - printf("%s ", cfgsize + offset); - } else - printf("%s ", $i); - } - printf("\n"); - printf("g: %d %d cfg 0 0 0\n", cfgsize, offset); - next; - } - { printf("%s\n", $0); }' >/tmp/disklabel.tmp + if [ X"$2" != X"no" ]; then + disklabel $1 2>&- | awk -vcfgsize=${CFG_NAND_SIZE:-65536} '($1 == "a:") { + cfgsize /= 512; + bootoff = $3; + freesize = $2 - cfgsize; + imgsize = freesize / 2; + + printf(" a: %d %d unused 0 0 0\n", imgsize, cfgsize + bootoff); + printf(" f: %d %d unused 0 0 0\n", imgsize, imgsize + cfgsize + bootoff); + printf(" g: %d %d cfg 0 0 0\n", cfgsize, bootoff); + next; + } + { printf("%s\n", $0); }' >/tmp/disklabel.tmp + else + disklabel $1 2>&- | awk -vcfgsize=${CFG_NAND_SIZE:-65536} '($1 == "a:") { + cfgsize /= 512; + bootoff = $3; + freesize = $2 - cfgsize; + imgsize = freesize; + + printf(" a: %d %d unused 0 0 0\n", imgsize, cfgsize + bootoff); + printf(" g: %d %d cfg 0 0 0\n", cfgsize, bootoff); + next; + } + { printf("%s\n", $0); }' >/tmp/disklabel.tmp + fi + if disklabel -R -m ${TARGET} $1 /tmp/disklabel.tmp; then rm -f /tmp/disklabel.tmp echo "OK" @@ -138,6 +149,27 @@ install2() fi } +mkbak2() +{ + if [ X"$2" != X"no" ]; then + echo -n "+++ Syncing ELWIX OS image as backup OS image into ${1}f ..." + if dd if=/dev/${1}a of=/dev/${1}f; then + echo "OK" + else + echo "Failed!" + exit 8 + fi + fi + + echo "+++ Make ELWIX OS system image partion for upgrade into ${REL}/sys4up_${IMGNAME}.bin ..." + if dd if=/dev/${1}a of=${REL}/sys4up_${IMGNAME}.bin; then + echo "OK" + else + echo "Failed!" + exit 9 + fi +} + cleandev() { mdconfig -d -u $1 @@ -156,6 +188,7 @@ gencksum() if [ -z "$1" -o ! -r "$1" ]; then echo echo "Error:: ELWIX OS tar file '$1' not found!" + echo "Syntax:: ./install2img.sh [CF size] [yes == make secondary backup image]" echo exit 2 else @@ -166,13 +199,15 @@ else fi mkdevice $IMG ${2:-"${IMG_SIZE}"} -initdev $DEV +initdev $DEV ${3:-"no"} mountdev $DEV install2 $1 umountdev #enablejfs $DEV boot2dev $DEV +mkbak2 $DEV ${3:-"no"} cleandev $DEV gencksum $IMG $MD5CHK $SHA1CHK +gencksum ${REL}/sys4up_${IMGNAME}.bin ${REL}/sys4up_${IMGNAME}.md5 ${REL}/sys4up_${IMGNAME}.sha1 echo "ELWIX OS image $IMGNAME complete."