Revision 89e671e3
b/pc-bios/optionrom/Makefile | ||
---|---|---|
37 | 37 |
%.img: %.o |
38 | 38 |
$(LD) --oformat binary -Ttext 0 -o $@ $< |
39 | 39 |
|
40 |
%.bin: %.img signrom
|
|
41 |
./signrom $< $@
|
|
40 |
%.bin: %.img |
|
41 |
$(SRC_PATH)/pc-bios/optionrom/signrom.sh $< $@
|
|
42 | 42 |
cp $@ $(SRC_PATH)/pc-bios/ |
43 | 43 |
|
44 |
signrom: signrom.c |
|
45 |
$(CC) -o $@ -g -Wall $^ |
|
46 |
|
|
47 | 44 |
clean: |
48 |
$(RM) *.o *.img *.bin signrom *~ |
|
45 |
$(RM) *.o *.img *.bin *~ |
/dev/null | ||
---|---|---|
1 |
/* |
|
2 |
* Extended Boot Option ROM |
|
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, write to the Free Software |
|
16 |
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 |
* |
|
18 |
* Copyright IBM Corporation, 2007 |
|
19 |
* Authors: Anthony Liguori <aliguori@us.ibm.com> |
|
20 |
*/ |
|
21 |
|
|
22 |
#include <stdio.h> |
|
23 |
#include <stdint.h> |
|
24 |
#include <string.h> |
|
25 |
|
|
26 |
int main(int argc, char **argv) |
|
27 |
{ |
|
28 |
FILE *fin, *fout; |
|
29 |
char buffer[512], oldbuffer[512]; |
|
30 |
int i, size, lag = 0; |
|
31 |
uint8_t sum = 0; |
|
32 |
|
|
33 |
if (argc != 3) { |
|
34 |
printf("Usage: %s ROM OUTPUT\n", argv[0]); |
|
35 |
return 1; |
|
36 |
} |
|
37 |
|
|
38 |
fin = fopen(argv[1], "rb"); |
|
39 |
fout = fopen(argv[2], "wb"); |
|
40 |
|
|
41 |
if (fin == NULL || fout == NULL) { |
|
42 |
fprintf(stderr, "Could not open input/output files\n"); |
|
43 |
return 1; |
|
44 |
} |
|
45 |
|
|
46 |
do { |
|
47 |
size = fread(buffer, 512, 1, fin); |
|
48 |
if (size == 1) { |
|
49 |
for (i = 0; i < 512; i++) |
|
50 |
sum += buffer[i]; |
|
51 |
|
|
52 |
if (lag) { |
|
53 |
if (fwrite(oldbuffer, 512, 1, fout) != 1) { |
|
54 |
fprintf(stderr, "Write failed\n"); |
|
55 |
return 1; |
|
56 |
} |
|
57 |
} |
|
58 |
lag = 1; |
|
59 |
memcpy(oldbuffer, buffer, 512); |
|
60 |
} |
|
61 |
} while (size == 1); |
|
62 |
|
|
63 |
if (size != 0) { |
|
64 |
fprintf(stderr, "Failed to read from input file\n"); |
|
65 |
return 1; |
|
66 |
} |
|
67 |
|
|
68 |
oldbuffer[511] = -sum; |
|
69 |
|
|
70 |
if (fwrite(oldbuffer, 512, 1, fout) != 1) { |
|
71 |
fprintf(stderr, "Failed to write to output file\n"); |
|
72 |
return 1; |
|
73 |
} |
|
74 |
|
|
75 |
fclose(fin); |
|
76 |
fclose(fout); |
|
77 |
|
|
78 |
return 0; |
|
79 |
} |
b/pc-bios/optionrom/signrom.sh | ||
---|---|---|
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 |
|
16 |
# along with this program; if not, write to the Free Software |
|
17 |
# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 |
# |
|
19 |
# Copyright Novell Inc, 2009 |
|
20 |
# Authors: Alexander Graf <agraf@suse.de> |
|
21 |
# |
|
22 |
# Syntax: signrom.sh <input> <output> |
|
23 |
|
|
24 |
# did we get proper arguments? |
|
25 |
test "$1" -a "$2" || exit 1 |
|
26 |
|
|
27 |
sum=0 |
|
28 |
|
|
29 |
# find out the file size |
|
30 |
x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n` |
|
31 |
#size=`expr $x \* 512 - 1` |
|
32 |
size=$(( $x * 512 - 1 )) |
|
33 |
|
|
34 |
# now get the checksum |
|
35 |
for i in `od -A n -t u1 -v "$1"`; do |
|
36 |
# add each byte's value to sum |
|
37 |
sum=$(( $sum + $i )) |
|
38 |
done |
|
39 |
|
|
40 |
sum=$(( $sum % 256 )) |
|
41 |
sum=$(( 256 - $sum )) |
|
42 |
|
|
43 |
# and write the output file |
|
44 |
cp "$1" "$2" |
|
45 |
printf "\\$sum" | dd of="$2" bs=1 count=1 seek=$size conv=notrunc 2>/dev/null |
Also available in: Unified diff