17 #include "../../../contrib/loaders/flash/hpmicro/hpm_xpi_flash.h"
19 #include "../../../contrib/loaders/flash/hpmicro/hpm_xpi_flash.inc"
21 #define TIMEOUT_IN_MS (10000U)
22 #define ERASE_CHIP_TIMEOUT_IN_MS (100000U)
23 #define SECTOR_ERASE_TIMEOUT_IN_MS (100)
24 #define TYPICAL_TIMEOUT_IN_MS (500U)
25 #define BLOCK_SIZE (4096U)
26 #define NOR_CFG_OPT_HEADER (0xFCF90000UL)
64 LOG_ERROR(
"Failed to execute run algorithm: %d", retval);
68 uint32_t stat =
buf_get_u32(reg_params[0].value, 0, xlen);
71 LOG_ERROR(
"init flash failed on target: 0x%" PRIx32, retval);
76 for (
size_t k = 0; k <
ARRAY_SIZE(reg_params); k++)
95 bank->num_sectors = 0;
107 LOG_WARNING(
"Couldn't allocate %zd-byte working area",
123 LOG_ERROR(
"Failed to run init flash algorithm: %d", retval);
129 LOG_WARNING(
"Couldn't allocate %zd-byte working area",
146 LOG_ERROR(
"Failed to run algorithm at: %d", retval);
153 LOG_ERROR(
"flash get info failed on target: 0x%" PRIx32, retval);
171 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
178 bank->sectors = sectors;
182 for (
size_t k = 0; k <
ARRAY_SIZE(reg_params); k++)
203 uint32_t left =
count, i = 0;
213 LOG_WARNING(
"Couldn't allocate %zd-byte working area",
229 LOG_ERROR(
"Failed to run init flash algorithm: %d", retval);
234 uint32_t avail_buffer_size;
236 if (avail_buffer_size <= 256) {
240 LOG_WARNING(
"no large enough working area available, can't do block memory writes");
244 data_size =
MIN(data_size, avail_buffer_size);
247 LOG_WARNING(
"Couldn't allocate %d-byte working area", data_size);
259 uint32_t trans_size =
MIN(data_size, left);
281 LOG_ERROR(
"flash write failed on target: 0x%" PRIx32, retval);
292 for (
size_t k = 0; k <
ARRAY_SIZE(reg_params); k++)
311 LOG_WARNING(
"Couldn't allocate %zd-byte working area",
327 LOG_ERROR(
"Failed to run init flash algorithm: %d", retval);
331 LOG_DEBUG(
"from sector %u to sector %u", first, last);
354 LOG_ERROR(
"flash erase failed on target: 0x%" PRIx32, retval);
360 for (
size_t k = 0; k <
ARRAY_SIZE(reg_params); k++)
377 LOG_WARNING(
"Couldn't allocate %zd-byte working area",
393 LOG_ERROR(
"Failed to run init flash algorithm: %d", retval);
412 LOG_ERROR(
"flash erase chip failed on target: 0x%" PRIx32, retval);
418 for (
size_t k = 0; k <
ARRAY_SIZE(reg_params); k++)
443 .
name =
"mass_erase",
444 .handler = hpm_xpi_handle_erase_chip_command,
447 .help =
"erase entire flash device",
456 .help =
"hpm_xpi command group",
501 bank->driver_priv = xpi_priv;
513 .flash_bank_command = hpm_xpi_flash_bank_command,
void init_reg_param(struct reg_param *param, const char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(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 32-bit word.
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.
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.
#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_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
uint64_t buffer
Pointer to data buffer to send over SPI.
#define ERROR_FLASH_OPERATION_FAILED
int default_flash_verify(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default verify implementation for flash memory.
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.
static int hpm_xpi_run_algo_flash_init(struct flash_bank *bank, target_addr_t algo_entry)
static int hpm_xpi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int hpm_xpi_auto_probe(struct flash_bank *bank)
static int hpm_xpi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int hpm_xpi_erase_chip(struct flash_bank *bank)
#define TYPICAL_TIMEOUT_IN_MS
static int hpm_xpi_probe(struct flash_bank *bank)
static uint8_t flash_algo[]
#define ERASE_CHIP_TIMEOUT_IN_MS
const struct command_registration hpm_xpi_command_handlers[]
static const struct command_registration hpm_xpi_exec_command_handlers[]
const struct flash_driver hpm_xpi_flash
#define NOR_CFG_OPT_HEADER
COMMAND_HANDLER(hpm_xpi_handle_erase_chip_command)
FLASH_BANK_COMMAND_HANDLER(hpm_xpi_flash_bank_command)
#define SECTOR_ERASE_TIMEOUT_IN_MS
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
static const struct npcx_flash_info flash_info[]
unsigned int riscv_xlen(const struct target *target)
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 total_sz_in_bytes
uint32_t sector_sz_in_bytes
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_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_RESOURCE_NOT_AVAILABLE
#define ERROR_TARGET_FAILURE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.