From: Zach W. <zw...@us...> - 2009-12-05 02:22:52
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 87a0119fa24fe0fc904dcf2e6569cc0b9cb580ed (commit) via f3e6f584f12dbde9ba9806ed4a412db0524d438c (commit) via ae6374e25dae7b02636e440549b87040d03cc5aa (commit) via d9dc604a4d790f557a7ba502babdabffa27eaa17 (commit) via 1527272fb21beee7839335ea5587e879163d2ed1 (commit) via 5fdee60fd4d38e59c7b5f7aca5ad50b90e7d61ee (commit) via c90702eaa7e7c4e7dd6d1efea61387a62748cfad (commit) via 04ee41de52065f648752c13652b3428260f1ac2a (commit) from 32f961daba1301ac22ed53c9bc0822effff168cf (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 87a0119fa24fe0fc904dcf2e6569cc0b9cb580ed Author: Zachary T Welch <zw...@su...> Date: Fri Dec 4 04:42:38 2009 -0800 reorder build order of src directory Descend into the library modules in order, from bottom-to-top. diff --git a/src/Makefile.am b/src/Makefile.am index e6462c1..ea753bb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,12 @@ -SUBDIRS = helper jtag xsvf svf target server flash pld +SUBDIRS = \ + helper \ + jtag \ + target \ + flash \ + svf \ + xsvf \ + pld \ + server lib_LTLIBRARIES = libopenocd.la bin_PROGRAMS = openocd commit f3e6f584f12dbde9ba9806ed4a412db0524d438c Author: Zachary T Welch <zw...@su...> Date: Fri Dec 4 16:40:19 2009 -0800 remove flash.h from tree Remove the now vestigial <flash/flash.h> header from the tree, replacing a few references with <flash/nor/core.h> diff --git a/src/flash/Makefile.am b/src/flash/Makefile.am index b5cd526..ba44adb 100644 --- a/src/flash/Makefile.am +++ b/src/flash/Makefile.am @@ -22,7 +22,6 @@ libflash_la_LIBADD = \ noinst_HEADERS = \ arm_nandio.h \ common.h \ - flash.h \ mflash.h \ nand.h diff --git a/src/flash/flash.h b/src/flash/flash.h deleted file mode 100644 index 056e1ae..0000000 --- a/src/flash/flash.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Dominic Rath * - * Dom...@gm... * - * * - * Copyright (C) 2007,2008 Ãyvind Harboe * - * oyv...@zy... * - * * - * Copyright (C) 2008 by Spencer Oliver * - * sp...@sp... * - * * - * 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 * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef FLASH_H -#define FLASH_H - -// this file will be removed - -#include <flash/nor/core.h> - -#endif /* FLASH_H */ diff --git a/src/flash/nor/at91sam7.h b/src/flash/nor/at91sam7.h index 8077879..eb35433 100644 --- a/src/flash/nor/at91sam7.h +++ b/src/flash/nor/at91sam7.h @@ -23,8 +23,6 @@ #ifndef AT91SAM7_H #define AT91SAM7_H -#include <flash/flash.h> - struct at91sam7_flash_bank { /* chip id register */ diff --git a/src/flash/nor/avrf.h b/src/flash/nor/avrf.h index 0f270e6..1a69e86 100644 --- a/src/flash/nor/avrf.h +++ b/src/flash/nor/avrf.h @@ -20,8 +20,6 @@ #ifndef AVRF_H #define AVRF_H -#include <helper/types.h> - struct avrf_type { char name[15]; diff --git a/src/flash/nor/cfi.h b/src/flash/nor/cfi.h index 565a2b6..fa717dc 100644 --- a/src/flash/nor/cfi.h +++ b/src/flash/nor/cfi.h @@ -20,8 +20,6 @@ #ifndef CFI_H #define CFI_H -#include <flash/flash.h> - #define CFI_STATUS_POLL_MASK_DQ5_DQ6_DQ7 0xE0 /* DQ5..DQ7 */ #define CFI_STATUS_POLL_MASK_DQ6_DQ7 0xC0 /* DQ6..DQ7 */ diff --git a/src/flash/nor/lpc2000.h b/src/flash/nor/lpc2000.h index 30be304..f1f90e7 100644 --- a/src/flash/nor/lpc2000.h +++ b/src/flash/nor/lpc2000.h @@ -23,8 +23,6 @@ #ifndef LPC2000_H #define LPC2000_H -#include <flash/flash.h> - typedef enum { lpc2000_v1, diff --git a/src/flash/nor/lpc288x.h b/src/flash/nor/lpc288x.h index 06f634a..cd5fb73 100644 --- a/src/flash/nor/lpc288x.h +++ b/src/flash/nor/lpc288x.h @@ -21,8 +21,6 @@ #ifndef lpc288x_H #define lpc288x_H -#include <flash/flash.h> - struct lpc288x_flash_bank { uint32_t working_area; diff --git a/src/flash/nor/non_cfi.c b/src/flash/nor/non_cfi.c index f98b108..7e73afa 100644 --- a/src/flash/nor/non_cfi.c +++ b/src/flash/nor/non_cfi.c @@ -23,8 +23,9 @@ #include "config.h" #endif -#include "non_cfi.h" +#include "imp.h" #include "cfi.h" +#include "non_cfi.h" #define KB 1024 diff --git a/src/flash/nor/non_cfi.h b/src/flash/nor/non_cfi.h index cc6004e..0219333 100644 --- a/src/flash/nor/non_cfi.h +++ b/src/flash/nor/non_cfi.h @@ -20,8 +20,6 @@ #ifndef NON_CFI_H #define NON_CFI_H -#include <flash/flash.h> - struct non_cfi { uint16_t mfr; diff --git a/src/flash/nor/pic32mx.h b/src/flash/nor/pic32mx.h index b33e831..b3bdad2 100644 --- a/src/flash/nor/pic32mx.h +++ b/src/flash/nor/pic32mx.h @@ -26,8 +26,6 @@ #ifndef PIC32MX_H #define PIC32MX_H -#include <flash/flash.h> - struct pic32mx_flash_bank { struct working_area *write_algorithm; diff --git a/src/flash/nor/stellaris.h b/src/flash/nor/stellaris.h index 85b709c..a5f04e4 100644 --- a/src/flash/nor/stellaris.h +++ b/src/flash/nor/stellaris.h @@ -20,8 +20,6 @@ #ifndef STELLARIS_FLASH_H #define STELLARIS_FLASH_H -#include <flash/flash.h> - struct stellaris_flash_bank { /* chip id register */ diff --git a/src/flash/nor/stm32x.h b/src/flash/nor/stm32x.h index b6e00ed..fcf895c 100644 --- a/src/flash/nor/stm32x.h +++ b/src/flash/nor/stm32x.h @@ -23,8 +23,6 @@ #ifndef STM32X_H #define STM32X_H -#include <flash/flash.h> - struct stm32x_options { uint16_t RDP; diff --git a/src/flash/nor/str7x.h b/src/flash/nor/str7x.h index 4daafb7..77dfee6 100644 --- a/src/flash/nor/str7x.h +++ b/src/flash/nor/str7x.h @@ -23,8 +23,6 @@ #ifndef STR7X_H #define STR7X_H -#include <flash/flash.h> - struct str7x_flash_bank { uint32_t *sector_bits; diff --git a/src/flash/nor/str9x.h b/src/flash/nor/str9x.h index 29adecf..ba5386f 100644 --- a/src/flash/nor/str9x.h +++ b/src/flash/nor/str9x.h @@ -23,8 +23,6 @@ #ifndef STR9X_H #define STR9X_H -#include <flash/flash.h> - struct str9x_flash_bank { uint32_t *sector_bits; diff --git a/src/flash/nor/str9xpec.h b/src/flash/nor/str9xpec.h index cb2ac78..6eecd8a 100644 --- a/src/flash/nor/str9xpec.h +++ b/src/flash/nor/str9xpec.h @@ -23,8 +23,6 @@ #ifndef STR9XPEC_H #define STR9XPEC_H -#include <flash/flash.h> -#include <jtag/jtag.h> struct str9xpec_flash_controller { diff --git a/src/flash/nor/tms470.h b/src/flash/nor/tms470.h index b2fea1b..ecbfad8 100644 --- a/src/flash/nor/tms470.h +++ b/src/flash/nor/tms470.h @@ -20,8 +20,6 @@ #ifndef TMS470_DOT_H #define TMS470_DOT_H -#include <flash/flash.h> - struct tms470_flash_bank { unsigned ordinal; diff --git a/src/openocd.c b/src/openocd.c index b6dc010..e500ba6 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -34,7 +34,7 @@ #include <helper/configuration.h> #include <xsvf/xsvf.h> #include <svf/svf.h> -#include <flash/flash.h> +#include <flash/nor/core.h> #include <flash/nand.h> #include <pld/pld.h> #include <flash/mflash.h> diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 21cd0fe..f9cca99 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -31,7 +31,7 @@ #include <target/target_request.h> #include <target/register.h> #include "server.h" -#include <flash/flash.h> +#include <flash/nor/core.h> #include "gdb_server.h" #include <target/image.h> #include <jtag/jtag.h> commit ae6374e25dae7b02636e440549b87040d03cc5aa Author: Zachary T Welch <zw...@su...> Date: Fri Dec 4 16:07:47 2009 -0800 split flash.h into into flash/nor/*.h Move the bulk of the flash.h file into flash/nor/core.h, leaving an empty husk that will be removed in the next patch. The NOR driver structure is an implementation detail, so move it into its own private header file <flash/nor/driver.h> along with helper declaration for finding them by name. diff --git a/src/flash/flash.h b/src/flash/flash.h index 8cd50f6..056e1ae 100644 --- a/src/flash/flash.h +++ b/src/flash/flash.h @@ -26,326 +26,8 @@ #ifndef FLASH_H #define FLASH_H -#include <flash/common.h> +// this file will be removed -struct image; - -#define FLASH_MAX_ERROR_STR (128) - -/** - * Describes the geometry and status of a single flash sector - * within a flash bank. A single bank typically consists of multiple - * sectors, each of which can be erased and protected independently. - */ -struct flash_sector -{ - /// Bus offset from start of the flash chip (in bytes). - uint32_t offset; - /// Number of bytes in this flash sector. - uint32_t size; - /** - * Indication of erasure status: 0 = not erased, 1 = erased, - * other = unknown. Set by @c flash_driver_s::erase_check. - */ - int is_erased; - /** - * Indication of protection status: 0 = unprotected/unlocked, - * 1 = protected/locked, other = unknown. Set by - * @c flash_driver_s::protect_check. - */ - int is_protected; -}; - -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. - */ -struct flash_driver -{ - /** - * Gives a human-readable name of this flash driver, - * This field is used to select and initialize the driver. - */ - char *name; - - /** - * 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 - * CMD_ARGV[5] = bus_width_bytes - * CMD_ARGV[6] = driver-specific parameters - * @endcode - * - * For example, CMD_ARGV[4] = 16 bit flash, CMD_ARGV[5] = 32bit bus. - * - * 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. - */ - int (*erase)(struct flash_bank *bank, int first, int last); - - /** - * Bank/sector protection routine (target-specific). - * When called, the driver should disable 'flash write' bits (or - * enable 'erase protection' bits) for the given @a bank and @a - * sectors. - * - * @param bank The bank to protect or unprotect. - * @param set If non-zero, enable protection; if 0, disable it. - * @param first The first sector to (un)protect, typicaly 0. - * @param last The last sector to (un)project, typically N-1. - * @returns ERROR_OK if successful; otherwise, an error code. - */ - int (*protect)(struct flash_bank *bank, int set, int first, int last); - - /** - * 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, - uint8_t *buffer, uint32_t offset, uint32_t count); - - /** - * 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. - * - * @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); - - /** - * A more gentle flavor of filash_driver_s::probe, performing - * setup with less noise. Generally, driver routines should test - * to seee if the bank has already been probed; if it has, the - * 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 - * it is programing the flash. - * - * @param bank - the bank to probe - * @returns ERROR_OK if successful; otherwise, an error code. - */ - int (*auto_probe)(struct flash_bank *bank); -}; - -#define FLASH_BANK_COMMAND_HANDLER(name) static __FLASH_BANK_COMMAND(name) - -/** - * Provides details of a flash bank, available either on-chip or through - * a major interface. - * - * This structure will be passed as a parameter to the callbacks in the - * flash_driver_s structure, some of which may modify the contents of - * this structure of the area of flash that it defines. Driver writers - * may use the @c driver_priv member to store additional data on a - * per-bank basis, if required. - */ -struct flash_bank -{ - char *name; - - struct target *target; /**< Target to which this bank belongs. */ - - struct flash_driver *driver; /**< Driver for this bank. */ - void *driver_priv; /**< Private driver storage pointer */ - - int bank_number; /**< The 'bank' (or chip number) of this instance. */ - uint32_t base; /**< The base address of this bank */ - uint32_t size; /**< The size of this chip bank, in bytes */ - - int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */ - int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */ - - /** - * The number of sectors on this chip. This value will - * be set intially to 0, and the flash driver must set this to - * some non-zero value during "probe()" or "auto_probe()". - */ - int num_sectors; - /// Array of sectors, allocated and initilized by the flash driver - struct flash_sector *sectors; - - struct flash_bank *next; /**< The next flash bank on this chip */ -}; - -/// Registers the 'flash' subsystem commands -int flash_register_commands(struct command_context *cmd_ctx); -/// Initializes the 'flash' subsystem drivers -int flash_init_drivers(struct command_context *cmd_ctx); - -/** - * Erases @a length bytes in the @a target flash, starting at @a addr. - * @returns ERROR_OK if successful; otherwise, an error code. - */ -int flash_erase_address_range(struct target *target, - uint32_t addr, uint32_t length); -/** - * Writes @a image into the @a target flash. The @a written parameter - * will contain the - * @param target The target with the flash to be programmed. - * @param image The image that will be programmed to flash. - * @param written On return, contains the number of bytes written. - * @param erase If non-zero, indicates the flash driver should first - * erase the corresponding banks or sectors before programming. - * @returns ERROR_OK if successful; otherwise, an error code. - */ -int flash_write(struct target *target, - struct image *image, uint32_t *written, int erase); -/** - * Forces targets to re-examine their erase/protection state. - * This routine must be called when the system may modify the status. - */ -void flash_set_dirty(void); -/// @returns The number of flash banks currently defined. -int flash_get_bank_count(void); -/** - * Provides default erased-bank check handling. Checks to see if - * the flash driver knows they are erased; if things look uncertain, - * this routine will call default_flash_mem_blank_check() to confirm. - * @returns ERROR_OK if successful; otherwise, an error code. - */ -int default_flash_blank_check(struct flash_bank *bank); -/** - * Provides a default blank flash memory check. Ensures the contents - * of the given bank have truly been erased. - * @param bank The flash bank. - * @returns ERROR_OK if successful; otherwise, an error code. - */ -int default_flash_mem_blank_check(struct flash_bank *bank); - -/** - * Returns the flash bank specified by @a name, which matches the - * driver name and a suffix (option) specify the driver-specific - * bank number. The suffix consists of the '.' and the driver-specific - * bank number: when two str9x banks are defined, then 'str9x.1' refers - * to the second. - */ -struct flash_bank *get_flash_bank_by_name(const char *name); -/** - * Returns a flash bank by the specified flash_bank_s bank_number, @a num. - * @param num The flash bank number. - * @returns A struct flash_bank for flash bank @a num, or NULL - */ -struct flash_bank *get_flash_bank_by_num(int num); -/** - * Retreives @a bank from a command argument, reporting errors parsing - * the bank identifier or retreiving the specified bank. The bank - * may be identified by its bank number or by @c name.instance, where - * @a instance is driver-specific. - * @param name_index The index to the string in args containing the - * bank identifier. - * @param bank On output, contians a pointer to the bank or NULL. - * @returns ERROR_OK on success, or an error indicating the problem. - */ -COMMAND_HELPER(flash_command_get_bank, unsigned name_index, - struct flash_bank **bank); -/** - * Returns the flash bank like get_flash_bank_by_num(), without probing. - * @param num The flash bank number. - * @returns A struct flash_bank for flash bank @a num, or NULL. - */ -struct flash_bank *get_flash_bank_by_num_noprobe(int num); -/** - * Returns the flash bank located at a specified address. - * @param target The target, presumed to contain one or more banks. - * @param addr An address that is within the range of the bank. - * @returns The struct flash_bank located at @a addr, or NULL. - */ -struct flash_bank *get_flash_bank_by_addr(struct target *target, uint32_t addr); +#include <flash/nor/core.h> #endif /* FLASH_H */ diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am index bafe424..f185081 100644 --- a/src/flash/nor/Makefile.am +++ b/src/flash/nor/Makefile.am @@ -34,6 +34,7 @@ noinst_HEADERS = \ avrf.h \ core.h \ cfi.h \ + driver.h \ imp.h \ lpc2000.h \ lpc288x.h \ diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h index 0c6a804..c1e26cd 100644 --- a/src/flash/nor/core.h +++ b/src/flash/nor/core.h @@ -1,4 +1,7 @@ /*************************************************************************** + * Copyright (C) 2005 by Dominic Rath <Dom...@gm...> * + * Copyright (C) 2007,2008 Ãyvind Harboe <oyv...@zy...> * + * Copyright (C) 2008 by Spencer Oliver <sp...@sp...> * * Copyright (C) 2009 Zachary T Welch <zw...@su...> * * * * This program is free software; you can redistribute it and/or modify * @@ -19,13 +22,157 @@ #ifndef FLASH_NOR_CORE_H #define FLASH_NOR_CORE_H -#include <flash/flash.h> +#include <flash/common.h> +struct image; + +#define FLASH_MAX_ERROR_STR (128) + +/** + * Describes the geometry and status of a single flash sector + * within a flash bank. A single bank typically consists of multiple + * sectors, each of which can be erased and protected independently. + */ +struct flash_sector +{ + /// Bus offset from start of the flash chip (in bytes). + uint32_t offset; + /// Number of bytes in this flash sector. + uint32_t size; + /** + * Indication of erasure status: 0 = not erased, 1 = erased, + * other = unknown. Set by @c flash_driver_s::erase_check. + */ + int is_erased; + /** + * Indication of protection status: 0 = unprotected/unlocked, + * 1 = protected/locked, other = unknown. Set by + * @c flash_driver_s::protect_check. + */ + int is_protected; +}; + +/** + * Provides details of a flash bank, available either on-chip or through + * a major interface. + * + * This structure will be passed as a parameter to the callbacks in the + * flash_driver_s structure, some of which may modify the contents of + * this structure of the area of flash that it defines. Driver writers + * may use the @c driver_priv member to store additional data on a + * per-bank basis, if required. + */ +struct flash_bank +{ + char *name; + + struct target *target; /**< Target to which this bank belongs. */ + + struct flash_driver *driver; /**< Driver for this bank. */ + void *driver_priv; /**< Private driver storage pointer */ + + int bank_number; /**< The 'bank' (or chip number) of this instance. */ + uint32_t base; /**< The base address of this bank */ + uint32_t size; /**< The size of this chip bank, in bytes */ + + int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */ + int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */ + + /** + * The number of sectors on this chip. This value will + * be set intially to 0, and the flash driver must set this to + * some non-zero value during "probe()" or "auto_probe()". + */ + int num_sectors; + /// Array of sectors, allocated and initilized by the flash driver + struct flash_sector *sectors; + + struct flash_bank *next; /**< The next flash bank on this chip */ +}; + +/// Registers the 'flash' subsystem commands +int flash_register_commands(struct command_context *cmd_ctx); +/// Initializes the 'flash' subsystem drivers +int flash_init_drivers(struct command_context *cmd_ctx); + +/** + * Erases @a length bytes in the @a target flash, starting at @a addr. + * @returns ERROR_OK if successful; otherwise, an error code. + */ +int flash_erase_address_range(struct target *target, + uint32_t addr, uint32_t length); +/** + * Writes @a image into the @a target flash. The @a written parameter + * will contain the + * @param target The target with the flash to be programmed. + * @param image The image that will be programmed to flash. + * @param written On return, contains the number of bytes written. + * @param erase If non-zero, indicates the flash driver should first + * erase the corresponding banks or sectors before programming. + * @returns ERROR_OK if successful; otherwise, an error code. + */ +int flash_write(struct target *target, + struct image *image, uint32_t *written, int erase); +/** + * Forces targets to re-examine their erase/protection state. + * This routine must be called when the system may modify the status. + */ +void flash_set_dirty(void); +/// @returns The number of flash banks currently defined. +int flash_get_bank_count(void); +/** + * Provides default erased-bank check handling. Checks to see if + * the flash driver knows they are erased; if things look uncertain, + * this routine will call default_flash_mem_blank_check() to confirm. + * @returns ERROR_OK if successful; otherwise, an error code. + */ +int default_flash_blank_check(struct flash_bank *bank); +/** + * Provides a default blank flash memory check. Ensures the contents + * of the given bank have truly been erased. + * @param bank The flash bank. + * @returns ERROR_OK if successful; otherwise, an error code. + */ +int default_flash_mem_blank_check(struct flash_bank *bank); + +/** + * Returns the flash bank specified by @a name, which matches the + * driver name and a suffix (option) specify the driver-specific + * bank number. The suffix consists of the '.' and the driver-specific + * bank number: when two str9x banks are defined, then 'str9x.1' refers + * to the second. + */ +struct flash_bank *get_flash_bank_by_name(const char *name); +/** + * Returns a flash bank by the specified flash_bank_s bank_number, @a num. + * @param num The flash bank number. + * @returns A struct flash_bank for flash bank @a num, or NULL + */ +struct flash_bank *get_flash_bank_by_num(int num); +/** + * Retreives @a bank from a command argument, reporting errors parsing + * the bank identifier or retreiving the specified bank. The bank + * may be identified by its bank number or by @c name.instance, where + * @a instance is driver-specific. + * @param name_index The index to the string in args containing the + * bank identifier. + * @param bank On output, contians a pointer to the bank or NULL. + * @returns ERROR_OK on success, or an error indicating the problem. + */ +COMMAND_HELPER(flash_command_get_bank, unsigned name_index, + struct flash_bank **bank); +/** + * Returns the flash bank like get_flash_bank_by_num(), without probing. + * @param num The flash bank number. + * @returns A struct flash_bank for flash bank @a num, or NULL. + */ +struct flash_bank *get_flash_bank_by_num_noprobe(int num); /** - * 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. + * Returns the flash bank located at a specified address. + * @param target The target, presumed to contain one or more banks. + * @param addr An address that is within the range of the bank. + * @returns The struct flash_bank located at @a addr, or NULL. */ -struct flash_driver *flash_driver_find_by_name(const char *name); +struct flash_bank *get_flash_bank_by_addr(struct target *target, uint32_t addr); #endif // FLASH_NOR_CORE_H diff --git a/src/flash/nor/driver.h b/src/flash/nor/driver.h new file mode 100644 index 0000000..de71a39 --- /dev/null +++ b/src/flash/nor/driver.h @@ -0,0 +1,201 @@ +/*************************************************************************** + * Copyright (C) 2005 by Dominic Rath <Dom...@gm...> * + * Copyright (C) 2007,2008 Ãyvind Harboe <oyv...@zy...> * + * Copyright (C) 2008 by Spencer Oliver <sp...@sp...> * + * Copyright (C) 2009 Zachary T Welch <zw...@su...> * + * * + * 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 * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef FLASH_NOR_DRIVER_H +#define FLASH_NOR_DRIVER_H + +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. + */ +struct flash_driver +{ + /** + * Gives a human-readable name of this flash driver, + * This field is used to select and initialize the driver. + */ + char *name; + + /** + * 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 + * CMD_ARGV[5] = bus_width_bytes + * CMD_ARGV[6] = driver-specific parameters + * @endcode + * + * For example, CMD_ARGV[4] = 16 bit flash, CMD_ARGV[5] = 32bit bus. + * + * 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. + */ + int (*erase)(struct flash_bank *bank, int first, int last); + + /** + * Bank/sector protection routine (target-specific). + * When called, the driver should disable 'flash write' bits (or + * enable 'erase protection' bits) for the given @a bank and @a + * sectors. + * + * @param bank The bank to protect or unprotect. + * @param set If non-zero, enable protection; if 0, disable it. + * @param first The first sector to (un)protect, typicaly 0. + * @param last The last sector to (un)project, typically N-1. + * @returns ERROR_OK if successful; otherwise, an error code. + */ + int (*protect)(struct flash_bank *bank, int set, int first, int last); + + /** + * 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, + uint8_t *buffer, uint32_t offset, uint32_t count); + + /** + * 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. + * + * @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); + + /** + * A more gentle flavor of filash_driver_s::probe, performing + * setup with less noise. Generally, driver routines should test + * to seee if the bank has already been probed; if it has, the + * 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 + * it is programing the flash. + * + * @param bank - the bank to probe + * @returns ERROR_OK if successful; otherwise, an error code. + */ + int (*auto_probe)(struct flash_bank *bank); +}; + +#define FLASH_BANK_COMMAND_HANDLER(name) static __FLASH_BANK_COMMAND(name) + +/** + * 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. + */ +struct flash_driver *flash_driver_find_by_name(const char *name); + +#endif // FLASH_NOR_DRIVER_H diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c index be72b5c..7f71d83 100644 --- a/src/flash/nor/drivers.c +++ b/src/flash/nor/drivers.c @@ -19,7 +19,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include <flash/nor/core.h> +#include "imp.h" extern struct flash_driver lpc2000_flash; extern struct flash_driver lpc288x_flash; diff --git a/src/flash/nor/imp.h b/src/flash/nor/imp.h index 84ef871..4c849fe 100644 --- a/src/flash/nor/imp.h +++ b/src/flash/nor/imp.h @@ -21,6 +21,7 @@ // this is an internal header #include "core.h" +#include "driver.h" // common flash internals #include <flash/common.h> // almost all drivers will need this file commit d9dc604a4d790f557a7ba502babdabffa27eaa17 Author: Zachary T Welch <zw...@su...> Date: Fri Dec 4 14:06:20 2009 -0800 remove target.h from flash.h The flash.h header does not require the target.h header file, but its implementation source files do. Move it to flash/nor/imp.h. diff --git a/src/flash/flash.h b/src/flash/flash.h index 1e1be85..8cd50f6 100644 --- a/src/flash/flash.h +++ b/src/flash/flash.h @@ -27,7 +27,6 @@ #define FLASH_H #include <flash/common.h> -#include <target/target.h> struct image; diff --git a/src/flash/nor/aduc702x.c b/src/flash/nor/aduc702x.c index 6696912..1b9f5c0 100644 --- a/src/flash/nor/aduc702x.c +++ b/src/flash/nor/aduc702x.c @@ -23,11 +23,11 @@ #include "config.h" #endif -#include <flash/flash.h> -#include <target/armv4_5.h> +#include "imp.h" #include <helper/binarybuffer.h> #include <helper/time_support.h> #include <target/algorithm.h> +#include <target/armv4_5.h> static int aduc702x_build_sector_list(struct flash_bank *bank); diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c index dd4f347..1194e25 100644 --- a/src/flash/nor/at91sam3.c +++ b/src/flash/nor/at91sam3.c @@ -57,13 +57,9 @@ #endif -#include <stdio.h> -#include <string.h> -#include <stddef.h> -#include <helper/types.h> -#include <flash/flash.h> -#include <helper/membuf.h> +#include "imp.h" #include "at91sam3.h" +#include <helper/membuf.h> #include <helper/time_support.h> #define REG_NAME_WIDTH (12) diff --git a/src/flash/nor/at91sam7.c b/src/flash/nor/at91sam7.c index 3201737..97d6b56 100644 --- a/src/flash/nor/at91sam7.c +++ b/src/flash/nor/at91sam7.c @@ -49,6 +49,7 @@ #include "config.h" #endif +#include "imp.h" #include "at91sam7.h" #include <helper/binarybuffer.h> diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index fbc9277..6c2d17f 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -21,9 +21,9 @@ #include "config.h" #endif +#include "imp.h" #include "avrf.h" #include <target/avrt.h> -#include <flash/flash.h> /* AVR_JTAG_Instructions */ diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c index 61b5d4c..c00d65f 100644 --- a/src/flash/nor/cfi.c +++ b/src/flash/nor/cfi.c @@ -23,6 +23,7 @@ #include "config.h" #endif +#include "imp.h" #include "cfi.h" #include "non_cfi.h" #include <target/armv4_5.h> diff --git a/src/flash/nor/ecos.c b/src/flash/nor/ecos.c index 8f8f746..799015e 100644 --- a/src/flash/nor/ecos.c +++ b/src/flash/nor/ecos.c @@ -21,10 +21,10 @@ #include "config.h" #endif -#include <flash/flash.h> +#include "imp.h" #include <target/embeddedice.h> -#include <target/image.h> #include <target/algorithm.h> +#include <target/image.h> #if 0 diff --git a/src/flash/nor/faux.c b/src/flash/nor/faux.c index c996522..948f305 100644 --- a/src/flash/nor/faux.c +++ b/src/flash/nor/faux.c @@ -21,7 +21,7 @@ #include "config.h" #endif -#include <flash/flash.h> +#include "imp.h" #include <target/image.h> #include "hello.h" diff --git a/src/flash/nor/imp.h b/src/flash/nor/imp.h index ade7297..84ef871 100644 --- a/src/flash/nor/imp.h +++ b/src/flash/nor/imp.h @@ -21,6 +21,10 @@ // this is an internal header #include "core.h" +// common flash internals +#include <flash/common.h> +// almost all drivers will need this file +#include <target/target.h> /** * Adds a new NOR bank to the global list of banks. diff --git a/src/flash/nor/lpc2000.c b/src/flash/nor/lpc2000.c index 295e3e7..d824c37 100644 --- a/src/flash/nor/lpc2000.c +++ b/src/flash/nor/lpc2000.c @@ -25,10 +25,11 @@ #include "config.h" #endif +#include "imp.h" #include "lpc2000.h" -#include <target/armv7m.h> #include <helper/binarybuffer.h> #include <target/algorithm.h> +#include <target/armv7m.h> /* flash programming support for NXP LPC17xx and LPC2xxx devices diff --git a/src/flash/nor/lpc288x.c b/src/flash/nor/lpc288x.c index 252a813..5cb36d0 100644 --- a/src/flash/nor/lpc288x.c +++ b/src/flash/nor/lpc288x.c @@ -31,6 +31,7 @@ #include "config.h" #endif +#include "imp.h" #include "lpc288x.h" #include <helper/binarybuffer.h> diff --git a/src/flash/nor/lpc2900.c b/src/flash/nor/lpc2900.c index dc466f8..0b42d48 100644 --- a/src/flash/nor/lpc2900.c +++ b/src/flash/nor/lpc2900.c @@ -23,11 +23,11 @@ #endif -#include <target/image.h> -#include <flash/flash.h> +#include "imp.h" #include <helper/binarybuffer.h> -#include <target/armv4_5.h> #include <target/algorithm.h> +#include <target/armv4_5.h> +#include <target/image.h> /* 1024 bytes */ diff --git a/src/flash/nor/ocl.c b/src/flash/nor/ocl.c index 6e3ad1c..961537e 100644 --- a/src/flash/nor/ocl.c +++ b/src/flash/nor/ocl.c @@ -21,8 +21,8 @@ #include "config.h" #endif +#include "imp.h" #include "ocl.h" -#include <flash/flash.h> #include <target/embeddedice.h> diff --git a/src/flash/nor/pic32mx.c b/src/flash/nor/pic32mx.c index d2289b2..7d98af3 100644 --- a/src/flash/nor/pic32mx.c +++ b/src/flash/nor/pic32mx.c @@ -27,6 +27,7 @@ #include "config.h" #endif +#include "imp.h" #include "pic32mx.h" #include <target/mips32.h> diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c index f0028ea..3988542 100644 --- a/src/flash/nor/stellaris.c +++ b/src/flash/nor/stellaris.c @@ -28,10 +28,11 @@ #include "config.h" #endif +#include "imp.h" #include "stellaris.h" -#include <target/armv7m.h> #include <helper/binarybuffer.h> #include <target/algorithm.h> +#include <target/armv7m.h> #define DID0_VER(did0) ((did0 >> 28)&0x07) diff --git a/src/flash/nor/stm32x.c b/src/flash/nor/stm32x.c index 3792547..9e761f9 100644 --- a/src/flash/nor/stm32x.c +++ b/src/flash/nor/stm32x.c @@ -24,10 +24,11 @@ #include "config.h" #endif +#include "imp.h" #include "stm32x.h" -#include <target/armv7m.h> #include <helper/binarybuffer.h> #include <target/algorithm.h> +#include <target/armv7m.h> static int stm32x_mass_erase(struct flash_bank *bank); diff --git a/src/flash/nor/str7x.c b/src/flash/nor/str7x.c index c5a1c34..4f93ec9 100644 --- a/src/flash/nor/str7x.c +++ b/src/flash/nor/str7x.c @@ -24,6 +24,7 @@ #include "config.h" #endif +#include "imp.h" #include "str7x.h" #include <target/armv4_5.h> #include <helper/binarybuffer.h> diff --git a/src/flash/nor/str9x.c b/src/flash/nor/str9x.c index 045ab20..36096ff 100644 --- a/src/flash/nor/str9x.c +++ b/src/flash/nor/str9x.c @@ -27,6 +27,7 @@ #include "config.h" #endif +#include "imp.h" #include "str9x.h" #include <target/arm966e.h> #include <target/algorithm.h> diff --git a/src/flash/nor/str9xpec.c b/src/flash/nor/str9xpec.c index 87a4b06..734f2d1 100644 --- a/src/flash/nor/str9xpec.c +++ b/src/flash/nor/str9xpec.c @@ -24,6 +24,7 @@ #include "config.h" #endif +#include "imp.h" #include "str9xpec.h" #include <target/arm7_9_common.h> diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c index 5965934..7efcbd4 100644 --- a/src/flash/nor/tms470.c +++ b/src/flash/nor/tms470.c @@ -22,6 +22,7 @@ #endif #include "tms470.h" +#include "imp.h" /* ---------------------------------------------------------------------- diff --git a/src/server/gdb_server.h b/src/server/gdb_server.h index 0414975..05666a5 100644 --- a/src/server/gdb_server.h +++ b/src/server/gdb_server.h @@ -27,6 +27,7 @@ #define GDB_SERVER_H struct image; +#include <target/target.h> #define GDB_BUFFER_SIZE 16384 commit 1527272fb21beee7839335ea5587e879163d2ed1 Author: Zachary T Welch <zw...@su...> Date: Fri Dec 4 13:42:09 2009 -0800 split NOR and NAND flash headers Moves common flash errors to <flash/common.h> to decouple these two mostly unrelated trees of code. diff --git a/src/flash/common.h b/src/flash/common.h index e0dcdb3..4098873 100644 --- a/src/flash/common.h +++ b/src/flash/common.h @@ -19,7 +19,7 @@ #ifndef FLASH_COMMON_H #define FLASH_COMMON_H -#include <helper/types.h> +#include <helper/log.h> /** * Parses the optional '.index' portion of a flash bank identifier. @@ -36,4 +36,13 @@ unsigned get_flash_name_index(const char *name); */ bool flash_driver_name_matches(const char *name, const char *expected); +#define ERROR_FLASH_BANK_INVALID -900 +#define ERROR_FLASH_SECTOR_INVALID -901 +#define ERROR_FLASH_OPERATION_FAILED -902 +#define ERROR_FLASH_DST_OUT_OF_BANK -903 +#define ERROR_FLASH_DST_BREAKS_ALIGNMENT -904 +#define ERROR_FLASH_BUSY -905 +#define ERROR_FLASH_SECTOR_NOT_ERASED -906 +#define ERROR_FLASH_BANK_NOT_PROBED -907 + #endif // FLASH_COMMON_H diff --git a/src/flash/flash.h b/src/flash/flash.h index 5e31c48..1e1be85 100644 --- a/src/flash/flash.h +++ b/src/flash/flash.h @@ -26,8 +26,8 @@ #ifndef FLASH_H #define FLASH_H +#include <flash/common.h> #include <target/target.h> -#include <helper/log.h> struct image; @@ -349,13 +349,4 @@ struct flash_bank *get_flash_bank_by_num_noprobe(int num); */ struct flash_bank *get_flash_bank_by_addr(struct target *target, uint32_t addr); -#define ERROR_FLASH_BANK_INVALID (-900) -#define ERROR_FLASH_SECTOR_INVALID (-901) -#define ERROR_FLASH_OPERATION_FAILED (-902) -#define ERROR_FLASH_DST_OUT_OF_BANK (-903) -#define ERROR_FLASH_DST_BREAKS_ALIGNMENT (-904) -#define ERROR_FLASH_BUSY (-905) -#define ERROR_FLASH_SECTOR_NOT_ERASED (-906) -#define ERROR_FLASH_BANK_NOT_PROBED (-907) - #endif /* FLASH_H */ diff --git a/src/flash/nand.h b/src/flash/nand.h index 230cf50..f91deda 100644 --- a/src/flash/nand.h +++ b/src/flash/nand.h @@ -25,7 +25,9 @@ #ifndef NAND_H #define NAND_H -#include <flash/flash.h> +#include <flash/common.h> +// to be removed later +#include <target/target.h> struct nand_device; diff --git a/src/openocd.c b/src/openocd.c index 0ae0d19..b6dc010 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -34,6 +34,7 @@ #include <helper/configuration.h> #include <xsvf/xsvf.h> #include <svf/svf.h> +#include <flash/flash.h> #include <flash/nand.h> #include <pld/pld.h> #include <flash/mflash.h> commit 5fdee60fd4d38e59c7b5f7aca5ad50b90e7d61ee Author: Zachary T Welch <zw...@su...> Date: Fri Dec 4 04:37:27 2009 -0800 eliminate src/flash/flash.c Move remaining NOR flash implemenation into flash/nor/core.c Removes flash.c from the build, leaving only its header to split. diff --git a/src/flash/Makefile.am b/src/flash/Makefile.am index cda59e4..b5cd526 100644 --- a/src/flash/Makefile.am +++ b/src/flash/Makefile.am @@ -9,7 +9,6 @@ METASOURCES = AUTO noinst_LTLIBRARIES = libflash.la libflash_la_SOURCES = \ common.c \ - flash.c \ arm_nandio.c \ nand_ecc.c \ nand_ecc_kw.c \ diff --git a/src/flash/flash.c b/src/flash/flash.c deleted file mode 100644 index dfeea5b..0000000 --- a/src/flash/flash.c +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Dominic Rath * - * Dom...@gm... * - * * - * Copyright (C) 2007,2008 Ãyvind Harboe * - * oyv...@zy... * - * * - * Copyright (C) 2008 by Spencer Oliver * - * sp...@sp... * - * * - * 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 * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "flash.h" -#include "common.h" -#include <target/image.h> -#include <helper/time_support.h> - -struct flash_bank *flash_banks; - -struct flash_bank *get_flash_bank_by_num_noprobe(int num) -{ - struct flash_bank *p; - int i = 0; - - for (p = flash_banks; p; p = p->next) - { - if (i++ == num) - { - return p; - } - } - LOG_ERROR("flash bank %d does not exist", num); - return NULL; -} - -int flash_get_bank_count(void) -{ - struct flash_bank *p; - int i = 0; - for (p = flash_banks; p; p = p->next) - { - i++; - } - return i; -} - -struct flash_bank *get_flash_bank_by_name(const char *name) -{ - unsigned requested = get_flash_name_index(name); - unsigned found = 0; - - struct flash_bank *bank; - for (bank = flash_banks; NULL != bank; bank = bank->next) - { - if (strcmp(bank->name, name) == 0) - return bank; - if (!flash_driver_name_matches(bank->driver->name, name)) - continue; - if (++found < requested) - continue; - return bank; - } - return NULL; -} - -struct flash_bank *get_flash_bank_by_num(int num) -{ - struct flash_bank *p = get_flash_bank_by_num_noprobe(num); - int retval; - - if (p == NULL) - return NULL; - - retval = p->driver->auto_probe(p); - - if (retval != ERROR_OK) - { - LOG_ERROR("auto_probe failed %d\n", retval); - return NULL; - } - return p; -} - -/* lookup flash bank by address */ -struct flash_bank *get_flash_bank_by_addr(struct target *target, uint32_t addr) -{ - struct flash_bank *c; - - /* cycle through bank list */ - for (c = flash_banks; c; c = c->next) - { - int retval; - retval = c->driver->auto_probe(c); - - if (retval != ERROR_OK) - { - LOG_ERROR("auto_probe failed %d\n", retval); - return NULL; - } - /* check whether address belongs to this flash bank */ - if ((addr >= c->base) && (addr <= c->base + (c->size - 1)) && target == c->target) - return c; - } - LOG_ERROR("No flash at address 0x%08" PRIx32 "\n", addr); - return NULL; -} - -int default_flash_mem_blank_check(struct flash_bank *bank) -{ - struct target *target = bank->target; - const int buffer_size = 1024; - int i; - uint32_t nBytes; - int retval = ERROR_OK; - - if (bank->target->state != TARGET_HALTED) - { - LOG_ERROR("Target not halted"); - return ERROR_TARGET_NOT_HALTED; - } - - uint8_t *buffer = malloc(buffer_size); - - for (i = 0; i < bank->num_sectors; i++) - { - uint32_t j; - bank->sectors[i].is_erased = 1; - - for (j = 0; j < bank->sectors[i].size; j += buffer_size) - { - uint32_t chunk; - chunk = buffer_size; - if (chunk > (j - bank->sectors[i].size)) - { - chunk = (j - bank->sectors[i].size); - } - - retval = target_read_memory(target, bank->base + bank->sectors[i].offset + j, 4, chunk/4, buffer); - if (retval != ERROR_OK) - { - goto done; - } - - for (nBytes = 0; nBytes < chunk; nBytes++) - { - if (buffer[nBytes] != 0xFF) - { - bank->sectors[i].is_erased = 0; - break; - } - } - } - } - - done: - free(buffer); - - return retval; -} - -int default_flash_blank_check(struct flash_bank *bank) -{ - struct target *target = bank->target; - int i; - int retval; - int fast_check = 0; - uint32_t blank; - - if (bank->target->state != TARGET_HALTED) - { - LOG_ERROR("Target not halted"); - return ERROR_TARGET_NOT_HALTED; - } - - for (i = 0; i < bank->num_sectors; i++) - { - uint32_t address = bank->base + bank->sectors[i].offset; - uint32_t size = bank->sectors[i].size; - - if ((retval = target_blank_check_memory(target, address, size, &blank)) != ERROR_OK) - { - fast_check = 0; - break; - } - if (blank == 0xFF) - bank->sectors[i].is_erased = 1; - else - bank->sectors[i].is_erased = 0; - fast_check = 1; - } - - if (!fast_check) - { - LOG_USER("Running slow fallback erase check - add working memory"); - return default_flash_mem_blank_check(bank); - } - - return ERROR_OK; -} diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c index 0fff8ef..c2ea134 100644 --- a/src/flash/nor/core.c +++ b/src/flash/nor/core.c @@ -1,4 +1,7 @@ /*************************************************************************** + * Copyright (C) 2005 by Dominic Rath <Dom...@gm...> * + * Copyright (C) 2007,2008 Ãyvind Harboe <oyv...@zy...> * + * Copyright (C) 2008 by Spencer Oliver <sp...@sp...> * * Copyright (C) 2009 Zachary T Welch <zw...@su...> * * * * This program is free software; you can redistribute it and/or modify * @@ -20,12 +23,13 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif -#include <flash/flash.h> +#include <flash/common.h> +#include <flash/nor/core.h> #include <flash/nor/imp.h> #include <target/image.h> -// in flash.c, to be moved here -extern struct flash_bank *flash_banks; + +struct flash_bank *flash_banks; int flash_driver_erase(struct flash_bank *bank, int first, int last) { @@ -68,7 +72,6 @@ int flash_driver_write(struct flash_bank *bank, return retval; } - void flash_bank_add(struct flash_bank *bank) { /* put flash bank in linked list */ @@ -96,6 +99,186 @@ struct flash_bank *flash_bank_list(void) return flash_banks; } +struct flash_bank *get_flash_bank_by_num_noprobe(int num) +{ + struct flash_bank *p; + int i = 0; + + for (p = flash_banks; p; p = p->next) + { + if (i++ == num) + { + return p; + } + } + LOG_ERROR("flash bank %d does not exist", num); + return NULL; +} + +int flash_get_bank_count(void) +{ + struct flash_bank *p; + int i = 0; + for (p = flash_banks; p; p = p->next) + { + i++; + } + return i; +} + +struct flash_bank *get_flash_bank_by_name(const char *name) +{ + unsigned requested = get_flash_name_index(name); + unsigned found = 0; + + struct flash_bank *bank; + for (bank = flash_banks; NULL != bank; bank = bank->next) + { + if (strcmp(bank->name, name) == 0) + return bank; + if (!flash_driver_name_matches(bank->driver->name, name)) + continue; + if (++found < requested) + continue; + return bank; + } + return NULL; +} + +struct flash_bank *get_flash_bank_by_num(int num) +{ + struct flash_bank *p = get_flash_bank_by_num_noprobe(num); + int retval; + + if (p == NULL) + return NULL; + + retval = p->driver->auto_probe(p); + + if (retval != ERROR_OK) + { + LOG_ERROR("auto_probe failed %d\n", retval); + return NULL; + } + return p; +} + +/* lookup flash bank by address */ +struct flash_bank *get_flash_bank_by_addr(struct target *target, uint32_t addr) +{ + struct flash_bank *c; + + /* cycle through bank list */ + for (c = flash_banks; c; c = c->next) + { + int retval; + retval = c->driver->auto_probe(c); + + if (retval != ERROR_OK) + { + LOG_ERROR("auto_probe failed %d\n", retval); + return NULL; + } + /* check whether address belongs to this flash bank */ + if ((addr >= c->base) && (addr <= c->base + (c->size - 1)) && target == c->target) + return c; + } + LOG_ERROR("No flash at address 0x%08" PRIx32 "\n", addr); + return NULL; +} + +int default_flash_mem_blank_check(struct flash_bank *bank) +{ + struct target *target = bank->target; + const int buffer_size = 1024; + int i; + uint32_t nBytes; + int retval = ERROR_OK; + + if (bank->target->state != TARGET_HALTED) + { + LOG_ERROR("Target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + uint8_t *buffer = malloc(buffer_size); + + for (i = 0; i < bank->num_sectors; i++) + { + uint32_t j; + bank->sectors[i].is_erased = 1; + + for (j = 0; j < bank->sectors[i].size; j += buffer_size) + { + uint32_t chunk; + chunk = buffer_size; + if (chunk > (j - bank->sectors[i].size)) + { + chunk = (j - bank->sectors[i].size); + } + + retval = target_read_memory(target, bank->base + bank->sectors[i].offset + j, 4, chunk/4, buffer); + if (retval != ERROR_OK) + { + goto done; + } + + for (nBytes = 0; nBytes < chunk; nBytes++) + { + if (buffer[nBytes] != 0xFF) + { + bank->sectors[i].is_erased = 0; + break; + } + } + } + } + + done: + free(buffer); + + return retval; +} + +int default_flash_blank_check(struct flash_bank *bank) +{ + struct target *target = bank->target; + int i; + int retval; + int fast_check = 0; + uint32_t blank; + + if (bank->target->state != TARGET_HALTED) + { + LOG_ERROR("Target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + for (i = 0; i < bank->num_sectors; i++) + { + uint32_t address = bank->base + bank->sectors[i].offset; + uint32_t size = bank->sectors[i].size; + + if ((retval = target_blank_check_memory(target, address, size, &blank)) != ERROR_OK) + { + fast_check = 0; + break; + } + if (blank == 0xFF) + bank->sectors[i].is_erased = 1; + else + bank->sectors[i].is_erased = 0; + fast_check = 1; + } + + if (!fast_check) + { + LOG_USER("Running slow fallback erase check - add working memory"); + return default_flash_mem_blank_check(bank); + } + + return ERROR_OK; +} /* erase given flash region, selects proper bank according to target and address */ static int flash_iterate_address_range(struct target *target, uint32_t addr, uint32_t length, int (*callback)(struct flash_bank *bank, int first, int last)) commit c90702eaa7e7c4e7dd6d1efea61387a62748cfad Author: Zachary T Welch <zw...@su...> Date: Fri Dec 4 04:10:42 2009 -0800 add flash/nor/drivers.c Encapsulates access to the flash_drivers array, providing a base of operations for future dynamic driver module loading features. diff --git a/src/flash/flash.c b/src/flash/flash.c index 2cf56ed..dfeea5b 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -32,49 +32,6 @@ #include <target/image.h> #include <helper/time_support.h> -/* flash drivers - */ -extern struct flash_driver lpc2000_flash; -extern struct flash_driver lpc288x_flash; -extern struct flash_driver lpc2900_flash; -extern struct flash_driver cfi_flash; -extern struct flash_dri... [truncated message content] |