Subject: [alpine-aports] [PATCH] testing/grub: add grub-xenhost (pv-grub2)

From: Henrik Riomar <[email-masked]>
Date: Sun, 6 Nov 2016 15:47:10 +0100

Based on the Debian handling of grub-xen-host

grub2-accept-empty-module.patch from http://savannah.gnu.org/bugs/?49012
---
 testing/grub/APKBUILD                        | 93 ++++++++++++++++++++++++----
 testing/grub/grub-xen-host_grub.cfg          | 24 +++++++
 testing/grub/grub2-accept-empty-module.patch | 22 +++++++
 3 files changed, 127 insertions(+), 12 deletions(-)
 create mode 100644 testing/grub/grub-xen-host_grub.cfg
 create mode 100644 testing/grub/grub2-accept-empty-module.patch

diff --git a/testing/grub/APKBUILD b/testing/grub/APKBUILD
index 2236135..17c6f3e 100644
--- a/testing/grub/APKBUILD
+++ b/testing/grub/APKBUILD
@@ -3,7 +3,7 @@
 pkgname=grub
 _ver=2.02~beta3
 pkgver=2.02_beta3
-pkgrel=1
+pkgrel=2
 pkgdesc="Bootloader with support for Linux, Multiboot and more"
 url="https://www.gnu.org/software/grub/"
 arch="all !armhf"
@@ -13,10 +13,14 @@ depends_dev=""
 makedepends="$depends_dev bison flex linux-headers xz-dev lvm2-dev
 	automake autoconf libtool python2"
 install=""
-subpackages="$pkgname-dev $pkgname-doc $pkgname-efi"
+# strip handled by grub Makefiles, abuild strip breaks xen pv-grub
+options="!strip"
+subpackages="$pkgname-dev $pkgname-doc $pkgname-efi $pkgname-xenhost"
 source="ftp://alpha.gnu.org/gnu/grub/grub-$_ver.tar.xz
 	2.02_beta3-gcc6-ld-no-pie.patch
 	fix-gcc-no-pie-specs.patch
+	grub2-accept-empty-module.patch
+	grub-xen-host_grub.cfg
 	"
 builddir="$srcdir/grub-$_ver"
 
@@ -59,37 +63,90 @@ _build_efi() {
 	make || return 1
 }
 
