24 #define SECTOR_ERASE_TIMEOUT_MS (35 * 1000)
26 #define XCF_PAGE_SIZE 32
27 #define XCF_DATA_SECTOR_SIZE (1024 * 1024)
29 #define ID_XCF01S 0x05044093
30 #define ID_XCF02S 0x05045093
31 #define ID_XCF04S 0x05046093
32 #define ID_XCF08P 0x05057093
33 #define ID_XCF16P 0x05058093
34 #define ID_XCF32P 0x05059093
35 #define ID_MEANINGFUL_MASK 0x0FFFFFFF
106 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
107 bank->sectors[i].is_erased = -1;
108 bank->sectors[i].is_protected = -1;
110 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
128 scan.in_value = irdata;
133 ret.isc_error = ((irdata[0] >> 7) & 3) == 1;
134 ret.prog_error = ((irdata[0] >> 5) & 3) == 1;
135 ret.prog_busy = ((irdata[0] >> 4) & 1) == 0;
136 ret.isc_mode = ((irdata[0] >> 3) & 1) == 1;
162 LOG_ERROR(
"*** XCF: FAILED to enter ISC mode");
191 LOG_ERROR(
"*** XCF: FAILED to leave ISC mode");
200 if (((wrpt >> sector) & 1) == 1)
209 for (
unsigned int i = first; i <= last; i++)
227 scan.in_value = data_buf;
243 if (((isc_default >> 2) & 1) == 1)
246 }
while (dt <= timeout_ms);
254 const uint8_t *data_buf,
int num_bits, int64_t timeout_ms)
266 scan.out_value = data_buf;
280 const uint8_t *data_buf,
int num_bits, int64_t timeout_ms)
292 scan.out_value = data_buf;
310 uint8_t select_block[3] = {0x0, 0x0, 0x0};
318 uint8_t wrpt[2] = {0xFF, 0xFF};
319 for (
unsigned int i = first; i <= last; i++)
320 wrpt[0] &= ~(1 << i);
328 uint8_t select_block[3] = {0, 0, 0};
371 done &= ~(1 << sector);
375 static void flip_u8(uint8_t *out,
const uint8_t *in,
int len)
377 for (
int i = 0; i < len; i++)
392 uint8_t reference[L];
393 memset(reference, 0xFF, 16);
394 reference[16] = 0x55;
395 reference[17] = 0x99;
396 reference[18] = 0xAA;
397 reference[19] = 0x66;
399 if (memcmp(reference,
buffer, L) == 0)
415 uint8_t *r_buffer,
bool write_flag, uint32_t
offset, uint32_t
count)
417 int dbg_count =
count;
441 if (
count < sector_bytes)
442 sector_bytes =
count;
445 count -= sector_bytes;
448 while (sector_bytes > 0) {
458 flip_u8(page_buf, w_buffer, len);
460 memcpy(page_buf, w_buffer, len);
468 LOG_DEBUG(
"written %d bytes from %d", dbg_written, dbg_count);
474 flip_u8(r_buffer, r_buffer, sector_bytes);
475 r_buffer += sector_bytes;
482 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
504 return bank->num_sectors;
509 return bank->num_sectors + 1;
521 uint8_t sucr[2] = {0xFC, 0xFF};
528 uint32_t btc = 0xFFFFFFFF;
530 btc |= ((
bank->num_sectors - 1) << 2);
563 LOG_ERROR(
"no memory for flash bank info");
567 priv->probed =
false;
590 priv->probed =
false;
592 if (!
bank->target->tap) {
598 if (!
bank->target->tap->has_idcode)
602 id =
bank->target->tap->idcode;
605 bank->num_sectors = 1;
608 bank->num_sectors = 2;
611 bank->num_sectors = 4;
614 LOG_ERROR(
"Unknown flash device ID 0x%" PRIX32,
id);
619 if (!
bank->sectors) {
630 LOG_INFO(
"device id = 0x%" PRIX32,
bank->target->tap->idcode);
631 LOG_INFO(
"flash size = %d configuration bits",
656 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
681 scan.in_value = &blankreg;
687 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
696 if ((first >=
bank->num_sectors)
697 || (last >=
bank->num_sectors)
748 uint16_t ccb = 0xFFFF;
754 LOG_INFO(
"current CCB = 0x%X", old_ccb);
761 if (strcmp(
"external",
CMD_ARGV[0]) == 0)
763 else if (strcmp(
"internal",
CMD_ARGV[0]) == 0)
765 else if (strcmp(
"serial",
CMD_ARGV[0]) == 0)
767 else if (strcmp(
"parallel",
CMD_ARGV[0]) == 0)
769 else if (strcmp(
"slave",
CMD_ARGV[0]) == 0)
771 else if (strcmp(
"master",
CMD_ARGV[0]) == 0)
773 else if (strcmp(
"40",
CMD_ARGV[0]) == 0)
775 else if (strcmp(
"20",
CMD_ARGV[0]) == 0)
837 .handler = xcf_handle_configure_command,
840 .help =
"Initiate FPGA loading procedure."
844 .handler = xcf_handle_ccb_command,
846 .usage =
"bank_id [('external'|'internal') "
847 "('serial'|'parallel') "
848 "('slave'|'master') "
850 .help =
"Write CCB register with supplied options and (silently) BTC "
851 "register with single revision options. Display current "
852 "CCB value when only bank_id supplied. "
853 "Following options available: "
854 "1) external or internal clock source; "
855 "2) serial or parallel bus mode; "
856 "3) slave or master mode; "
857 "4) clock frequency in MHz for internal clock in master mode;"
866 .help =
"Xilinx platform flash command group",
877 .flash_bank_command = xcf_flash_bank_command,
uint32_t flip_u32(uint32_t value, unsigned int num)
Inverts the ordering of bits inside a 32-bit word (e.g.
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#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 struct esp_usb_jtag * priv
#define ERROR_FLASH_SECTOR_INVALID
#define ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
#define ERROR_FLASH_DST_OUT_OF_BANK
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
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.
static struct scan_blk scan
void alive_sleep(uint64_t ms)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Describes the geometry and status of a single flash sector within a flash bank.
This structure defines a single scan field in the scan.
unsigned int num_bits
The number of bits this field specifies.
static uint16_t le_to_h_u16(const uint8_t *buf)
static void h_u32_to_le(uint8_t *buf, uint32_t val)
static void h_u24_to_le(uint8_t *buf, unsigned int val)
static void h_u16_to_le(uint8_t *buf, uint16_t val)
static int isc_enter(struct flash_bank *bank)
static int isc_set_protect(struct flash_bank *bank, unsigned int first, unsigned int last)
#define SECTOR_ERASE_TIMEOUT_MS
static const uint8_t cmd_isc_program[2]
static uint16_t isc_read_ccb(struct flash_bank *bank)
static int isc_set_register(struct flash_bank *bank, const uint8_t *cmd, const uint8_t *data_buf, int num_bits, int64_t timeout_ms)
static const uint8_t cmd_xsc_op_status[2]
static const uint8_t cmd_xsc_read[2]
static int isc_read_register(struct flash_bank *bank, const uint8_t *cmd, uint8_t *data_buf, int num_bits)
static const uint8_t cmd_bypass[2]
FLASH_BANK_COMMAND_HANDLER(xcf_flash_bank_command)
static const uint8_t cmd_xsc_data_btc[2]
static void flip_u8(uint8_t *out, const uint8_t *in, int len)
static unsigned int sucr_num(const struct flash_bank *bank)
static const uint8_t cmd_xsc_data_ccb[2]
static const uint8_t cmd_xsc_data_done[2]
static int isc_clear_protect(struct flash_bank *bank, unsigned int first, unsigned int last)
static const struct command_registration xcf_exec_command_handlers[]
static int sector_state(uint8_t wrpt, int sector)
static int isc_program_single_revision_btc(struct flash_bank *bank)
static void isc_data_read_out(struct flash_bank *bank, uint8_t *buffer, uint32_t count)
static const uint8_t cmd_xsc_data_sucr[2]
static int xcf_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int isc_program_ccb(struct flash_bank *bank, uint16_t ccb)
static int isc_wait_erase_program(struct flash_bank *bank, int64_t timeout_ms)
static const uint8_t cmd_xsc_blank_check[2]
static const uint8_t cmd_isc_enable[2]
const struct flash_driver xcf_flash
static int xcf_erase_check(struct flash_bank *bank)
COMMAND_HANDLER(xcf_handle_ccb_command)
static int isc_program_data_page(struct flash_bank *bank, const uint8_t *page_buf)
#define ID_MEANINGFUL_MASK
static int isc_program_singe_revision_sucr(struct flash_bank *bank)
static int fpga_configure(struct flash_bank *bank)
static const uint8_t cmd_xsc_unlock[2]
static uint8_t fill_select_block(unsigned int first, unsigned int last)
static int xcf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int xcf_info(struct flash_bank *bank, struct command_invocation *cmd)
static int xcf_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
static const uint8_t cmd_xsc_config[2]
static int isc_erase_sectors(struct flash_bank *bank, unsigned int first, unsigned int last)
static int xcf_auto_probe(struct flash_bank *bank)
static const uint8_t cmd_isc_data_shift[2]
static const uint8_t cmd_isc_erase[2]
static const struct command_registration xcf_command_handlers[]
static int xcf_probe(struct flash_bank *bank)
static int isc_set_data_done(struct flash_bank *bank, int sector)
static int isc_leave(struct flash_bank *bank)
static int xcf_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
static int xcf_protect_check(struct flash_bank *bank)
static const uint8_t cmd_isc_address_shift[2]
static const char * product_name(const struct flash_bank *bank)
static int read_write_data(struct flash_bank *bank, const uint8_t *w_buffer, uint8_t *r_buffer, bool write_flag, uint32_t offset, uint32_t count)
static void fill_sector_table(struct flash_bank *bank)
static const char *const xcf_name_list[]
static const uint8_t cmd_xsc_data_wrpt[2]
static unsigned int gucr_num(const struct flash_bank *bank)
static bool need_bit_reverse(const uint8_t *buffer)
static const uint8_t cmd_isc_disable[2]
static int isc_adr_shift(struct flash_bank *bank, int adr)
static struct xcf_status read_status(struct flash_bank *bank)
#define XCF_DATA_SECTOR_SIZE
static int isc_program_register(struct flash_bank *bank, const uint8_t *cmd, const uint8_t *data_buf, int num_bits, int64_t timeout_ms)