19 #define ERASE_SRAM 0x05
20 #define SRAM_ERASE_DONE 0x09
22 #define ADDRESS_INITIALIZATION 0x12
23 #define READ_USERCODE 0x13
24 #define CONFIG_ENABLE 0x15
25 #define TRANSFER_CONFIGURATION_DATA 0x17
26 #define CONFIG_DISABLE 0x3A
28 #define STATUS_REGISTER 0x41
29 #define ERASE_FLASH 0x75
30 #define ENABLE_2ND_FLASH 0x78
35 #define STAUS_MASK_MEMORY_ERASE BIT(5)
36 #define STAUS_MASK_SYSTEM_EDIT_MODE BIT(7)
58 for (
int i = 0; i <
length; i++)
59 res = (res << 1) | (*
bits++ ==
'1' ? 1 : 0);
89 int end_of_header = 0;
90 while (!end_of_header) {
92 char *line = fgets(
buffer, 256, stream);
93 if (!line || feof(stream) || ferror(stream))
99 size_t line_length = strlen(line);
100 if (line[line_length - 1] !=
'\n')
104 for (
unsigned int i = 0; i < line_length; i += 8) {
116 bit_file->
id = value & 0xffffffff;
117 }
else if (key == 0x3B) {
119 bit_file->
crc_en = (value &
BIT(23)) ? 1 : 0;
128 FILE *input_file = fopen(filename,
"r");
131 LOG_ERROR(
"Couldn't open %s: %s", filename, strerror(errno));
142 char digits_buffer[9];
144 char *digits = fgets(digits_buffer, 9, input_file);
145 if (feof(input_file))
147 if (!digits || ferror(input_file)) {
152 if (digits[0] ==
'\n')
155 if (strlen(digits) != 8) {
177 if (!filename || !bit_file)
180 const char *file_suffix_pos = strrchr(filename,
'.');
181 if (!file_suffix_pos) {
182 LOG_ERROR(
"Unable to detect filename suffix");
187 if (strcasecmp(file_suffix_pos,
".bin") == 0) {
190 }
else if (strcasecmp(file_suffix_pos,
".fs") == 0) {
195 LOG_ERROR(
"Filetype not supported, expecting .fs or .bin file");
228 uint8_t buf[4] = {0};
250 if (retries++ == 100000)
351 if (!gowin_info || !gowin_info->
tap)
371 if (is_fs &&
id != bit_file.
id) {
373 LOG_ERROR(
"Id on device (0x%8.8" PRIx32
") and id in bit-stream (0x%8.8" PRIx32
") don't match.",
436 if (!gowin_info || !gowin_info->
tap)
449 if (!gowin_info || !gowin_info->
tap)
462 if (!pld_device_info || !pld_device_info->
tap)
465 hub->
tap = pld_device_info->
tap;
469 }
else if (user_num == 2) {
472 LOG_ERROR(
"gowin devices only have user register 1 & 2");
509 uint32_t user_reg = 0;
534 .
name =
"read_status",
536 .handler = gowin_read_status_command_handler,
537 .help =
"reading status register from FPGA",
542 .handler = gowin_read_user_register_command_handler,
543 .help =
"reading user register from FPGA",
548 .handler = gowin_reload_command_handler,
549 .help =
"reload bitstream from flash to SRAM",
559 .help =
"gowin specific commands",
571 if (strcmp(
CMD_ARGV[2],
"-chain-position") != 0)
587 pld->driver_priv = gowin_info;
595 .pld_create_command = &gowin_pld_create_command,
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
static const struct device_t * device
uint32_t flip_u32(uint32_t value, unsigned int num)
Inverts the ordering of bits inside a 32-bit word (e.g.
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...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static int gowin_enable_config(struct jtag_tap *tap)
static const struct command_registration gowin_exec_command_handlers[]
PLD_CREATE_COMMAND_HANDLER(gowin_pld_create_command)
static uint64_t gowin_read_fs_file_bitsequence(const char *bits, int length)
#define STAUS_MASK_MEMORY_ERASE
static int gowin_check_status_flag(struct jtag_tap *tap, uint32_t mask, uint32_t flag)
COMMAND_HANDLER(gowin_read_status_command_handler)
static int gowin_reload(struct jtag_tap *tap)
static int gowin_reload_command(struct pld_device *pld_device)
static int gowin_erase_sram(struct jtag_tap *tap, bool tx_erase_done)
static int gowin_set_instr(struct jtag_tap *tap, uint8_t new_instr)
static int gowin_get_ipdbg_hub(int user_num, struct pld_device *pld_device, struct pld_ipdbg_hub *hub)
static int gowin_disable_config(struct jtag_tap *tap)
#define STAUS_MASK_SYSTEM_EDIT_MODE
static int gowin_load_to_sram(struct pld_device *pld_device, const char *filename)
static int gowin_read_register_command(struct pld_device *pld_device, uint32_t cmd, uint32_t *value)
static const struct command_registration gowin_command_handler[]
static int gowin_read_fs_file(struct gowin_bit_file *bit_file, const char *filename)
static int gowin_read_file(struct gowin_bit_file *bit_file, const char *filename, bool *is_fs)
static int gowin_runtest_idle(struct jtag_tap *tap, unsigned int frac_sec)
static int gowin_read_fs_file_header(struct gowin_bit_file *bit_file, FILE *stream)
static int gowin_add_byte_to_bit_file(struct gowin_bit_file *bit_file, uint8_t byte)
static int gowin_read_register(struct jtag_tap *tap, uint32_t reg, uint32_t *result)
struct pld_driver gowin_pld
#define ADDRESS_INITIALIZATION
#define TRANSFER_CONFIGURATION_DATA
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_sleep(uint32_t us)
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 ...)
struct pld_device * get_pld_device_by_name_or_numstr(const char *str)
#define ERROR_PLD_FILE_LOAD_FAILED
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
int cpld_read_raw_bit_file(struct raw_bit_file *bit_file, const char *filename)
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
struct raw_bit_file raw_file
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.
uint8_t * check_value
The value used to check the 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.
uint8_t * check_mask
The mask to go with check_value.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static uint32_t le_to_h_u32(const uint8_t *buf)