blob: d969674122c1c982fafc8a00adad351ba4c39840 [file] [log] [blame]
#
# Copyright 2021 Google LLC
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Check for EAPI 5+
case "${EAPI:-0}" in
0|1|2|3|4) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
5|6) inherit eapi7-ver ;;
7) ;;
esac
inherit linux-info linux-mod toolchain-funcs
IUSE="
+clang
+llvm_ias
module_sign
platform-key
"
REQUIRED_USE="
llvm_ias? ( clang )
"
DEPEND="
platform-key? ( sys-boot/platform-key )
virtual/linux-sources
"
# Because our kernel version string ends with '+' (e.g.
# "4.4.21+"), Gentoo Linux's linux-info.eclass cannot locate the kernel build
# output directory. Hence we set it up here.
KBUILD_OUTPUT="${KERNEL_DIR}"/build
cos-linux-mod_src_prepare() {
# Allowing gcc to be used when clang is not set.
# This is copied from cros-kernel2.eclass to make sure the third
# party kernel module uses the same compiler as kernel.
use clang || cros_use_gcc
default
}
cos-linux-mod_src_compile() {
BUILD_PARAMS="${BUILD_PARAMS} CC=${CC} LD=${LD}"
# Assemble with LLVM's integrated assembler on x86_64 and aarch64
if use llvm_ias; then
export LLVM_IAS=1
fi
linux-mod_src_compile
}
cos-linux-mod_src_install() {
local key_path="${KBUILD_OUTPUT}"/certs
if use platform-key ; then
key_path="${ROOT}"/build/share/platform-key
fi
if use module_sign ; then
for i in ${MODULE_NAMES}
do
unset libdir srcdir objdir
for n in $(find_module_params ${i})
do
eval ${n/:*}=${n/*:/}
done
libdir=${libdir:-misc}
srcdir=${srcdir:-${S}}
objdir=${objdir:-${srcdir}}
einfo "Signing ${modulename} module"
cos-linux-mod_sign "${objdir}/${modulename}.${KV_OBJ}" "${key_path}"
# Do not strip signature
dostrip -x "/lib/modules/${KV_FULL}/${libdir}/${modulename}.${KV_OBJ}"
done
fi
linux-mod_src_install
}
cos-linux-mod_sign() {
local module_file="$1"
local key_path="$2"
"${KBUILD_OUTPUT}"/scripts/sign-file \
sha256 \
"${key_path}"/signing_key.pem \
"${key_path}"/signing_key.x509 \
"${module_file}" || die "failed to sign a module"
}
cos-linux-mod_sign_detached() {
local module_file="$1"
local key_path="$2"
"${KBUILD_OUTPUT}"/scripts/sign-file \
-p \
sha256 \
"${key_path}"/signing_key.pem \
"${key_path}"/signing_key.x509 \
"${module_file}" || die "failed to sign a module"
}