kexec-tools: upgraded package to upstream

Upgraded sys-apps/kexec-tools to version 2.0.20-r3
Previous version didn't have support for kexec_file_load syscall on ARM64.

BUG=b/179916171
TEST=presubmit
RELEASE_NOTE=None

Change-Id: I8eabd27e443413aa64a77b1db3d2e09ce737e74e
Reviewed-on: https://cos-review.googlesource.com/c/third_party/overlays/portage-stable/+/12470
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Roy Yang <royyang@google.com>
diff --git a/metadata/md5-cache/sys-apps/kexec-tools-2.0.17 b/metadata/md5-cache/sys-apps/kexec-tools-2.0.17
deleted file mode 100644
index 12dc035..0000000
--- a/metadata/md5-cache/sys-apps/kexec-tools-2.0.17
+++ /dev/null
@@ -1,14 +0,0 @@
-DEFINED_PHASES=configure install postinst prepare setup
-DEPEND=lzma? ( app-arch/xz-utils ) zlib? ( sys-libs/zlib ) >=app-portage/elt-patches-20170815 virtual/pkgconfig
-DESCRIPTION=Load another kernel from the currently executing Linux kernel
-EAPI=6
-HOMEPAGE=https://kernel.org/pub/linux/utils/kernel/kexec/
-IUSE=booke lzma xen zlib kernel_linux
-KEYWORDS=*
-LICENSE=GPL-2
-RDEPEND=lzma? ( app-arch/xz-utils ) zlib? ( sys-libs/zlib )
-REQUIRED_USE=lzma? ( zlib )
-SLOT=0
-SRC_URI=mirror://kernel/linux/utils/kernel/kexec/kexec-tools-2.0.17.tar.xz
-_eclasses_=desktop	b1d22ac8bdd4679ab79c71aca235009d	eapi7-ver	756b3f27d8e46131d5cf3c51bd876446	epatch	ed88001f77c6dd0d5f09e45c1a5b480e	estack	686eaab303305a908fd57b2fd7617800	eutils	fcb2aa98e1948b835b5ae66ca52868c5	flag-o-matic	5d5921a298e95441da2f85be419894c0	libtool	f143db5a74ccd9ca28c1234deffede96	linux-info	327865b9921771330775d971263dc234	ltprune	2729691420b6deeda2a90b1f1183fb55	multilib	2477ebe553d3e4d2c606191fe6c33602	preserve-libs	ef207dc62baddfddfd39a164d9797648	systemd	71fd8d2065d102753fb9e4d20eaf3e9f	toolchain-funcs	605c126bed8d87e4378d5ff1645330cb	vcs-clean	2a0f74a496fa2b1552c4f3398258b7bf
-_md5_=9f28e6a4a06eb20927ec5f31375abee6
diff --git a/metadata/md5-cache/sys-apps/kexec-tools-2.0.20-r3 b/metadata/md5-cache/sys-apps/kexec-tools-2.0.20-r3
new file mode 100644
index 0000000..277636c
--- /dev/null
+++ b/metadata/md5-cache/sys-apps/kexec-tools-2.0.20-r3
@@ -0,0 +1,15 @@
+BDEPEND=>=app-portage/elt-patches-20170815 virtual/pkgconfig
+DEFINED_PHASES=compile configure install postinst prepare setup
+DEPEND=lzma? ( app-arch/xz-utils ) zlib? ( sys-libs/zlib )
+DESCRIPTION=Load another kernel from the currently executing Linux kernel
+EAPI=7
+HOMEPAGE=https://kernel.org/pub/linux/utils/kernel/kexec/
+IUSE=booke lzma xen zlib kernel_linux
+KEYWORDS=*
+LICENSE=GPL-2
+RDEPEND=lzma? ( app-arch/xz-utils ) zlib? ( sys-libs/zlib )
+REQUIRED_USE=lzma? ( zlib )
+SLOT=0
+SRC_URI=https://www.kernel.org/pub/linux/utils/kernel/kexec/kexec-tools-2.0.20.tar.xz
+_eclasses_=libtool	f143db5a74ccd9ca28c1234deffede96	linux-info	327865b9921771330775d971263dc234	multilib	2477ebe553d3e4d2c606191fe6c33602	systemd	71fd8d2065d102753fb9e4d20eaf3e9f	toolchain-funcs	605c126bed8d87e4378d5ff1645330cb
+_md5_=a33b17836fd56f6356c4303758dbee48
diff --git a/sys-apps/kexec-tools/Manifest b/sys-apps/kexec-tools/Manifest
index 75d9170..7d82850 100644
--- a/sys-apps/kexec-tools/Manifest
+++ b/sys-apps/kexec-tools/Manifest
@@ -1 +1 @@
-DIST kexec-tools-2.0.17.tar.xz 290612 SHA256 504c816b769da573167b63f3b6d4fce3740f231c98d8db0c4fda47a4b90482a9 SHA512 e0f254ca2b26fa02cb61ba9a0735423b26bac2693fbd920eaf7cc2822c298de958bd65f7c37947ca1f6811a3752a58f7cf8aa903494f0109ea76b7159a037fa6 WHIRLPOOL 0947df528faa1e409d7090a5ddc9183996f66511b7cc036bf666bad46a3f5256fe2856405c602a41d60956c2de12aea4cff37f1edcb153264283fb55a0c10aa4
+DIST kexec-tools-2.0.20.tar.xz 297476 BLAKE2B 7e29e7f7d85296dd3e614c45f14c27eca74ce4426d5de2d20387d89f2f63afed318d6157cc4001849a04bb83505bbae87c43d34683ebaf9a70f5f29e3979ade3 SHA512 3112b6202c1030705c53e3f65a2b58aec14d65333a35aad681d48b9f2bd1c51a2e05c985a1e5e867ab02f8a9c97708483d9d225619db7c6993676f1a242e2d99
diff --git a/sys-apps/kexec-tools/files/kexec.init-2.0.13-r1 b/sys-apps/kexec-tools/files/kexec-r2.init
similarity index 82%
rename from sys-apps/kexec-tools/files/kexec.init-2.0.13-r1
rename to sys-apps/kexec-tools/files/kexec-r2.init
index 5415b3b..0578f51 100644
--- a/sys-apps/kexec-tools/files/kexec.init-2.0.13-r1
+++ b/sys-apps/kexec-tools/files/kexec-r2.init
@@ -1,5 +1,5 @@
 #!/sbin/openrc-run
