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

Function parse_vbt

util/intelvbttool/intelvbttool.c:733–794  ·  view source on GitHub ↗

Returns a new fileobject containing a valid VBT */

Source from the content-addressed store, hash-verified

731
732/* Returns a new fileobject containing a valid VBT */
733static void parse_vbt(const struct fileobject *fo,
734 struct fileobject **vbt)
735{
736 *vbt = NULL;
737
738 if (fo->size < sizeof(struct vbt_header)) {
739 printerr("image is too small\n");
740 return;
741 }
742
743 const struct vbt_header *head =
744 (const struct vbt_header *)fo->data;
745
746 if (memcmp(head->signature, "$VBT", 4) != 0) {
747 printerr("invalid VBT signature\n");
748 return;
749 }
750
751 if (!head->vbt_size || head->vbt_size > fo->size) {
752 printerr("invalid VBT size\n");
753 return;
754 }
755
756 if (!head->bdb_offset ||
757 head->bdb_offset > fo->size - sizeof(struct bdb_header)) {
758 printerr("invalid BDB offset\n");
759 return;
760 }
761
762 if (!head->header_size || head->header_size > fo->size) {
763 printerr("invalid header size\n");
764 return;
765 }
766
767 const struct bdb_header *const bdb_head =
768 (const struct bdb_header *)((const u8 *)head + head->bdb_offset);
769 if (memcmp(bdb_head->signature, "BIOS_DATA_BLOCK ", 16) != 0) {
770 printerr("invalid BDB signature\n");
771 return;
772 }
773
774 if (!bdb_head->header_size || bdb_head->header_size > fo->size) {
775 printerr("invalid BDB header size\n");
776 return;
777 }
778
779 /* Duplicate fo as caller is owner and remalloc frees the object */
780 struct fileobject *dupfo = malloc_fo_sub(fo, 0);
781 if (!dupfo) {
782 printerr("malloc failed\n");
783 return;
784 }
785
786 struct fileobject *newfo = remalloc_fo(dupfo, head->vbt_size);
787 if (!newfo) {
788 printerr("remalloc failed\n");
789 free_fo(dupfo);
790 return;

Callers 2

parse_vbiosFunction · 0.85
mainFunction · 0.85

Calls 5

printerrFunction · 0.85
malloc_fo_subFunction · 0.85
remalloc_foFunction · 0.85
free_foFunction · 0.85
memcmpFunction · 0.50

Tested by

no test coverage detected