treewide: use new procd sysupgrade $UPGRADE_BACKUP variable
[openwrt/staging/dedeckeh.git] / package / base-files / files / lib / upgrade / common.sh
index 9e9144cba4e9bbe0d95b77b5b3bec716e1403fb0..8e7866f69847953c48dce009e473a82366e75f99 100644 (file)
@@ -2,6 +2,8 @@
 
 RAM_ROOT=/tmp/root
 
+export BACKUP_FILE=sysupgrade.tgz      # file extracted by preinit
+
 [ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
 libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; }
 
@@ -101,35 +103,41 @@ get_magic_long() {
 }
 
 export_bootdevice() {
-       local cmdline uuid disk uevent line
+       local cmdline bootdisk rootpart uuid blockdev uevent line
        local MAJOR MINOR DEVNAME DEVTYPE
 
        if read cmdline < /proc/cmdline; then
                case "$cmdline" in
                        *block2mtd=*)
-                               disk="${cmdline##*block2mtd=}"
-                               disk="${disk%%,*}"
+                               bootdisk="${cmdline##*block2mtd=}"
+                               bootdisk="${bootdisk%%,*}"
                        ;;
                        *root=*)
-                               disk="${cmdline##*root=}"
-                               disk="${disk%% *}"
+                               rootpart="${cmdline##*root=}"
+                               rootpart="${rootpart%% *}"
+                       ;;
+               esac
+
+               case "$bootdisk" in
+                       /dev/*)
+                               uevent="/sys/class/block/${bootdisk##*/}/uevent"
                        ;;
                esac
 
-               case "$disk" in
-                       PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-02)
-                               uuid="${disk#PARTUUID=}"
-                               uuid="${uuid%-02}"
-                               for disk in $(find /dev -type b); do
-                                       set -- $(dd if=$disk bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "')
+               case "$rootpart" in
+                       PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-[a-f0-9][a-f0-9])
+                               uuid="${rootpart#PARTUUID=}"
+                               uuid="${uuid%-[a-f0-9][a-f0-9]}"
+                               for blockdev in $(find /dev -type b); do
+                                       set -- $(dd if=$blockdev bs=1 skip=440 count=4 2>/dev/null | hexdump -v -e '4/1 "%02x "')
                                        if [ "$4$3$2$1" = "$uuid" ]; then
-                                               uevent="/sys/class/block/${disk##*/}/uevent"
+                                               uevent="/sys/class/block/${blockdev##*/}/uevent"
                                                break
                                        fi
                                done
                        ;;
                        /dev/*)
-                               uevent="/sys/class/block/${disk##*/}/uevent"
+                               uevent="/sys/class/block/${rootpart##*/}/../uevent"
                        ;;
                esac
 
@@ -164,7 +172,7 @@ export_partdevice() {
 }
 
 hex_le32_to_cpu() {
-       [ "$(echo 01 | hexdump -v -n 2 -e '/2 "%x"')" == "3031" ] && {
+       [ "$(echo 01 | hexdump -v -n 2 -e '/2 "%x"')" = "3031" ] && {
                echo "${1:0:2}${1:8:2}${1:6:2}${1:4:2}${1:2:2}"
                return
        }
@@ -201,16 +209,6 @@ get_partitions() { # <device> <filename>
        fi
 }
 
-jffs2_copy_config() {
-       if grep rootfs_data /proc/mtd >/dev/null; then
-               # squashfs+jffs2
-               mtd -e rootfs_data jffs2write "$CONF_TAR" rootfs_data
-       else
-               # jffs2
-               mtd jffs2write "$CONF_TAR" rootfs
-       fi
-}
-
 indicate_upgrade() {
        . /etc/diag.sh
        set_state upgrade
@@ -222,34 +220,10 @@ indicate_upgrade() {
 # $(2): (optional) pipe command to extract firmware, e.g. dd bs=n skip=m
 default_do_upgrade() {
        sync
-       if [ "$SAVE_CONFIG" -eq 1 ]; then
-               get_image "$1" "$2" | mtd $MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}"
+       if [ "$UPGRADE_OPT_SAVE_CONFIG" -eq 1 ]; then
+               get_image "$1" "$2" | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j "$UPGRADE_BACKUP" write - "${PART_NAME:-image}"
        else
-               get_image "$1" "$2" | mtd write - "${PART_NAME:-image}"
+               get_image "$1" "$2" | mtd $MTD_ARGS write - "${PART_NAME:-image}"
        fi
        [ $? -ne 0 ] && exit 1
 }
-
-do_upgrade_stage2() {
-       v "Performing system upgrade..."
-       if [ -n "$do_upgrade" ]; then
-               eval "$do_upgrade"
-       elif type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
-               platform_do_upgrade "$IMAGE"
-       else
-               default_do_upgrade "$IMAGE"
-       fi
-
-       if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev/null 2>/dev/null; then
-               platform_copy_config
-       fi
-
-       v "Upgrade completed"
-       sleep 1
-
-       v "Rebooting system..."
-       umount -a
-       reboot -f
-       sleep 5
-       echo b 2>/dev/null >/proc/sysrq-trigger
-}