Lines Matching +full:record +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-only
25 #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
40 if (n >= '0' && n <= '9') return n - '0'; in nybble()
41 else if (n >= 'A' && n <= 'F') return n - ('A' - 10); in nybble()
42 else if (n >= 'a' && n <= 'f') return n - ('a' - 10); in nybble()
53 static int process_ihex(uint8_t *data, ssize_t size);
54 static void file_record(struct ihex_binrec *record);
66 fprintf(stderr, " -w: wide records (16-bit length)\n"); in usage()
67 fprintf(stderr, " -s: sort records by address\n"); in usage()
68 fprintf(stderr, " -j: include records for CS:IP/EIP address\n"); in usage()
79 while ((opt = getopt(argc, argv, "wsj")) != -1) { in main()
98 if (!strcmp(argv[optind], "-")) in main()
102 if (infd == -1) { in main()
117 if (!strcmp(argv[optind+1], "-")) in main()
121 if (outfd == -1) { in main()
132 static int process_ihex(uint8_t *data, ssize_t size) in process_ihex() argument
134 struct ihex_binrec *record; in process_ihex() local
145 /* search for the start of record character */ in process_ihex()
146 while (i < size) { in process_ihex()
151 /* Minimum record length would be about 10 characters */ in process_ihex()
152 if (i + 10 > size) { in process_ihex()
153 fprintf(stderr, "Can't find valid record at line %d\n", line); in process_ihex()
154 return -EINVAL; in process_ihex()
162 record_size = ALIGN(sizeof(*record) + len, 4); in process_ihex()
163 record = malloc(record_size); in process_ihex()
164 if (!record) { in process_ihex()
166 return -ENOMEM; in process_ihex()
168 memset(record, 0, record_size); in process_ihex()
169 record->len = len; in process_ihex()
172 if (i + 8 + (record->len * 2) > size) { in process_ihex()
173 fprintf(stderr, "Not enough data to read complete record at line %d\n", in process_ihex()
175 return -EINVAL; in process_ihex()
178 record->addr = hex(data + i, &crc) << 8; i += 2; in process_ihex()
179 record->addr |= hex(data + i, &crc); i += 2; in process_ihex()
182 for (j = 0; j < record->len; j++, i += 2) in process_ihex()
183 record->data[j] = hex(data + i, &crc); in process_ihex()
189 line, crcbyte, (unsigned char)(crcbyte-crc)); in process_ihex()
190 return -EINVAL; in process_ihex()
193 /* Done reading the record */ in process_ihex()
196 /* old style EOF record? */ in process_ihex()
197 if (!record->len) in process_ihex()
200 record->addr += offset; in process_ihex()
201 file_record(record); in process_ihex()
204 case 1: /* End-Of-File Record */ in process_ihex()
205 if (record->addr || record->len) { in process_ihex()
206 fprintf(stderr, "Bad EOF record (type 01) format at line %d", in process_ihex()
208 return -EINVAL; in process_ihex()
212 case 2: /* Extended Segment Address Record (HEX86) */ in process_ihex()
213 case 4: /* Extended Linear Address Record (HEX386) */ in process_ihex()
214 if (record->addr || record->len != 2) { in process_ihex()
215 fprintf(stderr, "Bad HEX86/HEX386 record (type %02X) at line %d\n", in process_ihex()
217 return -EINVAL; in process_ihex()
222 offset = record->data[0] << 8 | record->data[1]; in process_ihex()
226 case 3: /* Start Segment Address Record */ in process_ihex()
227 case 5: /* Start Linear Address Record */ in process_ihex()
228 if (record->addr || record->len != 4) { in process_ihex()
229 fprintf(stderr, "Bad Start Address record (type %02X) at line %d\n", in process_ihex()
231 return -EINVAL; in process_ihex()
234 memcpy(&data32, &record->data[0], sizeof(data32)); in process_ihex()
236 memcpy(&record->data[0], &data32, sizeof(data32)); in process_ihex()
239 * starts. If requested output this as a record. */ in process_ihex()
241 file_record(record); in process_ihex()
245 fprintf(stderr, "Unknown record (type %02X)\n", type); in process_ihex()
246 return -EINVAL; in process_ihex()
254 static void file_record(struct ihex_binrec *record) in file_record() argument
258 while ((*p) && (!sort_records || (*p)->addr < record->addr)) in file_record()
259 p = &((*p)->next); in file_record()
261 record->next = *p; in file_record()
262 *p = record; in file_record()
267 return p->len + sizeof(p->addr) + sizeof(p->len); in ihex_binrec_size()
278 p->addr = htonl(p->addr); in output_records()
279 p->len = htons(p->len); in output_records()
280 if (write(outfd, &p->addr, writelen) != writelen) in output_records()
282 p = p->next; in output_records()
284 /* EOF record is zero length, since we don't bother to represent in output_records()