fpga_compress: interleave (combine) fpga_lf.bit and fpga_hf.bit before compression.
authorpwpiwi <pwpiwi@users.noreply.github.com>
Wed, 29 Apr 2015 15:59:33 +0000 (17:59 +0200)
committerpwpiwi <pwpiwi@users.noreply.github.com>
Tue, 26 May 2015 06:31:28 +0000 (08:31 +0200)
fpga_loader.c: change to unweave fpga_lf and fpga_hf accordingly
prepare fpga_compress, fpga_loader and Makefile to handle more than two FPGA config files
revert removal of fullimage Makefile target. Remove osimage instead.

Makefile
armsrc/Makefile
armsrc/fpgaloader.c
armsrc/fpgaloader.h
armsrc/ldscript
client/fpga_compress.c
include/proxmark3.h
recovery/Makefile

index afbaad9e18c00571eab1a37a904675996863af9c..0e065b41dc9ee86c6245d421163f66990c0a75e5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,10 +31,10 @@ client: client/all
 flash-bootrom: bootrom/obj/bootrom.elf $(FLASH_TOOL)
        $(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$<)
 
-flash-os: armsrc/obj/osimage.elf $(FLASH_TOOL)
+flash-os: armsrc/obj/fullimage.elf $(FLASH_TOOL)
        $(FLASH_TOOL) $(FLASH_PORT) $(subst /,$(PATHSEP),$<)
 
-flash-all: bootrom/obj/bootrom.elf armsrc/obj/osimage.elf $(FLASH_TOOL)
+flash-all: bootrom/obj/bootrom.elf armsrc/obj/fullimage.elf $(FLASH_TOOL)
        $(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$(filter-out $(FLASH_TOOL),$^))
 
 newtarbin:
index 9efbb1ad6e9c131282f5d5a8c6695adc93a875ad..b1ce4e4d707e66a2a3844cbb6d7012c1c468f07d 100644 (file)
@@ -22,6 +22,9 @@ SRC_ISO14443b = iso14443.c
 SRC_CRAPTO1 = crapto1.c crypto1.c des.c aes.c 
 SRC_CRC = iso14443crc.c crc.c crc16.c crc32.c
 
+#the FPGA bitstream files. Note: order matters!
+FPGA_BITSTREAMS = fpga_lf.bit fpga_hf.bit
+
 #the zlib source files required for decompressing the fpga config at run time
 SRC_ZLIB = inflate.c inffast.c inftrees.c adler32.c zutil.c
 #additional defines required to compile zlib
@@ -67,16 +70,13 @@ FPGA_COMPRESSOR = ../client/fpga_compress
 
 all: $(OBJS)
 
-$(OBJDIR)/fpga_lf.o: $(OBJDIR)/fpga_lf.bit.z
-       $(OBJCOPY) -O elf32-littlearm -I binary -B arm --redefine-sym _binary_obj_fpga_lf_bit_z_start=_binary_fpga_lf_bit_start --redefine-sym _binary_obj_fpga_lf_bit_z_end=_binary_fpga_lf_bit_end --prefix-sections=fpga_lf_bit  $^ $@
-
-$(OBJDIR)/fpga_hf.o: $(OBJDIR)/fpga_hf.bit.z
-       $(OBJCOPY) -O elf32-littlearm -I binary -B arm --redefine-sym _binary_obj_fpga_hf_bit_z_start=_binary_fpga_hf_bit_start --redefine-sym _binary_obj_fpga_hf_bit_z_end=_binary_fpga_hf_bit_end --prefix-sections=fpga_hf_bit  $^ $@
+$(OBJDIR)/fpga_all.o: $(OBJDIR)/fpga_all.bit.z
+       $(OBJCOPY) -O elf32-littlearm -I binary -B arm --prefix-sections=fpga_all_bit $^ $@
 
-$(OBJDIR)/%.bit.z: %.bit $(FPGA_COMPRESSOR)
+$(OBJDIR)/fpga_all.bit.z: $(FPGA_BITSTREAMS) $(FPGA_COMPRESSOR)
        $(FPGA_COMPRESSOR) $(filter %.bit,$^) $@  
 
-$(OBJDIR)/osimage.elf: $(VERSIONOBJ) $(OBJDIR)/fpga_lf.o $(OBJDIR)/fpga_hf.o $(THUMBOBJ) $(ARMOBJ)
+$(OBJDIR)/fullimage.elf: $(VERSIONOBJ) $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ)
        $(CC) $(LDFLAGS) -Wl,-T,ldscript,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS)
 
 tarbin: $(OBJS)
