added yours sincerely for files where I feel that I've made non-trivial contributions.
[fw/openocd] / src / target / image.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
5  *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                      *
6  *   oyvind.harboe@zylin.com                                               *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program; if not, write to the                         *
20  *   Free Software Foundation, Inc.,                                       *
21  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
22  ***************************************************************************/
23 #ifndef IMAGE_H
24 #define IMAGE_H
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #ifdef HAVE_ELF_H
31 #include <elf.h>
32 #endif
33 #include "replacements.h"
34 #include "fileio.h"
35 #include "target.h"
36
37 #define IMAGE_MAX_ERROR_STRING          (256)
38 #define IMAGE_MAX_SECTIONS                      (128)
39
40 #define IMAGE_MEMORY_CACHE_SIZE         (2048)
41
42 typedef enum image_type
43 {
44     IMAGE_BINARY,       /* plain binary */
45     IMAGE_IHEX,         /* intel hex-record format */
46     IMAGE_MEMORY,       /* target-memory pseudo-image */
47     IMAGE_ELF,          /* ELF binary */
48     IMAGE_SRECORD,      /* motorola s19 */
49     IMAGE_BUILDER,      /* when building a new image */
50 } image_type_t;
51
52 typedef struct image_section_s
53 {
54         u32 base_address;
55         u32 size;
56         int flags;
57         void *private;          /* private data */
58 } image_section_t;
59
60 typedef struct image_s
61 {
62         image_type_t type;              /* image type (plain, ihex, ...) */
63         void *type_private;             /* type private data */
64         int num_sections;               /* number of sections contained in the image */
65         image_section_t *sections;      /* array of sections */
66         int base_address_set;   /* whether the image has a base address set (for relocation purposes) */
67         int base_address;               /* base address, if one is set */
68         int start_address_set;  /* whether the image has a start address (entry point) associated */
69         u32 start_address;              /* start address, if one is set */
70 } image_t;
71
72 typedef struct image_binary_s
73 {
74         fileio_t fileio;
75 } image_binary_t;
76
77 typedef struct image_ihex_s
78 {
79         fileio_t fileio;
80         u8 *buffer;
81 } image_ihex_t;
82
83 typedef struct image_memory_s
84 {
85         target_t *target;
86         u8 *cache;
87         u32 cache_address;
88 } image_memory_t;
89
90 typedef struct fileio_elf_s
91 {
92         fileio_t fileio;
93         Elf32_Ehdr *header;
94         Elf32_Phdr *segments;
95         u32 segment_count;
96         u8 endianness;
97 } image_elf_t;
98
99 typedef struct image_mot_s
100 {
101         fileio_t fileio;
102         u8 *buffer;
103 } image_mot_t;
104
105 extern int image_open(image_t *image, char *url, char *type_string);
106 extern int image_read_section(image_t *image, int section, u32 offset, u32 size, u8 *buffer, u32 *size_read);
107 extern int image_close(image_t *image);
108 extern int image_add_section(image_t *image, u32 base, u32 size, int flags, u8 *data);
109
110 extern int image_calculate_checksum(u8* buffer, u32 nbytes, u32* checksum);
111
112 #define ERROR_IMAGE_FORMAT_ERROR        (-1400)
113 #define ERROR_IMAGE_TYPE_UNKNOWN        (-1401)
114 #define ERROR_IMAGE_TEMPORARILY_UNAVAILABLE             (-1402)
115 #define ERROR_IMAGE_CHECKSUM            (-1403)
116
117 #endif /* IMAGE_H */