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

Function cbfs_locate_entry

util/cbfstool/cbfs_image.c:1960–2049  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1958}
1959
1960int32_t cbfs_locate_entry(struct cbfs_image *image, size_t size,
1961 size_t page_size, size_t align, size_t metadata_size)
1962{
1963 struct cbfs_file *entry;
1964 size_t need_len;
1965 size_t addr, addr_next, addr2, addr3, offset;
1966
1967 /* Default values: allow fitting anywhere in ROM. */
1968 if (!page_size)
1969 page_size = image->has_header ? image->header.romsize :
1970 image->buffer.size;
1971 if (!align)
1972 align = 1;
1973
1974 if (size > page_size)
1975 ERROR("Input file size (%zd) greater than page size (%zd).\n",
1976 size, page_size);
1977
1978 size_t image_align = image->has_header ? image->header.align :
1979 CBFS_ALIGNMENT;
1980 if (page_size % image_align)
1981 WARN("%s: Page size (%#zx) not aligned with CBFS image (%#zx).\n",
1982 __func__, page_size, image_align);
1983
1984 need_len = metadata_size + size;
1985
1986 // Merge empty entries to build get max available space.
1987 cbfs_legacy_walk(image, cbfs_merge_empty_entry, NULL);
1988
1989 /* Three cases of content location on memory page:
1990 * case 1.
1991 * | PAGE 1 | PAGE 2 |
1992 * | <header><content>| Fit. Return start of content.
1993 *
1994 * case 2.
1995 * | PAGE 1 | PAGE 2 |
1996 * | <header><content> | Fits when we shift content to align
1997 * shift-> | <header>|<content> | at starting of PAGE 2.
1998 *
1999 * case 3. (large content filling whole page)
2000 * | PAGE 1 | PAGE 2 | PAGE 3 |
2001 * | <header>< content > | Can't fit. If we shift content to
2002 * |trial-> <header>< content > | PAGE 2, header can't fit in free
2003 * | shift-> <header><content> space, so we must use PAGE 3.
2004 *
2005 * The returned address can be then used as "base-address" (-b) in add-*
2006 * commands (will be re-calculated and positioned by cbfs_add_entry_at).
2007 * For stage targets, the address is also used to re-link stage before
2008 * being added into CBFS.
2009 */
2010 for (entry = cbfs_find_first_entry(image);
2011 entry && cbfs_is_valid_entry(image, entry);
2012 entry = cbfs_find_next_entry(image, entry)) {
2013
2014 uint32_t type = be32toh(entry->type);
2015 if (type != CBFS_TYPE_NULL)
2016 continue;
2017

Callers 1

do_cbfs_locateFunction · 0.85

Calls 9

cbfs_legacy_walkFunction · 0.85
cbfs_find_first_entryFunction · 0.85
cbfs_is_valid_entryFunction · 0.85
cbfs_find_next_entryFunction · 0.85
cbfs_get_entry_addrFunction · 0.85
absolute_alignFunction · 0.85
is_in_same_pageFunction · 0.85
is_in_rangeFunction · 0.85
align_upFunction · 0.70

Tested by

no test coverage detected