Statistics
| Branch: | Revision:

root / pc-bios / optionrom / signrom.c @ 253d0942

History | View | Annotate | Download (1.8 kB)

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
}