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

Function cbfs_add_master_header

util/cbfstool/cbfstool.c:780–868  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

778}
779
780static int cbfs_add_master_header(void)
781{
782 const char * const name = "cbfs master header";
783 struct cbfs_image image;
784 struct cbfs_file *header = NULL;
785 struct buffer buffer;
786 int ret = 1;
787 size_t offset;
788 size_t size;
789 void *h_loc;
790
791 if (cbfs_image_from_buffer(&image, param.image_region,
792 param.headeroffset)) {
793 ERROR("Selected image region is not a CBFS.\n");
794 return 1;
795 }
796
797 if (cbfs_get_entry(&image, name)) {
798 ERROR("'%s' already in ROM image.\n", name);
799 return 1;
800 }
801
802 if (buffer_create(&buffer, sizeof(struct cbfs_header), name) != 0)
803 return 1;
804
805 struct cbfs_header *h = (struct cbfs_header *)buffer.data;
806 h->magic = htobe32(CBFS_HEADER_MAGIC);
807 h->version = htobe32(CBFS_HEADER_VERSION);
808 /* The 4 bytes are left out for two reasons:
809 * 1. the cbfs master header pointer resides there
810 * 2. some cbfs implementations assume that an image that resides
811 * below 4GB has a bootblock and get confused when the end of the
812 * image is at 4GB == 0.
813 */
814 h->bootblocksize = htobe32(4);
815 h->align = htobe32(CBFS_ALIGNMENT);
816 /* The offset and romsize fields within the master header are absolute
817 * values within the boot media. As such, romsize needs to relfect
818 * the end 'offset' for a CBFS. To achieve that the current buffer
819 * representing the CBFS region's size is added to the offset of
820 * the region within a larger image.
821 */
822 offset = buffer_get(param.image_region) -
823 buffer_get_original_backing(param.image_region);
824 size = buffer_size(param.image_region);
825 h->romsize = htobe32(size + offset);
826 h->offset = htobe32(offset);
827 h->architecture = htobe32(CBFS_ARCHITECTURE_UNKNOWN);
828
829 /* Never add a hash attribute to the master header. */
830 header = cbfs_create_file_header(CBFS_TYPE_CBFSHEADER,
831 buffer_size(&buffer), name);
832 if (!header)
833 goto done;
834 if (cbfs_add_entry(&image, &buffer, 0, header, 0) != 0) {
835 ERROR("Failed to add cbfs master header into ROM image.\n");
836 goto done;
837 }

Callers

nothing calls this directly

Calls 13

cbfs_image_from_bufferFunction · 0.85
cbfs_get_entryFunction · 0.85
buffer_createFunction · 0.85
buffer_getFunction · 0.85
buffer_sizeFunction · 0.85
cbfs_create_file_headerFunction · 0.85
cbfs_add_entryFunction · 0.85
fill_header_offsetFunction · 0.85
buffer_deleteFunction · 0.85

Tested by

no test coverage detected