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