Browse Source

Automate cfgware.h file generation. Will automatically search the .bit file from sd2sneslite rle it and convert to .h file.

Godzil 11 years ago
parent
commit
043eeea399
3 changed files with 59 additions and 2 deletions
  1. 10 1
      src/Makefile
  2. 4 1
      src/utils/Makefile
  3. 45 0
      src/utils/bin2h.c

+ 10 - 1
src/Makefile

@@ -124,7 +124,8 @@ NM = $(ARCH)-nm
 REMOVE = rm -f
 COPY = cp
 AWK = awk
-
+RLE = ../utils/rle
+BIN2H = utils/bin2h
 
 #---------------- Compiler Options ----------------
 #  -g*:          generate debugging information
@@ -230,6 +231,13 @@ HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
 ELFSIZE = $(SIZE) -A $(TARGET).elf
 
 
+# Generate cfgware.h
+cfgware.h: $(OBJDIR)/fpga_rle.bit
+	$(E) "  BIN2H  $@"
+	$(Q) $(BIN2H) $< $@
+$(OBJDIR)/fpga_rle.bit: sd2sneslite.bit
+	$(E) "  RLE    $@"
+	$(Q) $(RLE) $< $@
 
 # Generate autoconf.h from config
 .PRECIOUS : $(OBJDIR)/autoconf.h
@@ -302,6 +310,7 @@ clean_list :
 	$(Q)$(REMOVE) $(TARGET).sym
 	$(Q)$(REMOVE) $(TARGET).lss
 	$(Q)$(REMOVE) $(OBJ)
+	$(Q)$(REMOVE) cfgware.h
 	$(Q)$(REMOVE) $(OBJDIR)/autoconf.h
 	$(Q)$(REMOVE) $(OBJDIR)/*.bin
 	$(Q)$(REMOVE) $(LST)

+ 4 - 1
src/utils/Makefile

@@ -2,11 +2,14 @@
 CC = gcc
 CFLAGS = -Wall -Wstrict-prototypes -Werror
 
-all: lpcchksum genhdr
+all: lpcchksum genhdr bin2h
 
 genhdr: genhdr.o
 	$(CC) $(CFLAGS) $^ --output $@
 
+bin2h: bin2h.o
+	$(CC) $(CFLAGS) $^ --output $@
+
 lpcchksum: lpcchksum.o
 	$(CC) $(CFLAGS) $^ --output $@
 

+ 45 - 0
src/utils/bin2h.c

@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+   FILE *fpIn = NULL, *fpOut = NULL;
+   unsigned char buffer[5], i;
+   if ( argc == 3 )
+   {
+      fpIn = fopen(argv[1], "rb");
+      fpOut = fopen(argv[2], "wt");
+   }
+   else if (argc == 2)
+   {
+      fpIn = fopen(argv[1], "rb");
+      fpOut = stdout;
+   }
+   else if ( argc == 1 )
+   {
+      fpIn = stdin;
+      fpOut = stdout;
+   }
+   else
+   {
+      fprintf(stderr, "usage: %s [infile] [outfile]\n", argv[0]);
+      return -1;
+   }
+   
+   if (fpIn == NULL) { fprintf(stderr, "Can't open '%s`: Aborting.", argv[1]); return -1; }
+   if (fpOut == NULL) { fprintf(stderr, "Can't open '%s`: Aborting.", argv[2]); return -1; }
+   
+   fprintf(fpOut, "const uint8_t cfgware[] = {\n");
+   i = 0;
+   while(!feof(fpIn))
+   {
+      fread(buffer, 1, 1, fpIn);
+      fprintf(fpOut, "0x%02X, ", buffer[0]);
+      i++; if (i > 8) { fprintf(fpOut, "\n"); i = 0; }
+   }
+   if (i > 0)
+      fprintf(fpOut, "\n");
+   fprintf(fpOut, "};");
+   fclose(fpOut); fclose(fpIn);
+   return 0;
+}