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