From 2acfa12f0d3f47810bdfda83b6eef12a63e71703 Mon Sep 17 00:00:00 2001 From: gitknilch Date: Tue, 29 Mar 2011 14:35:10 +0200 Subject: [PATCH] move fixcrc to patcheeprom, add patching of node id (pretty ugly) --- firmware/tools/.gitignore | 2 +- firmware/tools/Makefile | 4 +++- firmware/tools/{fixcrc.c => patcheeprom.c} | 26 ++++++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) rename firmware/tools/{fixcrc.c => patcheeprom.c} (57%) diff --git a/firmware/tools/.gitignore b/firmware/tools/.gitignore index 188dff2..7d6ddd9 100644 --- a/firmware/tools/.gitignore +++ b/firmware/tools/.gitignore @@ -1 +1 @@ -fixcrc +patcheeprom diff --git a/firmware/tools/Makefile b/firmware/tools/Makefile index fd23463..a2a632f 100644 --- a/firmware/tools/Makefile +++ b/firmware/tools/Makefile @@ -1,2 +1,4 @@ -all: fixcrc +CFLAGS ?= -Wall -O3 + +all: patcheeprom diff --git a/firmware/tools/fixcrc.c b/firmware/tools/patcheeprom.c similarity index 57% rename from firmware/tools/fixcrc.c rename to firmware/tools/patcheeprom.c index 3d7fefb..98e5eff 100644 --- a/firmware/tools/fixcrc.c +++ b/firmware/tools/patcheeprom.c @@ -1,4 +1,5 @@ #include +#include #include /* EEPROM data size, not including checksum */ @@ -23,11 +24,31 @@ uint16_t crc16_update(uint16_t crc, uint8_t a) return crc; } +/* oh, this is soooo ugly... :-( */ int main(int argc, char ** argv) { - int i, c; + int i, c, id; uint16_t checksum = 0; - for (i = 0; i < EEP_DATA_SIZE; i++) { + + if ((argc < 2) || ((id = atoi(argv[1])) > 15) || (id <= 0)) + { + fputs("usage: patcheeprom id < eeprom-template > eeprom-binary\n\n", stderr); + return 127; + } + /* print out magic byte and add it to checksum */ + putchar(0x23); + checksum = crc16_update(checksum, 0x23); + + /* print out id and add it to checksum */ + putchar(id); + checksum = crc16_update(checksum, id); + + /* ignore first two bytes of input */ + getchar(); + getchar(); + + /* now copy template and adapt checksum */ + for (i = 2; i < EEP_DATA_SIZE; i++) { if ((c = getchar()) == EOF) { return 1; @@ -39,6 +60,7 @@ int main(int argc, char ** argv) return 2; } } + /* print out checksum, and we're done */ putchar(checksum & 0xff); putchar(checksum >> 8); -- 2.39.2