ao-tools: Add debug printf support
[fw/altos] / ao-tools / lib / ao-hex.h
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_HEX_H_
19 #define _AO_HEX_H_
20
21 #include <stdint.h>
22
23 #define AO_HEX_RECORD_NORMAL                    0x00
24 #define AO_HEX_RECORD_EOF                       0x01
25 #define AO_HEX_RECORD_EXTENDED_ADDRESS_4        0x02
26 #define AO_HEX_RECORD_EXTENDED_ADDRESS_8        0x04
27 #define AO_HEX_RECORD_SYMBOL                    0xfe
28
29 /* Intel hex file format data
30  */
31 struct ao_hex_record {
32         uint8_t length;
33         uint16_t address;
34         uint8_t type;
35         uint8_t checksum;
36         uint8_t data[0];
37 };
38
39 struct ao_hex_file {
40         int                     nrecord;
41         struct ao_hex_record    *records[0];
42 };
43
44 struct ao_hex_image {
45         uint32_t        address;
46         uint32_t        length;
47         uint8_t         data[0];
48 };
49
50 struct ao_hex_file *
51 ao_hex_file_read(FILE *file, char *name);
52
53 void
54 ao_hex_file_free(struct ao_hex_file *hex);
55
56 struct ao_hex_image *
57 ao_hex_image_create(struct ao_hex_file *hex);
58
59 void
60 ao_hex_image_free(struct ao_hex_image *image);
61
62 struct ao_hex_image *
63 ao_hex_load(char *filename);
64
65 int
66 ao_hex_image_equal(struct ao_hex_image *a, struct ao_hex_image *b);
67
68 #endif /* _AO_HEX_H_ */