@@ -95,6 +95,6 @@ clean:
 help:
        @echo Multi-OS Makefile, you are running on $(DETECTED_OS)
        @echo Possible targets:
-       @echo + all    - Build the OS image $(OBJDIR)/osimage.s19
+       @echo + all    - Build the full image $(OBJDIR)/fullimage.s19
        @echo + clean  - Clean $(OBJDIR)
 
index 573aac3a8af9f8f288279a401a79aa443214e47a..a2c9d1e4b2064a631f2a61c035310904d4038439 100644 (file)
@@ -26,13 +26,15 @@ extern void Dbprintf(const char *fmt, ...);
 static int downloaded_bitstream = FPGA_BITSTREAM_ERR;
 
 // this is where the bitstreams are located in memory:
-extern uint8_t _binary_fpga_lf_bit_start, _binary_fpga_lf_bit_end;
-extern uint8_t _binary_fpga_hf_bit_start, _binary_fpga_hf_bit_end;
+extern uint8_t _binary_obj_fpga_all_bit_z_start, _binary_obj_fpga_all_bit_z_end;
+
 static uint8_t *fpga_image_ptr = NULL;
+static uint32_t uncompressed_bytes_cnt;
 
 static const uint8_t _bitparse_fixed_header[] = {0x00, 0x09, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x00, 0x00, 0x01};
 #define FPGA_BITSTREAM_FIXED_HEADER_SIZE       sizeof(_bitparse_fixed_header)
-#define OUTPUT_BUFFER_LEN 80
+#define OUTPUT_BUFFER_LEN              80
+#define FPGA_INTERLEAVE_SIZE   288
 
 //-----------------------------------------------------------------------------
 // Set up the Serial Peripheral Interface as master
@@ -171,7 +173,7 @@ bool FpgaSetupSscDma(uint8_t *buf, int len)
 }
 
 
-static int get_from_fpga_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer)
+static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer)
 {
        if (fpga_image_ptr == compressed_fpga_stream->next_out) {       // need more data
                compressed_fpga_stream->next_out = output_buffer;
@@ -186,10 +188,24 @@ static int get_from_fpga_stream(z_streamp compressed_fpga_stream, uint8_t *outpu
                }
        }
 
+       uncompressed_bytes_cnt++;
+       
        return *fpga_image_ptr++;
 }
 
 
+static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
+{
+       while((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % FPGA_BITSTREAM_MAX != (bitstream_version - 1)) {
+               // skip undesired data belonging to other bitstream_versions
+               get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
+       }
+
+       return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
+       
+}
+
+
 static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size)
 {
        Dbprintf("zlib requested %d bytes", items*size);
@@ -207,22 +223,12 @@ static void fpga_inflate_free(voidpf opaque, voidpf address)
 static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
 {
        uint8_t header[FPGA_BITSTREAM_FIXED_HEADER_SIZE];
-       uint8_t *fpga_image_start;
-       uint32_t fpga_image_size;
        
-       if (bitstream_version == FPGA_BITSTREAM_LF) {
-               fpga_image_start = &_binary_fpga_lf_bit_start;
-               fpga_image_size = (uint32_t)&_binary_fpga_lf_bit_end - (uint32_t)&_binary_fpga_lf_bit_start;
-       } else if (bitstream_version == FPGA_BITSTREAM_HF) {
-               fpga_image_start = &_binary_fpga_hf_bit_start;
-               fpga_image_size = (uint32_t)&_binary_fpga_hf_bit_end - (uint32_t)&_binary_fpga_hf_bit_start;
-       } else {
-               return false;
-       }       
-
+       uncompressed_bytes_cnt = 0;
+       
        // initialize z_stream structure for inflate:
-       compressed_fpga_stream->next_in = fpga_image_start;
-       compressed_fpga_stream->avail_in = fpga_image_size;
+       compressed_fpga_stream->next_in = &_binary_obj_fpga_all_bit_z_start;
+       compressed_fpga_stream->avail_in = &_binary_obj_fpga_all_bit_z_start - &_binary_obj_fpga_all_bit_z_end;
        compressed_fpga_stream->next_out = output_buffer;
        compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
        compressed_fpga_stream->zalloc = &fpga_inflate_malloc;
@@ -233,7 +239,7 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s
        fpga_image_ptr = output_buffer;
 
        for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
-               header[i] = get_from_fpga_stream(compressed_fpga_stream, output_buffer);
+               header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
        }
        
        // Check for a valid .bit file (starts with _bitparse_fixed_header)
@@ -259,7 +265,7 @@ static void DownloadFPGA_byte(unsigned char w)
 }
 
 // Download the fpga image starting at current stream position with length FpgaImageLen bytes
