diff --git a/CHANGELOG.md b/CHANGELOG.md index 678c390c3..9ff998f3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed `fpga_compress` - PM3ULTIMATE builds again, its bitstreams are an exact multiple of the interleave size (@iceman1001) - Fixed `hf legic eload` - an upload after a command that left a different FPGA bitstream loaded now writes the whole image (@iceman1001) - Fixed `hf legic sim` - no longer wipes the emulator memory that `hf legic eload` just filled (@iceman1001) - Changed emulator memory - raised from 4096 to 8192 bytes (@iceman1001) diff --git a/tools/fpga_compress/fpga_compress.c b/tools/fpga_compress/fpga_compress.c index 29e5481ec..740d85346 100644 --- a/tools/fpga_compress/fpga_compress.c +++ b/tools/fpga_compress/fpga_compress.c @@ -40,11 +40,27 @@ static void usage(void) { fprintf(stdout, " Decompress . Write result to \n\n"); } +// feof() only reports true once a read has already run off the end, so a file +// whose length is an exact multiple of FPGA_INTERLEAVE_SIZE still looks unfinished +// after its last whole chunk. That earned one more interleave round of pure +// padding, which pushed total_size past the buffer and got the whole set rejected +// as "too big" -- PM3ULTIMATE's bitstreams are exactly 243 * 288 bytes. +// Peek one byte instead, so a file that has been read to its last byte counts as +// finished right away. 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; + + if (feof(infile[i])) { + continue; } + + int c = fgetc(infile[i]); + if (c == EOF) { + continue; + } + + ungetc(c, infile[i]); + return false; } return true; } @@ -61,9 +77,14 @@ static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, boo uint32_t total_size = 0; do { - if (total_size >= num_infiles * FPGA_CONFIG_SIZE) { + // Each round writes num_infiles * FPGA_INTERLEAVE_SIZE bytes, so ask whether + // that round fits rather than whether we have already filled the buffer. + // `>` alone let a round start with the buffer full and overrun it; `>=` + // rejected a set that exactly filled it, which is what the bitstreams of a + // platform sized to FPGA_CONFIG_SIZE do. + if (total_size + (num_infiles * FPGA_INTERLEAVE_SIZE) > num_infiles * FPGA_CONFIG_SIZE) { fprintf(stderr, - "Input files too big (total >= %li bytes). These are probably not PM3 FPGA config files.\n" + "Input files too big (total > %li bytes). These are probably not PM3 FPGA config files.\n" , num_infiles * FPGA_CONFIG_SIZE );