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