summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2021-01-10 12:54:02 +0100
committerMichał Górny <mgorny@gentoo.org>2021-01-13 12:54:24 +0100
commitc71a27d1d6c1936dd41cb8e3b645e68d4b7a08ba (patch)
tree1dfbfd6f3a22ab52551599dc4e4ea3bb12ced867 /eclass/dist-kernel-utils.eclass
parentapp-misc/fdupes: Synced live ebuild (diff)
downloadgentoo-c71a27d1d6c1936dd41cb8e3b645e68d4b7a08ba.tar.gz
gentoo-c71a27d1d6c1936dd41cb8e3b645e68d4b7a08ba.tar.bz2
gentoo-c71a27d1d6c1936dd41cb8e3b645e68d4b7a08ba.zip
dist-kernel-utils.eclass: Introduce eclass for helper functions
Move some of the utility functions from kernel-install.eclass into dist-kernel-utils.eclass, in order to permit using them without having all kernel-install phases exported. This will be used in order to support rebuilding initramfs in sys-fs/zfs-kmod. Since the eclasses are used only by dist-kernel project eclasses and ebuilds, update the function prefix while moving them. Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/dist-kernel-utils.eclass')
-rw-r--r--eclass/dist-kernel-utils.eclass96
1 files changed, 96 insertions, 0 deletions
diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
new file mode 100644
index 000000000000..cf7165d89947
--- /dev/null
+++ b/eclass/dist-kernel-utils.eclass
@@ -0,0 +1,96 @@
+# Copyright 2020-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: dist-kernel-utils.eclass
+# @MAINTAINER:
+# Distribution Kernel Project <dist-kernel@gentoo.org>
+# @AUTHOR:
+# Michał Górny <mgorny@gentoo.org>
+# @SUPPORTED_EAPIS: 7
+# @BLURB: Utility functions related to Distribution Kernels
+# @DESCRIPTION:
+# This eclass provides various utility functions related to Distribution
+# Kernels.
+
+if [[ ! ${_DIST_KERNEL_UTILS} ]]; then
+
+case "${EAPI:-0}" in
+ 0|1|2|3|4|5|6)
+ die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
+ ;;
+ 7)
+ ;;
+ *)
+ die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
+ ;;
+esac
+
+# @FUNCTION: dist-kernel_build_initramfs
+# @USAGE: <output> <version>
+# @DESCRIPTION:
+# Build an initramfs for the kernel. <output> specifies the absolute
+# path where initramfs will be created, while <version> specifies
+# the kernel version, used to find modules.
+#
+# Note: while this function uses dracut at the moment, other initramfs
+# variants may be supported in the future.
+dist-kernel_build_initramfs() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
+ local output=${1}
+ local version=${2}
+
+ ebegin "Building initramfs via dracut"
+ dracut --force "${output}" "${version}"
+ eend ${?} || die "Building initramfs failed"
+}
+
+# @FUNCTION: dist-kernel_get_image_path
+# @DESCRIPTION:
+# Get relative kernel image path specific to the current ${ARCH}.
+dist-kernel_get_image_path() {
+ case ${ARCH} in
+ amd64|x86)
+ echo arch/x86/boot/bzImage
+ ;;
+ arm64)
+ echo arch/arm64/boot/Image.gz
+ ;;
+ arm)
+ echo arch/arm/boot/zImage
+ ;;
+ ppc64)
+ # ./ is required because of ${image_path%/*}
+ # substitutions in the code
+ echo ./vmlinux
+ ;;
+ *)
+ die "${FUNCNAME}: unsupported ARCH=${ARCH}"
+ ;;
+ esac
+}
+
+# @FUNCTION: dist-kernel_install_kernel
+# @USAGE: <version> <image> <system.map>
+# @DESCRIPTION:
+# Install kernel using installkernel tool. <version> specifies
+# the kernel version, <image> full path to the image, <system.map>
+# full path to System.map.
+dist-kernel_install_kernel() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments"
+ local version=${1}
+ local image=${2}
+ local map=${3}
+
+ ebegin "Installing the kernel via installkernel"
+ # note: .config is taken relatively to System.map;
+ # initrd relatively to bzImage
+ installkernel "${version}" "${image}" "${map}"
+ eend ${?} || die "Installing the kernel failed"
+}
+
+_DIST_KERNEL_UTILS=1
+fi