add nandalign
authorGrazvydas Ignotas <notasas@gmail.com>
Sun, 3 Jul 2016 00:08:26 +0000 (03:08 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 3 Jul 2016 00:10:28 +0000 (03:10 +0300)
this adds a marker for x-load to stop reading NAND

tools/nandalign.c [new file with mode: 0644]

diff --git a/tools/nandalign.c b/tools/nandalign.c
new file mode 100644 (file)
index 0000000..343cca4
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <string.h>
+
+static unsigned char fillpage[0x20000];
+#define END_MARK 0x646e65ff    /* end */
+
+int main(int argc, char *argv[])
+{
+       FILE *f;
+       long size, finalsize, offset;
+       int mark = END_MARK;
+
+       memset(fillpage, 0xff, sizeof(fillpage));
+       memcpy(fillpage + sizeof(fillpage) - 8, &mark, 4);
+       memcpy(fillpage + sizeof(fillpage) - 4, &mark, 4);
+
+       if (argv[1] == NULL) {
+               fprintf(stderr, "usage:\n%s <uboot.bin>\n", argv[0]);
+               return 1;
+       }
+
+       f = fopen(argv[1], "r+");
+       if (f == NULL) {
+               perror("fopen");
+               return 1;
+       }
+
+       fseek(f, 0, SEEK_END);
+       size = ftell(f);
+       finalsize = (size + 8 + 0x20000 - 1) & ~(0x20000 - 1);
+
+       if (finalsize - size > 0x20000) {
+               offset = finalsize - size - 0x20000;
+               fwrite(fillpage, 1, offset, f);
+               size += offset;
+       }
+       offset = 0x20000 - (finalsize - size);
+       fwrite(fillpage + offset, 1, finalsize - size, f);
+       fclose(f);
+
+       return 0;
+}