summaryrefslogtreecommitdiff
path: root/src/flash
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2010-12-31 19:46:01 +0800
committerØyvind Harboe <oyvind.harboe@zylin.com>2011-01-02 19:56:59 +0100
commit5f3603b8ef732311516dcdad43261ca668e20626 (patch)
treeefb9f1b9f6a4de3269f549134d180ccb50942651 /src/flash
parent21a1c6ec33f87b6285e47ad6597cd49ad89a9485 (diff)
downloadopenocd_libswd-5f3603b8ef732311516dcdad43261ca668e20626.tar.gz
openocd_libswd-5f3603b8ef732311516dcdad43261ca668e20626.tar.bz2
openocd_libswd-5f3603b8ef732311516dcdad43261ca668e20626.tar.xz
openocd_libswd-5f3603b8ef732311516dcdad43261ca668e20626.zip
NAND/TCL: prepare for common "target" reference
Every NAND driver keeps private copy of "target" structure. Prepare infostructure to move private "target" copy in common/shared struct nand_device. Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/flash')
-rw-r--r--src/flash/nand/core.h1
-rw-r--r--src/flash/nand/tcl.c28
2 files changed, 26 insertions, 3 deletions
diff --git a/src/flash/nand/core.h b/src/flash/nand/core.h
index 709c37b3..73fd0edd 100644
--- a/src/flash/nand/core.h
+++ b/src/flash/nand/core.h
@@ -60,6 +60,7 @@ struct nand_ecclayout {
struct nand_device
{
const char *name;
+ struct target *target;
struct nand_flash_controller *controller;
void *controller_priv;
struct nand_manufacturer *manufacturer;
diff --git a/src/flash/nand/tcl.c b/src/flash/nand/tcl.c
index 70584fff..e4bfb4d1 100644
--- a/src/flash/nand/tcl.c
+++ b/src/flash/nand/tcl.c
@@ -27,6 +27,7 @@
#include "core.h"
#include "imp.h"
#include "fileio.h"
+#include <target/target.h>
// to be removed
extern struct nand_device *nand_devices;
@@ -537,16 +538,37 @@ COMMAND_HANDLER(handle_nand_list_drivers)
static COMMAND_HELPER(create_nand_device, const char *bank_name,
struct nand_flash_controller *controller)
{
+ struct nand_device *c;
+ struct target *target;
+ int retval;
+
+ if (CMD_ARGC < 2)
+ {
+ LOG_ERROR("missing target");
+ return ERROR_COMMAND_ARGUMENT_INVALID;
+ }
+ target = get_target(CMD_ARGV[1]);
+ if (!target) {
+ LOG_ERROR("invalid target %s", CMD_ARGV[1]);
+ return ERROR_COMMAND_ARGUMENT_INVALID;
+ }
+
if (NULL != controller->commands)
{
- int retval = register_commands(CMD_CTX, NULL,
+ retval = register_commands(CMD_CTX, NULL,
controller->commands);
if (ERROR_OK != retval)
return retval;
}
- struct nand_device *c = malloc(sizeof(struct nand_device));
+ c = malloc(sizeof(struct nand_device));
+ if (c == NULL)
+ {
+ LOG_ERROR("End of memory");
+ return ERROR_FAIL;
+ }
c->name = strdup(bank_name);
+ c->target = target;
c->controller = controller;
c->controller_priv = NULL;
c->manufacturer = NULL;
@@ -557,7 +579,7 @@ static COMMAND_HELPER(create_nand_device, const char *bank_name,
c->use_raw = 0;
c->next = NULL;
- int retval = CALL_COMMAND_HANDLER(controller->nand_device_command, c);
+ retval = CALL_COMMAND_HANDLER(controller->nand_device_command, c);
if (ERROR_OK != retval)
{
LOG_ERROR("'%s' driver rejected nand flash", controller->name);