42d1a9
#! /bin/bash
42d1a9
42d1a9
# The modules_sign target checks for corresponding .o files for every .ko that
42d1a9
# is signed. This doesn't work for package builds which re-use the same build
42d1a9
# directory for every variant, and the .config may change between variants.
42d1a9
# So instead of using this script to just sign lib/modules/$KernelVer/extra,
42d1a9
# sign all .ko in the buildroot.
42d1a9
42d1a9
# This essentially duplicates the 'modules_sign' Kbuild target and runs the
42d1a9
# same commands for those modules.
42d1a9
42d1a9
MODSECKEY=$1
42d1a9
MODPUBKEY=$2
42d1a9
moddir=$3
42d1a9
42d1a9
modules=$(find "$moddir" -type f -name '*.ko')
42d1a9
42d1a9
NPROC=$(nproc)
42d1a9
[ -z "$NPROC" ] && NPROC=1
42d1a9
42d1a9
# NB: this loop runs 2000+ iterations. Try to be fast.
42d1a9
echo "$modules" | xargs -r -n16 -P "$NPROC" sh -c "
42d1a9
for mod; do
42d1a9
    ./scripts/sign-file sha256 $MODSECKEY $MODPUBKEY \$mod
42d1a9
    rm -f \$mod.sig \$mod.dig
42d1a9
done
42d1a9
" DUMMYARG0   # xargs appends ARG1 ARG2..., which go into $mod in for loop.
42d1a9
42d1a9
RANDOMMOD=$(echo "$modules" | sort -R | head -n 1)
42d1a9
if [ "~Module signature appended~" != "$(tail -c 28 "$RANDOMMOD")" ]; then
42d1a9
    echo "*****************************"
42d1a9
    echo "*** Modules are unsigned! ***"
42d1a9
    echo "*****************************"
42d1a9
    exit 1
42d1a9
fi
42d1a9
42d1a9
exit 0