summaryrefslogtreecommitdiff
blob: 502d03bee2b3a9241e302fdfa8aa093c04135df4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="Grub2 built as a PV grub per the Xen PV Boot Protocol"
HOMEPAGE="https://wiki.xenproject.org/wiki/PvGrub2"

LICENSE="BSD-2"
SLOT="0"
KEYWORDS="amd64"
IUSE="pvh"

DEPEND="
	sys-boot/grub:2=[grub_platforms_xen]
	pvh? ( >=sys-boot/grub-2.04:2=[grub_platforms_xen-pvh] )
"
RDEPEND="${DEPEND}"

S="${WORKDIR}"

RESTRICT="binchecks strip test"

src_configure() {
	:
}

src_compile() {
	cat > "${S}/grub-bootstrap.cfg" <<- EOF || die
		normal (memdisk)/grub.cfg
	EOF

	cat > "${S}/grub.cfg" <<- EOF || die
		if search -s -f /boot/xen/pvboot-x86_64.elf ; then
			echo "Chainloading (${root})/boot/xen/pvboot-x86_64.elf"
			multiboot "/boot/xen/pvboot-x86_64.elf"
			boot
		fi

		if search -s -f /xen/pvboot-x86_64.elf ; then
			echo "Chainloading (${root})/xen/pvboot-x86_64.elf"
			multiboot "/xen/pvboot-x86_64.elf"
			boot
		fi

		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
	EOF

	tar cf memdisk.tar grub.cfg || die "failed to tar"

	local grub_mkimage=grub-mkimage
	if type grub2-mkimage &> /dev/null; then
		grub_mkimage=grub2-mkimage
	fi

	local args=(
		"${grub_mkimage}"
		-O x86_64-xen
		-c grub-bootstrap.cfg
		-m memdisk.tar
		-p "${EPREFIX}"/usr/lib/grub/x86_64-xen/*.mod
		-o grub-x86_64-xen.bin
	)

	echo "${args[@]}"
	"${args[@]}" || die "failed to grub-mkimage"

	if use pvh; then
		local args=(
			"${grub_mkimage}"
			-O i386-xen_pvh
			-c grub-bootstrap.cfg
			-m memdisk.tar
			-p "${EPREFIX}"/usr/lib/grub/i386-xen_pvh/*.mod
			-o grub-i386-xen_pvh.bin
		)

		echo "${args[@]}"
		"${args[@]}" || die "failed to grub-mkimage"
	fi

}

src_install() {
	exeinto /usr/libexec/xen/bin
	doexe grub-x86_64-xen.bin
	if use pvh; then
		doexe grub-i386-xen_pvh.bin
	fi
}