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

Function do_cbfs_locate

util/cbfstool/cbfstool.c:608–667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606}
607
608static int do_cbfs_locate(uint32_t *cbfs_addr, size_t data_size)
609{
610 uint32_t metadata_size = 0;
611
612 if (!param.name) {
613 ERROR("You need to specify -n/--name.\n");
614 return 1;
615 }
616
617 struct cbfs_image image;
618 if (cbfs_image_from_buffer(&image, param.image_region,
619 param.headeroffset))
620 return 1;
621
622 if (cbfs_get_entry(&image, param.name))
623 WARN("'%s' already in CBFS.\n", param.name);
624
625 if (!data_size) {
626 ERROR("File '%s' is empty?\n", param.name);
627 return 1;
628 }
629
630 /* Compute required page size */
631 if (param.force_pow2_pagesize) {
632 param.pagesize = 1;
633 while (param.pagesize < data_size)
634 param.pagesize <<= 1;
635 DEBUG("Page size is %d (0x%x)\n", param.pagesize, param.pagesize);
636 }
637
638 /* Include cbfs_file size along with space for with name. */
639 metadata_size += cbfs_calculate_file_header_size(param.name);
640 /* Adjust metadata_size if additional attributes were added */
641 if (param.autogen_attr) {
642 if (param.alignment)
643 metadata_size += sizeof(struct cbfs_file_attr_align);
644 if (param.baseaddress_assigned || param.stage_xip)
645 metadata_size += sizeof(struct cbfs_file_attr_position);
646 }
647 if (param.precompression || param.compression != CBFS_COMPRESS_NONE)
648 metadata_size += sizeof(struct cbfs_file_attr_compression);
649 if (param.type == CBFS_TYPE_STAGE)
650 metadata_size += sizeof(struct cbfs_file_attr_stageheader);
651
652 /* Take care of the hash attribute if it is used */
653 if (param.hash != VB2_HASH_INVALID)
654 metadata_size += cbfs_file_attr_hash_size(param.hash);
655
656 int32_t address = cbfs_locate_entry(&image, data_size, param.pagesize,
657 param.alignment, metadata_size);
658
659 if (address < 0) {
660 ERROR("'%s'(%u + %zu) can't fit in CBFS for page-size %#x, align %#x.\n",
661 param.name, metadata_size, data_size, param.pagesize, param.alignment);
662 return 1;
663 }
664
665 *cbfs_addr = address;

Callers 3

cbfs_add_componentFunction · 0.85
cbfstool_convert_fspFunction · 0.85
cbfstool_convert_mkstageFunction · 0.85

Calls 5

cbfs_image_from_bufferFunction · 0.85
cbfs_get_entryFunction · 0.85
cbfs_file_attr_hash_sizeFunction · 0.85
cbfs_locate_entryFunction · 0.85

Tested by

no test coverage detected