From 99a855ddddbc6627d95ecec39df8e73c033c732e Mon Sep 17 00:00:00 2001 From: Wolfgang Spraul Date: Thu, 20 Sep 2012 08:08:13 +0200 Subject: [PATCH] disable auto-crc by default --- bit2fp.c | 10 +++++++--- libs/bit.h | 6 ++++++ libs/bit_frames.c | 4 ++-- libs/bit_regs.c | 25 +++++++++++++++---------- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/bit2fp.c b/bit2fp.c index 346a222..78a6a4e 100644 --- a/bit2fp.c +++ b/bit2fp.c @@ -12,7 +12,7 @@ int main(int argc, char** argv) { struct fpga_model model; - int bit_header, bit_regs, fp_header, pull_model, file_arg, flags; + int bit_header, bit_regs, bit_crc, fp_header, pull_model, file_arg, flags; int print_swbits, rc = -1; struct fpga_config config; @@ -21,13 +21,14 @@ int main(int argc, char** argv) fprintf(stderr, "\n" "%s - bitstream to floorplan\n" - "Usage: %s [--bit-header] [--bit-regs] [--no-model] [--no-fp-header]\n" - " %*s [--printf-swbits] \n" + "Usage: %s [--bit-header] [--bit-regs] [--bit-crc] [--no-model]\n" + " %*s [--no-fp-header] [--printf-swbits] \n" "\n", argv[0], argv[0], (int) strlen(argv[0]), ""); goto fail; } bit_header = 0; bit_regs = 0; + bit_crc = 0; pull_model = 1; fp_header = 1; file_arg = 1; @@ -38,6 +39,8 @@ int main(int argc, char** argv) bit_header = 1; else if (!strcmp(argv[file_arg], "--bit-regs")) bit_regs = 1; + else if (!strcmp(argv[file_arg], "--bit-crc")) + bit_crc = 1; else if (!strcmp(argv[file_arg], "--no-model")) pull_model = 0; else if (!strcmp(argv[file_arg], "--no-fp-header")) @@ -83,6 +86,7 @@ int main(int argc, char** argv) flags = DUMP_BITS; if (bit_header) flags |= DUMP_HEADER_STR; if (bit_regs) flags |= DUMP_REGS; + if (bit_crc) flags |= DUMP_CRC; if ((rc = dump_config(&config, flags))) FAIL(rc); return EXIT_SUCCESS; fail: diff --git a/libs/bit.h b/libs/bit.h index 2056b84..50d6ded 100644 --- a/libs/bit.h +++ b/libs/bit.h @@ -17,6 +17,7 @@ enum fpga_config_reg { #define REG_NOOP -1 // pseudo register for noops #define COR1_DEF 0x3D00 +#define COR1_CRC_BYPASS 0x0010 #define COR2_DEF 0x09EE #define MASK_DEF 0xCF @@ -66,6 +67,9 @@ struct fpga_bits int len; }; +// Use the default value together with COR1 CRC_BYPASS +#define DEFAULT_AUTO_CRC 0x9876DEFC + struct fpga_config { char header_str[4][MAX_HEADER_STR_LEN]; @@ -78,6 +82,7 @@ struct fpga_config int FLR_reg; struct fpga_bits bits; + uint32_t auto_crc; }; int read_bitfile(struct fpga_config* cfg, FILE* f); @@ -85,6 +90,7 @@ int read_bitfile(struct fpga_config* cfg, FILE* f); #define DUMP_HEADER_STR 0x0001 #define DUMP_REGS 0x0002 #define DUMP_BITS 0x0004 +#define DUMP_CRC 0x0008 int dump_config(struct fpga_config* cfg, int flags); void free_config(struct fpga_config* cfg); diff --git a/libs/bit_frames.c b/libs/bit_frames.c index dad1e3a..4f85c5d 100644 --- a/libs/bit_frames.c +++ b/libs/bit_frames.c @@ -351,9 +351,9 @@ static int bitpos_is_set(struct extract_state* es, int y, int x, if (swpos->minor == 20) { two_bits_val = ((get_bit(es->bits, row_num, es->model->x_major[x], - 20, start_in_frame + swpos->two_bits_o) != 0) << 0) + 20, start_in_frame + swpos->two_bits_o) != 0) << 1) | ((get_bit(es->bits, row_num, es->model->x_major[x], - 20, start_in_frame + swpos->two_bits_o+1) != 0) << 1); + 20, start_in_frame + swpos->two_bits_o+1) != 0) << 0); if (two_bits_val != swpos->two_bits_val) return 0; diff --git a/libs/bit_regs.c b/libs/bit_regs.c index f1af665..ec99e1f 100644 --- a/libs/bit_regs.c +++ b/libs/bit_regs.c @@ -86,7 +86,7 @@ static void dump_header(struct fpga_config* cfg) } } -static int dump_regs(struct fpga_config* cfg, int start, int end) +static int dump_regs(struct fpga_config* cfg, int start, int end, int dump_crc) { uint16_t u16; int i, rc; @@ -156,8 +156,10 @@ static int dump_regs(struct fpga_config* cfg, int start, int end) continue; } if (cfg->reg[i].reg == CRC) { - // Don't print CRC cfg->reg[i].int_v for cleaner diff. - printf("T1 CRC\n"); + if (dump_crc) + printf("T1 CRC 0x%X\n", cfg->reg[i].int_v); + else + printf("T1 CRC\n"); continue; } if (cfg->reg[i].reg == COR1) { @@ -905,7 +907,7 @@ int dump_config(struct fpga_config* cfg, int flags) if (flags & DUMP_HEADER_STR) dump_header(cfg); if (flags & DUMP_REGS) { - rc = dump_regs(cfg, /*start*/ 0, cfg->num_regs_before_bits); + rc = dump_regs(cfg, /*start*/ 0, cfg->num_regs_before_bits, flags & DUMP_CRC); if (rc) FAIL(rc); } if (flags & DUMP_BITS) { @@ -915,9 +917,11 @@ int dump_config(struct fpga_config* cfg, int flags) if (rc) FAIL(rc); printf_iob(cfg->bits.d, cfg->bits.len, BRAM_DATA_START + BRAM_DATA_LEN, 896*2/8); + if (flags & DUMP_CRC) + printf("auto-crc 0x%X\n", cfg->auto_crc); } if (flags & DUMP_REGS) { - rc = dump_regs(cfg, cfg->num_regs_before_bits, cfg->num_regs); + rc = dump_regs(cfg, cfg->num_regs_before_bits, cfg->num_regs, flags & DUMP_CRC); if (rc) FAIL(rc); } return 0; @@ -1021,6 +1025,7 @@ static int read_bits(struct fpga_config* cfg, uint8_t* d, int len, int inpos, in cfg->bits.len = (4*505 + 4*144) * 130 + 896*2; cfg->bits.d = calloc(cfg->bits.len, 1 /* elsize */); if (!cfg->bits.d) FAIL(ENOMEM); + cfg->auto_crc = 0; FAR_block = -1; FAR_row = -1; @@ -1185,8 +1190,7 @@ static int read_bits(struct fpga_config* cfg, uint8_t* d, int len, int inpos, in if (u16) FAIL(EINVAL); } src_off += 2*u32; - // two CRC words - u32 = __be32_to_cpu(*(uint32_t*)&d[src_off]); + cfg->auto_crc = __be32_to_cpu(*(uint32_t*)&d[src_off]); src_off += 4; } rc = EINVAL; @@ -1455,7 +1459,7 @@ static struct fpga_config_reg_rw s_defregs_before_bits[] = {{ CMD, .int_v = CMD_RCRC }, { REG_NOOP }, { FLR, .int_v = 896 }, - { COR1, .int_v = COR1_DEF }, + { COR1, .int_v = COR1_DEF | COR1_CRC_BYPASS }, { COR2, .int_v = COR2_DEF }, { IDCODE, .int_v = XC6SLX9 }, { MASK, .int_v = MASK_DEF }, @@ -1498,7 +1502,7 @@ static struct fpga_config_reg_rw s_defregs_after_bits[] = { CMD, .int_v = CMD_START }, { MASK, .int_v = MASK_DEF | MASK_SECURITY }, { CTL, .int_v = CTL_DEF }, - { CRC }, + { CRC, .int_v = DEFAULT_AUTO_CRC }, { CMD, .int_v = CMD_DESYNC }, { REG_NOOP }, { REG_NOOP }, { REG_NOOP }, { REG_NOOP }, { REG_NOOP }, { REG_NOOP }, { REG_NOOP }, { REG_NOOP }, @@ -1665,7 +1669,8 @@ static int write_bits(FILE* f, struct fpga_model* model) nwritten = fwrite(&u16, /*size*/ 1, sizeof(u16), f); if (nwritten != sizeof(u16)) FAIL(errno); - u32 = 0; // todo: 32-bit auto-crc value + // todo: support real auto-crc calculation + u32 = DEFAULT_AUTO_CRC; u32 = __cpu_to_be32(u32); nwritten = fwrite(&u32, /*size*/ 1, sizeof(u32), f); if (nwritten != sizeof(u32)) FAIL(errno);