2 * Copyright 2010 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * compute rom checksum byte
23 #include <sys/types.h>
25 #define MAX_SIZE 65536
26 unsigned char buf
[MAX_SIZE
];
28 int main(int argc
, char **argv
)
35 fprintf(stderr
, "usage: %s filename\n", argv
[0]);
38 if ((fd
= open(argv
[1], O_RDWR
)) < 0) {
42 if ((fsize
= read(fd
, buf
, MAX_SIZE
)) < 0) {
46 if (fsize
>= MAX_SIZE
&& read(fd
, &buf
[MAX_SIZE
- 1], 1) > 0) {
47 fprintf(stderr
, "FAIL: %s is larger than %d bytes\n", argv
[1], MAX_SIZE
);
50 i
= fsize
- 2048 * (fsize
/ 2048);
52 fprintf(stderr
, "FAIL: %s is %zd bytes, need 2K pad-1\n", argv
[1], fsize
);
55 for (i
= sum
= 0; i
< fsize
; i
++) {
62 fprintf(stderr
, "%s: sum = 0x%02x, wrote byte 0x%02x\n", argv
[1], sum
, csum
);