-# Copyright 1999-2017 Gentoo Foundation
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # Set up some defaults.
@@ -14,16 +14,16 @@
 auto_prefix_bootpath() {
 	# Only auto-add prefix to relative paths.
 	case $1 in
-	*/*) echo "$1";;
-	*)   echo "${BOOTPART}/$1" ;;
+		*/*) echo "$1";;
+		*)   echo "${BOOTPART}/$1" ;;
 	esac
 }
 
 get_genkernel_arch() {
 	case $1 in
-	  x86_64) echo "amd64" ;;
-	  i[3456]86) echo "x86" ;;
-	  *) echo "$1" ;;
+		x86_64) echo "amd64" ;;
+		i[3456]86) echo "x86" ;;
+		*) echo "$1" ;;
 	esac
 }
 
@@ -34,12 +34,15 @@
 		return
 	fi
 
-	local x kver="$(uname -r)" karch="$(uname -m)" 
+	local x kver="$(uname -r)" karch="$(uname -m)"
 	local gkarch="$(get_genkernel_arch $karch)"
 	for x in \
 		"bzImage" \
+		"vmlinux" \
 		"vmlinuz" \
+		"kernel" \
 		"bzImage-${kver}" \
+		"vmlinux-${kver}" \
 		"vmlinuz-${kver}" \
 		"kernel-genkernel-${karch}-${kver}" \
 		"kernel-genkernel-${gkarch}-${kver}" \
