Re: [OpenWrt-Devel] [PATCH] ar71xx/all0258n: sysupgrade support

2011-11-01 Thread Gabor Juhos
2011.10.27. 4:41 keltezéssel, Daniel Golle írta:
 U-Boot on the ALL0258N needs offset, size and md5 for kernel and rootfs to be
 stored in the U-Boot environment.
 If the checksums don't match during boot, a failsafe-system is booted instead.
 This patch adds a board-specific sysupgrade hack for the all0258n which
 calculates and updates the checksums for the U-Boot environment.
 
 I also fixed the aparently wrong magic-check for ap121 as obviously 
 $magic_long
 was ment when comparing with 68737173 and not $magic.
 
 Signed-off-by: Daniel Golle dgo...@allnet.de

Applied, thanks!

Gabor
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] ar71xx/all0258n: sysupgrade support

2011-10-27 Thread Gabor Juhos
Hi Daniel,

2011.10.27. 4:41 keltezéssel, Daniel Golle írta:
 U-Boot on the ALL0258N needs offset, size and md5 for kernel and rootfs to be
 stored in the U-Boot environment.
 If the checksums don't match during boot, a failsafe-system is booted instead.
 This patch adds a board-specific sysupgrade hack for the all0258n which
 calculates and updates the checksums for the U-Boot environment.
 
 I also fixed the aparently wrong magic-check for ap121 as obviously 
 $magic_long
 was ment when comparing with 68737173 and not $magic.

Good catch! However this change should go into a separate patch.

Gabor
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] ar71xx/all0258n: sysupgrade support

2011-10-26 Thread Daniel Golle
U-Boot on the ALL0258N needs offset, size and md5 for kernel and rootfs to be
stored in the U-Boot environment.
If the checksums don't match during boot, a failsafe-system is booted instead.
This patch adds a board-specific sysupgrade hack for the all0258n which
calculates and updates the checksums for the U-Boot environment.

I also fixed the aparently wrong magic-check for ap121 as obviously $magic_long
was ment when comparing with 68737173 and not $magic.

Signed-off-by: Daniel Golle dgo...@allnet.de

Index: target/linux/ar71xx/base-files/lib/upgrade/platform.sh
===
--- target/linux/ar71xx/base-files/lib/upgrade/platform.sh  (revision 28611)
+++ target/linux/ar71xx/base-files/lib/upgrade/platform.sh  (working copy)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2009 OpenWrt.org
+# Copyright (C) 2011 OpenWrt.org
 #
 
 . /lib/ar71xx.sh
@@ -69,8 +69,12 @@
[ $ARGC -gt 1 ]  return 1
 
case $board in
+   all0258n )
+   platform_check_image_all0258n $1  return 0
+   return 1
+   ;;
ap121 | ap121-mini | ap96 | db120 | zcn-1523h-2 | zcn-1523h-5)
-   [ $magic != 68737173 -a $magic != 19852003 ]  {
+   [ $magic_long != 68737173 -a $magic_long != 19852003 ] 
 {
echo Invalid image type.
return 1
}
@@ -141,6 +145,9 @@
routerstation | routerstation-pro | ls-sr71 | eap7660d | ja76pf )
platform_do_upgrade_combined $ARGV
;;
+   all0258n )
+   platform_do_upgrade_all0258n $ARGV
+   ;;
*)
default_do_upgrade $ARGV
;;
Index: target/linux/ar71xx/base-files/lib/upgrade/all0258n.sh
===
--- target/linux/ar71xx/base-files/lib/upgrade/all0258n.sh  (revision 0)
+++ target/linux/ar71xx/base-files/lib/upgrade/all0258n.sh  (revision 0)
@@ -0,0 +1,161 @@
+# The U-Boot loader of the ALL0258N requires image sizes and checksums to be
+# provided in the U-Boot environment.
+# In case the check fails during boot, a failsafe-system is started to provide
+# a minimal web-interface for flashing a new firmware.
+
+CI_FLADDR=0x9f05
+
+# make sure we got uboot-envtools and fw_env.config copied over to the ramfs
+platform_add_ramfs_ubootenv() {
+   [ -e /usr/sbin/fw_printenv ]  install_bin /usr/sbin/fw_printenv 
/usr/sbin/fw_setenv
+   [ -e /etc/fw_env.config ]  install_file /etc/fw_env.config
+}
+append sysupgrade_pre_upgrade platform_add_ramfs_ubootenv
+
+# determine size of the main firmware partition
+platform_get_firmware_size() {
+   local dev size erasesize name
+   while read dev size erasesize name; do
+   name=${name#''}; name=${name%''}
+   case $name in
+   firmware)
+   printf %d 0x$size
+   break
+   ;;
+   esac
+   done  /proc/mtd
+}
+
+# get the first 4 bytes (magic) of a given file starting at offset in hex 
format
+get_magic_long_at() {
+   dd if=$1 skip=$(( $CI_BLKSZ / 4 * $2 )) bs=4 count=1 2/dev/null | 
hexdump -v -n 4 -e '1/1 %02x'
+}
+
+get_filesize() {
+   wc -c $1 | while read image_size _n ; do echo $image_size ; break; 
done
+}
+
+# scan through the update image pages until matching a magic
+platform_get_offset() {
+   offsetcount=0
+   magiclong=x
+   if [ -n $3 ]; then
+   offsetcount=$3
+   fi
+   while magiclong=$( get_magic_long_at $1 $offsetcount )  [ -n 
$magiclong ]; do
+   case $magiclong in
+   2705*)
+   # U-Boot image magic
+   if [ $2 = uImage ]; then
+   echo $offsetcount
+   return
+   fi
+   ;;
+   68737173|73717368)
+   # SquashFS
+   if [ $2 = rootfs ]; then
+   echo $offsetcount
+   return
+   fi
+   ;;
+   deadc0de|19852003)
+   # JFFS2 empty page
+   if [ $2 = rootfs-data ]; then
+   echo $offsetcount
+   return
+   fi
+   ;;
+   esac
+   offsetcount=$(( $offsetcount + 1 ))
+   done
+}
+
+platform_check_image_all0258n() {
+   local fw_printenv=/usr/sbin/fw_printenv
+   [ ! -n $fw_printenv -o ! -x $fw_printenv ]  {
+   echo Please install uboot-envtools!
+   return 1
+