mod-sign.sh 1.1 KB

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