@@ -10,30 +10,51 @@ INHIBIT_PACKAGE_STRIP = "1"
1010export HOST_EXTRACFLAGS = "${BUILD_CFLAGS} ${BUILD_LDFLAGS} "
1111
1212# Set KERNEL_MODULE_SIG_KEY in local.conf to the filepath of a private key
13- # for signing kernel modules. If unset, signing can be done offline.
13+ # for signing kernel modules. If unset, signing can be done offline.
1414export KERNEL_MODULE_SIG_KEY
1515# Set KERNEL_MODULE_SIG_CERT in local.conf to the filepath of the corresponging
16- # public key to verify the signed modules. If unset, an autogenerated
17- # build-time keypair will be generated and used for signing and embedding.
16+ # public key to verify the signed modules.
1817export KERNEL_MODULE_SIG_CERT
1918
19+ def get_signing_cert (d ):
20+ path = d . getVar ("KERNEL_MODULE_SIG_CERT" )
21+ if path :
22+ return path + ":" + str (os . path . exists (path ))
23+ return ""
24+
25+ def get_signing_key (d ):
26+ path = d . getVar ("KERNEL_MODULE_SIG_KEY" )
27+ if path :
28+ return path + ":" + str (os . path . exists (path ))
29+ return ""
30+
2031# Kernel builds will override this with ${B}/scripts/sign-file
2132SIGN_FILE = "${STAGING_KERNEL_BUILDDIR} /scripts/sign-file"
2233
2334fakeroot do_sign_modules () {
24- if [ -n "${KERNEL_MODULE_SIG_KEY} " ] &&
25- grep -q '^CONFIG_MODULE_SIG=y' ${STAGING_KERNEL_BUILDDIR} /. config ; then
35+ if ! grep -q '^CONFIG_MODULE_SIG=y' "${STAGING_KERNEL_BUILDDIR} /.config" ; then
36+ bbnote "Kernel module signing deactivated in kernel configuration ${STAGING_KERNEL_BUILDDIR} /.config."
37+ return
38+ fi
39+ if [ -z "${KERNEL_MODULE_SIG_CERT} " ]; then
40+ bbfatal "Kernel module signing should only be used when setting \
41+ KERNEL_MODULE_SIG_CERT in local.conf."
42+ fi
43+
44+ if [ -n "${KERNEL_MODULE_SIG_KEY} " ]; then
2645 SIG_HASH = $( grep CONFIG_MODULE_SIG_HASH = \
2746 ${STAGING_KERNEL_BUILDDIR} /. config | \
2847 cut -d '"' -f 2 )
29- [ -z "$SIG_HASH" ] && bbfatal CONFIG_MODULE_SIG_HASH is not set in . config
48+ [ -z "$SIG_HASH" ] && bbfatal " CONFIG_MODULE_SIG_HASH is not set in .config"
3049
3150 [ -x "${SIGN_FILE} " ] || bbfatal "Cannot find scripts/sign-file"
3251
3352 find ${D} -name "*.ko" -print0 | \
34- xargs --no -run -if -empty -0 -n 1 \
53+ xargs -t - -no -run -if -empty -0 -n 1 \
3554 ${SIGN_FILE} $SIG_HASH ${KERNEL_MODULE_SIG_KEY} \
3655 ${KERNEL_MODULE_SIG_CERT}
56+ else
57+ bbnote "Kernel module offline signing enabled, modules still need to be signed."
3758 fi
3859}
3960
@@ -44,3 +65,6 @@ addtask sign_modules after do_install before do_package
4465do_install [lockfiles ] = "${TMPDIR} /kernel-scripts.lock"
4566# Explicit keys sign modules in do_sign_modules
4667do_sign_modules [lockfiles ] = "${TMPDIR} /kernel-scripts.lock"
68+
69+ do_sign_modules [depends ] += "virtual/kernel:do_shared_workdir"
70+ do_sign_modules [file -checksums ] += "${@ get_signing_key (d )} ${@ get_signing_cert (d )}"
0 commit comments