-static void DownloadFPGA(int FpgaImageLen, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
+static void DownloadFPGA(int bitstream_version, int FpgaImageLen, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
 {
 
        Dbprintf("DownloadFPGA(len: %d)", FpgaImageLen);
@@ -316,7 +322,7 @@ static void DownloadFPGA(int FpgaImageLen, z_streamp compressed_fpga_stream, uin
        }
 
        for(i = 0; i < FpgaImageLen; i++) {
-               int b = get_from_fpga_stream(compressed_fpga_stream, output_buffer);
+               int b = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
                if (b < 0) {
                        Dbprintf("Error %d during FpgaDownload", b);
                        break;
@@ -348,13 +354,13 @@ static void DownloadFPGA(int FpgaImageLen, z_streamp compressed_fpga_stream, uin
  * (big endian), <length> bytes content. Except for section 'e' which has 4 bytes
  * length.
  */
-static int bitparse_find_section(char section_name, unsigned int *section_length, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
+static int bitparse_find_section(int bitstream_version, char section_name, unsigned int *section_length, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
 {
        int result = 0;
        #define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100  // maximum number of bytes to search for the requested section
        uint16_t numbytes = 0;
        while(numbytes < MAX_FPGA_BIT_STREAM_HEADER_SEARCH) {
-               char current_name = get_from_fpga_stream(compressed_fpga_stream, output_buffer);
+               char current_name = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
                numbytes++;
                unsigned int current_length = 0;
                if(current_name < 'a' || current_name > 'e') {
@@ -365,12 +371,12 @@ static int bitparse_find_section(char section_name, unsigned int *section_length
                switch(current_name) {
                case 'e':
                        /* Four byte length field */
-                       current_length += get_from_fpga_stream(compressed_fpga_stream, output_buffer) << 24;
-                       current_length += get_from_fpga_stream(compressed_fpga_stream, output_buffer) << 16;
+                       current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 24;
+                       current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 16;
                        numbytes += 2;
                default: /* Fall through, two byte length field */
-                       current_length += get_from_fpga_stream(compressed_fpga_stream, output_buffer) << 8;
-                       current_length += get_from_fpga_stream(compressed_fpga_stream, output_buffer) << 0;
+                       current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 8;
+                       current_length += get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer) << 0;
                        numbytes += 2;
                }
 
@@ -387,7 +393,7 @@ static int bitparse_find_section(char section_name, unsigned int *section_length
                }
 
                for (uint16_t i = 0; i < current_length && numbytes < MAX_FPGA_BIT_STREAM_HEADER_SEARCH; i++) {
-                       get_from_fpga_stream(compressed_fpga_stream, output_buffer);
+                       get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
                        numbytes++;
                }
        }
@@ -414,8 +420,8 @@ void FpgaDownloadAndGo(int bitstream_version)
        }
 
        unsigned int bitstream_length;
-       if(bitparse_find_section('e', &bitstream_length, &compressed_fpga_stream, output_buffer)) {
-               DownloadFPGA(bitstream_length, &compressed_fpga_stream, output_buffer);
+       if(bitparse_find_section(bitstream_version, 'e', &bitstream_length, &compressed_fpga_stream, output_buffer)) {
+               DownloadFPGA(bitstream_version, bitstream_length, &compressed_fpga_stream, output_buffer);
                downloaded_bitstream = bitstream_version;
        }
 
@@ -437,9 +443,9 @@ void FpgaGatherVersion(int bitstream_version, char *dst, int len)
                return;
        }
 
-       if(bitparse_find_section('a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
+       if(bitparse_find_section(bitstream_version, 'a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
                for (uint16_t i = 0; i < fpga_info_len; i++) {
-                       char c = (char)get_from_fpga_stream(&compressed_fpga_stream, output_buffer);
+                       char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
                        if (i < sizeof(tempstr)) {
                                tempstr[i] = c;
                        }
@@ -450,30 +456,30 @@ void FpgaGatherVersion(int bitstream_version, char *dst, int len)
                        strncat(dst, "HF ", len-1);
        }
        strncat(dst, "FPGA image built", len-1);
-       if(bitparse_find_section('b', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
+       if(bitparse_find_section(bitstream_version, 'b', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
                strncat(dst, " for ", len-1);
                for (uint16_t i = 0; i < fpga_info_len; i++) {
-                       char c = (char)get_from_fpga_stream(&compressed_fpga_stream, output_buffer);
+                       char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
                        if (i < sizeof(tempstr)) {
                                tempstr[i] = c;
                        }
                }
                strncat(dst, tempstr, len-1);
        }
-       if(bitparse_find_section('c', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
+       if(bitparse_find_section(bitstream_version, 'c', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
                strncat(dst, " on ", len-1);
                for (uint16_t i = 0; i < fpga_info_len; i++) {
-                       char c = (char)get_from_fpga_stream(&compressed_fpga_stream, output_buffer);
+                       char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
                        if (i < sizeof(tempstr)) {
                                tempstr[i] = c;
                        }
                }
                strncat(dst, tempstr, len-1);
        }
-       if(bitparse_find_section('d', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
+       if(bitparse_find_section(bitstream_version, 'd', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
                strncat(dst, " at ", len-1);
                for (uint16_t i = 0; i < fpga_info_len; i++) {
-                       char c = (char)get_from_fpga_stream(&compressed_fpga_stream, output_buffer);
+                       char c = (char)get_from_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer);
                        if (i < sizeof(tempstr)) {
                                tempstr[i] = c;
                        }
index 6981b216d1222ec9cfe910b5ca868301e3eaae7b..0bad38094b62d355dc6cd13fb427b8c3c9310876 100644 (file)
@@ -21,6 +21,13 @@ bool FpgaSetupSscDma(uint8_t *buf, int len);
 #define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
 void SetAdcMuxFor(uint32_t whichGpio);
 
+// definitions for multiple FPGA config files support
+#define FPGA_BITSTREAM_MAX 2   // the total number of FPGA bitstreams (configs)
+#define FPGA_BITSTREAM_ERR 0
+#define FPGA_BITSTREAM_LF 1
+#define FPGA_BITSTREAM_HF 2
+
+
 // Definitions for the FPGA commands.
 #define FPGA_CMD_SET_CONFREG                                           (1<<12)
 #define FPGA_CMD_SET_DIVISOR                                           (2<<12)
index ce7a330e93d8424c1d2ce017e08024d7e81a5857..6175564dceff930950c4b272d3b60536cc1cbda2 100644 (file)
@@ -34,8 +34,7 @@ SECTIONS
        .rodata : {
                *(.rodata)
                *(.rodata.*)
-               *(fpga_lf_bit.data)
-               *(fpga_hf_bit.data)
+               *(fpga_all_bit.data)
                KEEP(*(.version_information))
        } >osimage :text
 
index db1ef81b6a0fd27cd7ca04d6fb29e5d10c8a2138..d4376ccc96a1cdc50f92bcc21e1ba0f258639005 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include "zlib.h"
 
 #define MAX(a,b) ((a)>(b)?(a):(b))
 
 // zlib configuration
 #define COMPRESS_LEVEL                 9               // use best possible compression
-
-#define FPGA_CONFIG_SIZE       42175
-static uint8_t fpga_config[FPGA_CONFIG_SIZE];
+#define COMPRESS_WINDOW_BITS   15              // default = 15 for a window of 2^15 = 32KBytes
+#define COMPRESS_MEM_LEVEL             9               // determines the amount of memory allocated during compression. Default = 8. Must be < 9
+/* COMPRESS_STRATEGY can be 
+       Z_DEFAULT_STRATEGY (the default), 
+       Z_FILTERED (more huffmann, less string matching),
+       Z_HUFFMAN_ONLY (huffman only, no string matching)
+       Z_RLE (distances limited to one)
+       Z_FIXED (prevents the use of dynamic Huffman codes)
+*/     
+#define        COMPRESS_STRATEGY               Z_DEFAULT_STRATEGY
+// zlib tuning parameters:
+#define COMPRESS_GOOD_LENGTH           258
+#define        COMPRESS_MAX_LAZY                       258     
+#define        COMPRESS_MAX_NICE_LENGTH        258
+#define        COMPRESS_MAX_CHAIN                      8192
+
+#define FPGA_INTERLEAVE_SIZE   288     // (the FPGA's internal config frame size is 288 bits. Interleaving with 288 bytes should give best compression)
+#define FPGA_CONFIG_SIZE               42336   // our current fpga_[lh]f.bit files are 42175 bytes. Rounded up to next multiple of FPGA_INTERLEAVE_SIZE
 
 static void usage(char *argv0)
 {
-       fprintf(stderr, "Usage:   %s <infile> <outfile>\n\n", argv0);
+       fprintf(stderr, "Usage:   %s <infile1> <infile2> ... <infile_n> <outfile>\n\n", argv0);
+       fprintf(stderr, "Combines n FPGA bitstream files and compresses them into one.\n\n");
 }
 
 
@@ -40,40 +57,78 @@ static void fpga_deflate_free(voidpf opaque, voidpf address)
 }
 
 
-int zlib_compress(FILE *infile, FILE *outfile)
+static bool all_feof(FILE *infile[], uint8_t num_infiles)
+{
+       for (uint16_t i = 0; i < num_infiles; i++) {
+               if (!feof(infile[i])) {
+                       return false;
+               }
+       }
+       
+       return true;
+}
+
+
+int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile)
 {
-       int i, ret;
+       uint8_t *fpga_config;
+       uint32_t i;
+       int ret;
+       uint8_t c;              
        z_stream compressed_fpga_stream;
+
+       fpga_config = malloc(num_infiles * FPGA_CONFIG_SIZE);
        
-       // read the input file into fpga_config[] and count occurrences of each symbol:
+       // read the input files interleaving into fpga_config[]
        i = 0;
-       while(!feof(infile)) {
-               uint8_t c;
-               c = fgetc(infile);
-               fpga_config[i++] = c;
-               if (i > FPGA_CONFIG_SIZE+1) {
-                       fprintf(stderr, "Input file too big (> %d bytes). This is probably not a PM3 FPGA config file.", FPGA_CONFIG_SIZE);
-                       fclose(infile);
-                       fclose(outfile);
+       do {
+               for(uint16_t j = 0; j < num_infiles; j++) {
+                       for(uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) {
+                               c = fgetc(infile[j]);
+                               if (!feof(infile[j])) fpga_config[i++] = c; else fpga_config[i++] = '\0';
+                       }
+               }
+
+               if (i > num_infiles * FPGA_CONFIG_SIZE) {
+                       fprintf(stderr, "Input files too big (total of %ld > %d bytes). These are probably not PM3 FPGA config files.", i, num_infiles*FPGA_CONFIG_SIZE);
+                       for(uint16_t j = 0; j < num_infiles; j++) {
+                               fclose(infile[j]);
+                       }
                        return -1;
                }
-       }
+       } while (!all_feof(infile, num_infiles));
 
+       fprintf(stderr, "Read a total of %ld bytes from %d files\n", i, num_infiles);
+       
        // initialize zlib structures
        compressed_fpga_stream.next_in = fpga_config;
        compressed_fpga_stream.avail_in = i;
        compressed_fpga_stream.zalloc = fpga_deflate_malloc;
        compressed_fpga_stream.zfree = fpga_deflate_free;
        
+       ret = deflateInit2(&compressed_fpga_stream, 
+                                               COMPRESS_LEVEL,
+                                               Z_DEFLATED,
+                                               COMPRESS_WINDOW_BITS,
+                                               COMPRESS_MEM_LEVEL,
+                                               COMPRESS_STRATEGY);
+
        // estimate the size of the compressed output
        unsigned int outsize_max = deflateBound(&compressed_fpga_stream, compressed_fpga_stream.avail_in);
+       fprintf(stderr, "Allocating %ld bytes for output file (estimated upper bound)\n", outsize_max);
        uint8_t *outbuf = malloc(outsize_max);
        compressed_fpga_stream.next_out = outbuf;
        compressed_fpga_stream.avail_out = outsize_max;
-       fprintf(stderr, "Allocated %d bytes for output file (estimated upper bound)\n", outsize_max);
        
-       ret = deflateInit(&compressed_fpga_stream, COMPRESS_LEVEL);
-                               
+                                       
+       if (ret == Z_OK) {
+               ret = deflateTune(&compressed_fpga_stream,
+                                                       COMPRESS_GOOD_LENGTH,
+                                                       COMPRESS_MAX_LAZY,
+                                                       COMPRESS_MAX_NICE_LENGTH,
+                                                       COMPRESS_MAX_CHAIN);
+       }
+       
        if (ret == Z_OK) {
                ret = deflate(&compressed_fpga_stream, Z_FINISH);
        }
@@ -84,8 +139,12 @@ int zlib_compress(FILE *infile, FILE *outfile)
                fprintf(stderr, "Error in deflate(): %d %s\n", ret, compressed_fpga_stream.msg);
                free(outbuf);
                deflateEnd(&compressed_fpga_stream);
-               fclose(infile);
+               for(uint16_t j = 0; j < num_infiles; j++) {
+                       fclose(infile[j]);
+               }
                fclose(outfile);
+               free(infile);
+               free(fpga_config);
                return -1;
                }
                
@@ -95,9 +154,13 @@ int zlib_compress(FILE *infile, FILE *outfile)
 
        free(outbuf);
        deflateEnd(&compressed_fpga_stream);
-       fclose(infile);
+       for(uint16_t j = 0; j < num_infiles; j++) {
+               fclose(infile[j]);
+       }
        fclose(outfile);
-
+       free(infile);
+       free(fpga_config);
+       
        return 0;
        
 }
@@ -106,29 +169,29 @@ int zlib_compress(FILE *infile, FILE *outfile)
 
 int main(int argc, char **argv)
 {
-       char *infilename;
-       char *outfilename;
+       FILE **infiles;
+       FILE *outfile;
        
-       if (argc != 3) {
+       if (argc == 1 || argc == 2) {
                usage(argv[0]);
                return -1;
-       } else {
-               infilename = argv[1];
-               outfilename = argv[2];
-       }       
-
-       FILE *infile = fopen(infilename, "rb");
-       if (infile == NULL) {
-               fprintf(stderr, "Error. Cannot open input file %s", infilename);
-               return -1;
+       }
+       
+       infiles = calloc(argc-2, sizeof(FILE*));
+       
+       for (uint16_t i = 0; i < argc-2; i++) { 
+               infiles[i] = fopen(argv[i+1], "rb");
+               if (infiles[i] == NULL) {
+                       fprintf(stderr, "Error. Cannot open input file %s", argv[i+1]);
+                       return -1;
                }
-               
-       FILE *outfile = fopen(outfilename, "wb");
+       }
+
+       outfile = fopen(argv[argc-1], "wb");
        if (outfile == NULL) {
-               fprintf(stderr, "Error. Cannot open output file %s", outfilename);
-               fclose(infile);
+               fprintf(stderr, "Error. Cannot open output file %s", argv[argc-1]);
                return -1;
                }
                
-       return zlib_compress(infile, outfile);
+       return zlib_compress(infiles, argc-2, outfile);
 }
index b3530c64f2ae22b920458e05e4f483340b1baac4..4a59636e7f6cc156e438a332208116ccd3eb9439 100644 (file)
 #define SPI_FPGA_MODE  0
 #define SPI_LCD_MODE   1
 
-#define FPGA_BITSTREAM_ERR 0
-#define FPGA_BITSTREAM_LF 1
-#define FPGA_BITSTREAM_HF 2
-
 #define TRUE 1
 #define FALSE 0
 
index 4cf3f3a96a354d72ecb9c0ea3a6374310b4e71d0..bb8e3a763fbf2ac77ccc161229358215d9589b9a 100644 (file)
@@ -1,17 +1,17 @@
 include ../common/Makefile.common
 
-BINS = bootrom.bin osimage.bin proxmark3_recovery.bin
+BINS = bootrom.bin fullimage.bin proxmark3_recovery.bin
 
 all: $(BINS)
 
 bootrom.bin: ../bootrom/obj/bootrom.elf
        $(OBJCOPY) --gap-fill=0xff --pad-to 0x00102000 -O binary $^ $@
 
-osimage.bin: ../armsrc/obj/osimage.elf
+fullimage.bin: ../armsrc/obj/fullimage.elf
        $(OBJCOPY) --gap-fill=0xff -O binary $^ $@
 
-proxmark3_recovery.bin: bootrom.bin osimage.bin
-       cat bootrom.bin osimage.bin > $@
+proxmark3_recovery.bin: bootrom.bin fullimage.bin
+       cat bootrom.bin fullimage.bin > $@
 
 clean: 
        rm -f $(BINS)
Impressum, Datenschutz