1
0

nand-preinit.sh 740 B

123456789101112131415161718192021
  1. #!/bin/sh
  2. # Copyright (C) 2014 OpenWrt.org
  3. nand_takeover() {
  4. . /lib/upgrade/nand.sh
  5. mtd=$(find_mtd_index "$CI_UBIPART")
  6. esize=$(cat /proc/mtd | grep mtd$mtd |cut -d" " -f 3)
  7. [ -z "$esize" ] && return 1
  8. esize=$(printf "%d" 0x$esize)
  9. for a in `seq 0 64`; do
  10. mtd -o $((a * esize)) -l 400 dump /dev/mtd$mtd > /tmp/takeover.hdr
  11. MAGIC=$(dd if=/tmp/takeover.hdr bs=1 skip=261 count=5 2> /dev/null)
  12. SIZE=$(printf "%d" 0x$(dd if=/tmp/takeover.hdr bs=4 count=1 2> /dev/null | hexdump -v -n 4 -e '1/1 "%02x"'))
  13. [ "$MAGIC" = "ustar" ] && {
  14. mtd -o $((a * esize)) -l $((SIZE + 4)) dump /dev/mtd$mtd | dd bs=1 skip=4 of=/tmp/sysupgrade.tar
  15. nand_do_upgrade_stage2 /tmp/sysupgrade.tar
  16. }
  17. done
  18. }
  19. boot_hook_add initramfs nand_takeover