- reworked image handling to support multiple sections (tested with ihex file contain...
[fw/openocd] / src / target / image.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 IMAGE_H
21 #define IMAGE_H
22
23 #include "fileio.h"
24 #include "target.h"
25
26 #define IMAGE_MAX_ERROR_STRING          (128)
27 #define IMAGE_MAX_SECTIONS                      (128)
28
29 typedef enum image_type
30 {
31     IMAGE_BINARY,       /* plain binary */
32     IMAGE_IHEX,         /* intel hex-record format */
33     IMAGE_MEMORY,       /* target-memory pseudo-image */
34 /*
35  * Possible future enhancements:
36  * IMAGE_ELF,
37  * IMAGE_SRECORD,
38  */
39 } image_type_t;
40
41 typedef struct image_section_s
42 {
43         u32 base_address;
44         u32 size;
45         int flags;
46 } image_section_t;
47
48 typedef struct image_s
49 {
50         image_type_t type;              /* image type (plain, ihex, ...) */
51         void *type_private;             /* type private data */
52         int num_sections;               /* number of sections contained in the image */
53         image_section_t *sections;      /* array of sections */
54         int base_address_set;   /* whether the image has a base address set (for relocation purposes) */
55         int base_address;               /* base address, if one is set */
56         int start_address_set;  /* whether the image has a start address (entry point) associated */
57         u32 start_address;              /* start address, if one is set */
58         char error_str[IMAGE_MAX_ERROR_STRING];
59 } image_t;
60
61 typedef struct image_binary_s
62 {
63         fileio_t fileio;
64 } image_binary_t;
65
66 typedef struct image_ihex_s
67 {
68         fileio_t fileio;
69         u8 *buffer;
70         u8 **section_pointer;
71 } image_ihex_t;
72
73 typedef struct image_memory_s
74 {
75         target_t *target;
76 } image_memory_t;
77
78 extern int image_open(image_t *image, void *source, enum fileio_access access);
79 extern int image_read_section(image_t *image, int section, u32 offset, u32 size, u8 *buffer, u32 *size_read);
80 extern int image_close(image_t *image);
81 extern int identify_image_type(image_type_t *type, char *type_string);
82
83 #define ERROR_IMAGE_FORMAT_ERROR        (-1400)
84 #define ERROR_IMAGE_TYPE_UNKNOWN        (-1401)
85
86 #endif /* IMAGE_H */