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  bool read_only;
89  unsigned int chip_width;
90  unsigned int bus_width;
93  uint8_t erased_value;
94 
98 
110 
116  unsigned int num_sectors;
119 
126  unsigned int num_prot_blocks;
129 
130  struct flash_bank *next;
131 };
132 
134 int flash_register_commands(struct command_context *cmd_ctx);
135 
144  bool pad, target_addr_t addr, uint32_t length);
145 
147  uint32_t length);
148 
164 
175 int flash_write(struct target *target,
176  struct image *image, uint32_t *written, bool erase);
177 
182 void flash_set_dirty(void);
183 
185 unsigned int flash_get_bank_count(void);
186 
189 
191 void flash_free_all_banks(void);
192 
202  uint8_t *buffer, uint32_t offset, uint32_t count);
203 
213  const uint8_t *buffer, uint32_t offset, uint32_t count);
214 
229 int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result);
237 struct flash_bank *get_flash_bank_by_name_noprobe(const char *name);
244 int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank);
255 COMMAND_HELPER(flash_command_get_bank, unsigned int name_index,
256  struct flash_bank **bank);
268 COMMAND_HELPER(flash_command_get_bank_probe_optional, unsigned int name_index,
269  struct flash_bank **bank, bool do_probe);
275 struct flash_bank *get_flash_bank_by_num_noprobe(unsigned int num);
284 int get_flash_bank_by_addr(struct target *target, target_addr_t addr, bool check,
285  struct flash_bank **result_bank);
293 struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size,
294  unsigned int num_blocks);
295 
296 #endif /* OPENOCD_FLASH_NOR_CORE_H */
const char * name
Definition: armv4_5.c:76
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
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.
COMMAND_HELPER(flash_command_get_bank, unsigned int 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_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.
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
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:104
unsigned int num_prot_blocks
The number of protection blocks in this bank.
Definition: nor/core.h:126
struct flash_sector * sectors
Array of sectors, allocated and initialized by the flash driver.
Definition: nor/core.h:118
uint8_t default_padded_value
Default padded value used, normally this matches the flash erased value.
Definition: nor/core.h:97
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:89
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:116
uint32_t write_start_alignment
Required alignment of flash write start address.
Definition: nor/core.h:101
struct flash_sector * prot_blocks
Array of protection blocks, allocated and initialized by the flash driver.
Definition: nor/core.h:128
unsigned int bus_width
Maximum bus width, in bytes (1,2,4 bytes)
Definition: nor/core.h:90
struct flash_bank * next
The next flash bank on this chip.
Definition: nor/core.h:130
bool read_only
a ROM region - mainly to list in gdb memory map
Definition: nor/core.h:87
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:109
char * name
Definition: nor/core.h:76
uint8_t erased_value
Erased value.
Definition: nor/core.h:93
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:119
uint64_t target_addr_t
Definition: types.h:279
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22