1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2022 by Daniel Anselmi *
6 ***************************************************************************/
12 #include <jtag/jtag.h>
13 #include <jtag/adapter.h>
17 #define JTAG_CONFIGURE 0x06
19 struct gatemate_pld_device
{
23 struct gatemate_bit_file
{
24 struct raw_bit_file raw_file
;
28 static int gatemate_add_byte_to_bitfile(struct gatemate_bit_file
*bit_file
, uint8_t byte
)
30 const size_t chunk_size
= 8192;
31 if (bit_file
->raw_file
.length
+ 1 > bit_file
->capacity
) {
33 if (bit_file
->raw_file
.data
)
34 buffer
= realloc(bit_file
->raw_file
.data
, bit_file
->capacity
+ chunk_size
);
36 buffer
= malloc(chunk_size
);
38 LOG_ERROR("Out of memory");
41 bit_file
->raw_file
.data
= buffer
;
42 bit_file
->capacity
+= chunk_size
;
45 bit_file
->raw_file
.data
[bit_file
->raw_file
.length
++] = byte
;
50 static int gatemate_read_cfg_line(struct gatemate_bit_file
*bit_file
, const char *line_buffer
, size_t nread
)
52 for (size_t idx
= 0; idx
< nread
; ++idx
) {
53 if (line_buffer
[idx
] == ' ') {
55 } else if (line_buffer
[idx
] == 0) {
57 } else if (idx
+ 1 < nread
) {
58 if (isxdigit(line_buffer
[idx
]) && isxdigit(line_buffer
[idx
+ 1])) {
60 unhexify(&byte
, line_buffer
+ idx
, 2);
61 int retval
= gatemate_add_byte_to_bitfile(bit_file
, byte
);
62 if (retval
!= ERROR_OK
)
64 } else if (line_buffer
[idx
] == '/' && line_buffer
[idx
+ 1] == '/') {
69 LOG_ERROR("parsing failed");
76 static int gatemate_getline(char **buffer
, size_t *buf_size
, FILE *input_file
)
78 const size_t chunk_size
= 32;
84 if (read
+ 1 > *buf_size
) {
87 new_buffer
= realloc(*buffer
, *buf_size
+ chunk_size
);
89 new_buffer
= malloc(chunk_size
);
91 LOG_ERROR("Out of memory");
95 *buf_size
+= chunk_size
;
98 int c
= fgetc(input_file
);
99 if ((c
== EOF
&& read
) || (char)c
== '\n') {
100 (*buffer
)[read
++] = 0;
102 } else if (c
== EOF
) {
106 (*buffer
)[read
++] = (char)c
;
112 static int gatemate_read_cfg_file(struct gatemate_bit_file
*bit_file
, const char *filename
)
114 FILE *input_file
= fopen(filename
, "r");
117 LOG_ERROR("Couldn't open %s: %s", filename
, strerror(errno
));
118 return ERROR_PLD_FILE_LOAD_FAILED
;
121 int retval
= ERROR_OK
;
122 char *line_buffer
= NULL
;
123 size_t buffer_length
= 0;
125 while (((nread
= gatemate_getline(&line_buffer
, &buffer_length
, input_file
)) != -1) && (retval
== ERROR_OK
))
126 retval
= gatemate_read_cfg_line(bit_file
, line_buffer
, (size_t)nread
);
132 if (retval
!= ERROR_OK
)
133 free(bit_file
->raw_file
.data
);
137 static int gatemate_read_file(struct gatemate_bit_file
*bit_file
, const char *filename
)
139 memset(bit_file
, 0, sizeof(struct gatemate_bit_file
));
141 if (!filename
|| !bit_file
)
142 return ERROR_COMMAND_SYNTAX_ERROR
;
144 /* check if binary .bit or ascii .cfg */
145 const char *file_suffix_pos
= strrchr(filename
, '.');
146 if (!file_suffix_pos
) {
147 LOG_ERROR("Unable to detect filename suffix");
148 return ERROR_PLD_FILE_LOAD_FAILED
;
151 if (strcasecmp(file_suffix_pos
, ".bit") == 0)
152 return cpld_read_raw_bit_file(&bit_file
->raw_file
, filename
);
153 else if (strcasecmp(file_suffix_pos
, ".cfg") == 0)
154 return gatemate_read_cfg_file(bit_file
, filename
);
156 LOG_ERROR("Filetype not supported, expecting .bit or .cfg file");
157 return ERROR_PLD_FILE_LOAD_FAILED
;
160 static int gatemate_set_instr(struct jtag_tap
*tap
, uint8_t new_instr
)
162 struct scan_field field
;
163 field
.num_bits
= tap
->ir_length
;
164 void *t
= calloc(DIV_ROUND_UP(field
.num_bits
, 8), 1);
166 LOG_ERROR("Out of memory");
170 buf_set_u32(t
, 0, field
.num_bits
, new_instr
);
171 field
.in_value
= NULL
;
172 jtag_add_ir_scan(tap
, &field
, TAP_IDLE
);
173 jtag_add_runtest(3, TAP_IDLE
);
178 static int gatemate_load(struct pld_device
*pld_device
, const char *filename
)
183 struct gatemate_pld_device
*gatemate_info
= pld_device
->driver_priv
;
185 if (!gatemate_info
|| !gatemate_info
->tap
)
187 struct jtag_tap
*tap
= gatemate_info
->tap
;
189 struct gatemate_bit_file bit_file
;
190 int retval
= gatemate_read_file(&bit_file
, filename
);
191 if (retval
!= ERROR_OK
)
194 retval
= gatemate_set_instr(tap
, JTAG_CONFIGURE
);
195 if (retval
!= ERROR_OK
)
198 struct scan_field field
;
199 field
.num_bits
= bit_file
.raw_file
.length
* 8;
200 field
.out_value
= bit_file
.raw_file
.data
;
201 field
.in_value
= NULL
;
202 jtag_add_dr_scan(tap
, 1, &field
, TAP_IDLE
);
204 retval
= jtag_execute_queue();
205 free(bit_file
.raw_file
.data
);
210 PLD_DEVICE_COMMAND_HANDLER(gatemate_pld_device_command
)
212 struct jtag_tap
*tap
;
214 struct gatemate_pld_device
*gatemate_info
;
217 return ERROR_COMMAND_SYNTAX_ERROR
;
219 tap
= jtag_tap_by_string(CMD_ARGV
[1]);
221 command_print(CMD
, "Tap: %s does not exist", CMD_ARGV
[1]);
225 gatemate_info
= malloc(sizeof(struct gatemate_pld_device
));
226 if (!gatemate_info
) {
227 LOG_ERROR("Out of memory");
230 gatemate_info
->tap
= tap
;
232 pld
->driver_priv
= gatemate_info
;
237 struct pld_driver gatemate_pld
= {
239 .pld_device_command
= &gatemate_pld_device_command
,
240 .load
= &gatemate_load
,
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)