Pablo Greco d6c4c4
#! /bin/bash
Pablo Greco d6c4c4
Pablo Greco d6c4c4
# The modules_sign target checks for corresponding .o files for every .ko that
Pablo Greco d6c4c4
# is signed. This doesn't work for package builds which re-use the same build
Pablo Greco d6c4c4
# directory for every flavour, and the .config may change between flavours.
Pablo Greco d6c4c4
# So instead of using this script to just sign lib/modules/$KernelVer/extra,
Pablo Greco d6c4c4
# sign all .ko in the buildroot.
Pablo Greco d6c4c4
Pablo Greco d6c4c4
# This essentially duplicates the 'modules_sign' Kbuild target and runs the
Pablo Greco d6c4c4
# same commands for those modules.
Pablo Greco d6c4c4
Pablo Greco d6c4c4
MODSECKEY=$1
Pablo Greco d6c4c4
MODPUBKEY=$2
Pablo Greco d6c4c4
Pablo Greco d6c4c4
moddir=$3
Pablo Greco d6c4c4
Pablo Greco d6c4c4
modules=`find $moddir -name *.ko`
Pablo Greco d6c4c4
Pablo Greco d6c4c4
for mod in $modules
Pablo Greco d6c4c4
do
Pablo Greco d6c4c4
    dir=`dirname $mod`
Pablo Greco d6c4c4
    file=`basename $mod`
Pablo Greco d6c4c4
Pablo Greco d6c4c4
    ./scripts/sign-file sha256 ${MODSECKEY} ${MODPUBKEY} ${dir}/${file}
Pablo Greco d6c4c4
    rm -f ${dir}/${file}.{sig,dig}
Pablo Greco d6c4c4
done
Pablo Greco d6c4c4
Pablo Greco d6c4c4
RANDOMMOD=$(find $moddir -type f -name '*.ko' | sort -R | head -n 1)
Pablo Greco d6c4c4
if [ "~Module signature appended~" != "$(tail -c 28 $RANDOMMOD)" ]; then
Pablo Greco d6c4c4
    echo "*****************************"
Pablo Greco d6c4c4
    echo "*** Modules are unsigned! ***"
Pablo Greco d6c4c4
    echo "*****************************"
Pablo Greco d6c4c4
    exit 1
Pablo Greco d6c4c4
fi
Pablo Greco d6c4c4
Pablo Greco d6c4c4
exit 0