signrom.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # Option ROM Signing utility
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. #
  17. # Copyright Novell Inc, 2009
  18. # Authors: Alexander Graf <agraf@suse.de>
  19. #
  20. # Syntax: signrom.sh <input> <output>
  21. # did we get proper arguments?
  22. test "$1" -a "$2" || exit 1
  23. sum=0
  24. # find out the file size
  25. x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n`
  26. #size=`expr $x \* 512 - 1`
  27. size=$(( $x * 512 - 1 ))
  28. # now get the checksum
  29. nums=`od -A n -t u1 -v -N $size "$1"`
  30. for i in ${nums}; do
  31. # add each byte's value to sum
  32. sum=`expr \( $sum + $i \) % 256`
  33. done
  34. sum=$(( (256 - $sum) % 256 ))
  35. sum_octal=$( printf "%o" $sum )
  36. # and write the output file
  37. cp "$1" "$2"
  38. printf "\\$sum_octal" | dd of="$2" bs=1 count=1 seek=$size conv=notrunc 2>/dev/null