]> git.zerfleddert.de Git - fnordlicht-mini/commitdiff
move fixcrc to patcheeprom, add patching of node id (pretty ugly)
authorgitknilch <gitknilch@cwde.de>
Tue, 29 Mar 2011 12:35:10 +0000 (14:35 +0200)
committergitknilch <gitknilch@cwde.de>
Tue, 29 Mar 2011 12:35:10 +0000 (14:35 +0200)
firmware/tools/.gitignore
firmware/tools/Makefile
firmware/tools/fixcrc.c [deleted file]
firmware/tools/patcheeprom.c [new file with mode: 0644]

index 188dff2097fc7554ab562d7bdc60381cf5debf3c..7d6ddd9629a0df08a8c059ee2d1fad10ee1e6c0d 100644 (file)
@@ -1 +1 @@
-fixcrc
+patcheeprom
index fd234636c0cc0ff55fa50f4141618cf3bc476f8d..a2a632f0207ee62ae237301e753b8d5299add495 100644 (file)
@@ -1,2 +1,4 @@
-all: fixcrc
+CFLAGS ?= -Wall -O3
+
+all: patcheeprom
 
diff --git a/firmware/tools/fixcrc.c b/firmware/tools/fixcrc.c
deleted file mode 100644 (file)
index 3d7fefb..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-#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 & 0xff);
-    putchar(checksum >> 8);
-
-    return 0;
-}
-
diff --git a/firmware/tools/patcheeprom.c b/firmware/tools/patcheeprom.c
new file mode 100644 (file)
index 0000000..98e5eff
--- /dev/null
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <stdlib.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;
+}
+
+/* oh, this is soooo ugly... :-( */
+int main(int argc, char ** argv)
+{
+    int i, c, id;
+    uint16_t checksum = 0;
+
+    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;
+        }
+
+        checksum = crc16_update(checksum, c);
+
+        if (putchar(c) == EOF) {
+            return 2;
+        }
+    }
+    /* print out checksum, and we're done */
+    putchar(checksum & 0xff);
+    putchar(checksum >> 8);
+
+    return 0;
+}
+
Impressum, Datenschutz