38 #define FESPI_REG_SCKDIV 0x00
39 #define FESPI_REG_SCKMODE 0x04
40 #define FESPI_REG_CSID 0x10
41 #define FESPI_REG_CSDEF 0x14
42 #define FESPI_REG_CSMODE 0x18
44 #define FESPI_REG_DCSSCK 0x28
45 #define FESPI_REG_DSCKCS 0x2a
46 #define FESPI_REG_DINTERCS 0x2c
47 #define FESPI_REG_DINTERXFR 0x2e
49 #define FESPI_REG_FMT 0x40
50 #define FESPI_REG_TXFIFO 0x48
51 #define FESPI_REG_RXFIFO 0x4c
52 #define FESPI_REG_TXCTRL 0x50
53 #define FESPI_REG_RXCTRL 0x54
55 #define FESPI_REG_FCTRL 0x60
56 #define FESPI_REG_FFMT 0x64
58 #define FESPI_REG_IE 0x70
59 #define FESPI_REG_IP 0x74
63 #define FESPI_SCK_POL 0x1
64 #define FESPI_SCK_PHA 0x2
66 #define FESPI_FMT_PROTO(x) ((x) & 0x3)
67 #define FESPI_FMT_ENDIAN(x) (((x) & 0x1) << 2)
68 #define FESPI_FMT_DIR(x) (((x) & 0x1) << 3)
69 #define FESPI_FMT_LEN(x) (((x) & 0xf) << 16)
72 #define FESPI_TXWM(x) ((x) & 0xffff)
74 #define FESPI_RXWM(x) ((x) & 0xffff)
76 #define FESPI_IP_TXWM 0x1
77 #define FESPI_IP_RXWM 0x2
79 #define FESPI_FCTRL_EN 0x1
81 #define FESPI_INSN_CMD_EN 0x1
82 #define FESPI_INSN_ADDR_LEN(x) (((x) & 0x7) << 1)
83 #define FESPI_INSN_PAD_CNT(x) (((x) & 0xf) << 4)
84 #define FESPI_INSN_CMD_PROTO(x) (((x) & 0x3) << 8)
85 #define FESPI_INSN_ADDR_PROTO(x) (((x) & 0x3) << 10)
86 #define FESPI_INSN_DATA_PROTO(x) (((x) & 0x3) << 12)
87 #define FESPI_INSN_CMD_CODE(x) (((x) & 0xff) << 16)
88 #define FESPI_INSN_PAD_CODE(x) (((x) & 0xff) << 24)
92 #define FESPI_CSMODE_AUTO 0
93 #define FESPI_CSMODE_HOLD 2
94 #define FESPI_CSMODE_OFF 3
96 #define FESPI_DIR_RX 0
97 #define FESPI_DIR_TX 1
99 #define FESPI_PROTO_S 0
100 #define FESPI_PROTO_D 1
101 #define FESPI_PROTO_Q 2
103 #define FESPI_ENDIAN_MSB 0
104 #define FESPI_ENDIAN_LSB 1
108 #define FESPI_CMD_TIMEOUT (100)
109 #define FESPI_PROBE_TIMEOUT (100)
110 #define FESPI_MAX_TIMEOUT (3000)
128 {
"Freedom E310-G000 SPI Flash", 0x10e31913, 0x10014000 },
129 {
"Freedom E310-G002 SPI Flash", 0x20000913, 0x10014000 },
148 bank->driver_priv = fespi_info;
149 fespi_info->
probed =
false;
225 if (now -
start > 1000) {
245 if (now -
start > 1000) {
265 if (now -
start > 1000) {
266 LOG_ERROR(
"rxfifo didn't go positive (value=0x%" PRIx32
").", value);
328 sector =
bank->sectors[sector].offset;
329 if (
bank->size > 0x1000000) {
363 LOG_DEBUG(
"%s: from sector %u to sector %u", __func__, first, last);
370 if ((last < first) || (last >=
bank->num_sectors)) {
375 if (!(fespi_info->
probed)) {
380 for (
unsigned int sector = first; sector <= last; sector++) {
381 if (
bank->sectors[sector].is_protected) {
382 LOG_ERROR(
"Flash sector %u protected", sector);
394 LOG_ERROR(
"WM Didn't go high before attempting.");
407 for (
unsigned int sector = first; sector <= last; sector++) {
422 unsigned int first,
unsigned int last)
424 for (
unsigned int sector = first; sector <= last; sector++)
425 bank->sectors[sector].is_protected = set;
457 for (ii = 0; ii < len; ii++) {
474 #include "../../../contrib/loaders/flash/fespi/riscv32_fespi.inc"
478 #include "../../../contrib/loaders/flash/fespi/riscv64_fespi.inc"
486 uint32_t cur_count, page_size;
489 LOG_DEBUG(
"bank->size=0x%x offset=0x%08" PRIx32
" count=0x%08" PRIx32,
498 LOG_WARNING(
"Write past end of flash. Extra data discarded.");
503 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
507 (
bank->sectors[sector].offset +
bank->sectors[sector].size))
509 &&
bank->sectors[sector].is_protected) {
510 LOG_ERROR(
"Flash sector %u protected", sector);
534 unsigned int data_wa_size = 0;
540 algorithm_wa->
address, retval);
546 if (data_wa_size < 128) {
547 LOG_WARNING(
"Couldn't allocate data working area.");
556 LOG_WARNING(
"Couldn't allocate %zd-byte working area.", bin_size);
574 cur_count =
MIN(
count, data_wa_size);
587 cur_count, data_wa->
address, retval);
593 ", count=0x%" PRIx32
"), buffer=%02x %02x %02x %02x %02x %02x ..." PRIx32,
601 algorithm_wa->
address, retval);
606 if (algorithm_result != 0) {
607 LOG_ERROR(
"Algorithm returned error %" PRId64, algorithm_result);
632 uint32_t page_offset =
offset % page_size;
636 if (page_offset +
count > page_size)
637 cur_count = page_size - page_offset;
735 fespi_info->
probed =
false;
742 if (!target_device->
name) {
743 LOG_ERROR(
"Device ID 0x%" PRIx32
" is not known as FESPI capable",
777 if (p->device_id ==
id) {
782 if (!fespi_info->
dev) {
783 LOG_ERROR(
"Unknown flash device (ID 0x%08" PRIx32
")",
id);
787 LOG_INFO(
"Found flash device \'%s\' (ID 0x%08" PRIx32
")",
793 if (
bank->size <= (1UL << 16))
794 LOG_WARNING(
"device needs 2-byte addresses - not implemented");
808 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
809 sectors[sector].
offset = sector * sectorsize;
810 sectors[sector].
size = sectorsize;
815 bank->sectors = sectors;
816 fespi_info->
probed =
true;
838 if (!(fespi_info->
probed)) {
844 " Device \'%s\' (ID 0x%08" PRIx32
")\n",
852 .flash_bank_command = fespi_flash_bank_command,
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
static void buf_set_u64(uint8_t *_buffer, unsigned int first, unsigned int num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define COMMAND_PARSE_ADDRESS(in, out)
#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...
static int fespi_read_reg(struct flash_bank *bank, uint32_t *value, target_addr_t address)
static int fespi_wip(struct flash_bank *bank, int timeout)
static int fespi_rx(struct flash_bank *bank, uint8_t *out)
static int slow_fespi_write_buffer(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t len)
static int fespi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int fespi_protect_check(struct flash_bank *bank)
const struct flash_driver fespi_flash
static int fespi_tx(struct flash_bank *bank, uint8_t in)
static int fespi_enable_hw_mode(struct flash_bank *bank)
static const uint8_t riscv64_bin[]
static int fespi_probe(struct flash_bank *bank)
static int get_fespi_info(struct flash_bank *bank, struct command_invocation *cmd)
static int fespi_txwm_wait(struct flash_bank *bank)
static int fespi_erase_sector(struct flash_bank *bank, int sector)
static int fespi_disable_hw_mode(struct flash_bank *bank)
static const struct fespi_target target_devices[]
static int fespi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command)
#define FESPI_CSMODE_HOLD
static int fespi_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
static int fespi_auto_probe(struct flash_bank *bank)
static int fespi_read_flash_id(struct flash_bank *bank, uint32_t *id)
static int fespi_set_dir(struct flash_bank *bank, bool dir)
#define FESPI_CSMODE_AUTO
static int fespi_write_reg(struct flash_bank *bank, target_addr_t address, uint32_t value)
#define FESPI_PROBE_TIMEOUT
static const uint8_t riscv32_bin[]
#define FESPI_MAX_TIMEOUT
#define ERROR_FLASH_OPER_UNSUPPORTED
#define ERROR_FLASH_SECTOR_INVALID
#define ERROR_FLASH_BANK_NOT_PROBED
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
The JTAG interface can be implemented with a software or hardware fifo.
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
unsigned int riscv_xlen(const struct target *target)
static struct riscv_info * riscv_info(const struct target *target) __attribute__((unused))
static bool is_riscv(const struct riscv_info *riscv_info)
const struct flash_device flash_devices[]
#define SPIFLASH_READ_STATUS
#define SPIFLASH_WRITE_ENABLE
#define SPIFLASH_DEF_PAGESIZE
When run_command is called, a new instance will be created on the stack, filled with the proper value...
const struct flash_device * dev
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.
int is_erased
Indication of erasure status: 0 = not erased, 1 = erased, other = unknown.
uint32_t offset
Bus offset from start of the flash chip (in bytes).
int is_protected
Indication of protection status: 0 = unprotected/unlocked, 1 = protected/locked, other = unknown.
uint32_t size
Number of bytes in this flash sector.
uint32_t idcode
device identification code
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
uint32_t target_get_working_area_avail(struct target *target)
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_TIMEOUT
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.