OpenOCD
xcf.c File Reference
Include dependency graph for xcf.c:

Go to the source code of this file.

Data Structures

struct  xcf_priv
 
struct  xcf_status
 

Macros

#define ID_MEANINGFUL_MASK   0x0FFFFFFF
 
#define ID_XCF01S   0x05044093
 
#define ID_XCF02S   0x05045093
 
#define ID_XCF04S   0x05046093
 
#define ID_XCF08P   0x05057093
 
#define ID_XCF16P   0x05058093
 
#define ID_XCF32P   0x05059093
 
#define SECTOR_ERASE_TIMEOUT_MS   (35 * 1000)
 
#define XCF_DATA_SECTOR_SIZE   (1024 * 1024)
 
#define XCF_PAGE_SIZE   32
 

Functions

 COMMAND_HANDLER (xcf_handle_ccb_command)
 
 COMMAND_HANDLER (xcf_handle_configure_command)
 
static void fill_sector_table (struct flash_bank *bank)
 
static uint8_t fill_select_block (unsigned int first, unsigned int last)
 
 FLASH_BANK_COMMAND_HANDLER (xcf_flash_bank_command)
 
static void flip_u8 (uint8_t *out, const uint8_t *in, int len)
 
static int fpga_configure (struct flash_bank *bank)
 
static unsigned int gucr_num (const struct flash_bank *bank)
 
static int isc_adr_shift (struct flash_bank *bank, int adr)
 
