[OpenWrt-Devel] [PATCH 2/3] x86: add bootloader upgrade on sysupgrade
Tomasz Maciej Nowak
tomek_n at o2.pl
Mon May 27 08:46:29 EDT 2019
Currently bootloader always stays on the same version as when first
written to boot medium. That creates inconveniences as it always stays
with same features or/and bugs. Users wishing to add support to
additional modules or new version, would need to write the whole image,
potentially destroying previous system configuration. To fix these, this
commit adds additional routine to sysupgrade which upgrades
unconditionally the bootloader to the latest state provided by OpenWrt.
Signed-off-by: Tomasz Maciej Nowak <tomek_n at o2.pl>
---
package/boot/grub2/Makefile | 5 +++++
.../x86/base-files/lib/upgrade/platform.sh | 20 ++++++++++++++++++-
target/linux/x86/image/Makefile | 7 ++++---
3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/package/boot/grub2/Makefile b/package/boot/grub2/Makefile
index d6af65128e..d3a347ce84 100644
--- a/package/boot/grub2/Makefile
+++ b/package/boot/grub2/Makefile
@@ -83,6 +83,11 @@ define Host/Configure
$(Host/Configure/Default)
endef
+define Package/grub2/install
+ $(INSTALL_DIR) $(1)/usr/sbin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/grub-bios-setup $(1)/usr/sbin/
+endef
+
define Package/grub2-editenv/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/grub-editenv $(1)/usr/sbin/
diff --git a/target/linux/x86/base-files/lib/upgrade/platform.sh b/target/linux/x86/base-files/lib/upgrade/platform.sh
index 439ba8f512..1a42fd3a11 100644
--- a/target/linux/x86/base-files/lib/upgrade/platform.sh
+++ b/target/linux/x86/base-files/lib/upgrade/platform.sh
@@ -1,3 +1,5 @@
+RAMFS_COPY_BIN='grub-bios-setup'
+
platform_check_image() {
local diskdev partdev diff
[ "$#" -gt 1 ] && return 1
@@ -45,7 +47,7 @@ platform_copy_config() {
}
platform_do_upgrade() {
- local diskdev partdev diff
+ local diskdev partdev diff bootpart
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
@@ -92,4 +94,20 @@ 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
+
+ #upgrade bootloader
+ 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
}
diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
index ca5fd72153..7f69f35ae8 100644
--- a/target/linux/x86/image/Makefile
+++ b/target/linux/x86/image/Makefile
@@ -67,11 +67,11 @@ ifneq ($(CONFIG_GRUB_IMAGES),)
grub-mkimage \
-p /boot/grub \
-d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
- -o $(KDIR)/grub2/core.img \
+ -o $(KDIR)/root.grub/boot/grub/core.img \
-O i386-pc \
-c ./grub-early.cfg \
$(GRUB2_MODULES)
- $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
+ $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/root.grub/boot/grub/
echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
sed \
-e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
@@ -81,6 +81,7 @@ ifneq ($(CONFIG_GRUB_IMAGES),)
-e 's#@TITLE@#$(GRUB_TITLE)#g' \
./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
-$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/
+ grub-bios-setup -V | cut -d' ' -f3 > $(KDIR)/root.grub/boot/grub/version
PADDING="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" $(SCRIPT_DIR)/gen_image_generic.sh \
$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
$(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
@@ -88,7 +89,7 @@ ifneq ($(CONFIG_GRUB_IMAGES),)
256
grub-bios-setup \
--device-map="$(KDIR)/grub2/device.map" \
- -d "$(KDIR)/grub2" \
+ -d "$(KDIR)/root.grub/boot/grub" \
-r "hd0,msdos1" \
"$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
endef
--
2.21.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list