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