@@ -65,6 +68,7 @@
 	local gkarch="$(get_genkernel_arch $karch)"
 	for x in \
 		"initrd" \
+		"initramfs" \
 		"initrd.img-${kver}" \
 		"initrd-${kver}.img" \
 		"initrd-${kver}" \
@@ -115,12 +119,22 @@
 		fi
 	fi
 
+	local is_rootpart_autodetected=no
 	if [ -z "${ROOTPART}" ]; then
 		ROOTPART="$(readlink -f "$(sed -n '/^\/[^ ]* \/ / s,^\([^ ]*\).*,\1,p' /proc/mounts)")"
+		is_rootpart_autodetected=yes
 	fi
 
+	local is_reusing_cmdline=no
 	if [ -z "${KPARAM}" ]; then
 		kparamopt="--reuse-cmdline"
+		is_reusing_cmdline=yes
+	fi
+
+	if ! yesno "${is_rootpart_autodetected}" || ! yesno "${is_reusing_cmdline}"; then
+		# Only append root when explicit set in config or
+		# if we aren't re-using kernel cmdline
+		KPARAM="${KPARAM:+"${KPARAM} "}root=${ROOTPART}"
 	fi
 
 	if [ -n "${initrd}" ]; then
@@ -133,7 +147,7 @@
 	ebegin "Using kernel image ${img}${msg} for kexec"
 
 	kexec ${KEXEC_OPT_ARGS} ${kparamopt} \
-		-l "${img}" --append="root=${ROOTPART} ${KPARAM}" ${initrdopt}
+		-l "${img}" ${KPARAM:+--append="${KPARAM}"} ${initrdopt}
 	local ret=$?
 
 	${mounted} && umount "${BOOTPART}"
