x86: add bootloader upgrade on sysupgrade
[openwrt/staging/jogo.git] / target / linux / x86 / base-files / lib / upgrade / platform.sh
index 439ba8f5125d97932248ff966340165a84e1b24a..8be96dfcd45f7a85e11683c1d4a218e1c4680719 100644 (file)
@@ -1,3 +1,5 @@
+RAMFS_COPY_BIN='grub-bios-setup'
+
 platform_check_image() {
        local diskdev partdev diff
        [ "$#" -gt 1 ] && return 1
@@ -39,11 +41,31 @@ platform_copy_config() {
 
        if export_partdevice partdev 1; then
                mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
-               cp -af "$CONF_TAR" /mnt/
+               cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
                umount /mnt
        fi
 }
 
+platform_do_bootloader_upgrade() {
+       local bootpart
+       local diskdev="$1"
+
+       if export_partdevice bootpart 1; then
+               mkdir -p /tmp/boot
+               mount -o rw,noatime "/dev/$bootpart" /tmp/boot
+               echo "(hd0) /dev/$diskdev" > /tmp/device.map
+
+               echo "Upgrading bootloader on /dev/$diskdev..."
+               grub-bios-setup \
+                       -m "/tmp/device.map" \
+                       -d "/tmp/boot/boot/grub" \
+                       -r "hd0,msdos1" \
+                       "/dev/$diskdev"
+
+               umount /tmp/boot
+       fi
+}
+
 platform_do_upgrade() {
        local diskdev partdev diff
 
@@ -54,7 +76,7 @@ platform_do_upgrade() {
 
        sync
 
-       if [ "$SAVE_PARTITIONS" = "1" ]; then
+       if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
                get_partitions "/dev/$diskdev" bootdisk
 
                #extract the boot sector from the image
@@ -92,4 +114,6 @@ platform_do_upgrade() {
        #copy partition uuid
        echo "Writing new UUID to /dev/$diskdev..."
        get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
+
+       platform_do_bootloader_upgrade "$diskdev"
 }