17 #define JTAG_CONFIGURE 0x06
18 #define JTAG_SPI_BYPASS 0x05
32 const size_t chunk_size = 8192;
38 buffer = malloc(chunk_size);
54 for (
size_t idx = 0; idx < nread; ++idx) {
55 if (line_buffer[idx] ==
' ') {
57 }
else if (line_buffer[idx] == 0) {
59 }
else if (idx + 1 < nread) {
60 if (isxdigit(line_buffer[idx]) && isxdigit(line_buffer[idx + 1])) {
62 unhexify(&
byte, line_buffer + idx, 2);
66 }
else if (line_buffer[idx] ==
'/' && line_buffer[idx + 1] ==
'/') {
80 const size_t chunk_size = 32;
86 if (read + 1 > *buf_size) {
89 new_buffer = realloc(*
buffer, *buf_size + chunk_size);
91 new_buffer = malloc(chunk_size);
97 *buf_size += chunk_size;
100 int c = fgetc(input_file);
101 if ((c == EOF && read) || (
char)c ==
'\n') {
102 (*buffer)[read++] = 0;
104 }
else if (c == EOF) {
108 (*buffer)[read++] = (char)c;
116 FILE *input_file = fopen(filename,
"r");
119 LOG_ERROR(
"Couldn't open %s: %s", filename, strerror(errno));
124 char *line_buffer =
NULL;
125 size_t buffer_length = 0;
143 if (!filename || !bit_file)
147 const char *file_suffix_pos = strrchr(filename,
'.');
148 if (!file_suffix_pos) {
149 LOG_ERROR(
"Unable to detect filename suffix");
153 if (strcasecmp(file_suffix_pos,
".bit") == 0)
155 else if (strcasecmp(file_suffix_pos,
".cfg") == 0)
158 LOG_ERROR(
"Filetype not supported, expecting .bit or .cfg file");
187 if (!gatemate_info || !gatemate_info->
tap)
216 *has_instruction =
true;
226 if (!pld_device_info)
247 if (!pld_device_info)
263 unsigned int *trailing_write_bits)
268 *facing_read_bits = 1;
269 *trailing_write_bits = 1;
279 if (strcmp(
CMD_ARGV[2],
"-chain-position") != 0)
289 if (!gatemate_info) {
295 pld->driver_priv = gatemate_info;
302 .pld_create_command = &gatemate_pld_create_command,
static const struct device_t * device
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
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...
static int gatemate_disconnect_spi_from_jtag(struct pld_device *pld_device)
static int gatemate_add_byte_to_bitfile(struct gatemate_bit_file *bit_file, uint8_t byte)
static int gatemate_get_stuff_bits(struct pld_device *pld_device, unsigned int *facing_read_bits, unsigned int *trailing_write_bits)
static int gatemate_has_jtagspi_instruction(struct pld_device *device, bool *has_instruction)
static int gatemate_getline(char **buffer, size_t *buf_size, FILE *input_file)
static int gatemate_set_instr(struct jtag_tap *tap, uint8_t new_instr)
static int gatemate_connect_spi_to_jtag(struct pld_device *pld_device)
struct pld_driver gatemate_pld
static int gatemate_read_cfg_line(struct gatemate_bit_file *bit_file, const char *line_buffer, size_t nread)
static int gatemate_load(struct pld_device *pld_device, const char *filename)
static int gatemate_read_file(struct gatemate_bit_file *bit_file, const char *filename)
PLD_CREATE_COMMAND_HANDLER(gatemate_pld_create_command)
static int gatemate_read_cfg_file(struct gatemate_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_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)
struct raw_bit_file raw_file
uint8_t * cur_instr
current instruction
unsigned int ir_length
size of instruction register
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.