static int isc_clear_protect (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static void isc_data_read_out (struct flash_bank *bank, uint8_t *buffer, uint32_t count)
 
static int isc_enter (struct flash_bank *bank)
 
static int isc_erase_sectors (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int isc_leave (struct flash_bank *bank)
 
static int isc_program_ccb (struct flash_bank *bank, uint16_t ccb)
 
static int isc_program_data_page (struct flash_bank *bank, const uint8_t *page_buf)
 
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)
 
static int isc_program_singe_revision_sucr (struct flash_bank *bank)
 
static int isc_program_single_revision_btc (struct flash_bank *bank)
 
static uint16_t isc_read_ccb (struct flash_bank *bank)
 
static int isc_read_register (struct flash_bank *bank, const uint8_t *cmd, uint8_t *data_buf, int num_bits)
 
static int isc_set_data_done (struct flash_bank *bank, int sector)
 
static int isc_set_protect (struct flash_bank *bank, unsigned int first, unsigned int last)
 
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 int isc_wait_erase_program (struct flash_bank *bank, int64_t timeout_ms)
 
static bool need_bit_reverse (const uint8_t *buffer)
 
static const char * product_name (const struct flash_bank *bank)
 
static struct xcf_status read_status (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 int sector_state (uint8_t wrpt, int sector)
 
static unsigned int sucr_num (const struct flash_bank *bank)
 
static int xcf_auto_probe (struct flash_bank *bank)
 
static int xcf_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int xcf_erase_check (struct flash_bank *bank)
 
static int xcf_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int xcf_probe (struct flash_bank *bank)
 
static int xcf_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int xcf_protect_check (struct flash_bank *bank)
 
static int xcf_read (struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int xcf_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 

Variables

static const uint8_t cmd_bypass [2] = {0xFF, 0xFF}
 
static const uint8_t cmd_isc_address_shift [2] = {0xEB, 0x00}
 
static const uint8_t cmd_isc_data_shift [2] = {0xED, 0x00}
 
static const uint8_t cmd_isc_disable [2] = {0xF0, 0x00}
 
static const uint8_t cmd_isc_enable [2] = {0xE8, 0x00}
 
static const uint8_t cmd_isc_erase [2] = {0xEC, 0x00}
 
static const uint8_t cmd_isc_program [2] = {0xEA, 0x00}
 
static const uint8_t cmd_xsc_blank_check [2] = {0x0D, 0x00}
 
static const uint8_t cmd_xsc_config [2] = {0xEE, 0x00}
 
static const uint8_t cmd_xsc_data_btc [2] = {0xF2, 0x00}
 
static const uint8_t cmd_xsc_data_ccb [2] = {0x0C, 0x00}
 
static const uint8_t cmd_xsc_data_done [2] = {0x09, 0x00}
 
static const uint8_t cmd_xsc_data_sucr [2] = {0x0E, 0x00}
 
static const uint8_t cmd_xsc_data_wrpt [2] = {0xF7, 0x00}
 
static const uint8_t cmd_xsc_op_status [2] = {0xE3, 0x00}
 
static const uint8_t cmd_xsc_read [2] = {0xEF, 0x00}
 
static const uint8_t cmd_xsc_unlock [2] = {0x55, 0xAA}
 
static const struct command_registration xcf_command_handlers []
 
static const struct command_registration xcf_exec_command_handlers []
 
const struct flash_driver xcf_flash
 
static const char *const xcf_name_list []
 

Macro Definition Documentation

◆ ID_MEANINGFUL_MASK

#define ID_MEANINGFUL_MASK   0x0FFFFFFF

Definition at line 35 of file xcf.c.

◆ ID_XCF01S

#define ID_XCF01S   0x05044093

Definition at line 29 of file xcf.c.

◆ ID_XCF02S

#define ID_XCF02S   0x05045093

Definition at line 30 of file xcf.c.

◆ ID_XCF04S

#define ID_XCF04S   0x05046093

Definition at line 31 of file xcf.c.

◆ ID_XCF08P

#define ID_XCF08P   0x05057093

Definition at line 32 of file xcf.c.

◆ ID_XCF16P

#define ID_XCF16P   0x05058093

Definition at line 33 of file xcf.c.

◆ ID_XCF32P

#define ID_XCF32P   0x05059093

Definition at line 34 of file xcf.c.

◆ SECTOR_ERASE_TIMEOUT_MS

#define SECTOR_ERASE_TIMEOUT_MS   (35 * 1000)

Definition at line 24 of file xcf.c.

◆ XCF_DATA_SECTOR_SIZE

#define XCF_DATA_SECTOR_SIZE   (1024 * 1024)

Definition at line 27 of file xcf.c.

◆ XCF_PAGE_SIZE

#define XCF_PAGE_SIZE   32

Definition at line 26 of file xcf.c.

Function Documentation

◆ COMMAND_HANDLER() [1/2]

◆ COMMAND_HANDLER() [2/2]

COMMAND_HANDLER ( xcf_handle_configure_command  )

◆ fill_sector_table()

static void fill_sector_table ( struct flash_bank bank)
static

Definition at line 101 of file xcf.c.

References bank, and XCF_DATA_SECTOR_SIZE.

Referenced by xcf_probe().

◆ fill_select_block()

static uint8_t fill_select_block ( unsigned int  first,
unsigned int  last 
)
static

Definition at line 208 of file xcf.c.

Referenced by isc_clear_protect(), and isc_erase_sectors().

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( xcf_flash_bank_command  )

Definition at line 559 of file xcf.c.

References bank, ERROR_FAIL, ERROR_OK, LOG_ERROR, and priv.

◆ flip_u8()

static void flip_u8 ( uint8_t *  out,
const uint8_t *  in,
int  len 
)
static

Definition at line 377 of file xcf.c.

References flip_u32().

Referenced by read_write_data().

◆ fpga_configure()

static int fpga_configure ( struct flash_bank bank)
static

Definition at line 538 of file xcf.c.

References bank, cmd_xsc_config, ERROR_OK, jtag_add_ir_scan(), jtag_execute_queue(), NULL, scan, and TAP_IDLE.

Referenced by COMMAND_HANDLER().

◆ gucr_num()

static unsigned int gucr_num ( const struct flash_bank bank)
static

Definition at line 504 of file xcf.c.

References bank.

Referenced by COMMAND_HANDLER().

◆ isc_adr_shift()

static int isc_adr_shift ( struct flash_bank bank,
int  adr 
)
static

Definition at line 336 of file xcf.c.

References bank, cmd_isc_address_shift, h_u24_to_le(), and isc_set_register().

Referenced by read_write_data().

◆ isc_clear_protect()

static int isc_clear_protect ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

Definition at line 309 of file xcf.c.

References bank, cmd_xsc_unlock, fill_select_block(), and isc_set_register().

Referenced by COMMAND_HANDLER(), xcf_erase(), and xcf_protect().

◆ isc_data_read_out()

static void isc_data_read_out ( struct flash_bank bank,
uint8_t *  buffer,
uint32_t  count 
)
static

◆ isc_enter()

◆ isc_erase_sectors()

static int isc_erase_sectors ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

◆ isc_leave()

◆ isc_program_ccb()

static int isc_program_ccb ( struct flash_bank bank,
uint16_t  ccb 
)
static

Definition at line 514 of file xcf.c.

References bank, cmd_xsc_data_ccb, h_u16_to_le(), and isc_program_register().

Referenced by COMMAND_HANDLER().

◆ isc_program_data_page()

static int isc_program_data_page ( struct flash_bank bank,
const uint8_t *  page_buf 
)
static

Definition at line 343 of file xcf.c.

References bank, cmd_isc_data_shift, isc_program_register(), and XCF_PAGE_SIZE.

Referenced by read_write_data().

◆ isc_program_register()

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 
)
static

◆ isc_program_singe_revision_sucr()

static int isc_program_singe_revision_sucr ( struct flash_bank bank)
static

Definition at line 521 of file xcf.c.

References bank, cmd_xsc_data_sucr, and isc_program_register().

Referenced by COMMAND_HANDLER().

◆ isc_program_single_revision_btc()

static int isc_program_single_revision_btc ( struct flash_bank bank)
static

Definition at line 527 of file xcf.c.

References bank, cmd_xsc_data_btc, h_u32_to_le(), and isc_program_register().

Referenced by COMMAND_HANDLER().

◆ isc_read_ccb()

static uint16_t isc_read_ccb ( struct flash_bank bank)
static

Definition at line 497 of file xcf.c.

References bank, cmd_xsc_data_ccb, isc_read_register(), and le_to_h_u16().

Referenced by COMMAND_HANDLER().

◆ isc_read_register()

static int isc_read_register ( struct flash_bank bank,
const uint8_t *  cmd,
uint8_t *  data_buf,
int  num_bits 
)
static

◆ isc_set_data_done()

static int isc_set_data_done ( struct flash_bank bank,
int  sector 
)
static

Definition at line 370 of file xcf.c.

References bank, cmd_xsc_data_done, and isc_program_register().

Referenced by COMMAND_HANDLER(), and read_write_data().

◆ isc_set_protect()

static int isc_set_protect ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

Definition at line 317 of file xcf.c.

References bank, cmd_xsc_data_wrpt, and isc_program_register().

Referenced by xcf_protect().

◆ isc_set_register()

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

◆ isc_wait_erase_program()

static int isc_wait_erase_program ( struct flash_bank bank,
int64_t  timeout_ms 
)
static

◆ need_bit_reverse()

static bool need_bit_reverse ( const uint8_t *  buffer)
static

Definition at line 391 of file xcf.c.

References buffer.

Referenced by read_write_data().

◆ product_name()

static const char* product_name ( const struct flash_bank bank)
static

Definition at line 86 of file xcf.c.

References bank, ID_MEANINGFUL_MASK, ID_XCF08P, ID_XCF16P, ID_XCF32P, and xcf_name_list.

Referenced by xcf_info(), and xcf_probe().

◆ read_status()

static struct xcf_status read_status ( struct flash_bank bank)
static

Definition at line 101 of file xcf.c.

Referenced by isc_enter(), and isc_leave().

◆ read_write_data()

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

◆ sector_state()

static int sector_state ( uint8_t  wrpt,
int  sector 
)
static

Definition at line 200 of file xcf.c.

Referenced by xcf_erase_check(), and xcf_protect_check().

◆ sucr_num()

static unsigned int sucr_num ( const struct flash_bank bank)
static

Definition at line 509 of file xcf.c.

References bank.

Referenced by COMMAND_HANDLER().

◆ xcf_auto_probe()

static int xcf_auto_probe ( struct flash_bank bank)
static

Definition at line 640 of file xcf.c.

References bank, ERROR_OK, priv, and xcf_probe().

◆ xcf_erase()

static int xcf_erase ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

◆ xcf_erase_check()

static int xcf_erase_check ( struct flash_bank bank)
static

◆ xcf_info()

static int xcf_info ( struct flash_bank bank,
struct command_invocation cmd 
)
static

Definition at line 573 of file xcf.c.

References bank, cmd, command_print_sameline(), ERROR_OK, priv, and product_name().

◆ xcf_probe()

static int xcf_probe ( struct flash_bank bank)
static

◆ xcf_protect()

static int xcf_protect ( struct flash_bank bank,
int  set,
unsigned int  first,
unsigned int  last 
)
static

◆ xcf_protect_check()

static int xcf_protect_check ( struct flash_bank bank)
static

◆ xcf_read()

static int xcf_read ( struct flash_bank bank,
uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

Definition at line 711 of file xcf.c.

References bank, buffer, count, NULL, offset, and read_write_data().

◆ xcf_write()

static int xcf_write ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

Definition at line 716 of file xcf.c.

References bank, buffer, count, NULL, offset, and read_write_data().

Variable Documentation

◆ cmd_bypass

const uint8_t cmd_bypass[2] = {0xFF, 0xFF}
static

Definition at line 60 of file xcf.c.

◆ cmd_isc_address_shift

const uint8_t cmd_isc_address_shift[2] = {0xEB, 0x00}
static

Definition at line 62 of file xcf.c.

Referenced by isc_adr_shift().

◆ cmd_isc_data_shift

const uint8_t cmd_isc_data_shift[2] = {0xED, 0x00}
static

Definition at line 63 of file xcf.c.

Referenced by isc_program_data_page().

◆ cmd_isc_disable

const uint8_t cmd_isc_disable[2] = {0xF0, 0x00}
static

Definition at line 64 of file xcf.c.

Referenced by isc_leave().

◆ cmd_isc_enable

const uint8_t cmd_isc_enable[2] = {0xE8, 0x00}
static

Definition at line 65 of file xcf.c.

Referenced by isc_enter().

◆ cmd_isc_erase

const uint8_t cmd_isc_erase[2] = {0xEC, 0x00}
static

Definition at line 66 of file xcf.c.

Referenced by isc_erase_sectors().

◆ cmd_isc_program

const uint8_t cmd_isc_program[2] = {0xEA, 0x00}
static

Definition at line 67 of file xcf.c.

Referenced by isc_program_register().

◆ cmd_xsc_blank_check

const uint8_t cmd_xsc_blank_check[2] = {0x0D, 0x00}
static

Definition at line 69 of file xcf.c.

Referenced by xcf_erase_check().

◆ cmd_xsc_config

const uint8_t cmd_xsc_config[2] = {0xEE, 0x00}
static

Definition at line 70 of file xcf.c.

Referenced by fpga_configure().

◆ cmd_xsc_data_btc

const uint8_t cmd_xsc_data_btc[2] = {0xF2, 0x00}
static

Definition at line 71 of file xcf.c.

Referenced by isc_program_single_revision_btc().

◆ cmd_xsc_data_ccb

const uint8_t cmd_xsc_data_ccb[2] = {0x0C, 0x00}
static

Definition at line 72 of file xcf.c.

Referenced by isc_program_ccb(), and isc_read_ccb().

◆ cmd_xsc_data_done

const uint8_t cmd_xsc_data_done[2] = {0x09, 0x00}
static

Definition at line 73 of file xcf.c.

Referenced by isc_set_data_done().

◆ cmd_xsc_data_sucr

const uint8_t cmd_xsc_data_sucr[2] = {0x0E, 0x00}
static

Definition at line 74 of file xcf.c.

Referenced by isc_program_singe_revision_sucr().

◆ cmd_xsc_data_wrpt

const uint8_t cmd_xsc_data_wrpt[2] = {0xF7, 0x00}
static

Definition at line 75 of file xcf.c.

Referenced by isc_set_protect(), and xcf_protect_check().

◆ cmd_xsc_op_status

const uint8_t cmd_xsc_op_status[2] = {0xE3, 0x00}
static

Definition at line 76 of file xcf.c.

Referenced by isc_wait_erase_program().

◆ cmd_xsc_read

const uint8_t cmd_xsc_read[2] = {0xEF, 0x00}
static

Definition at line 77 of file xcf.c.

Referenced by isc_data_read_out().

◆ cmd_xsc_unlock

const uint8_t cmd_xsc_unlock[2] = {0x55, 0xAA}
static

Definition at line 78 of file xcf.c.

Referenced by isc_clear_protect().

◆ xcf_command_handlers

const struct command_registration xcf_command_handlers[]
static
Initial value:
= {
{
.name = "xcf",
.mode = COMMAND_ANY,
.help = "Xilinx platform flash command group",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration xcf_exec_command_handlers[]
Definition: xcf.c:836

Definition at line 823 of file xcf.c.

◆ xcf_exec_command_handlers

const struct command_registration xcf_exec_command_handlers[]
static
Initial value:
= {
{
.name = "configure",
.handler = xcf_handle_configure_command,
.mode = COMMAND_EXEC,
.usage = "bank_id",
.help = "Initiate FPGA loading procedure."
},
{
.name = "ccb",
.handler = xcf_handle_ccb_command,
.mode = COMMAND_EXEC,
.usage = "bank_id [('external'|'internal') "
"('serial'|'parallel') "
"('slave'|'master') "
"('40'|'20')]",
.help = "Write CCB register with supplied options and (silently) BTC "
"register with single revision options. Display current "
"CCB value when only bank_id supplied. "
"Following options available: "
"1) external or internal clock source; "
"2) serial or parallel bus mode; "
"3) slave or master mode; "
"4) clock frequency in MHz for internal clock in master mode;"
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 823 of file xcf.c.

◆ xcf_flash

const struct flash_driver xcf_flash
Initial value:
= {
.name = "xcf",
.usage = NULL,
.commands = xcf_command_handlers,
.flash_bank_command = xcf_flash_bank_command,
.erase = xcf_erase,
.protect = xcf_protect,
.write = xcf_write,
.read = xcf_read,
.probe = xcf_probe,
.auto_probe = xcf_auto_probe,
.erase_check = xcf_erase_check,
.protect_check = xcf_protect_check,
.info = xcf_info,
.free_driver_priv = default_flash_free_driver_priv,
}
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
#define NULL
Definition: usb.h:16
static int xcf_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: xcf.c:695
static int xcf_erase_check(struct flash_bank *bank)
Definition: xcf.c:664
static int xcf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: xcf.c:716
static int xcf_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: xcf.c:573
static int xcf_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: xcf.c:722
static int xcf_auto_probe(struct flash_bank *bank)
Definition: xcf.c:640
static const struct command_registration xcf_command_handlers[]
Definition: xcf.c:864
static int xcf_probe(struct flash_bank *bank)
Definition: xcf.c:585
static int xcf_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: xcf.c:711
static int xcf_protect_check(struct flash_bank *bank)
Definition: xcf.c:650

Definition at line 823 of file xcf.c.

◆ xcf_name_list

const char* const xcf_name_list[]
static
Initial value:
= {
"XCF08P",
"XCF16P",
"XCF32P",
"unknown"
}

Definition at line 37 of file xcf.c.

Referenced by product_name().