+_build_xen() {
+	cd $builddir/xen
+	./configure \
+		--build=$CBUILD \
+		--host=$CHOST \
+		--prefix=/usr \
+		--sysconfdir=/etc \
+		--mandir=/usr/share/man \
+		--localstatedir=/var \
+		--disable-nls \
+		--disable-werror \
+		--with-platform=xen \
+		--target=$CARCH \
+		|| return 1
+	make || return 1
+}
+
 build() {
 	cd "$builddir"
 	autoreconf -vif || return 1
-	
+
+	cd "$srcdir"
+	tmpdir="$srcdir"/tmp
+	mv "$builddir" "$tmpdir"
+
+	mkdir "$builddir"
+	cp -r "$tmpdir" "$builddir"/bios
+	cp -r "$tmpdir" "$builddir"/efi
+	mv    "$tmpdir" "$builddir"/xen
+
 	# BIOS build
 	if [ ! "$CARCH" = aarch64 ]; then
 		msg "Building grub for platform BIOS"
-		cp -r "$builddir" "$builddir"/bios
 		_build_bios || return 1
 	fi
 	
 	# EFI build
 	msg "Building grub for platform EFI"
-	cp -r "$builddir" "$builddir"/efi
 	_build_efi || return 1
+
+	# xenhost build
+	msg "Building grub for platform XEN"
+	_build_xen || return 1
 }
 
 package() {
-	# install both version into the same directory
+	# install BIOS & EFI version into the same directory
 	# and overwrite similar files.
 	
 	# BIOS install
 	if [ ! "$CARCH" = aarch64 ]; then
 		cd "$builddir"/bios
-		make DESTDIR="$pkgdir" install || return 1
+		make DESTDIR="$pkgdir" install-strip || return 1
 	fi
 
 	# EFI install
 	cd "$builddir"/efi
-	make DESTDIR="$pkgdir" install || return 1
-	
+	make DESTDIR="$pkgdir" install-strip || return 1
+
+	# xenhost install
+	cd "$builddir"/xen
+
+	grub_dir=`mktemp -d`
+	cfg=`mktemp`
+	grub_memdisk=`mktemp`
+
+	mkdir -p $grub_dir/boot/grub
+	echo 'normal (memdisk)/grub.cfg' > $cfg
+	sed -e "s/@@PVBOOT_ARCH@@/$CARCH/g" \
+		$srcdir/grub-xen-host_grub.cfg \
+			> $grub_dir/grub.cfg
+	tar -cf - -C $grub_dir grub.cfg > $grub_memdisk
+
+	./grub-mkimage \
+		-O $CARCH-xen \
+		-c $cfg \
+		-d ./grub-core ./grub-core/*.mod \
+		-m $grub_memdisk \
+		-o $pkgdir/grub-$CARCH-xen.bin
+
+	rm -r "$grub_dir"
+	rm "$cfg"
+	rm "$grub_memdisk"
+
 	rm -f "$pkgdir"/usr/lib/charset.alias
 }
 
@@ -107,12 +164,24 @@ efi() {
 	mv $pkgdir/usr/lib/grub/*-efi $subpkgdir/usr/lib/grub/
 }
 
+xenhost() {
+	pkgdesc="$pkgdesc (XEN host version)"
+	mkdir -p $subpkgdir/usr/lib/grub-xen
+	mv $pkgdir/*-xen.bin $subpkgdir/usr/lib/grub-xen/
+}
+
 md5sums="ab399fc6f74a97d66ff77f04b743149c  grub-2.02~beta3.tar.xz
 7a09f166141e2a57f1829dd6cf1424fa  2.02_beta3-gcc6-ld-no-pie.patch
-632f1e9dee0f8a4a52e592cb29cdf8cc  fix-gcc-no-pie-specs.patch"
+632f1e9dee0f8a4a52e592cb29cdf8cc  fix-gcc-no-pie-specs.patch
+5065825ac12ee3162534b8733df84227  grub2-accept-empty-module.patch
+429182bb65be24887b377304e43ecbef  grub-xen-host_grub.cfg"
 sha256sums="30ec3d555e52a702c3eef449872ef874eff28b320f40b55ffc47f70db8e5ada1  grub-2.02~beta3.tar.xz
 14912f087e047259e803be020c0506d9865c1507ae34683c6668b8d4a140c93b  2.02_beta3-gcc6-ld-no-pie.patch
-eaa876af6b6253c2ca98a03201b98b0e0a27b9acc120b7937c9292882f2f0e0b  fix-gcc-no-pie-specs.patch"
+eaa876af6b6253c2ca98a03201b98b0e0a27b9acc120b7937c9292882f2f0e0b  fix-gcc-no-pie-specs.patch
+ddc84d56d61043314b5c03af3c9628dca3e3d14dc01b29c4b586f47ce962bdbe  grub2-accept-empty-module.patch
+bc658b2a0c0e014e38590c50d5241e33cbc73cf8fbfd31688445be3ceb7da373  grub-xen-host_grub.cfg"
 sha512sums="4a530efef4dae45f4046cf3550563f14acb24d25cb88d5e06c93953ca5b1eec115118c6860233a9f627edcddae2571e5d6b867b70ff9dd5c184c9fef83ef7e11  grub-2.02~beta3.tar.xz
 fc15c95bf26b28eee3b5a0d8e5fac538445179cea19a8657cd360e37dd5a95010ea2b899d1e4f3692b778a71f79526539ad1c741f028186f0daf135ee1678da0  2.02_beta3-gcc6-ld-no-pie.patch
-b9eab870006ab7842e0af27171d3b66fea10835d3fd4e606f241a9898aa28bfc4c1cdf59cece8ad50d2e284a44cba74eb0f390ac29627518f86257a8d586976e  fix-gcc-no-pie-specs.patch"
+b9eab870006ab7842e0af27171d3b66fea10835d3fd4e606f241a9898aa28bfc4c1cdf59cece8ad50d2e284a44cba74eb0f390ac29627518f86257a8d586976e  fix-gcc-no-pie-specs.patch
+098a1742aef131c85d63b934a9815879b991f2e73030cb90ac4b5dcd07d249fa0dd0a281e52ada0e10f05d59223493bd416eb47543242bf0ba336a0ebc9b2a1a  grub2-accept-empty-module.patch
+4e7394e0fff6772c89683039ccf81099ebbfe4f498e6df408977a1488fd59389b6e19afdbf0860ec271e2b2aea0df7216243dcc8235d1ca3af0e7f4d0a9d60a4  grub-xen-host_grub.cfg"
diff --git a/testing/grub/grub-xen-host_grub.cfg b/testing/grub/grub-xen-host_grub.cfg
new file mode 100644
index 0000000..f0eecbb
--- /dev/null
+++ b/testing/grub/grub-xen-host_grub.cfg
@@ -0,0 +1,24 @@
+# First search for a suitable grub to chainload
+if search -s -f /boot/xen/pvboot-@@PVBOOT_ARCH@@.elf ; then
+	echo "Chainloading (${root})/boot/xen/pvboot-@@PVBOOT_ARCH@@.elf"
+	multiboot "/boot/xen/pvboot-@@PVBOOT_ARCH@@.elf"
+	boot
+fi
+
+if search -s -f /xen/pvboot-@@PVBOOT_ARCH@@.elf ; then
+	echo "Chainloading (${root})/xen/pvboot-@@PVBOOT_ARCH@@.elf"
+	multiboot "/xen/pvboot-@@PVBOOT_ARCH@@.elf"
+	boot
+fi
+
+# Second try looking for grub.cfg
+
+if search -s -f /boot/grub/grub.cfg ; then
+	echo "Reading (${root})/boot/grub/grub.cfg"
+	configfile /boot/grub/grub.cfg
+fi
+
+if search -s -f /grub/grub.cfg ; then
+	echo "Reading (${root})/grub/grub.cfg"
+	configfile /grub/grub.cfg
+fi
diff --git a/testing/grub/grub2-accept-empty-module.patch b/testing/grub/grub2-accept-empty-module.patch
new file mode 100644
index 0000000..d3d7545
--- /dev/null
+++ b/testing/grub/grub2-accept-empty-module.patch
@@ -0,0 +1,22 @@
+From: Michael Matz <[email-masked]>
+
+Accept empty modules
+
+For the Xen platform the all_video.mod module is empty.
+With old binutils the .symtab section remained (containing
+only section symbols), so the check didn't trigger, but starting
+with binutils 2.27 not even a .symtab remains.  As there are
+also no relocations that's no problem (and that is checked
+independendly).
+--- grub-2.02~beta3/util/grub-module-verifierXX.c.mm	2016-02-11 10:57:41.000000000 +0000
++++ grub-2.02~beta3/util/grub-module-verifierXX.c	2016-08-31 15:26:36.000000000 +0000
+@@ -199,7 +199,8 @@ check_symbols (const struct grub_module_
+       Elf_Shdr *s = find_section (arch, e, ".moddeps");
+ 
+       if (!s)
+-	grub_util_error ("no symbol table and no .moddeps section");
++	/*grub_util_error ("no symbol table and no .moddeps section");*/
++	return; /* An empty module happens for all_video.module for Xen */
+ 
+       if (!s->sh_size)
+ 	grub_util_error ("no symbol table and empty .moddeps section");
-- 
2.10.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---