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