2009-12-05 00:07:47 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Dominic Rath <Dominic.Rath@gmx.de> *
|
|
|
|
* Copyright (C) 2007,2008 Øyvind Harboe <oyvind.harboe@zylin.com> *
|
|
|
|
* Copyright (C) 2008 by Spencer Oliver <spen@spen-soft.co.uk> *
|
|
|
|
* Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
|
2010-05-11 03:16:33 +00:00
|
|
|
* Copyright (C) 2010 by Antonio Borneo <borneo.antonio@gmail.com> *
|
2009-12-05 00:07:47 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
2016-05-16 20:41:00 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2009-12-05 00:07:47 +00:00
|
|
|
***************************************************************************/
|
2012-01-31 17:55:03 +00:00
|
|
|
|
2015-09-21 19:07:46 +00:00
|
|
|
#ifndef OPENOCD_FLASH_NOR_DRIVER_H
|
|
|
|
#define OPENOCD_FLASH_NOR_DRIVER_H
|
2009-12-05 00:07:47 +00:00
|
|
|
|
|
|
|
struct flash_bank;
|
|
|
|
|
|
|
|
#define __FLASH_BANK_COMMAND(name) \
|
|
|
|
COMMAND_HELPER(name, struct flash_bank *bank)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Provides the implementation-independent structure that defines
|
|
|
|
* all of the callbacks required by OpenOCD flash drivers.
|
|
|
|
*
|
|
|
|
* Driver authors must implement the routines defined here, providing an
|
|
|
|
* instance with the fields filled out. After that, the instance must
|
|
|
|
* be registered in flash.c, so it can be used by the driver lookup system.
|
|
|
|
*
|
|
|
|
* Specifically, the user can issue the command: @par
|
|
|
|
* @code
|
|
|
|
* flash bank DRIVERNAME ...parameters...
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* OpenOCD will search for the driver with a @c flash_driver_s::name
|
|
|
|
* that matches @c DRIVERNAME.
|
|
|
|
*
|
|
|
|
* The flash subsystem calls some of the other drivers routines a using
|
|
|
|
* corresponding static <code>flash_driver_<i>callback</i>()</code>
|
|
|
|
* routine in flash.c.
|
|
|
|
*/
|
2012-01-31 17:55:03 +00:00
|
|
|
struct flash_driver {
|
2009-12-05 00:07:47 +00:00
|
|
|
/**
|
|
|
|
* Gives a human-readable name of this flash driver,
|
|
|
|
* This field is used to select and initialize the driver.
|
|
|
|
*/
|
2010-12-29 21:07:21 +00:00
|
|
|
const char *name;
|
2009-12-05 00:07:47 +00:00
|
|
|
|
2011-12-28 12:10:52 +00:00
|
|
|
/**
|
|
|
|
* Gives a human-readable description of arguments.
|
|
|
|
*/
|
|
|
|
const char *usage;
|
|
|
|
|
2009-12-05 00:07:47 +00:00
|
|
|
/**
|
|
|
|
* An array of driver-specific commands to register. When called
|
|
|
|
* during the "flash bank" command, the driver can register addition
|
|
|
|
* commands to support new flash chip functions.
|
|
|
|
*/
|
|
|
|
const struct command_registration *commands;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finish the "flash bank" command for @a bank. The
|
|
|
|
* @a bank parameter will have been filled in by the core flash
|
|
|
|
* layer when this routine is called, and the driver can store
|
|
|
|
* additional information in its struct flash_bank::driver_priv field.
|
|
|
|
*
|
|
|
|
* The CMD_ARGV are: @par
|
|
|
|
* @code
|
|
|
|
* CMD_ARGV[0] = bank
|
|
|
|
* CMD_ARGV[1] = drivername {name above}
|
|
|
|
* CMD_ARGV[2] = baseaddress
|
|
|
|
* CMD_ARGV[3] = lengthbytes
|
|
|
|
* CMD_ARGV[4] = chip_width_in bytes
|
2010-05-07 09:04:32 +00:00
|
|
|
* CMD_ARGV[5] = bus_width_in_bytes
|
2009-12-05 00:07:47 +00:00
|
|
|
* CMD_ARGV[6] = driver-specific parameters
|
|
|
|
* @endcode
|
|
|
|
*
|
2010-05-07 09:04:32 +00:00
|
|
|
* For example, CMD_ARGV[4] = 2 (for 16 bit flash),
|
|
|
|
* CMD_ARGV[5] = 4 (for 32 bit bus).
|
2009-12-05 00:07:47 +00:00
|
|
|
*
|
|
|
|
* If extra arguments are provided (@a CMD_ARGC > 6), they will
|
|
|
|
* start in @a CMD_ARGV[6]. These can be used to implement
|
|
|
|
* driver-specific extensions.
|
|
|
|
*
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
__FLASH_BANK_COMMAND((*flash_bank_command));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bank/sector erase routine (target-specific). When
|
|
|
|
* called, the flash driver should erase the specified sectors
|
|
|
|
* using whatever means are at its disposal.
|
|
|
|
*
|
|
|
|
* @param bank The bank of flash to be erased.
|
|
|
|
* @param first The number of the first sector to erase, typically 0.
|
|
|
|
* @param last The number of the last sector to erase, typically N-1.
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
2020-06-07 15:00:13 +00:00
|
|
|
int (*erase)(struct flash_bank *bank, unsigned int first,
|
|
|
|
unsigned int last);
|
2009-12-05 00:07:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bank/sector protection routine (target-specific).
|
2010-12-14 08:29:26 +00:00
|
|
|
*
|
2018-11-15 11:19:25 +00:00
|
|
|
* If protection is not implemented, set method to NULL
|
|
|
|
*
|
2010-12-14 08:29:26 +00:00
|
|
|
* When called, the driver should enable/disable protection
|
|
|
|
* for MINIMUM the range covered by first..last sectors
|
|
|
|
* inclusive. Some chips have alignment requirements will
|
|
|
|
* cause the actual range to be protected / unprotected to
|
|
|
|
* be larger than the first..last range.
|
2009-12-05 00:07:47 +00:00
|
|
|
*
|
|
|
|
* @param bank The bank to protect or unprotect.
|
|
|
|
* @param set If non-zero, enable protection; if 0, disable it.
|
2020-07-11 22:00:47 +00:00
|
|
|
* @param first The first sector to (un)protect, typically 0.
|
2009-12-05 00:07:47 +00:00
|
|
|
* @param last The last sector to (un)project, typically N-1.
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
2020-06-07 15:00:13 +00:00
|
|
|
int (*protect)(struct flash_bank *bank, int set, unsigned int first,
|
|
|
|
unsigned int last);
|
2009-12-05 00:07:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Program data into the flash. Note CPU address will be
|
|
|
|
* "bank->base + offset", while the physical address is
|
|
|
|
* dependent upon current target MMU mappings.
|
|
|
|
*
|
|
|
|
* @param bank The bank to program
|
|
|
|
* @param buffer The data bytes to write.
|
|
|
|
* @param offset The offset into the chip to program.
|
|
|
|
* @param count The number of bytes to write.
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*write)(struct flash_bank *bank,
|
2014-03-10 21:23:07 +00:00
|
|
|
const uint8_t *buffer, uint32_t offset, uint32_t count);
|
2009-12-05 00:07:47 +00:00
|
|
|
|
2010-05-11 03:16:33 +00:00
|
|
|
/**
|
|
|
|
* Read data from the flash. Note CPU address will be
|
|
|
|
* "bank->base + offset", while the physical address is
|
|
|
|
* dependent upon current target MMU mappings.
|
|
|
|
*
|
|
|
|
* @param bank The bank to read.
|
|
|
|
* @param buffer The data bytes read.
|
|
|
|
* @param offset The offset into the chip to read.
|
|
|
|
* @param count The number of bytes to read.
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*read)(struct flash_bank *bank,
|
|
|
|
uint8_t *buffer, uint32_t offset, uint32_t count);
|
|
|
|
|
Flash, FRAM and EEPROM driver for STM32 QUAD-/OCTOSPI interface
- write speed up to 150 kByte/s on STM32F469I-disco (due to
SWD clock and USB connection), up to 1 MByte/s on Nucleo-F767ZI
with external STLink-V3 or Nucleo-G474RE with two W25Q256FV in
dual 4-line mode or STM32H73BI-Disco in octal mode
- tested with STM32L476G-disco (64MBit flash, 3-byte addr),
STM32F412G-Disco, STM32F469I-Disco, STM32F746G-Disco, and
STM32L476G-Disco (all 128Mbit flash, 3-byte addr),
STM32F723E-Disco, STM32F769I-Disco (512Mbit flash, 4-byte addr)
STM32L4R9I-Disco, STM32L4P5G-Disco (512MBit octo-flash, DTR, 4-byte addr)
STM32H745I-Disco, STM32H747I-Disco (two 512MBit flash, 4-byte addr)
STM32H73BI-Disco, STM32H735G-Disco (512MBit octo-flash, DTR, 4-byte addr)
- suitable cfg for Discovery boards included
- limited parsing of SFDP data if flash device not hardcoded
(tested only in single/quad mode as most devices either don't
support SFDP at all or have empty(!) SFDP memory)
- 'set' command for auto detection override (e. g. for EEPROMs)
- 'cmd' command for arbitrary SPI commands (reconfiguration, testing etc.)
- makefile for creation of binary loader files
- tcl/board/stm32f469discovery.cfg superseded by stm32f469i-disco.cfg
- tcl/board/stm32f7discovery.cfg removed as name is ambiguous
(superseded by stm32f746g-disco.cfg vs. stm32f769i-disco.cfg)
- dual 4-line mode tested on Nucleo-F767ZI, Nucleo-H743ZI and Nucleo-H7A3ZI-Q
with two W25Q256FV, and on Nucleo-L496ZP-P and Nucleo-L4R5ZI
with two W25Q128FV, sample cfg files included and on STM32H745I-Disco,
STM32H747I-Disco, STM32H750B-Disco
- read/verify/erase_check uses indirect read mode to work around silicon bug in
H7, L4+ and MP1 memory mapped mode (last bytes not readable, accessing last
bytes causes debug interface to hang)
- octospi supported only in single/dual 1-line, 2-line, 4-line
and single 8-line modes, (not in hyper flash mode)
Requirements:
GPIOs must be initialized appropriately, and SPI flash chip be configured
appropriately (1-line ..., QPI, 4-byte addresses ...). This is board/chip
specific, cf. included cfg files. The driver infers most parameters from
current setting in CR, CCR, ... registers.
Change-Id: I54858fbbe8758c3a5fe58812e93f5f39514704f8
Signed-off-by: Andreas Bolsch <hyphen0break@gmail.com>
Reviewed-on: http://openocd.zylin.com/4321
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Christopher Head <chead@zaber.com>
2016-12-21 09:35:58 +00:00
|
|
|
/**
|
|
|
|
* Verify data in flash. Note CPU address will be
|
|
|
|
* "bank->base + offset", while the physical address is
|
|
|
|
* dependent upon current target MMU mappings.
|
|
|
|
*
|
|
|
|
* @param bank The bank to verify
|
|
|
|
* @param buffer The data bytes to verify against.
|
|
|
|
* @param offset The offset into the chip to verify.
|
|
|
|
* @param count The number of bytes to verify.
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*verify)(struct flash_bank *bank,
|
|
|
|
const uint8_t *buffer, uint32_t offset, uint32_t count);
|
|
|
|
|
2009-12-05 00:07:47 +00:00
|
|
|
/**
|
|
|
|
* Probe to determine what kind of flash is present.
|
|
|
|
* This is invoked by the "probe" script command.
|
|
|
|
*
|
|
|
|
* @param bank The bank to probe
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*probe)(struct flash_bank *bank);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the erasure status of a flash bank.
|
|
|
|
* When called, the driver routine must perform the required
|
|
|
|
* checks and then set the @c flash_sector_s::is_erased field
|
|
|
|
* for each of the flash banks's sectors.
|
|
|
|
*
|
|
|
|
* @param bank The bank to check
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*erase_check)(struct flash_bank *bank);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the specific bank is "protected" or not.
|
|
|
|
* When called, the driver routine must must perform the
|
|
|
|
* required protection check(s) and then set the @c
|
|
|
|
* flash_sector_s::is_protected field for each of the flash
|
|
|
|
* bank's sectors.
|
|
|
|
*
|
2018-11-15 11:19:25 +00:00
|
|
|
* If protection is not implemented, set method to NULL
|
|
|
|
*
|
2009-12-05 00:07:47 +00:00
|
|
|
* @param bank - the bank to check
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*protect_check)(struct flash_bank *bank);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display human-readable information about the flash
|
|
|
|
* bank into the given buffer. Drivers must be careful to avoid
|
|
|
|
* overflowing the buffer.
|
|
|
|
*
|
|
|
|
* @param bank - the bank to get info about
|
|
|
|
* @param char - where to put the text for the human to read
|
|
|
|
* @param buf_size - the size of the human buffer.
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*info)(struct flash_bank *bank, char *buf, int buf_size);
|
|
|
|
|
|
|
|
/**
|
2020-07-11 22:00:47 +00:00
|
|
|
* A more gentle flavor of flash_driver_s::probe, performing
|
2009-12-05 00:07:47 +00:00
|
|
|
* setup with less noise. Generally, driver routines should test
|
2012-05-20 00:29:30 +00:00
|
|
|
* to see if the bank has already been probed; if it has, the
|
2009-12-05 00:07:47 +00:00
|
|
|
* driver probably should not perform its probe a second time.
|
|
|
|
*
|
|
|
|
* This callback is often called from the inside of other
|
|
|
|
* routines (e.g. GDB flash downloads) to autoprobe the flash as
|
2020-07-11 22:00:47 +00:00
|
|
|
* it is programming the flash.
|
2009-12-05 00:07:47 +00:00
|
|
|
*
|
|
|
|
* @param bank - the bank to probe
|
|
|
|
* @returns ERROR_OK if successful; otherwise, an error code.
|
|
|
|
*/
|
|
|
|
int (*auto_probe)(struct flash_bank *bank);
|
2018-02-15 01:29:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deallocates private driver structures.
|
|
|
|
* Use default_flash_free_driver_priv() to simply free(bank->driver_priv)
|
|
|
|
*
|
|
|
|
* @param bank - the bank being destroyed
|
|
|
|
*/
|
|
|
|
void (*free_driver_priv)(struct flash_bank *bank);
|
2009-12-05 00:07:47 +00:00
|
|
|
};
|
|
|
|
|
2012-01-31 17:55:03 +00:00
|
|
|
#define FLASH_BANK_COMMAND_HANDLER(name) \
|
|
|
|
static __FLASH_BANK_COMMAND(name)
|
2009-12-05 00:07:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a NOR flash driver by its name.
|
|
|
|
* @param name The name of the requested driver.
|
|
|
|
* @returns The flash_driver called @c name, or NULL if not found.
|
|
|
|
*/
|
2018-12-13 19:53:59 +00:00
|
|
|
const struct flash_driver *flash_driver_find_by_name(const char *name);
|
2009-12-05 00:07:47 +00:00
|
|
|
|
2015-09-21 19:07:46 +00:00
|
|
|
#endif /* OPENOCD_FLASH_NOR_DRIVER_H */
|