Debian Codegraph @

src/intel_hex.h

raw
1 /*
2 * dfu-programmer
3 *
4 * $Id$
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #ifndef __INTEL_HEX_H__
22 #define __INTEL_HEX_H__
23
24 #include <stdint.h>
25 #include <stdbool.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 typedef struct {
32 size_t total_size; // the total size of the buffer
33 size_t page_size; // the size of a flash page
34 uint32_t block_start; // the start addr of a transfer
35 uint32_t block_end; // the end addr of a transfer
36 uint32_t data_start; // the first valid data addr
37 uint32_t data_end; // the last valid data addr
38 uint32_t valid_start; // the first valid memory addr
39 uint32_t valid_end; // the last valid memory addr
40 } intel_buffer_info_t;
41
42 typedef struct {
43 intel_buffer_info_t info;
44 uint16_t *data;
45 } intel_buffer_out_t;
46
47 typedef struct {
48 intel_buffer_info_t info;
49 uint8_t *data;
50 } intel_buffer_in_t;
51
52
53 int32_t intel_process_data( intel_buffer_out_t *bout,
54 char value, uint32_t target_offset, uint32_t address);
55 /* process a data value by adding to the buffer at the appropriate address or if
56 * the address is out of range do nothing and return -1. Also update the valid
57 * range of data in bout
58 * return 0 on success, -1 on address error
59 */
60
61 // NOTE : intel_process_data should be moved to a different module dealing with
62 // processing any data and putting it into a buffer
63
64 int32_t intel_hex_to_buffer( char *filename, intel_buffer_out_t *bout,
65 uint32_t target_offset, bool quiet );
66 /* Used to read in a file in intel hex format and return a chunk of
67 * memory containing the memory image described in the file.
68 *
69 * \param filename the name of the intel hex file to process
70 * \param target_offset is the flash memory address location of buffer[0]
71 * \param quiet tells fcn to suppress terminal messages
72 * \param bout buffer_out structure containing pointer to memory data for the
73 * program and for the user page. Each is an array of int16_t's where
74 * the values 0-255 are valid memory values, and anything else
75 * indicates an unused memory location. These do not need to be
76 * initialized before passing this parameter to the function.
77 *
78 * when passed to the function, program_usage and user_usage must
79 * indicate the maximum size of each of these memory sections
80 * in bytes. After the program has run they will indicate the
81 * amount of available memory image used for each section
82 *
83 * \return success integer
84 * 0 = success
85 * + = the amount of data that exists outside the specified memory
86 * area and has not been added to the buffer
87 * - = all sorts of error codes (eg, no data in flash memory, ...)
88 * if the hex file contains no valid data an error is NOT thrown
89 * but the presence of valid data can be checked using the
90 * data_start field in intel_buffer_out_t
91 */
92
93 int32_t intel_hex_from_buffer( intel_buffer_in_t *buin,
94 bool force_full, uint32_t target_offset );
95 /* Used to convert a buffer to an intel hex formatted file.
96 * target offset is the address location of buffer 0
97 * force_full sets whether to keep writing entirely blank pages.
98 */
99
100 int32_t intel_init_buffer_out(intel_buffer_out_t *bout,
101 size_t total_size, size_t page_size );
102 /* initialize a buffer used to send data to flash memory
103 * the total size and page size must be provided.
104 * the data array is filled with 0xFFFF (an invalid memory
105 * value) indicating that it is unassigned. data start and
106 * data end are initialized with UINT32_MAX indicating there
107 * is no valid data in the buffer. these two values are simply
108 * convenience values so the start and end of data do not need
109 * to be found multiple times.
110 */
111
112 int32_t intel_init_buffer_in(intel_buffer_in_t *buin,
113 size_t total_size, size_t page_size );
114 /* initialize a buffer_in, used for reading the contents of program
115 * memory. total memory size must be provided. the data array is filled
116 * with 0xFF, which is unprogrammed memory.
117 */
118
119 int32_t intel_validate_buffer( intel_buffer_in_t *buin,
120 intel_buffer_out_t *bout, bool quiet);
121 /* compare the contents of buffer_in with buffer_out to check that a target
122 * memory image matches with a memory read.
123 * return 0 for full validation, positive number if data bytes outside region do
124 * not validate, negative number if bytes inside region that do not validate
125 */
126
127 int32_t intel_flash_prep_buffer( intel_buffer_out_t *bout );
128 /* prepare the buffer so that valid data fills each page that contains data.
129 * unassigned data in buffer is given a value of 0xff (blank memory)
130 * the buffer pointer must align with the beginning of a flash page
131 * return 0 on success, -1 if assigning data would extend flash above size
132 */
133
134
135 #ifdef __cplusplus
136 }
137 #endif
138
139 #endif