[OpenWrt-Devel] [RFC 5/6] x86/grub2: add bootloader upgrade on sysupgrade
Tomasz Maciej Nowak
tomek_n at o2.pl
Sun Jan 13 16:49:14 EST 2019
Enable bootloader upgrade on sysupgrade for all x86 subtargets to keep
it up to date. To achieve this grub2 user installable packages are
created, with appropriate variant added to subtarget default packages.
The bootloader upgrade is performed on each sysupgrade process.
Signed-off-by: Tomasz Maciej Nowak <tomek_n at o2.pl>
---
package/boot/grub2/Makefile | 42 ++++++++++++++++++-
target/linux/x86/64/target.mk | 2 +-
.../x86/base-files/lib/upgrade/platform.sh | 27 +++++++++++-
target/linux/x86/generic/target.mk | 2 +-
target/linux/x86/geode/target.mk | 2 +-
target/linux/x86/legacy/target.mk | 1 +
6 files changed, 71 insertions(+), 5 deletions(-)
diff --git a/package/boot/grub2/Makefile b/package/boot/grub2/Makefile
index cefc4ed92e..4445a30ea8 100644
--- a/package/boot/grub2/Makefile
+++ b/package/boot/grub2/Makefile
@@ -31,7 +31,7 @@ include $(INCLUDE_DIR)/package.mk
define Package/grub2
CATEGORY:=Boot Loaders
SECTION:=boot
- TITLE:=GRand Unified Bootloader
+ TITLE:=GRand Unified Bootloader $(1)
URL:=http://www.gnu.org/software/grub/
DEPENDS:=@TARGET_x86
endef
@@ -49,6 +49,20 @@ define Package/grub2-editenv/description
Edit grub2 environment files.
endef
+define Package/grub2-generic
+ $(call Package/grub2,for 64 and generic subtargets)
+ DEPENDS:=@TARGET_x86_64||TARGET_x86_generic
+ PROVIDES+=grub2
+ HIDDEN:=y
+endef
+
+define Package/grub2-legacy
+ $(call Package/grub2,for geode and legacy subtargets)
+ DEPENDS:=@TARGET_x86_geode||TARGET_x86_legacy
+ PROVIDES+=grub2
+ HIDDEN:=y
+endef
+
HOST_BUILD_PREFIX := $(STAGING_DIR_HOST)
CONFIGURE_VARS += \
@@ -119,6 +133,32 @@ define Package/grub2-editenv/install
$(INSTALL_BIN) $(PKG_BUILD_DIR)/grub-editenv $(1)/usr/sbin/
endef
+define Package/grub2-generic/install
+ $(INSTALL_DIR) $(1)/usr/sbin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/grub-bios-setup $(1)/usr/sbin/
+
+ $(INSTALL_DIR) $(1)/usr/lib/grub/grub2
+ $(CP) $(STAGING_DIR_HOST)/lib/grub/grub2-generic/core.img \
+ $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img \
+ $(1)/usr/lib/grub/grub2/
+ printf 'BL=$(PKG_NAME)\nBL_VARIANT=generic\nBL_VERSION=$(PKG_VERSION)\nBL_RELEASE=$(PKG_RELEASE)\n' \
+ > $(1)/usr/lib/grub/grub2/bl-release
+endef
+
+define Package/grub2-legacy/install
+ $(INSTALL_DIR) $(1)/usr/sbin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/grub-bios-setup $(1)/usr/sbin/
+
+ $(INSTALL_DIR) $(1)/usr/lib/grub/grub2
+ $(CP) $(STAGING_DIR_HOST)/lib/grub/grub2-legacy/core.img \
+ $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img \
+ $(1)/usr/lib/grub/grub2/
+ printf 'BL=$(PKG_NAME)\nBL_VARIANT=legacy\nBL_VERSION=$(PKG_VERSION)\nBL_RELEASE=$(PKG_RELEASE)\n' \
+ > $(1)/usr/lib/grub/grub2/bl-release
+endef
+
$(eval $(call HostBuild))
$(eval $(call BuildPackage,grub2))
$(eval $(call BuildPackage,grub2-editenv))
+$(eval $(call BuildPackage,grub2-generic))
+$(eval $(call BuildPackage,grub2-legacy))
diff --git a/target/linux/x86/64/target.mk b/target/linux/x86/64/target.mk
index 5dd0015a03..4035dda289 100644
--- a/target/linux/x86/64/target.mk
+++ b/target/linux/x86/64/target.mk
@@ -1,6 +1,6 @@
ARCH:=x86_64
BOARDNAME:=x86_64
-DEFAULT_PACKAGES += kmod-button-hotplug kmod-e1000e kmod-e1000 kmod-r8169 kmod-igb kmod-bnx2
+DEFAULT_PACKAGES += grub2-generic kmod-button-hotplug kmod-e1000e kmod-e1000 kmod-r8169 kmod-igb kmod-bnx2
define Target/Description
Build images for 64 bit systems including virtualized guests.
diff --git a/target/linux/x86/base-files/lib/upgrade/platform.sh b/target/linux/x86/base-files/lib/upgrade/platform.sh
index 439ba8f512..0a2a9592c2 100644
--- a/target/linux/x86/base-files/lib/upgrade/platform.sh
+++ b/target/linux/x86/base-files/lib/upgrade/platform.sh
@@ -45,7 +45,7 @@ platform_copy_config() {
}
platform_do_upgrade() {
- local diskdev partdev diff
+ local diskdev partdev diff bootdev rootdev
export_bootdevice && export_partdevice diskdev 0 || {
echo "Unable to determine upgrade device"
@@ -92,4 +92,29 @@ 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 bootdev 1; then
+ mkdir -p /tmp/boot
+ mount -o rw,noatime "/dev/$bootdev" /tmp/boot
+
+ if export_partdevice rootdev 2; then
+ mount -o noatime "/dev/$rootdev" /mnt
+
+ echo "(hd0) /dev/$diskdev" > /tmp/device.map
+
+ echo "Upgrading bootloader on /dev/$diskdev..."
+ type /mnt/usr/sbin/grub-bios-setup >/dev/null 2>/dev/null \
+ && /mnt/usr/sbin/grub-bios-setup \
+ -m "/tmp/device.map" \
+ -d "/mnt/usr/lib/grub/grub2" \
+ -r "hd0,msdos1" \
+ "/dev/$diskdev" \
+ && cp -f /mnt/usr/lib/grub/grub2/bl-release /tmp/boot/boot/
+
+ umount /mnt
+ fi
+
+ umount /tmp/boot
+ fi
}
diff --git a/target/linux/x86/generic/target.mk b/target/linux/x86/generic/target.mk
index 90586f56d6..0a6f332dd0 100644
--- a/target/linux/x86/generic/target.mk
+++ b/target/linux/x86/generic/target.mk
@@ -1,7 +1,7 @@
BOARDNAME:=Generic
CPU_TYPE :=pentium4
FEATURES += audio pci pcie usb
-DEFAULT_PACKAGES += kmod-button-hotplug
+DEFAULT_PACKAGES += grub2-generic kmod-button-hotplug
define Target/Description
Build firmware images for modern x86 based boards with CPUs
diff --git a/target/linux/x86/geode/target.mk b/target/linux/x86/geode/target.mk
index cd7afef944..d3e9d8111e 100644
--- a/target/linux/x86/geode/target.mk
+++ b/target/linux/x86/geode/target.mk
@@ -1,6 +1,6 @@
BOARDNAME:=AMD Geode based systems
FEATURES+=pci usb gpio
-DEFAULT_PACKAGES+=kmod-button-hotplug
+DEFAULT_PACKAGES+=grub2-legacy kmod-button-hotplug
define Target/Description
Build firmware images for AMD Geode GX/LX based systems (net5501, alix, geos)
diff --git a/target/linux/x86/legacy/target.mk b/target/linux/x86/legacy/target.mk
index bd0a87d67f..3f301637eb 100644
--- a/target/linux/x86/legacy/target.mk
+++ b/target/linux/x86/legacy/target.mk
@@ -1,4 +1,5 @@
BOARDNAME:=Legacy
+DEFAULT_PACKAGES+=grub2-legacy
define Target/Description
Build firmware images for legacy x86 based boards
--
2.20.1
_______________________________________________
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