From: Spencer O. <nt...@us...> - 2010-05-27 22:32:22
|
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 215353ef67434e41b13f8948dc7dceefc110e3fe (commit) via ee4106ee995a1fc81778f4ebd496d6782e592b63 (commit) via 94dc7c0a939c042c71767b5cbdc1e1327ccecbea (commit) via 5319ccd7eb4761f1481dcbb041b256848efc005e (commit) from ef72484b785ec7462a0415afea679d08b864c7fb (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 215353ef67434e41b13f8948dc7dceefc110e3fe Author: Spencer Oliver <nt...@us...> Date: Mon May 24 12:32:58 2010 +0100 flash: virtual driver update for get_flash_bank_by_name_noprobe Make sure we do not probe a flash when getting info. Signed-off-by: Spencer Oliver <nt...@us...> diff --git a/src/flash/nor/virtual.c b/src/flash/nor/virtual.c index 4908c0c..eb1885e 100644 --- a/src/flash/nor/virtual.c +++ b/src/flash/nor/virtual.c @@ -27,7 +27,7 @@ static struct flash_bank* virtual_get_master_bank(struct flash_bank *bank) { struct flash_bank* master_bank; - master_bank = get_flash_bank_by_name(bank->driver_priv); + master_bank = get_flash_bank_by_name_noprobe(bank->driver_priv); if (master_bank == NULL) { LOG_ERROR("master flash bank '%s' does not exist", (char*)bank->driver_priv); } @@ -61,7 +61,7 @@ FLASH_BANK_COMMAND_HANDLER(virtual_flash_bank_command) /* get the master flash bank */ const char *bank_name = CMD_ARGV[6]; - struct flash_bank *master_bank = get_flash_bank_by_name(bank_name); + struct flash_bank *master_bank = get_flash_bank_by_name_noprobe(bank_name); if (master_bank == NULL) { commit ee4106ee995a1fc81778f4ebd496d6782e592b63 Author: Spencer Oliver <nt...@us...> Date: Mon May 24 12:30:29 2010 +0100 nor: add get_flash_bank_by_name autoprobe When a flash cmd is called using the flash name the autoprobe function is not called. autoprobe is called if flash_command_get_bank falls through to get_flash_bank_by_num. This makes both get_flash_bank_by_name and get_flash_bank_by_num behave the same. Signed-off-by: Spencer Oliver <nt...@us...> diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c index 00f73f2..1bd09b4 100644 --- a/src/flash/nor/core.c +++ b/src/flash/nor/core.c @@ -178,7 +178,7 @@ int flash_get_bank_count(void) return i; } -struct flash_bank *get_flash_bank_by_name(const char *name) +struct flash_bank *get_flash_bank_by_name_noprobe(const char *name) { unsigned requested = get_flash_name_index(name); unsigned found = 0; @@ -197,6 +197,26 @@ struct flash_bank *get_flash_bank_by_name(const char *name) return NULL; } +struct flash_bank *get_flash_bank_by_name(const char *name) +{ + struct flash_bank *bank; + int retval; + + bank = get_flash_bank_by_name_noprobe(name); + if (bank != NULL) + { + retval = bank->driver->auto_probe(bank); + + if (retval != ERROR_OK) + { + LOG_ERROR("auto_probe failed %d\n", retval); + return NULL; + } + } + + return bank; +} + int get_flash_bank_by_num(int num, struct flash_bank **bank) { struct flash_bank *p = get_flash_bank_by_num_noprobe(num); @@ -660,7 +680,7 @@ int flash_write_unlock(struct target *target, struct image *image, intptr_t diff = (intptr_t)sections[section] - (intptr_t)image->sections; int t_section_num = diff / sizeof(struct imageection); - LOG_DEBUG("image_read_section: section = %d, t_section_num = %d, section_offset = %d, buffer_size = %d, size_read = %d", + LOG_DEBUG("image_read_section: section = %d, t_section_num = %d, section_offset = %d, buffer_size = %d, size_read = %d", (int)section, (int)t_section_num, (int)section_offset, (int)buffer_size, (int)size_read); if ((retval = image_read_section(image, t_section_num, section_offset, diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h index a35f64f..17f1c53 100644 --- a/src/flash/nor/core.h +++ b/src/flash/nor/core.h @@ -170,7 +170,15 @@ int default_flash_mem_blank_check(struct flash_bank *bank); */ 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. + * 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_noprobe(const char *name); +/** + * Returns the flash bank like get_flash_bank_by_name(), without probing. * @param num The flash bank number. * @param bank returned bank if fn returns ERROR_OK * @returns ERROR_OK if successful diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 80d9a27..b3dbd7b 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -796,7 +796,7 @@ COMMAND_HANDLER(handle_flash_bank_command) } /* check the flash bank name is unique */ - if (get_flash_bank_by_name(bank_name) != NULL) + if (get_flash_bank_by_name_noprobe(bank_name) != NULL) { /* flash bank name already exists */ LOG_ERROR("flash bank name '%s' already exists", bank_name); commit 94dc7c0a939c042c71767b5cbdc1e1327ccecbea Author: Spencer Oliver <nt...@us...> Date: Mon May 24 11:43:09 2010 +0100 cfg: add pic32 virtual banks make use of the new virtual bank flash driver. Signed-off-by: Spencer Oliver <nt...@us...> diff --git a/tcl/target/pic32mx.cfg b/tcl/target/pic32mx.cfg index 0b99cdb..202668b 100644 --- a/tcl/target/pic32mx.cfg +++ b/tcl/target/pic32mx.cfg @@ -69,8 +69,15 @@ $_TARGETNAME configure -event reset-init { set _FLASHNAME $_CHIPNAME.flash0 flash bank $_FLASHNAME pic32mx 0x1fc00000 0 0 0 $_TARGETNAME +# add virtual banks for kseg0 and kseg1 +flash bank vbank0 virtual 0xbfc00000 0 0 0 $_TARGETNAME $_FLASHNAME +flash bank vbank1 virtual 0x9fc00000 0 0 0 $_TARGETNAME $_FLASHNAME + set _FLASHNAME $_CHIPNAME.flash1 flash bank $_FLASHNAME pic32mx 0x1d000000 0 0 0 $_TARGETNAME +# add virtual banks for kseg0 and kseg1 +flash bank vbank2 virtual 0xbd000000 0 0 0 $_TARGETNAME $_FLASHNAME +flash bank vbank3 virtual 0x9d000000 0 0 0 $_TARGETNAME $_FLASHNAME # For more information about the configuration files, take a look at: # openocd.texi commit 5319ccd7eb4761f1481dcbb041b256848efc005e Author: Spencer Oliver <nt...@us...> Date: Mon May 24 11:41:50 2010 +0100 flash: add virtual flash bank driver This adds a virtual flash bank driver that allows virtual banks to be defined that refer to an existing flash bank. For example the real address for bank0 on the pic32 is 0x1fc00000 but the user program will either be in kseg0 (0xbfc00000) or kseg1 (0x9fc00000). This also means that gdb will be aware of all the read only flash addresses. Signed-off-by: Spencer Oliver <nt...@us...> diff --git a/doc/openocd.texi b/doc/openocd.texi index c95803a..a3ca124 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4672,6 +4672,26 @@ the flash clock. @end deffn @end deffn +@deffn {Flash Driver} virtual +This is a special driver that maps a previously defined bank to another +address. All bank settings will be copied from the master physical bank. + +The @var{virtual} driver defines one mandatory parameters, + +@itemize +@item @var{master_bank} The bank that this virtual address refers to. +@end itemize + +So in the following example addresses 0xbfc00000 and 0x9fc00000 refer to +the flash bank defined at address 0x1fc00000. Any cmds executed on +the virtual banks are actually performed on the physical banks. +@example +flash bank $_FLASHNAME pic32mx 0x1fc00000 0 0 0 $_TARGETNAME +flash bank vbank0 virtual 0xbfc00000 0 0 0 $_TARGETNAME $_FLASHNAME +flash bank vbank1 virtual 0x9fc00000 0 0 0 $_TARGETNAME $_FLASHNAME +@end example +@end deffn + @subsection str9xpec driver @cindex str9xpec diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am index 5d0a4df..eec6f50 100644 --- a/src/flash/nor/Makefile.am +++ b/src/flash/nor/Makefile.am @@ -28,7 +28,8 @@ NOR_DRIVERS = \ str7x.c \ str9x.c \ str9xpec.c \ - tms470.c + tms470.c \ + virtual.c noinst_HEADERS = \ at91sam7.h \ diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c index 3e09a00..68f2f88 100644 --- a/src/flash/nor/drivers.c +++ b/src/flash/nor/drivers.c @@ -39,6 +39,7 @@ extern struct flash_driver ocl_flash; extern struct flash_driver pic32mx_flash; extern struct flash_driver avr_flash; extern struct flash_driver faux_flash; +extern struct flash_driver virtual_flash; /** * The list of built-in flash drivers. @@ -63,6 +64,7 @@ static struct flash_driver *flash_drivers[] = { &pic32mx_flash, &avr_flash, &faux_flash, + &virtual_flash, NULL, }; diff --git a/src/flash/nor/virtual.c b/src/flash/nor/virtual.c new file mode 100644 index 0000000..4908c0c --- /dev/null +++ b/src/flash/nor/virtual.c @@ -0,0 +1,244 @@ +/*************************************************************************** + * Copyright (C) 2010 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 "imp.h" + +static struct flash_bank* virtual_get_master_bank(struct flash_bank *bank) +{ + struct flash_bank* master_bank; + + master_bank = get_flash_bank_by_name(bank->driver_priv); + if (master_bank == NULL) { + LOG_ERROR("master flash bank '%s' does not exist", (char*)bank->driver_priv); + } + + return master_bank; +} + +static void virtual_update_bank_info(struct flash_bank *bank) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + + if (master_bank == NULL) { + return; + } + + /* update the info we do not have */ + bank->size = master_bank->size; + bank->chip_width = master_bank->chip_width; + bank->bus_width = master_bank->bus_width; + bank->num_sectors = master_bank->num_sectors; + bank->sectors = master_bank->sectors; +} + +FLASH_BANK_COMMAND_HANDLER(virtual_flash_bank_command) +{ + if (CMD_ARGC < 7) + { + LOG_WARNING("incomplete flash_bank virtual configuration"); + return ERROR_FLASH_OPERATION_FAILED; + } + + /* get the master flash bank */ + const char *bank_name = CMD_ARGV[6]; + struct flash_bank *master_bank = get_flash_bank_by_name(bank_name); + + if (master_bank == NULL) + { + LOG_ERROR("master flash bank '%s' does not exist", bank_name); + return ERROR_FLASH_OPERATION_FAILED; + } + + /* save master bank name - use this to get settings later */ + bank->driver_priv = strdup(bank_name); + + return ERROR_OK; +} + +static int virtual_protect(struct flash_bank *bank, int set, int first, int last) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->protect(master_bank, set, + first, last)) != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int virtual_protect_check(struct flash_bank *bank) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->protect_check(master_bank)) != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int virtual_erase(struct flash_bank *bank, int first, int last) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->erase(master_bank, + first, last)) != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int virtual_write(struct flash_bank *bank, uint8_t *buffer, + uint32_t offset, uint32_t count) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->write(master_bank, buffer, + offset, count)) != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int virtual_probe(struct flash_bank *bank) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->probe(master_bank)) != ERROR_OK) + return retval; + + /* update the info we do not have */ + virtual_update_bank_info(bank); + + return ERROR_OK; +} + +static int virtual_auto_probe(struct flash_bank *bank) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->auto_probe(master_bank)) != ERROR_OK) + return retval; + + /* update the info we do not have */ + virtual_update_bank_info(bank); + + return ERROR_OK; +} + +static int virtual_info(struct flash_bank *bank, char *buf, int buf_size) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + snprintf(buf, buf_size, "%s driver for flash bank %s at 0x%8.8" PRIx32 "", + bank->driver->name, master_bank->name, master_bank->base); + + return ERROR_OK; +} + +int virtual_blank_check(struct flash_bank *bank) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->erase_check(master_bank)) != ERROR_OK) + return retval; + + return ERROR_OK; +} + +int virtual_flash_read(struct flash_bank *bank, + uint8_t *buffer, uint32_t offset, uint32_t count) +{ + struct flash_bank *master_bank = virtual_get_master_bank(bank); + int retval; + + if (master_bank == NULL) { + return ERROR_FLASH_OPERATION_FAILED; + } + + /* call master handler */ + if ((retval = master_bank->driver->read(master_bank, buffer, + offset, count)) != ERROR_OK) + return retval; + + return ERROR_OK; +} + +struct flash_driver virtual_flash = { + .name = "virtual", + .flash_bank_command = virtual_flash_bank_command, + .erase = virtual_erase, + .protect = virtual_protect, + .write = virtual_write, + .read = virtual_flash_read, + .probe = virtual_probe, + .auto_probe = virtual_auto_probe, + .erase_check = virtual_blank_check, + .protect_check = virtual_protect_check, + .info = virtual_info, +}; ----------------------------------------------------------------------- Summary of changes: doc/openocd.texi | 20 ++++ src/flash/nor/Makefile.am | 3 +- src/flash/nor/core.c | 24 ++++- src/flash/nor/core.h | 10 ++- src/flash/nor/drivers.c | 2 + src/flash/nor/tcl.c | 2 +- src/flash/nor/virtual.c | 244 +++++++++++++++++++++++++++++++++++++++++++++ tcl/target/pic32mx.cfg | 7 ++ 8 files changed, 307 insertions(+), 5 deletions(-) create mode 100644 src/flash/nor/virtual.c hooks/post-receive -- Main OpenOCD repository |