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

Function ifwi_dir_replace

util/cbfstool/ifwitool.c:1697–1788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1695}
1696
1697static enum ifwi_ret ifwi_dir_replace(int type)
1698{
1699 if (!(subparts[type].attr & CONTAINS_DIR)) {
1700 ERROR("Sub-Partition %s(%d) does not support dir ops.\n",
1701 subparts[type].name, type);
1702 return COMMAND_ERR;
1703 }
1704
1705 if (!param.dentry_name) {
1706 ERROR("%s: -e option required.\n", __func__);
1707 return COMMAND_ERR;
1708 }
1709
1710 struct buffer subpart_dir_buf;
1711 parse_subpart_dir(&subpart_dir_buf, &ifwi_image.subpart_buf[type],
1712 subparts[type].name);
1713
1714 uint32_t i;
1715 struct subpart_dir *s = buffer_get(&subpart_dir_buf);
1716
1717 for (i = 0; i < s->h.num_entries; i++) {
1718 if (!strcmp((char *)s->e[i].name, param.dentry_name))
1719 break;
1720 }
1721
1722 if (i == s->h.num_entries) {
1723 ERROR("Entry %s not found in subpartition for %s.\n",
1724 param.dentry_name, param.subpart_name);
1725 exit(-1);
1726 }
1727
1728 struct buffer b;
1729 if (buffer_from_file(&b, param.file_name)) {
1730 ERROR("Failed to read %s\n", param.file_name);
1731 exit(-1);
1732 }
1733
1734 struct buffer dst;
1735 size_t dst_size = buffer_size(&ifwi_image.subpart_buf[type]) +
1736 buffer_size(&b) - s->e[i].length;
1737 size_t subpart_start = s->e[i].offset;
1738 size_t subpart_end = s->e[i].offset + s->e[i].length;
1739
1740 alloc_buffer(&dst, dst_size, ifwi_image.subpart_buf[type].name);
1741
1742 uint8_t *src_data = buffer_get(&ifwi_image.subpart_buf[type]);
1743 uint8_t *dst_data = buffer_get(&dst);
1744 size_t curr_offset = 0;
1745
1746 /* Copy data before the sub-partition entry. */
1747 memcpy(dst_data + curr_offset, src_data, subpart_start);
1748 curr_offset += subpart_start;
1749
1750 /* Copy sub-partition entry. */
1751 memcpy(dst_data + curr_offset, buffer_get(&b), buffer_size(&b));
1752 curr_offset += buffer_size(&b);
1753
1754 /* Copy remaining data. */

Callers 1

ifwi_replaceFunction · 0.85

Calls 12

parse_subpart_dirFunction · 0.85
buffer_getFunction · 0.85
exitFunction · 0.85
buffer_from_fileFunction · 0.85
buffer_sizeFunction · 0.85
alloc_bufferFunction · 0.85
buffer_deleteFunction · 0.85
printfFunction · 0.85
calc_checksumFunction · 0.70
strcmpFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected