]> git.zerfleddert.de Git - fnordlicht-mini/commitdiff
very crude tool to fix eeprom checksum in binary
authorgitknilch <gitknilch@cwde.de>
Fri, 25 Mar 2011 13:44:37 +0000 (14:44 +0100)
committergitknilch <gitknilch@cwde.de>
Fri, 25 Mar 2011 13:44:37 +0000 (14:44 +0100)
firmware/tools/Makefile [new file with mode: 0644]
firmware/tools/fixcrc.c [new file with mode: 0644]

diff --git a/firmware/tools/Makefile b/firmware/tools/Makefile
new file mode 100644 (file)
index 0000000..fd23463
--- /dev/null
@@ -0,0 +1,2 @@
+all: fixcrc
+
diff --git a/firmware/tools/fixcrc.c b/firmware/tools/fixcrc.c
new file mode 100644 (file)
index 0000000..4b3f616
--- /dev/null
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <inttypes.h>
+
+/* EEPROM data size, not including checksum */
+#define EEP_DATA_SIZE 494
+/* FIXME: actually we should either find a way to include the declaration of
+      struct storage_t here or at least make this a command line parameter */
+
+/* code from http://www.nongnu.org/avr-libc/user-manual/group__util__crc.html */
+uint16_t crc16_update(uint16_t crc, uint8_t a)
+{
+    int i;
+
+    crc ^= a;
+    for (i = 0; i < 8; ++i)
+    {
+        if (crc & 1)
+            crc = (crc >> 1) ^ 0xA001;
+        else
+            crc = (crc >> 1);
+    }
+
+    return crc;
+}
+
+int main(int argc, char ** argv)
+{
+    int i, c;
+    uint16_t checksum = 0;
+    for (i = 0; i < EEP_DATA_SIZE; i++) {
+
+        if ((c = getchar()) == EOF) {
+            return 1;
+        }
+
+        checksum = crc16_update(checksum, c);
+
+        if (putchar(c) == EOF) {
+            return 2;
+        }
+    }
+    putchar(checksum >> 8);
+    putchar(checksum & 0xff);
+
+    return 0;
+}
+
Impressum, Datenschutz