18 #include "../../../contrib/loaders/flash/npcx/npcx_flash.h"
22 #include "../../../contrib/loaders/flash/npcx/npcx_algo.inc"
25 #define NPCX_FLASH_TIMEOUT_MS 8000
57 .
name =
"256KB Flash",
62 .name =
"512KB Flash",
72 .name =
"Unknown Flash",
94 LOG_INFO(
"Hint: Use '-work-area-phys 0x%" PRIx32
"' in your target configuration",
95 NPCX_FLASH_LOADER_WORKING_ADDR);
117 NPCX_FLASH_LOADER_PROGRAM_ADDR, 0,
155 uint32_t status_addr = params_addr + offsetof(
struct npcx_flash_params, sync);
169 }
while (
status == NPCX_FLASH_LOADER_EXECUTE);
171 if (
status != NPCX_FLASH_LOADER_WAIT) {
183 struct npcx_flash_params algo_params;
201 sizeof(algo_params), (uint8_t *)&algo_params);
209 sizeof(algo_params), (uint8_t *)&algo_params);
244 NPCX_FLASH_LOADER_BUFFER_SIZE +
245 NPCX_FLASH_LOADER_PROGRAM_SIZE;
246 npcx_bank->
buffer_addr = NPCX_FLASH_LOADER_BUFFER_ADDR;
247 npcx_bank->
params_addr = NPCX_FLASH_LOADER_PARAMS_ADDR;
259 if (!
bank->sectors) {
264 bank->num_sectors = num_sectors;
266 bank->write_start_alignment = 0;
267 bank->write_end_alignment = 0;
270 for (
unsigned int i = 0; i < num_sectors; i++) {
273 bank->sectors[i].is_erased = -1;
274 bank->sectors[i].is_protected = 0;
299 if (CMD_ARGC < 6 || CMD_ARGC > 7)
310 LOG_WARNING(
"No FIU is selection, using default.");
311 npcx_bank->
fiu_ver = NPCX_FIU_NPCX;
316 if (strcmp(fiu,
"npcx.fiu") == 0) {
317 npcx_bank->
fiu_ver = NPCX_FIU_NPCX;
318 }
else if (strcmp(fiu,
"npcx_v2.fiu") == 0) {
319 npcx_bank->
fiu_ver = NPCX_FIU_NPCX_V2;
320 }
else if (strcmp(fiu,
"npck.fiu") == 0) {
321 npcx_bank->
fiu_ver = NPCX_FIU_NPCK;
333 bank->driver_priv = npcx_bank;
342 struct npcx_flash_params algo_params;
365 sizeof(algo_params), (uint8_t *)&algo_params);
374 sizeof(algo_params), (uint8_t *)&algo_params);
391 struct npcx_flash_params algo_params;
398 if ((first == 0) && (last == (
bank->num_sectors - 1))) {
424 sizeof(algo_params), (uint8_t *)&algo_params);
433 sizeof(algo_params), (uint8_t *)&algo_params);
450 struct npcx_flash_params algo_params;
469 uint32_t address =
offset;
472 uint32_t
size = (
count > NPCX_FLASH_LOADER_BUFFER_SIZE) ?
473 NPCX_FLASH_LOADER_BUFFER_SIZE :
count;
479 LOG_ERROR(
"Unable to write data to target memory");
491 sizeof(algo_params), (uint8_t *)&algo_params);
498 sizeof(algo_params), (uint8_t *)&algo_params);
531 .flash_bank_command = npcx_flash_bank_command,
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
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 ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
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.
#define LOG_WARNING(expr ...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define NPCX_FLASH_TIMEOUT_MS
static int npcx_auto_probe(struct flash_bank *bank)
static const uint8_t npcx_algo[]
static enum npcx_flash_device_index npcx_get_flash_id(struct flash_bank *bank, uint32_t *flash_id)
static int npcx_info(struct flash_bank *bank, struct command_invocation *cmd)
static int npcx_wait_algo_done(struct flash_bank *bank, uint32_t params_addr)
static const struct npcx_flash_info flash_info[]
static int npcx_init(struct flash_bank *bank)
static int npcx_chip_erase(struct flash_bank *bank)
const struct flash_driver npcx_flash
FLASH_BANK_COMMAND_HANDLER(npcx_flash_bank_command)
static int npcx_quit(struct flash_bank *bank)
static int npcx_get_flash(uint32_t flash_id)
static int npcx_probe(struct flash_bank *bank)
static int npcx_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int npcx_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
size_t size
Size of the control block search area.
unsigned int common_magic
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.
uint32_t algo_working_size
struct armv7m_algorithm armv7m_info
const uint8_t * algo_code
enum npcx_flash_device_index flash
struct working_area * working_area
int target_halt(struct target *target)
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
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)
int target_wait_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Waits for an algorithm started with target_start_algorithm() to complete.
int target_start_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, void *arch_info)
Executes a target-specific native code algorithm and leaves it running.
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_INVALID
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.