mflash.c
FLASH_SRCS = \
+ common.c \
cfi.c \
non_cfi.c \
faux.c \
at91sam3.h \
avrf.h \
cfi.h \
+ common.h \
flash.h \
lpc2000.h \
lpc288x.h \
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net> *
+ * *
+ * 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 "common.h"
+#include "log.h"
+
+unsigned get_flash_name_index(const char *name)
+{
+ const char *index = strchr(name, '.');
+ if (NULL == index)
+ return 0;
+ unsigned requested;
+ int retval = parse_uint(index + 1, &requested);
+ // detect parsing error by forcing past end of bank list
+ return (ERROR_OK == retval) ? requested : ~0U;
+}
+
+bool flash_driver_name_matches(const char *name, const char *expected)
+{
+ unsigned blen = strlen(name);
+ // only match up to the length of the driver name...
+ if (strncmp(name, expected, blen) != 0)
+ return false;
+
+ // ...then check that name terminates at this spot.
+ return expected[blen] == '.' || expected[blen] == '\0';
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net> *
+ * *
+ * 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_COMMON_H
+#define FLASH_COMMON_H
+
+#include "types.h"
+
+/**
+ * Parses the optional '.index' portion of a flash bank identifier.
+ * @param name The desired driver name, passed by the user.
+ * @returns The parsed index request, or 0 if not present. If the
+ * name provides a suffix but it does not parse as an unsigned integer,
+ * the routine returns ~0U. This will prevent further matching.
+ */
+unsigned get_flash_name_index(const char *name);
+/**
+ * Attempt to match the @c expected name with the @c name of a driver.
+ * @param name The name of the driver (from the bank's device structure).
+ * @param expected The expected driver name, passed by the user.
+ */
+bool flash_driver_name_matches(const char *name, const char *expected);
+
+#endif // FLASH_COMMON_H
#endif
#include "flash.h"
+#include "common.h"
#include "image.h"
#include "time_support.h"
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 (!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);
return p;
}
-COMMAND_HELPER(flash_command_get_bank_by_num,
- unsigned name_index, struct flash_bank **bank)
+COMMAND_HELPER(flash_command_get_bank_by_num, unsigned name_index,
+ struct flash_bank **bank)
{
const char *name = CMD_ARGV[name_index];
+ *bank = get_flash_bank_by_name(name);
+ if (*bank)
+ return ERROR_OK;
+
unsigned bank_num;
COMMAND_PARSE_NUMBER(uint, name, bank_num);
*/
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.
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 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.
#endif
#include "nand.h"
+#include "common.h"
#include "time_support.h"
#include "fileio.h"
return ERROR_OK;
}
+struct nand_device *get_nand_device_by_name(const char *name)
+{
+ unsigned requested = get_flash_name_index(name);
+ unsigned found = 0;
+
+ struct nand_device *nand;
+ for (nand = nand_devices; NULL != nand; nand = nand->next)
+ {
+ if (!flash_driver_name_matches(nand->controller->name, name))
+ continue;
+ if (++found < requested)
+ continue;
+ return nand;
+ }
+ return NULL;
+}
+
struct nand_device *get_nand_device_by_num(int num)
{
struct nand_device *p;
struct nand_device **nand)
{
const char *str = CMD_ARGV[name_index];
+ *nand = get_nand_device_by_name(str);
+ if (*nand)
+ return ERROR_OK;
+
unsigned num;
COMMAND_PARSE_NUMBER(uint, str, num);
*nand = get_nand_device_by_num(num);
if (!*nand) {
- command_print(CMD_CTX, "NAND flash device '#%s' is out of bounds", str);
+ command_print(CMD_CTX, "NAND flash device '%s' not found", str);
return ERROR_INVALID_ARGUMENTS;
}
return ERROR_OK;
};
+/**
+ * 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 davinci banks are defined, then 'davinci.1' refers
+ * to the second (e.g. DM355EVM).
+ */
+struct nand_device *get_nand_device_by_name(const char *name);
+
struct nand_device *get_nand_device_by_num(int num);
int nand_read_page_raw(struct nand_device *nand, uint32_t page,