17 #include "../../../contrib/loaders/flash/npcx/npcx_flash.h"
21 #include "../../../contrib/loaders/flash/npcx/npcx_algo.inc"
24 #define NPCX_FLASH_TIMEOUT_MS 8000
25 #define NPCX_FLASH_BASE_ADDR 0x64000000
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);
105 LOG_ERROR(
"%s: Failed to load flash helper algorithm",
118 NPCX_FLASH_LOADER_PROGRAM_ADDR, 0,
121 LOG_ERROR(
"%s: Failed to start flash helper algorithm",
158 uint32_t status_addr =
params_addr + offsetof(
struct npcx_flash_params, sync);
172 }
while (
status == NPCX_FLASH_LOADER_EXECUTE);
174 if (
status != NPCX_FLASH_LOADER_WAIT) {
175 LOG_ERROR(
"%s: Flash operation failed, status=0x%" PRIx32,
188 struct npcx_flash_params algo_params;
205 sizeof(algo_params), (uint8_t *)&algo_params);
213 sizeof(algo_params), (uint8_t *)&algo_params);
248 NPCX_FLASH_LOADER_BUFFER_SIZE +
249 NPCX_FLASH_LOADER_PROGRAM_SIZE;
250 npcx_bank->
buffer_addr = NPCX_FLASH_LOADER_BUFFER_ADDR;
251 npcx_bank->
params_addr = NPCX_FLASH_LOADER_PARAMS_ADDR;
262 if (!
bank->sectors) {
268 bank->num_sectors = num_sectors;
270 bank->write_start_alignment = 0;
271 bank->write_end_alignment = 0;
274 for (
unsigned int i = 0; i < num_sectors; i++) {
277 bank->sectors[i].is_erased = -1;
278 bank->sectors[i].is_protected = 0;
317 bank->driver_priv = npcx_bank;
327 struct npcx_flash_params algo_params;
349 sizeof(algo_params), (uint8_t *)&algo_params);
358 sizeof(algo_params), (uint8_t *)&algo_params);
375 struct npcx_flash_params algo_params;
382 if ((first == 0) && (last == (
bank->num_sectors - 1))) {
407 sizeof(algo_params), (uint8_t *)&algo_params);
416 sizeof(algo_params), (uint8_t *)&algo_params);
433 struct npcx_flash_params algo_params;
452 uint32_t address =
offset;
455 uint32_t
size = (
count > NPCX_FLASH_LOADER_BUFFER_SIZE) ?
456 NPCX_FLASH_LOADER_BUFFER_SIZE :
count;
462 LOG_ERROR(
"Unable to write data to target memory");
473 sizeof(algo_params), (uint8_t *)&algo_params);
480 sizeof(algo_params), (uint8_t *)&algo_params);
513 .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 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_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)
#define NPCX_FLASH_BASE_ADDR
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_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, int timeout_ms, void *arch_info)
Waits for an algorithm started with target_start_algorithm() to complete.
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_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_RESOURCE_NOT_AVAILABLE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.