hotfix_updater: add u-boot, tweak uImage handling
authorGrazvydas Ignotas <notasas@gmail.com>
Fri, 18 Jun 2010 18:16:48 +0000 (21:16 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Fri, 18 Jun 2010 18:17:00 +0000 (21:17 +0300)
hotfix_updater/updater.sh

index 3abcd87..b1bebbe 100755 (executable)
@@ -1,10 +1,19 @@
 #!/bin/bash
 
-oldkern2=b00a5d617f11366689488395b19411de
-oldkern1=3112d1782a90c2c87ae17a152a35deae
-newkern=aed218fe59ff93618bddd2b52b020014
+# kernels we are sure we want to update
+oldkern="\
+3112d1782a90c2c87ae17a152a35deae \
+b00a5d617f11366689488395b19411de \
+aed218fe59ff93618bddd2b52b020014 \
+"
+newkern=53ca541a471f726eb1103f19d4306e61
 currkern=$(md5sum /boot/uImage | cut -d" " -f1)
-needfree=$(ls -lk uImage | grep uImage | cut -d" " -f5)
+
+# u-boot versions we want to update
+oldubootvers="\
+U-Boot_2010.03_(May_19_2010_-_18:30:30) \
+"
+
 oldinterfaces=23f72750f2f7335b9c2ed3f55aaa5061
 oldrcwl1251=7a6361e842f0f589418218436affbe07
 newmmenu=af66a5118a9bfef8eca5de13ee64c6a1
@@ -16,49 +25,135 @@ err="Your system has been updated without any errors."
 
 rm /tmp/updater.log
 
-if zenity --question --title="Update Package 2" --text="This PND updates your Pandora OS. You can safely delete it after it has finished.\nThis pack includes all updates from Hotfix 1 as well.\n\nDo you want to start the upgrade now? " --ok-label="Start now" --cancel-label="Don't do it" ; then
+if zenity --question --title="Update Package 2" --text="\
+This PND updates your Pandora OS. You can safely delete it after it has finished.\n\
+This pack includes all updates from Hotfix 1 as well.\n\n\
+Do you want to start the upgrade now? " --ok-label="Start now" --cancel-label="Don't do it" ; then
 
 (
-echo "10"
-echo "# Updating kernel if needed"
-
 
 # Kernel Update
 
-  if [ $oldkern1 = $currkern -o $oldkern2 = $currkern ]; then   
+echo "7"
+echo "# Updating kernel if needed"
+
+update_kernel()
+{
+     have_error=false
+
      rm /boot/uImage.old 
+     needfree=$(ls -lk uImage | grep uImage | cut -d" " -f5)
      currfree=$(df /boot | grep boot | awk '{print $4}')
      if [ $currfree -lt $needfree ]; then
         err="There is not enough diskspace on /boot/ to update the kernel.\n\nKernel couldn't be updated."
         echo "Kernel not updated - not enough diskspace on /boot/" >> /tmp/updater.log
-      else
+        have_error=true
+     else
         cp uImage /boot/uImage.new 
         sync
+        bad_checksum=false
         currkern=$(md5sum /boot/uImage.new | cut -d" " -f1)
-          if [ $currkern = $newkern ]; then
+          if [ "$currkern" = "$newkern" ]; then
             mv /boot/uImage /boot/uImage.old 
             mv /boot/uImage.new /boot/uImage 
             currkern=$(md5sum /boot/uImage | cut -d" " -f1)
-            if [ $currkern != $newkern ]; then
+            if [ "$currkern" != "$newkern" ]; then
                rm /boot/uImage 
                mv /boot/uImage.old /boot/uImage 
-               err="There was a checksum error while copying the kernel.\n\nKernel couldn't be updated. Please check your SD-Card and try to recopy the PND-File."
-               echo "Kernel not updated - checksum error" >> /tmp/updater.log
+               bad_checksum=true
             fi
           else
             rm /boot/uImage.new 
+            bad_checksum=true
+          fi
+          if $bad_checksum; then
             err="There was a checksum error while copying the kernel.\n\nKernel couldn't be updated. Please check your SD-Card and try to recopy the PND-File."
             echo "Kernel not updated - checksum error" >> /tmp/updater.log
+            have_error=true
           fi
      fi
-    echo "Kernel successfully updated" >> /tmp/updater.log
-    sync
+
+     if ! $have_error; then
+       echo "Kernel successfully updated" >> /tmp/updater.log
+     fi
+     sync
+}
+
+kernel_known=false
+for oknl in $oldkern $newkern; do
+  if [ "$oknl" = "$currkern" ]; then
+    kernel_known=true
+    break
+  fi
+done
+
+if [ "$kernel_known" = "true" -o -z "$currkern" ]; then
+  if [ "$currkern" != "$newkern" ]; then
+    update_kernel
   else
     echo "Kernel already up-to-date" >> /tmp/updater.log
   fi
+else
+  if zenity --question --title="Custom kernel?" --text="\
+You seem to have custom or newer kernel in flash.\n\n\
+Update it anyway?\n\
+(if unsure, select Yes)" --ok-label="Yes" --cancel-label="No" ; then
+    update_kernel
+  else
+    echo "Kernel update skipped" >> /tmp/updater.log
+  fi
+fi
   
 
+# u-boot Update
+
+echo "15"
+echo "# U-Boot if needed"
+
+update_uboot()
+{
+  if flash_eraseall /dev/mtd1 && nandwrite -p /dev/mtd1 u-boot.bin; then
+    # XXX: perhaps we need to check if write went ok?
+    echo "u-boot.bin flashed." >> /tmp/updater.log
+  else
+    echo "u-boot.bin flashing failed." >> /tmp/updater.log
+  fi
+}
+
+rm /tmp/u-boot.bin.nand 2> /deb/null
+nanddump -o -b -q -f /tmp/u-boot.bin.nand /dev/mtd1
+uboot_nand_ver=`strings /tmp/u-boot.bin.nand | grep 'U-Boot 20' | head -n 1 | sed 's/ /_/g'`
+uboot_ver=`strings u-boot.bin | grep 'U-Boot 20' | head -n 1 | sed 's/ /_/g'`
+uboot_size=`stat -c %s u-boot.bin`
+
+dd if=/tmp/u-boot.bin.nand of=/tmp/u-boot.bin.nand.cmp bs=$uboot_size count=1
+if ! cmp u-boot.bin /tmp/u-boot.bin.nand.cmp
+then
+  uboot_need_to_ask=true
+  for oldver in $oldubootvers; do
+    if [ "$oldver" = "$uboot_nand_ver" ]; then
+      uboot_need_to_ask=false
+      break
+    fi
+  done
+
+  if $uboot_need_to_ask; then
+    if zenity --question --title="Custom u-boot?" --text="\
+You seem to have custom or newer u-boot in flash.\n\n\
+Update it anyway?\n\
+(if unsure, select Yes)" --ok-label="Yes" --cancel-label="No" ; then
+      update_uboot
+    else
+      echo "u-boot update skipped\n(nand has $uboot_nand_ver)" >> /tmp/updater.log
+    fi
+  else
+    update_uboot
+  fi
+else
+  echo "u-boot already up-to-date\n($uboot_nand_ver)" >> /tmp/updater.log
+fi
+
+
 # HotFix 1
 
 # Libraries for HotFix 1