30 #define TRAILING_ZEROS 4000
31 #define RUNTEST_START_CYCLES 100
32 #define RUNTEST_FINISH_CYCLES 100
46 FILE *input_file = fopen(filename,
"r");
48 LOG_ERROR(
"couldn't open %s: %s", filename, strerror(errno));
52 fseek(input_file, 0, SEEK_END);
53 long length = ftell(input_file);
54 fseek(input_file, 0, SEEK_SET);
58 LOG_ERROR(
"Failed to get length from file %s: %s", filename, strerror(errno));
64 if (!bit_file->
data) {
70 bool end_detected =
false;
72 for (
size_t idx = 0; !end_detected && idx < bit_file->
length; ++idx) {
73 size_t read_count = fread(
buffer,
sizeof(
char), 3, input_file);
74 end_detected = feof(input_file);
75 if ((read_count == 3 &&
buffer[2] !=
'\n') ||
76 (read_count != 3 && !end_detected) ||
77 (read_count != 2 && end_detected)) {
89 LOG_ERROR(
"unexpected char in hex string");
102 if (!filename || !bit_file)
106 const char *file_ending_pos = strrchr(filename,
'.');
107 if (!file_ending_pos) {
108 LOG_ERROR(
"Unable to detect filename suffix");
112 if (strcasecmp(file_ending_pos,
".bin") == 0) {
114 }
else if ((strcasecmp(file_ending_pos,
".bit") == 0) ||
115 (strcasecmp(file_ending_pos,
".hex") == 0)) {
149 if (!efinix_info || !efinix_info->
tap)
170 for (
size_t i = 0; i < bit_file.
length; i++)
214 if (!pld_device_info || !pld_device_info->
tap)
217 hub->
tap = pld_device_info->
tap;
220 LOG_ERROR(
"family unknown, please specify for 'pld create'");
227 if (user_num > num_user) {
228 LOG_ERROR(
"Devices has only user register 1 to %d", num_user);
246 LOG_ERROR(
"efinix devices only have user register 1 to %d", num_user);
263 if (strcmp(
CMD_ARGV[2],
"-chain-position") != 0)
274 if (strcmp(
CMD_ARGV[4],
"-family") != 0)
277 if (strcmp(
CMD_ARGV[5],
"trion") == 0) {
279 }
else if (strcmp(
CMD_ARGV[5],
"titanium") == 0) {
295 pld->driver_priv = efinix_info;
302 .pld_create_command = &efinix_pld_create_command,
uint32_t flip_u32(uint32_t value, unsigned int num)
Inverts the ordering of bits inside a 32-bit word (e.g.
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
struct pld_driver efinix_pld
static int efinix_load(struct pld_device *pld_device, const char *filename)
static int efinix_set_instr(struct jtag_tap *tap, uint8_t new_instr)
PLD_CREATE_COMMAND_HANDLER(efinix_pld_create_command)
#define RUNTEST_START_CYCLES
static int efinix_get_jtagspi_userircode(struct pld_device *pld_device, unsigned int *ir)
static int efinix_get_ipdbg_hub(int user_num, struct pld_device *pld_device, struct pld_ipdbg_hub *hub)
#define RUNTEST_FINISH_CYCLES
static int efinix_read_file(struct raw_bit_file *bit_file, const char *filename)
static int efinix_read_bit_file(struct raw_bit_file *bit_file, const char *filename)
struct jtag_tap * jtag_tap_by_string(const char *s)
void jtag_add_runtest(unsigned int num_cycles, tap_state_t state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_tlr(void)
Run a TAP_RESET reset where the end state is TAP_RESET, regardless of the start state.
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap_state_t state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
The JTAG interface can be implemented with a software or hardware fifo.
#define LOG_ERROR(expr ...)
#define ERROR_PLD_FILE_LOAD_FAILED
int cpld_read_raw_bit_file(struct raw_bit_file *bit_file, const char *filename)
enum efinix_family_e family
unsigned int ir_length
size of instruction register
unsigned int user_ir_code
This structure defines a single scan field in the scan.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
unsigned int num_bits
The number of bits this field specifies.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.