diff --git a/sys-apps/kexec-tools/files/kexec-tools-2.0.20-build-multiboot2-for-i386.patch b/sys-apps/kexec-tools/files/kexec-tools-2.0.20-build-multiboot2-for-i386.patch
new file mode 100644
index 0000000..8f63ddb
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec-tools-2.0.20-build-multiboot2-for-i386.patch
@@ -0,0 +1,68 @@
+From 2c9f26ed20a791a7df0182ba82e93abb52f5a615 Mon Sep 17 00:00:00 2001
+From: Chris Packham <chris.packham@alliedtelesis.co.nz>
+Date: Mon, 18 Nov 2019 12:52:15 +1300
+Subject: kexec: build multiboot2 for i386
+
+This addresses the following compilation issues when building for i386.
+
+ kexec/arch/i386/kexec-x86.c:39:22: error: 'multiboot2_x86_probe' undeclared here (not in a function); did you mean 'multiboot_x86_probe'?
+   { "multiboot2-x86", multiboot2_x86_probe, multiboot2_x86_load,
+                       ^~~~~~~~~~~~~~~~~~~~
+                       multiboot_x86_probe
+ kexec/arch/i386/kexec-x86.c:39:44: error: 'multiboot2_x86_load' undeclared here (not in a function); did you mean 'multiboot_x86_load'?
+   { "multiboot2-x86", multiboot2_x86_probe, multiboot2_x86_load,
+                                             ^~~~~~~~~~~~~~~~~~~
+                                             multiboot_x86_load
+ kexec/arch/i386/kexec-x86.c:40:4: error: 'multiboot2_x86_usage' undeclared here (not in a function); did you mean 'multiboot_x86_usage'?
+     multiboot2_x86_usage },
+     ^~~~~~~~~~~~~~~~~~~~
+     multiboot_x86_usage
+ make: *** [Makefile:114: kexec/arch/i386/kexec-x86.o] Error 1
+ make: *** Waiting for unfinished jobs....
+
+Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
+Signed-off-by: Simon Horman <horms@verge.net.au>
+---
+ kexec/arch/i386/Makefile    | 2 +-
+ kexec/arch/i386/kexec-x86.h | 5 +++++
+ 2 files changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/kexec/arch/i386/Makefile b/kexec/arch/i386/Makefile
+index 105cefd..f486103 100644
+--- a/kexec/arch/i386/Makefile
++++ b/kexec/arch/i386/Makefile
+@@ -7,6 +7,7 @@ i386_KEXEC_SRCS += kexec/arch/i386/kexec-elf-x86.c
+ i386_KEXEC_SRCS += kexec/arch/i386/kexec-elf-rel-x86.c
+ i386_KEXEC_SRCS += kexec/arch/i386/kexec-bzImage.c
+ i386_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c
++i386_KEXEC_SRCS += kexec/arch/i386/kexec-mb2-x86.c
+ i386_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c
+ i386_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c
+ i386_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c
+@@ -14,7 +15,6 @@ i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c
+ 
+ dist += kexec/arch/i386/Makefile $(i386_KEXEC_SRCS)			\
+ 	kexec/arch/i386/crashdump-x86.h					\
+-	kexec/arch/i386/kexec-mb2-x86.c					\
+ 	kexec/arch/i386/kexec-x86.h					\
+ 	kexec/arch/i386/x86-linux-setup.h				\
+ 	kexec/arch/i386/include/arch/options.h
+diff --git a/kexec/arch/i386/kexec-x86.h b/kexec/arch/i386/kexec-x86.h
+index 1b58c3b..0f941df 100644
+--- a/kexec/arch/i386/kexec-x86.h
++++ b/kexec/arch/i386/kexec-x86.h
+@@ -60,6 +60,11 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len,
+ 	struct kexec_info *info);
+ void multiboot_x86_usage(void);
+ 
++int multiboot2_x86_load(int argc, char **argv, const char *buf, off_t len,
++			struct kexec_info *info);
++void multiboot2_x86_usage(void);
++int multiboot2_x86_probe(const char *buf, off_t buf_len);
++
+ int elf_x86_probe(const char *buf, off_t len);
+ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
+ 	struct kexec_info *info);
+-- 
+cgit 1.2-0.3.lf.el7
+
diff --git a/sys-apps/kexec-tools/files/kexec-tools-2.0.20-remove-duplicated-variable-declarations.patch b/sys-apps/kexec-tools/files/kexec-tools-2.0.20-remove-duplicated-variable-declarations.patch
new file mode 100644
index 0000000..d71e76b
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec-tools-2.0.20-remove-duplicated-variable-declarations.patch
@@ -0,0 +1,99 @@
+From cc087b11462af9f971a2c090d07e8d780a867b50 Mon Sep 17 00:00:00 2001
+From: Kairui Song <kasong@redhat.com>
+Date: Wed, 29 Jan 2020 13:38:19 +0800
+Subject: kexec-tools: Remove duplicated variable declarations
+
+When building kexec-tools for Fedora 32, following error is observed:
+
+/usr/bin/ld: kexec/arch/x86_64/kexec-bzImage64.o:(.bss+0x0): multiple definition of `bzImage_support_efi_boot';
+kexec/arch/i386/kexec-bzImage.o:(.bss+0x0): first defined here
+
+/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm/../../fs2dt.h:33: multiple definition of `my_debug';
+kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/kexec/fs2dt.h:33: first defined here
+
+/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:68: multiple definition of `arm64_mem';
+kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:68: first defined here
+
+/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:54: multiple definition of `initrd_size';
+kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:54: first defined here
+
+/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:53: multiple definition of `initrd_base';
+kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:53: first defined here
+
+And apparently, these variables are wrongly declared multiple times. So
+remove duplicated declaration.
+
+Signed-off-by: Kairui Song <kasong@redhat.com>
+Signed-off-by: Simon Horman <horms@verge.net.au>
+---
+ kexec/arch/arm64/kexec-arm64.h      | 6 +++---
+ kexec/arch/ppc64/kexec-elf-ppc64.c  | 2 --
+ kexec/arch/x86_64/kexec-bzImage64.c | 1 -
+ kexec/fs2dt.h                       | 2 +-
+ 4 files changed, 4 insertions(+), 7 deletions(-)
+
+diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h
+index 628de79..ed447ac 100644
+--- a/kexec/arch/arm64/kexec-arm64.h
++++ b/kexec/arch/arm64/kexec-arm64.h
+@@ -50,8 +50,8 @@ int zImage_arm64_load(int argc, char **argv, const char *kernel_buf,
+ void zImage_arm64_usage(void);
+ 
+ 
+-off_t initrd_base;
+-off_t initrd_size;
++extern off_t initrd_base;
++extern off_t initrd_size;
+ 
+ /**
+  * struct arm64_mem - Memory layout info.
+@@ -65,7 +65,7 @@ struct arm64_mem {
+ };
+ 
+ #define arm64_mem_ngv UINT64_MAX
+-struct arm64_mem arm64_mem;
++extern struct arm64_mem arm64_mem;
+ 
+ uint64_t get_phys_offset(void);
+ uint64_t get_vp_offset(void);
+diff --git a/kexec/arch/ppc64/kexec-elf-ppc64.c b/kexec/arch/ppc64/kexec-elf-ppc64.c
+index 3510b70..695b8b0 100644
+--- a/kexec/arch/ppc64/kexec-elf-ppc64.c
++++ b/kexec/arch/ppc64/kexec-elf-ppc64.c
+@@ -44,8 +44,6 @@
+ uint64_t initrd_base, initrd_size;
+ unsigned char reuse_initrd = 0;
+ const char *ramdisk;
+-/* Used for enabling printing message from purgatory code */
+-int my_debug = 0;
+ 
+ int elf_ppc64_probe(const char *buf, off_t len)
+ {
+diff --git a/kexec/arch/x86_64/kexec-bzImage64.c b/kexec/arch/x86_64/kexec-bzImage64.c
+index 8edb3e4..ba8dc48 100644
+--- a/kexec/arch/x86_64/kexec-bzImage64.c
++++ b/kexec/arch/x86_64/kexec-bzImage64.c
+@@ -42,7 +42,6 @@
+ #include <arch/options.h>
+ 
+ static const int probe_debug = 0;
+-int bzImage_support_efi_boot;
+ 
+ int bzImage64_probe(const char *buf, off_t len)
+ {
+diff --git a/kexec/fs2dt.h b/kexec/fs2dt.h
+index 7633273..fe24931 100644
+--- a/kexec/fs2dt.h
++++ b/kexec/fs2dt.h
+@@ -30,7 +30,7 @@ extern struct bootblock bb[1];
+ 
+ /* Used for enabling printing message from purgatory code
+  * Only has implemented for PPC64 */
+-int my_debug;
++extern int my_debug;
+ extern int dt_no_old_root;
+ 
+ void reserve(unsigned long long where, unsigned long long length);
+-- 
+cgit 1.2-0.3.lf.el7
+
diff --git a/sys-apps/kexec-tools/kexec-tools-2.0.17.ebuild b/sys-apps/kexec-tools/kexec-tools-2.0.17.ebuild
deleted file mode 100644
index 6a1682c..0000000
--- a/sys-apps/kexec-tools/kexec-tools-2.0.17.ebuild
+++ /dev/null
@@ -1,85 +0,0 @@
-# Copyright 1999-2018 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI=6
-
-if [[ ${PV} == "9999" ]] ; then
-	inherit git-r3 autotools
-	EGIT_REPO_URI="https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git"
-else
-	SRC_URI="mirror://kernel/linux/utils/kernel/kexec/${P}.tar.xz"
-	KEYWORDS="*"
-fi
-
-inherit flag-o-matic libtool linux-info systemd toolchain-funcs
-
-DESCRIPTION="Load another kernel from the currently executing Linux kernel"
-HOMEPAGE="https://kernel.org/pub/linux/utils/kernel/kexec/"
-
-LICENSE="GPL-2"
-SLOT="0"
-IUSE="booke lzma xen zlib"
-
-REQUIRED_USE="lzma? ( zlib )"
-
-DEPEND="
-	lzma? ( app-arch/xz-utils )
-	zlib? ( sys-libs/zlib )"
-RDEPEND="${DEPEND}"
-
-CONFIG_CHECK="~KEXEC"
-
-PATCHES=(
-	"${FILESDIR}"/${PN}-2.0.4-disable-kexec-test.patch
-	"${FILESDIR}"/${PN}-2.0.4-out-of-source.patch
-)
-
-pkg_setup() {
-	# GNU Make's $(COMPILE.S) passes ASFLAGS to $(CCAS), CCAS=$(CC)
-	export ASFLAGS="${CCASFLAGS}"
-}
-
-src_prepare() {
-	default
-	if [[ ${PV} == "9999" ]] ; then
-		eautoreconf
-	else
-		elibtoolize
-	fi
-	filter-flags '-mindirect-branch=thunk*'
-}
-
-src_configure() {
-	local myeconfargs=(
-		$(use_with booke)
-		$(use_with lzma)
-		$(use_with xen)
-		$(use_with zlib)
-	)
-	econf "${myeconfargs[@]}"
-}
-
-src_install() {
-	default
-
-	dodoc "${FILESDIR}"/README.Gentoo
-
-	newinitd "${FILESDIR}"/kexec.init-2.0.13-r1 kexec
-	newconfd "${FILESDIR}"/kexec.conf-2.0.4 kexec
-
-	insinto /etc
-	doins "${FILESDIR}"/kexec.conf
-
-	insinto /etc/kernel/postinst.d
-	doins "${FILESDIR}"/90_kexec
-
-	systemd_dounit "${FILESDIR}"/kexec.service
-}
-
-pkg_postinst() {
-	if systemd_is_booted || has_version sys-apps/systemd; then
-		elog "For systemd support the new config file is"
-		elog "   /etc/kexec.conf"
-		elog "Please adopt it to your needs as there is no autoconfig anymore"
-	fi
-}
diff --git a/sys-apps/kexec-tools/kexec-tools-2.0.20-r3.ebuild b/sys-apps/kexec-tools/kexec-tools-2.0.20-r3.ebuild
new file mode 100644
index 0000000..6e1a010
--- /dev/null
+++ b/sys-apps/kexec-tools/kexec-tools-2.0.20-r3.ebuild
@@ -0,0 +1,126 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit libtool linux-info systemd
+
+if [[ ${PV} == "9999" ]] ; then
+	inherit git-r3 autotools
+	EGIT_REPO_URI="https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git"
+else
+	SRC_URI="https://www.kernel.org/pub/linux/utils/kernel/kexec/${P/_/-}.tar.xz"
+	[[ "${PV}" == *_rc* ]] || \
+	KEYWORDS="*"
+fi
+
+DESCRIPTION="Load another kernel from the currently executing Linux kernel"
+HOMEPAGE="https://kernel.org/pub/linux/utils/kernel/kexec/"
+
+LICENSE="GPL-2"
+SLOT="0"
+IUSE="booke lzma xen zlib"
+
+REQUIRED_USE="lzma? ( zlib )"
+
+DEPEND="
+	lzma? ( app-arch/xz-utils )
+	zlib? ( sys-libs/zlib )"
+RDEPEND="${DEPEND}"
+
+S="${WORKDIR}/${P/_/-}"
+
+CONFIG_CHECK="~KEXEC"
+
+PATCHES=(
+	"${FILESDIR}"/${PN}-2.0.4-disable-kexec-test.patch
+	"${FILESDIR}"/${PN}-2.0.4-out-of-source.patch
+	"${FILESDIR}"/${P}-remove-duplicated-variable-declarations.patch
+	"${FILESDIR}"/${P}-build-multiboot2-for-i386.patch
+)
+
+pkg_setup() {
+	# GNU Make's $(COMPILE.S) passes ASFLAGS to $(CCAS), CCAS=$(CC)
+	export ASFLAGS="${CCASFLAGS}"
+}
+
+src_prepare() {
+	default
+
+	# Append PURGATORY_EXTRA_CFLAGS flags set by configure, instead of overriding them completely.
+	sed -e "/^PURGATORY_EXTRA_CFLAGS =/s/=/+=/" -i Makefile.in || die
+
+	if [[ "${PV}" == 9999 ]] ; then
+		eautoreconf
+	else
+		elibtoolize
+	fi
+}
+
+src_configure() {
+	local myeconfargs=(
+		$(use_with booke)
+		$(use_with lzma)
+		$(use_with xen)
+		$(use_with zlib)
+	)
+	econf "${myeconfargs[@]}"
+}
+
+src_compile() {
+	# Respect CFLAGS for purgatory.
+	# purgatory/Makefile uses PURGATORY_EXTRA_CFLAGS variable.
+	# -mfunction-return=thunk and -mindirect-branch=thunk conflict with
+	# -mcmodel=large which is added by build system.
+	# Replace them with -mfunction-return=thunk-inline and -mindirect-branch=thunk-inline.
+	local flag flags=()
+	for flag in ${CFLAGS}; do
+		[[ ${flag} == -mfunction-return=thunk ]] && flag="-mfunction-return=thunk-inline"
+		[[ ${flag} == -mindirect-branch=thunk ]] && flag="-mindirect-branch=thunk-inline"
+		flags+=("${flag}")
+	done
+	local -x PURGATORY_EXTRA_CFLAGS="${flags[*]}"
+
+	default
+}
+
+src_install() {
+	default
+
+	dodoc "${FILESDIR}"/README.Gentoo
+
+	newinitd "${FILESDIR}"/kexec-r2.init kexec
+	newconfd "${FILESDIR}"/kexec.conf-2.0.4 kexec
+
+	insinto /etc
+	doins "${FILESDIR}"/kexec.conf
+
+	insinto /etc/kernel/postinst.d
+	doins "${FILESDIR}"/90_kexec
+
+	systemd_dounit "${FILESDIR}"/kexec.service
+}
+
+pkg_postinst() {
+	if systemd_is_booted || has_version sys-apps/systemd; then
+		elog "For systemd support the new config file is"
+		elog "   /etc/kexec.conf"
+		elog "Please adopt it to your needs as there is no autoconfig anymore"
+	fi
+
+	local n_root_args=$(grep -o -- '\<root=' /proc/cmdline 2>/dev/null | wc -l)
+	local has_rootpart_set=no
+	if [[ -f "${EROOT}/etc/conf.d/kexec" ]]; then
+		if grep -q -E -- '^ROOTPART=' "${EROOT}/etc/conf.d/kexec" 2>/dev/null; then
+			has_rootpart_set=yes
+		fi
+	fi
+
+	if [[ ${n_root_args} > 1 && "${has_rootpart_set}" == "no"  ]]; then
+		ewarn "WARNING: Multiple root arguments (root=) on kernel command-line detected!"
+		ewarn "This was probably caused by a previous version of ${PN}."
+		ewarn "Please reboot system once *without* kexec to avoid boot problems"
+		ewarn "in case running system and initramfs do not agree on detected"
+		ewarn "root device name!"
+	fi
+}
diff --git a/sys-apps/kexec-tools/metadata.xml b/sys-apps/kexec-tools/metadata.xml
index 1443e32..2ea57db 100644
--- a/sys-apps/kexec-tools/metadata.xml
+++ b/sys-apps/kexec-tools/metadata.xml
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
 <pkgmetadata>
-  <herd>kernel-misc</herd>
-  <maintainer>
-    <email>jlec@gentoo.org</email>
+  <maintainer type="project">
+    <email>base-system@gentoo.org</email>
+    <name>Gentoo Base System</name>
   </maintainer>
   <use>
     <flag name="lzma">Enables support for LZMA compressed kernel images</flag>