OpenOCD
nor/core.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath <Dominic.Rath@gmx.de> *
5  * Copyright (C) 2007,2008 Øyvind Harboe <oyvind.harboe@zylin.com> *
6  * Copyright (C) 2008 by Spencer Oliver <spen@spen-soft.co.uk> *
7  * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
8  * Copyright (C) 2010 by Antonio Borneo <borneo.antonio@gmail.com> *
9  ***************************************************************************/
10 
11 #ifndef OPENOCD_FLASH_NOR_CORE_H
12 #define OPENOCD_FLASH_NOR_CORE_H
13 
14 #include <flash/common.h>
15 
21 struct image;
22 
28 struct flash_sector {
30  uint32_t offset;
32  uint32_t size;
42  int is_erased;
56 };
57 
59 #define FLASH_WRITE_ALIGN_SECTOR UINT32_MAX
60 
62 #define FLASH_WRITE_CONTINUOUS 0
63 #define FLASH_WRITE_GAP_SECTOR UINT32_MAX
64 
75 struct flash_bank {
76  char *name;
77 
78  struct target *target;
80  const struct flash_driver *driver;
81  void *driver_priv;
83  unsigned int bank_number;
85  uint32_t size;
87  unsigned int chip_width;
88  unsigned int bus_width;
91  uint8_t erased_value;
92 
96 
108 
114  unsigned int num_sectors;
117 
124  unsigned int num_prot_blocks;
127 
128  struct flash_bank *next;
129 };
130 
132 int flash_register_commands(struct command_context *cmd_ctx);
133 
142  bool pad, target_addr_t addr, uint32_t length);
143 
145  uint32_t length);
146 
162 
173 int flash_write(struct target *target,
174  struct image *image, uint32_t *written, bool erase);
175 
180 void flash_set_dirty(void);
181 
183 unsigned int flash_get_bank_count(void);
184 
187 
189 void flash_free_all_banks(void);
190 
200  uint8_t *buffer, uint32_t offset, uint32_t count);
201 
211  const uint8_t *buffer, uint32_t offset, uint32_t count);
212 
227 int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result);
235 struct flash_bank *get_flash_bank_by_name_noprobe(const char *name);
242 int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank);
253 COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
254  struct flash_bank **bank);
266 COMMAND_HELPER(flash_command_get_bank_probe_optional, unsigned int name_index,
267  struct flash_bank **bank, bool do_probe);
273 struct flash_bank *get_flash_bank_by_num_noprobe(unsigned int num);
282 int get_flash_bank_by_addr(struct target *target, target_addr_t addr, bool check,
283  struct flash_bank **result_bank);
291 struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size,
292  unsigned int num_blocks);
293 
294 #endif /* OPENOCD_FLASH_NOR_CORE_H */
const char * name
Definition: armv4_5.c:76
uint8_t bank
Definition: esirisc.c:135
uint8_t length
Definition: esp_usb_jtag.c:1
target_addr_t flash_write_align_start(struct flash_bank *bank, target_addr_t addr)
Align start address of a flash write region according to bank requirements.
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.
struct flash_bank * get_flash_bank_by_name_noprobe(const char *name)
Returns the flash bank specified by name, which matches the driver name and a suffix (option) specify...
struct flash_sector * alloc_block_array(uint32_t offset, uint32_t size, unsigned int num_blocks)
Allocate and fill an array of sectors or protection blocks.
target_addr_t flash_write_align_end(struct flash_bank *bank, target_addr_t addr)
Align end address of a flash write region according to bank requirements.
void flash_set_dirty(void)
Forces targets to re-examine their erase/protection state.
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int flash_unlock_address_range(struct target *target, target_addr_t addr, uint32_t length)
struct flash_bank * get_flash_bank_by_num_noprobe(unsigned int num)
Returns the flash bank like get_flash_bank_by_num(), without probing.
void flash_free_all_banks(void)
Deallocates all flash banks.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
unsigned int flash_get_bank_count(void)
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
int get_flash_bank_by_addr(struct target *target, target_addr_t addr, bool check, struct flash_bank **result_bank)
Returns the flash bank located at a specified address.
COMMAND_HELPER(flash_command_get_bank, unsigned name_index, struct flash_bank **bank)
Retrieves bank from a command argument, reporting errors parsing the bank identifier or retrieving th...
Definition: flash/nor/tcl.c:51
int flash_erase_address_range(struct target *target, bool pad, target_addr_t addr, uint32_t length)
Erases length bytes in the target flash, starting at addr.
int flash_write(struct target *target, struct image *image, uint32_t *written, bool erase)
Writes image into the target flash.
int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result)
Returns the flash bank specified by name, which matches the driver name and a suffix (option) specify...
int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank)
Returns the flash bank like get_flash_bank_by_name(), without probing.
int flash_register_commands(struct command_context *cmd_ctx)
Registers the 'flash' subsystem commands.
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
Provides details of a flash bank, available either on-chip or through a major interface.
Definition: nor/core.h:75
uint32_t write_end_alignment
Required alignment of flash write end address.
Definition: nor/core.h:102
unsigned int num_prot_blocks
The number of protection blocks in this bank.
Definition: nor/core.h:124
struct flash_sector * sectors
Array of sectors, allocated and initialized by the flash driver.
Definition: nor/core.h:116
uint8_t default_padded_value
Default padded value used, normally this matches the flash erased value.
Definition: nor/core.h:95
const struct flash_driver * driver
Driver for this bank.
Definition: nor/core.h:80
unsigned int chip_width
Width of the chip in bytes (1,2,4 bytes)
Definition: nor/core.h:87
target_addr_t base
The base address of this bank.
Definition: nor/core.h:84
void * driver_priv
Private driver storage pointer.
Definition: nor/core.h:81
uint32_t size
The size of this chip bank, in bytes.
Definition: nor/core.h:85
unsigned int num_sectors
The number of sectors on this chip.
Definition: nor/core.h:114
uint32_t write_start_alignment
Required alignment of flash write start address.
Definition: nor/core.h:99
struct flash_sector * prot_blocks
Array of protection blocks, allocated and initialized by the flash driver.
Definition: nor/core.h:126
unsigned int bus_width
Maximum bus width, in bytes (1,2,4 bytes)
Definition: nor/core.h:88
struct flash_bank * next
The next flash bank on this chip.
Definition: nor/core.h:128
struct target * target
Target to which this bank belongs.
Definition: nor/core.h:78
uint32_t minimal_write_gap
Minimal gap between sections to discontinue flash write Default FLASH_WRITE_GAP_SECTOR splits the wri...
Definition: nor/core.h:107
char * name
Definition: nor/core.h:76
uint8_t erased_value
Erased value.
Definition: nor/core.h:91
unsigned int bank_number
The 'bank' (or chip number) of this instance.
Definition: nor/core.h:83
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
Definition: nor/driver.h:39
Describes the geometry and status of a single flash sector within a flash bank.
Definition: nor/core.h:28
int is_erased
Indication of erasure status: 0 = not erased, 1 = erased, other = unknown.
Definition: nor/core.h:42
uint32_t offset
Bus offset from start of the flash chip (in bytes).
Definition: nor/core.h:30
int is_protected
Indication of protection status: 0 = unprotected/unlocked, 1 = protected/locked, other = unknown.
Definition: nor/core.h:55
uint32_t size
Number of bytes in this flash sector.
Definition: nor/core.h:32
Definition: image.h:48
Definition: target.h:116
uint64_t target_addr_t
Definition: types.h:335
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22