| 338 | } |
| 339 | |
| 340 | static int ifwi_parse(const char *image_name) |
| 341 | { |
| 342 | struct buffer *input_buff = &ifwi.input_buff; |
| 343 | struct buffer bpdt_buff; |
| 344 | |
| 345 | if (buffer_from_file(input_buff, image_name)) { |
| 346 | ERROR("Failed to read input file %s\n", image_name); |
| 347 | return -1; |
| 348 | } |
| 349 | |
| 350 | buffer_clone(&bpdt_buff, input_buff); |
| 351 | |
| 352 | ifwi.bpdt_ops = get_bpdt_ops(&bpdt_buff); |
| 353 | if (!ifwi.bpdt_ops) { |
| 354 | ERROR("No matching bpdt_ops!\n"); |
| 355 | return -1; |
| 356 | } |
| 357 | |
| 358 | ifwi.bpdt_hdr = ifwi.bpdt_ops->read_hdr(&bpdt_buff); |
| 359 | if (ifwi.bpdt_hdr == NULL) |
| 360 | return -1; |
| 361 | |
| 362 | read_bpdt_entries(&bpdt_buff); |
| 363 | set_file_end_offset(&bpdt_buff); |
| 364 | |
| 365 | if (!ifwi.bpdt_ops->validate_checksum(ifwi.bpdt_hdr, &ifwi.bpdt_entries[0])) { |
| 366 | ERROR("Checksum failed!\n"); |
| 367 | return -1; |
| 368 | } |
| 369 | |
| 370 | ifwi.subpart_hdr_ops = get_subpart_hdr_ops(); |
| 371 | if (ifwi.subpart_hdr_ops == NULL) { |
| 372 | ERROR("No matching subpart_hdr_ops for given BPDT!\n"); |
| 373 | return -1; |
| 374 | } |
| 375 | |
| 376 | ifwi.subpart_entry_ops = get_subpart_entry_ops(); |
| 377 | if (ifwi.subpart_entry_ops == NULL) { |
| 378 | ERROR("No matching subpart_entry_ops for given BPDT!\n"); |
| 379 | return -1; |
| 380 | } |
| 381 | |
| 382 | return subpart_read(&ifwi.input_buff); |
| 383 | } |
| 384 | |
| 385 | static int subpart_write(struct buffer *buff) |
| 386 | { |
no test coverage detected