]> git.sur5r.net Git - openocd/blob - src/flash/nor/core.c
a69c3f49bff67c65b112d3543917ccbc71c166ff
[openocd] / src / flash / nor / core.c
1 /***************************************************************************
2  *   Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net>             *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <flash/flash.h>
24 #include <flash/nor/imp.h>
25
26 // in flash.c, to be moved here
27 extern struct flash_driver *flash_drivers[];
28 extern struct flash_bank *flash_banks;
29
30 struct flash_driver *flash_driver_find_by_name(const char *name)
31 {
32         for (unsigned i = 0; flash_drivers[i]; i++)
33         {
34                 if (strcmp(name, flash_drivers[i]->name) == 0)
35                         return flash_drivers[i];
36         }
37         return NULL;
38 }
39
40 void flash_bank_add(struct flash_bank *bank)
41 {
42         /* put flash bank in linked list */
43         unsigned bank_num = 0;
44         if (flash_banks)
45         {
46                 /* find last flash bank */
47                 struct flash_bank *p = flash_banks;
48                 while (NULL != p->next)
49                 {
50                         bank_num += 1;
51                         p = p->next;
52                 }
53                 p->next = bank;
54                 bank_num += 1;
55         }
56         else
57                 flash_banks = bank;
58
59         bank->bank_number = bank_num;
60 }
61
62 struct flash_bank *flash_bank_list(void)
63 {
64         return flash_banks;
65 }