add flash/nor/drivers.c
authorZachary T Welch <zw@superlucidity.net>
Fri, 4 Dec 2009 12:10:42 +0000 (04:10 -0800)
committerZachary T Welch <zw@superlucidity.net>
Sat, 5 Dec 2009 00:56:23 +0000 (16:56 -0800)
Encapsulates access to the flash_drivers array, providing a base
of operations for future dynamic driver module loading features.

src/flash/flash.c
src/flash/nor/Makefile.am
src/flash/nor/core.c
src/flash/nor/drivers.c [new file with mode: 0644]

index 2cf56ed57b9a250bbce76e20c258514132afacf0..dfeea5b0d24049db7080aa35501be54bdba8c353 100644 (file)
 #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_driver at91sam3_flash;
-extern struct flash_driver at91sam7_flash;
-extern struct flash_driver str7x_flash;
-extern struct flash_driver str9x_flash;
-extern struct flash_driver aduc702x_flash;
-extern struct flash_driver stellaris_flash;
-extern struct flash_driver str9xpec_flash;
-extern struct flash_driver stm32x_flash;
-extern struct flash_driver tms470_flash;
-extern struct flash_driver ecosflash_flash;
-extern struct flash_driver ocl_flash;
-extern struct flash_driver pic32mx_flash;
-extern struct flash_driver avr_flash;
-extern struct flash_driver faux_flash;
-
-struct flash_driver *flash_drivers[] = {
-       &lpc2000_flash,
-       &lpc288x_flash,
-       &lpc2900_flash,
-       &cfi_flash,
-       &at91sam7_flash,
-       &at91sam3_flash,
-       &str7x_flash,
-       &str9x_flash,
-       &aduc702x_flash,
-       &stellaris_flash,
-       &str9xpec_flash,
-       &stm32x_flash,
-       &tms470_flash,
-       &ecosflash_flash,
-       &ocl_flash,
-       &pic32mx_flash,
-       &avr_flash,
-       &faux_flash,
-       NULL,
-};
-
 struct flash_bank *flash_banks;
 
 struct flash_bank *get_flash_bank_by_num_noprobe(int num)
index 67a5e558bf40da36879362de059dc4fb34555cb5..bafe424fb6c64eb8d871e0f3419869fa0fda279e 100644 (file)
@@ -4,7 +4,8 @@ noinst_LTLIBRARIES = libocdflashnor.la
 libocdflashnor_la_SOURCES = \
        core.c \
        tcl.c \
-       $(NOR_DRIVERS)
+       $(NOR_DRIVERS) \
+       drivers.c
 
 NOR_DRIVERS = \
        aduc702x.c \
index 2dbf1142fed2ef6b3b793b4d1fde777624e53b16..0fff8efc7e1361fefbdd2469203227cbacd2c594 100644 (file)
 #include <target/image.h>
 
 // in flash.c, to be moved here
-extern struct flash_driver *flash_drivers[];
 extern struct flash_bank *flash_banks;
 
-struct flash_driver *flash_driver_find_by_name(const char *name)
-{
-       for (unsigned i = 0; flash_drivers[i]; i++)
-       {
-               if (strcmp(name, flash_drivers[i]->name) == 0)
-                       return flash_drivers[i];
-       }
-       return NULL;
-}
-
 int flash_driver_erase(struct flash_bank *bank, int first, int last)
 {
        int retval;
diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c
new file mode 100644 (file)
index 0000000..be72b5c
--- /dev/null
@@ -0,0 +1,77 @@
+/***************************************************************************
+ *   Copyright (C) 2009 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 <flash/nor/core.h>
+
+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_driver at91sam3_flash;
+extern struct flash_driver at91sam7_flash;
+extern struct flash_driver str7x_flash;
+extern struct flash_driver str9x_flash;
+extern struct flash_driver aduc702x_flash;
+extern struct flash_driver stellaris_flash;
+extern struct flash_driver str9xpec_flash;
+extern struct flash_driver stm32x_flash;
+extern struct flash_driver tms470_flash;
+extern struct flash_driver ecosflash_flash;
+extern struct flash_driver ocl_flash;
+extern struct flash_driver pic32mx_flash;
+extern struct flash_driver avr_flash;
+extern struct flash_driver faux_flash;
+
+/**
+ * The list of built-in flash drivers.
+ * @todo Make this dynamically extendable with loadable modules.
+ */
+struct flash_driver *flash_drivers[] = {
+       &lpc2000_flash,
+       &lpc288x_flash,
+       &lpc2900_flash,
+       &cfi_flash,
+       &at91sam7_flash,
+       &at91sam3_flash,
+       &str7x_flash,
+       &str9x_flash,
+       &aduc702x_flash,
+       &stellaris_flash,
+       &str9xpec_flash,
+       &stm32x_flash,
+       &tms470_flash,
+       &ecosflash_flash,
+       &ocl_flash,
+       &pic32mx_flash,
+       &avr_flash,
+       &faux_flash,
+       NULL,
+};
+
+struct flash_driver *flash_driver_find_by_name(const char *name)
+{
+       for (unsigned i = 0; flash_drivers[i]; i++)
+       {
+               if (strcmp(name, flash_drivers[i]->name) == 0)
+                       return flash_drivers[i];
+       }
+       return NULL;
+}