diff --git a/CHANGELOG.md b/CHANGELOG.md index 887fb759e..cb7018c4e 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 -d` - a single bitstream archive was unpacked 2384 bytes short, the trailing partial interleave chunk was dropped (@iceman1001) - Fixed `fpga_compress` - a build with only one FPGA bitstream (`SKIP_LF`, `SKIP_FELICA`, `SKIP_ISO15693`) packed it as a single 1 MB block the ARM could not decompress, `inflate returned: -13247` (@iceman1001) - Fixed `FpgaDownloadAndGo` - a failed FPGA decompress leaked the ring buffer, leaving BigBuf 16 kB short for the rest of the session (@iceman1001) - Added `hf mf dump --sk` - save extracted keys to binary file (@iceman1001) diff --git a/tools/fpga_compress/fpga_compress.c b/tools/fpga_compress/fpga_compress.c index a484bd66c..29e5481ec 100644 --- a/tools/fpga_compress/fpga_compress.c +++ b/tools/fpga_compress/fpga_compress.c @@ -71,13 +71,23 @@ static int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, boo return (EXIT_FAILURE); } + // Pad a bitstream that ran out mid chunk with zeroes, so total_size stays a + // whole number of FPGA_INTERLEAVE_SIZE chunks. zlib_decompress() walks the + // output in whole chunks and drops a trailing partial one, so an unpadded + // stream comes back short - 42172 bytes of fpga_pm3_hf.bit returned as 39788. + // + // Not for "-s". That is the .data section, and start.c sizes the + // decompression with __data_end__ - __data_start__. Rounding .data up to a + // chunk boundary makes LZ4_decompress_safe() overrun that and return an + // error, which drops the firmware into the LED panic loop in + // uncompress_data_section(). for (uint16_t j = 0; j < num_infiles; j++) { for (uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) { uint8_t c = (uint8_t)fgetc(infile[j]); if (!feof(infile[j])) { fpga_config[total_size++] = c; - } else if (num_infiles > 1) { + } else if (single_block == false) { fpga_config[total_size++] = '\0'; } }