- "flash write_binary" is now "flash write_bank" to clarify the focus of the
[fw/openocd] / src / flash / flash.h
1 /***************************************************************************\r
2  *   Copyright (C) 2005 by Dominic Rath                                    *\r
3  *   Dominic.Rath@gmx.de                                                   *\r
4  *                                                                         *\r
5  *   This program is free software; you can redistribute it and/or modify  *\r
6  *   it under the terms of the GNU General Public License as published by  *\r
7  *   the Free Software Foundation; either version 2 of the License, or     *\r
8  *   (at your option) any later version.                                   *\r
9  *                                                                         *\r
10  *   This program is distributed in the hope that it will be useful,       *\r
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *\r
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *\r
13  *   GNU General Public License for more details.                          *\r
14  *                                                                         *\r
15  *   You should have received a copy of the GNU General Public License     *\r
16  *   along with this program; if not, write to the                         *\r
17  *   Free Software Foundation, Inc.,                                       *\r
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *\r
19  ***************************************************************************/\r
20 #ifndef FLASH_H\r
21 #define FLASH_H\r
22 \r
23 #include "target.h"\r
24 #include "image.h"\r
25 \r
26 #define FLASH_MAX_ERROR_STR     (128)\r
27 \r
28 typedef struct flash_sector_s\r
29 {\r
30         u32 offset;\r
31         u32 size;\r
32         int is_erased;\r
33         int is_protected;\r
34 } flash_sector_t;\r
35 \r
36 struct flash_bank_s;\r
37 \r
38 typedef struct flash_driver_s\r
39 {\r
40         char *name;\r
41         int (*register_commands)(struct command_context_s *cmd_ctx);\r
42         int (*flash_bank_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);\r
43         /* low level flash erase. Only invoke from flash_driver_erase()\r
44          * \r
45          * Will only be invoked when target is halted. \r
46          */\r
47         int (*erase)(struct flash_bank_s *bank, int first, int last);\r
48         /* invoked only from flash_driver_protect().\r
49          *  \r
50          * Only invoked if target is halted\r
51          */\r
52         int (*protect)(struct flash_bank_s *bank, int set, int first, int last);\r
53         /* low level flash write. Will only be invoked if the target is halted.\r
54          * use the flash_driver_write() wrapper to invoke.\r
55          */\r
56         int (*write)(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);\r
57         int (*probe)(struct flash_bank_s *bank);\r
58         int (*erase_check)(struct flash_bank_s *bank);\r
59         int (*protect_check)(struct flash_bank_s *bank);\r
60         int (*info)(struct flash_bank_s *bank, char *buf, int buf_size);\r
61         int (*auto_probe)(struct flash_bank_s *bank);\r
62 } flash_driver_t;\r
63 \r
64 typedef struct flash_bank_s\r
65 {\r
66         target_t *target;\r
67         flash_driver_t *driver;\r
68         void *driver_priv;\r
69         u32 base;\r
70         u32 size;\r
71         int chip_width;\r
72         int bus_width;\r
73         int num_sectors;\r
74         flash_sector_t *sectors;\r
75         struct flash_bank_s *next;\r
76 } flash_bank_t;\r
77 \r
78 extern int flash_register_commands(struct command_context_s *cmd_ctx);\r
79 extern int flash_init_drivers(struct command_context_s *cmd_ctx);\r
80 \r
81 extern int flash_erase_address_range(target_t *target, u32 addr, u32 length);\r
82 extern int flash_write(target_t *target, image_t *image, u32 *written, int erase);\r
83 extern void flash_set_dirty(void);\r
84 \r
85 extern flash_bank_t *get_flash_bank_by_num(int num);\r
86 extern flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr);\r
87 \r
88 #define         ERROR_FLASH_BANK_INVALID                (-900)\r
89 #define         ERROR_FLASH_SECTOR_INVALID              (-901)\r
90 #define         ERROR_FLASH_OPERATION_FAILED    (-902)\r
91 #define         ERROR_FLASH_DST_OUT_OF_BANK             (-903)\r
92 #define         ERROR_FLASH_DST_BREAKS_ALIGNMENT (-904)\r
93 #define         ERROR_FLASH_BUSY                                (-905)\r
94 #define         ERROR_FLASH_SECTOR_NOT_ERASED   (-906)\r
95 #define         ERROR_FLASH_BANK_NOT_PROBED             (-907)\r
96 \r
97 #endif /* FLASH_H */\r