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) == 0b01;
134 ret.prog_error = ((irdata[0] >> 5) & 3) == 0b01;
135 ret.prog_busy = ((irdata[0] >> 4) & 1) == 0;
136 ret.isc_mode = ((irdata[0] >> 3) & 1) == 1;
146 if (
true ==
status.isc_mode)
162 LOG_ERROR(
"*** XCF: FAILED to enter ISC mode");
192 LOG_ERROR(
"*** XCF: FAILED to leave ISC mode");
202 if (((wrpt >> sector) & 1) == 1)
211 for (
unsigned int i = first; i <= last; i++)
229 scan.in_value = data_buf;
245 if (((isc_default >> 2) & 1) == 1)
248 }
while (dt <= timeout_ms);
256 const uint8_t *data_buf,
int num_bits, int64_t timeout_ms)
268 scan.out_value = data_buf;
282 const uint8_t *data_buf,
int num_bits, int64_t timeout_ms)
294 scan.out_value = data_buf;
312 uint8_t select_block[3] = {0x0, 0x0, 0x0};
320 uint8_t wrpt[2] = {0xFF, 0xFF};
321 for (
unsigned int i = first; i <= last; i++)
322 wrpt[0] &= ~(1 << i);
330 uint8_t select_block[3] = {0, 0, 0};
373 done &= ~(1 << sector);
377 static void flip_u8(uint8_t *out,
const uint8_t *in,
int len)
379 for (
int i = 0; i < len; i++)
394 uint8_t reference[L];
395 memset(reference, 0xFF, 16);
396 reference[16] = 0x55;
397 reference[17] = 0x99;
398 reference[18] = 0xAA;
399 reference[19] = 0x66;
401 if (memcmp(reference,
buffer, L) == 0)
417 uint8_t *r_buffer,
bool write_flag, uint32_t
offset, uint32_t
count)
419 int dbg_count =
count;
443 if (
count < sector_bytes)
444 sector_bytes =
count;
447 count -= sector_bytes;
450 while (sector_bytes > 0) {
460 flip_u8(page_buf, w_buffer, len);
462 memcpy(page_buf, w_buffer, len);
470 LOG_DEBUG(
"written %d bytes from %d", dbg_written, dbg_count);
476 flip_u8(r_buffer, r_buffer, sector_bytes);
477 r_buffer += sector_bytes;
484 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
506 return bank->num_sectors;
511 return bank->num_sectors + 1;
523 uint8_t sucr[2] = {0xFC, 0xFF};
530 uint32_t btc = 0xFFFFFFFF;
532 btc |= ((
bank->num_sectors - 1) << 2);
565 LOG_ERROR(
"no memory for flash bank info");
569 priv->probed =
false;
592 priv->probed =
false;
594 if (!
bank->target->tap) {
600 if (!
bank->target->tap->hasidcode)
604 id =
bank->target->tap->idcode;
607 bank->num_sectors = 1;
610 bank->num_sectors = 2;
613 bank->num_sectors = 4;
616 LOG_ERROR(
"Unknown flash device ID 0x%" PRIX32,
id);
621 if (!
bank->sectors) {
632 LOG_INFO(
"device id = 0x%" PRIX32,
bank->target->tap->idcode);
633 LOG_INFO(
"flash size = %d configuration bits",
658 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
683 scan.in_value = &blankreg;
689 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
698 if ((first >=
bank->num_sectors)
699 || (last >=
bank->num_sectors)
750 uint16_t ccb = 0xFFFF;
756 LOG_INFO(
"current CCB = 0x%X", old_ccb);
763 if (strcmp(
"external",
CMD_ARGV[0]) == 0)
765 else if (strcmp(
"internal",
CMD_ARGV[0]) == 0)
767 else if (strcmp(
"serial",
CMD_ARGV[0]) == 0)
769 else if (strcmp(
"parallel",
CMD_ARGV[0]) == 0)
771 else if (strcmp(
"slave",
CMD_ARGV[0]) == 0)
773 else if (strcmp(
"master",
CMD_ARGV[0]) == 0)
775 else if (strcmp(
"40",
CMD_ARGV[0]) == 0)
777 else if (strcmp(
"20",
CMD_ARGV[0]) == 0)
839 .handler = xcf_handle_configure_command,
842 .help =
"Initiate FPGA loading procedure."
846 .handler = xcf_handle_ccb_command,
848 .usage =
"bank_id [('external'|'internal') "
849 "('serial'|'parallel') "
850 "('slave'|'master') "
852 .help =
"Write CCB register with supplied options and (silently) BTC "
853 "register with single revision options. Display current "
854 "CCB value when only bank_id supplied. "
855 "Following options available: "
856 "1) external or internal clock source; "
857 "2) serial or parallel bus mode; "
858 "3) slave or master mode; "
859 "4) clock frequency in MHz for internal clock in master mode;"
868 .help =
"Xilinx platform flash command group",
879 .flash_bank_command = xcf_flash_bank_command,
uint32_t flip_u32(uint32_t value, unsigned int num)
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.
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)