- added missing files for last commit
[fw/openocd] / src / helper / fileio.h
1 /***************************************************************************
2  *   Copyright (C) 2007 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 FILEIO_H
21 #define FILEIO_H
22
23 #define FILEIO_MAX_ERROR_STRING         (128)
24
25 /* make buffering of complete intel-hex format files optional
26  * to account for resource-limited hosts
27  */
28 #define FILEIO_BUFFER_COMPLETE_IHEX
29
30 #include <sys/stat.h>
31
32 enum fileio_pri_type
33 {
34         FILEIO_TEXT = 0x1,
35         FILEIO_IMAGE = 0x2,
36 };
37
38 enum fileio_sec_type
39 {
40         FILEIO_PLAIN = 0x10,
41         FILEIO_IHEX = 0x20,
42 /*
43  * Possible future enhancements:
44  * FILEIO_ELF,
45  * FILEIO_SRECORD,
46  */
47 };
48
49 enum fileio_location
50 {
51         FILEIO_LOCAL,
52 /*
53  * Possible future enhancements:
54  * FILEIO_NFS,
55  * FILEIO_BOOTP,
56  * FILEIO_[XYZ]MODEM,
57  * FILEIO_HTTP,
58  * FILEIO_FTP,
59  */
60 };
61
62 enum fileio_access
63 {
64         FILEIO_READ,            /* open for reading, position at beginning */
65         FILEIO_WRITE,           /* open for writing, position at beginning */
66         FILEIO_READWRITE,       /* open for writing, position at beginning, allow reading */
67         FILEIO_APPEND,          /* open for writing, position at end */
68         FILEIO_APPENDREAD,      /* open for writing, position at end, allow reading */
69 };
70
71 typedef struct fileio_s
72 {
73         char *url;
74         char error_str[FILEIO_MAX_ERROR_STRING];
75         long long size;
76         enum fileio_pri_type pri_type;
77         enum fileio_sec_type sec_type;
78         enum fileio_location location;
79         enum fileio_access access;
80         void *location_private;
81         void *pri_type_private;
82         void *sec_type_private;
83 } fileio_t;
84
85 typedef struct fileio_text_s
86 {
87 } fileio_text_t;
88
89 typedef struct fileio_image_s
90 {
91         u32 base_address;
92         int has_start_address;
93         u32 start_address;
94 } fileio_image_t;
95
96 typedef struct fileio_local_s
97 {
98         FILE *file;
99         struct stat file_stat;
100 } fileio_local_t;
101
102 typedef struct fileio_ihex_s
103 {
104         u32 position;
105         u32 raw_size;
106 #ifdef FILEIO_BUFFER_COMPLETE_IHEX
107         u8 *buffer;
108 #endif
109 } fileio_ihex_t;
110
111 extern int fileio_identify_image_type(enum fileio_sec_type *sec_type, char *type_string);
112 extern int fileio_write(fileio_t *fileio, u32 size, u8 *buffer, u32 *size_written);
113 extern int fileio_read(fileio_t *fileio, u32 size, u8 *buffer, u32 *size_read);
114 extern int fileio_seek(fileio_t *fileio, u32 position);
115 extern int fileio_close(fileio_t *fileio);
116 extern int fileio_open(fileio_t *fileio, char *url, enum fileio_access access,
117         enum fileio_pri_type pri_type, void *pri_info, enum fileio_sec_type sec_type);
118         
119 #define ERROR_FILEIO_LOCATION_UNKNOWN   (-1200)
120 #define ERROR_FILEIO_NOT_FOUND                  (-1201)
121 #define ERROR_FILEIO_OPERATION_FAILED           (-1202)
122 #define ERROR_FILEIO_ACCESS_NOT_SUPPORTED       (-1203)
123 #define ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN      (-1204)
124 #define ERROR_FILEIO_OPERATION_NOT_SUPPORTED    (-1205)
125
126 #endif /* FILEIO_H */