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