Statistics
| Branch: | Revision:

root / pc-bios / optionrom / signrom.sh @ 076d2471

History | View | Annotate | Download (1.3 kB)

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