3 * 2N Telekomunikace, Ladislav Michl <michl@2n.cz>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <sys/types.h>
34 extern unsigned long crc32(unsigned long, const unsigned char *, unsigned int);
36 uint32_t data[LOADER_SIZE/4 + 3];
38 int doit(char *path, unsigned version)
44 fd = open(path, O_RDONLY);
46 perror("Error opening file");
50 size = read(fd, p, LOADER_SIZE + 4);
52 perror("Error reading file");
55 if (size > LOADER_SIZE) {
56 fprintf(stderr, "File too large\n");
59 size = (((size - 1) >> 2) + 1) << 2;
60 data[0] = size + 4; /* add size of version field */
62 data[(size >> 2) + 2] = crc32(0, (unsigned char *)(data + 1), data[0]);
65 if (write(STDOUT_FILENO, data, size + 3*4) == -1) {
66 perror("Error writing file");
73 int main(int argc, char **argv)
76 return doit(argv[1], 0);
77 } else if ((argc == 4) && (strcmp(argv[1], "-v") == 0)) {
78 char *endptr, *nptr = argv[2];
79 unsigned ver = strtoul(nptr, &endptr, 0);
80 if (*nptr != '\0' && *endptr == '\0')
81 return doit(argv[3], ver);
83 fprintf(stderr, "Usage: crcit [-v version] <image>\n");