]>
git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/tools/patcheeprom.c
5 /* EEPROM data size, not including checksum */
6 #define EEP_DATA_SIZE 494
7 /* FIXME: actually we should either find a way to include the declaration of
8 struct storage_t here or at least make this a command line parameter */
10 /* code from http://www.nongnu.org/avr-libc/user-manual/group__util__crc.html */
11 uint16_t crc16_update(uint16_t crc
, uint8_t a
)
16 for (i
= 0; i
< 8; ++i
)
19 crc
= (crc
>> 1) ^ 0xA001;
27 /* oh, this is soooo ugly... :-( */
28 int main(int argc
, char ** argv
)
31 uint16_t checksum
= 0;
33 if ((argc
< 2) || ((id
= atoi(argv
[1])) > 15) || (id
<= 0))
35 fputs("usage: patcheeprom id < eeprom-template > eeprom-binary\n\n", stderr
);
38 /* print out magic byte and add it to checksum */
40 checksum
= crc16_update(checksum
, 0x23);
42 /* print out id and add it to checksum */
44 checksum
= crc16_update(checksum
, id
);
46 /* ignore first two bytes of input */
50 /* now copy template and adapt checksum */
51 for (i
= 2; i
< EEP_DATA_SIZE
; i
++) {
53 if ((c
= getchar()) == EOF
) {
57 checksum
= crc16_update(checksum
, c
);
59 if (putchar(c
) == EOF
) {
63 /* print out checksum, and we're done */
64 putchar(checksum
& 0xff);
65 putchar(checksum
>> 8);