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

Function cbfs_write

util/cbfstool/cbfstool.c:1686–1762  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1684}
1685
1686static int cbfs_write(void)
1687{
1688 if (!param.filename) {
1689 ERROR("You need to specify a valid input -f/--file.\n");
1690 return 1;
1691 }
1692 if (!partitioned_file_is_partitioned(param.image_file)) {
1693 ERROR("This operation isn't valid on legacy images having CBFS master headers\n");
1694 return 1;
1695 }
1696
1697 if (!param.force && region_is_modern_cbfs(param.region_name)) {
1698 ERROR("Target image region '%s' is a CBFS and must be manipulated using add and remove\n",
1699 param.region_name);
1700 return 1;
1701 }
1702
1703 struct buffer new_content;
1704 if (buffer_from_file(&new_content, param.filename))
1705 return 1;
1706
1707 if (buffer_check_magic(&new_content, FMAP_SIGNATURE,
1708 strlen(FMAP_SIGNATURE))) {
1709 ERROR("File '%s' appears to be an FMAP and cannot be added to an existing image\n",
1710 param.filename);
1711 buffer_delete(&new_content);
1712 return 1;
1713 }
1714 if (!param.force && buffer_check_magic(&new_content, CBFS_FILE_MAGIC,
1715 strlen(CBFS_FILE_MAGIC))) {
1716 ERROR("File '%s' appears to be a CBFS and cannot be inserted into a raw region\n",
1717 param.filename);
1718 buffer_delete(&new_content);
1719 return 1;
1720 }
1721
1722 unsigned offset = 0;
1723 if (param.fill_partial_upward && param.fill_partial_downward) {
1724 ERROR("You may only specify one of -u and -d.\n");
1725 buffer_delete(&new_content);
1726 return 1;
1727 } else if (!param.fill_partial_upward && !param.fill_partial_downward) {
1728 if (new_content.size != param.image_region->size) {
1729 ERROR("File to add is %zu bytes and would not fill %zu-byte target region (did you mean to pass either -u or -d?)\n",
1730 new_content.size, param.image_region->size);
1731 buffer_delete(&new_content);
1732 return 1;
1733 }
1734 } else {
1735 if (new_content.size > param.image_region->size) {
1736 ERROR("File to add is %zu bytes and would overflow %zu-byte target region\n",
1737 new_content.size, param.image_region->size);
1738 buffer_delete(&new_content);
1739 return 1;
1740 }
1741 if (param.u64val == (uint64_t)-1) {
1742 WARN("Written area will abut %s of target region: any unused space will keep its current contents\n",
1743 param.fill_partial_upward ? "bottom" : "top");

Callers

nothing calls this directly

Calls 11

region_is_modern_cbfsFunction · 0.85
buffer_from_fileFunction · 0.85
buffer_check_magicFunction · 0.85
strlenFunction · 0.85
buffer_deleteFunction · 0.85
buffer_getFunction · 0.85
buffer_sizeFunction · 0.85
maybe_update_fmap_hashFunction · 0.85
memsetFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected