mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
Merge pull request #2748 from n-hutton/deterministic_bitfile_builds2
force bitfiles to be identical for same source code
This commit is contained in:
commit
f1c402d26e
8 changed files with 76 additions and 23 deletions
|
@ -44,6 +44,9 @@ XST_OPTS_AREA += -opt_level 2
|
||||||
XST_OPTS_AREA += -fsm_style bram
|
XST_OPTS_AREA += -fsm_style bram
|
||||||
XST_OPTS_AREA += -fsm_encoding compact
|
XST_OPTS_AREA += -fsm_encoding compact
|
||||||
|
|
||||||
|
# par specific option (set determistic seed)
|
||||||
|
PAR_OPTIONS = -t 1
|
||||||
|
|
||||||
# Types of selective module compilation:
|
# Types of selective module compilation:
|
||||||
# WITH_LF Enables selection of LF modules (and disables all HF)
|
# WITH_LF Enables selection of LF modules (and disables all HF)
|
||||||
|
|
||||||
|
@ -179,12 +182,13 @@ work:
|
||||||
%.ncd: %_map.ncd
|
%.ncd: %_map.ncd
|
||||||
$(Q)$(RM) $@
|
$(Q)$(RM) $@
|
||||||
$(info [-] PAR $@)
|
$(info [-] PAR $@)
|
||||||
$(Q)$(XILINX_TOOLS_PREFIX)par $(VERBOSITY) -w $< $@
|
$(Q)$(XILINX_TOOLS_PREFIX)par $(PAR_OPTIONS) $(VERBOSITY) -w $< $@
|
||||||
|
|
||||||
%.bit: %.ncd
|
%.bit: %.ncd
|
||||||
$(Q)$(RM) $@ $*.drc $*.rbt
|
$(Q)$(RM) $@ $*.drc $*.rbt
|
||||||
$(info [=] BITGEN $@)
|
$(info [=] BITGEN $@)
|
||||||
$(Q)$(XILINX_TOOLS_PREFIX)bitgen $(VERBOSITY) -w $* $@
|
$(Q)$(XILINX_TOOLS_PREFIX)bitgen $(VERBOSITY) -w $* $@
|
||||||
|
python3 ../strip_date_time_from_binary.py $@ || true
|
||||||
$(Q)$(CP) $@ ..
|
$(Q)$(CP) $@ ..
|
||||||
|
|
||||||
# Build all targets
|
# Build all targets
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
51
fpga/strip_date_time_from_binary.py
Normal file
51
fpga/strip_date_time_from_binary.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# File to take a .bit file generated by xilinx webpack ISE
|
||||||
|
# and replace the date and time embedded within with 'F'.
|
||||||
|
# The header of the bitfile is seperated by ascii markers
|
||||||
|
# 'a', 'b', 'c', 'd' etc.
|
||||||
|
# see fpga_compress.c for comparison
|
||||||
|
|
||||||
|
def parse_and_split_file(filename):
|
||||||
|
split_chars = ['a', 'b', 'c', 'd'] # Characters to split on
|
||||||
|
extracted_data = [] # for debug
|
||||||
|
|
||||||
|
print("Overwriting date and time in bitfile {}".format(filename))
|
||||||
|
|
||||||
|
with open(filename, 'rb') as f: # Read as binary to handle non-text files
|
||||||
|
data = f.read(100) # Read first 100 bytes which should contain all information
|
||||||
|
|
||||||
|
decoded_data = bytearray(data)
|
||||||
|
|
||||||
|
for i in range(len(decoded_data) - 3):
|
||||||
|
# subsequent two bytes after marker are null and the length
|
||||||
|
next_byte = decoded_data[i+1]
|
||||||
|
data_length = decoded_data[i+2] - 1 # Don't overwrite terminating char
|
||||||
|
|
||||||
|
if decoded_data[i] == ord(split_chars[0]) and next_byte == 0x0:
|
||||||
|
start = i+3
|
||||||
|
extracted_data.append(decoded_data[start:start+data_length])
|
||||||
|
|
||||||
|
# time, date
|
||||||
|
if split_chars[0] == 'c' or split_chars[0] == 'd':
|
||||||
|
decoded_data[start:start+data_length] = bytes('F', encoding='ascii') * data_length
|
||||||
|
|
||||||
|
split_chars.pop(0)
|
||||||
|
|
||||||
|
if not split_chars:
|
||||||
|
break
|
||||||
|
|
||||||
|
print("Extracted data from bitfile: {}".format(extracted_data))
|
||||||
|
|
||||||
|
with open(filename, 'r+b') as f: # Write back modified bytes
|
||||||
|
f.seek(0)
|
||||||
|
f.write(decoded_data.ljust(100, b' '))
|
||||||
|
print("writing complete")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("Usage: python script.py <filename>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
filename = sys.argv[1]
|
||||||
|
parse_and_split_file(filename)
|
|
@ -18,9 +18,13 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include "time.h"
|
||||||
#include "fpga.h"
|
#include "fpga.h"
|
||||||
#include "lz4hc.h"
|
#include "lz4hc.h"
|
||||||
|
|
||||||
|
int fileno(FILE *);
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
@ -354,6 +358,8 @@ static int FpgaGatherVersion(FILE *infile, char *infile_name, char *dst, int len
|
||||||
for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
|
for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
|
||||||
if (fgetc(infile) != bitparse_fixed_header[i]) {
|
if (fgetc(infile) != bitparse_fixed_header[i]) {
|
||||||
fprintf(stderr, "Invalid FPGA file. Aborting...\n\n");
|
fprintf(stderr, "Invalid FPGA file. Aborting...\n\n");
|
||||||
|
fprintf(stderr, "File: %s\n", infile_name);
|
||||||
|
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,30 +386,22 @@ static int FpgaGatherVersion(FILE *infile, char *infile_name, char *dst, int len
|
||||||
strncat(dst, tempstr, len - strlen(dst) - 1);
|
strncat(dst, tempstr, len - strlen(dst) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncat(dst, " ", len - strlen(dst) - 1);
|
// Get file statistics to extract date and time via file timestamp
|
||||||
if (bitparse_find_section(infile, 'c', &fpga_info_len)) {
|
int fd = fileno(infile);
|
||||||
for (uint32_t i = 0; i < fpga_info_len; i++) {
|
struct stat fileStat;
|
||||||
char c = (char)fgetc(infile);
|
|
||||||
if (i < sizeof(tempstr)) {
|
if (fstat(fd, &fileStat) == 0) {
|
||||||
if (c == '/') c = '-';
|
struct tm *modTime = localtime(&fileStat.st_mtime);
|
||||||
if (c == ' ') c = '0';
|
|
||||||
tempstr[i] = c;
|
|
||||||
}
|
char timeBuf[64];
|
||||||
}
|
snprintf(timeBuf, sizeof(timeBuf), " %02d-%02d-%04d %02d:%02d:%02d",
|
||||||
strncat(dst, tempstr, len - strlen(dst) - 1);
|
modTime->tm_mday, modTime->tm_mon + 1, modTime->tm_year + 1900,
|
||||||
|
modTime->tm_hour, modTime->tm_min, modTime->tm_sec);
|
||||||
|
|
||||||
|
strncat(dst, timeBuf, len - strlen(dst) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitparse_find_section(infile, 'd', &fpga_info_len)) {
|
|
||||||
strncat(dst, " ", len - strlen(dst) - 1);
|
|
||||||
for (uint32_t i = 0; i < fpga_info_len; i++) {
|
|
||||||
char c = (char)fgetc(infile);
|
|
||||||
if (i < sizeof(tempstr)) {
|
|
||||||
if (c == ' ') c = '0';
|
|
||||||
tempstr[i] = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strncat(dst, tempstr, len - strlen(dst) - 1);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue