MCPcopy Create free account
hub / github.com/coreboot/coreboot / ifwi_parse

Function ifwi_parse

util/cbfstool/ifwitool.c:860–917  ·  view source on GitHub ↗

Parse input image file to identify different sub-partitions. */

Source from the content-addressed store, hash-verified

858
859/* Parse input image file to identify different sub-partitions. */
860static int ifwi_parse(void)
861{
862 DEBUG("Parsing IFWI image...\n");
863 const char *image_name = param.image_name;
864
865 /* Read input file. */
866 struct buffer *buff = &ifwi_image.input_buff;
867 if (buffer_from_file(buff, image_name)) {
868 ERROR("Failed to read input file %s.\n", image_name);
869 return -1;
870 }
871
872 INFO("Buffer %p size 0x%zx\n", buff->data, buff->size);
873
874 /* Look for BPDT signature at 4K intervals. */
875 size_t offset = 0, lbp = LBP1;
876 void *data = buffer_get(buff);
877
878 while (offset < buffer_size(buff)) {
879 if (read_at_le32(data, offset) == BPDT_SIGNATURE) {
880 if (lbp == param.logical_boot_partition)
881 break;
882 offset += bpdt_size((uint8_t *)data + offset);
883 lbp++;
884 } else
885 offset += 4 * KiB;
886 }
887
888 if (offset >= buffer_size(buff)) {
889 ERROR("Image does not contain BPDT for LBP=%zd!!\n",
890 param.logical_boot_partition);
891 return -1;
892 }
893
894 ifwi_image.input_ifwi_start_offset = offset;
895 INFO("BPDT starts at offset 0x%zx.\n", offset);
896
897 data = (uint8_t *)data + offset;
898 size_t ifwi_size = buffer_size(buff) - offset;
899
900 /* Read BPDT and sub-partitions. */
901 uintptr_t end_offset;
902 end_offset = ifwi_image.input_ifwi_start_offset +
903 alloc_bpdt_buffer(data, ifwi_size, 0, &ifwi_image.bpdt, "BPDT");
904
905 /* Parse S-BPDT, if any. */
906 parse_sbpdt(data, ifwi_size);
907
908 /*
909 * Store end offset of IFWI. Required for copying any trailing non-IFWI
910 * part of the image.
911 * ASSUMPTION: IFWI image always ends on a 4K boundary.
912 */
913 ifwi_image.input_ifwi_end_offset = ALIGN_UP(end_offset, 4 * KiB);
914 DEBUG("Parsing done.\n");
915
916 return 0;
917}

Callers 1

mainFunction · 0.70

Calls 7

buffer_from_fileFunction · 0.85
buffer_getFunction · 0.85
buffer_sizeFunction · 0.85
read_at_le32Function · 0.85
bpdt_sizeFunction · 0.85
alloc_bpdt_bufferFunction · 0.85
parse_sbpdtFunction · 0.85

Tested by

no test coverage detected