[coreboot-gerrit] New patch to review for coreboot: libpayload: provide cbfs_file_find_attr()

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Thu Sep 17 18:47:03 CET 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11678

-gerrit

commit 127b77edf15046dc89bdc4925d4acaf89e8498e7
Author: Patrick Georgi <pgeorgi at chromium.org>
Date:   Thu Sep 17 20:45:52 2015 +0200

    libpayload: provide cbfs_file_find_attr()
    
    cbfs_file_find_attr(file, tag) finds the first attribute of file with
    the given tag.
    
    Change-Id: I78ee3b996b4b086605244c5d7d57ef7e3fc1db47
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
---
 payloads/libpayload/include/cbfs_core.h |  5 +++++
 payloads/libpayload/libcbfs/cbfs_core.c | 21 +++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/payloads/libpayload/include/cbfs_core.h b/payloads/libpayload/include/cbfs_core.h
index 3878e55..ec59a20 100644
--- a/payloads/libpayload/include/cbfs_core.h
+++ b/payloads/libpayload/include/cbfs_core.h
@@ -170,6 +170,11 @@ struct cbfs_file_attribute *cbfs_file_first_attr(struct cbfs_file *file);
 struct cbfs_file_attribute *cbfs_file_next_attr(struct cbfs_file *file,
 	struct cbfs_file_attribute *attr);
 
+/* Given a cbfs_file and an attribute tag, return the first instance of the
+ * attribute or NULL if none found. */
+struct cbfs_file_attribute *cbfs_file_find_attr(struct cbfs_file *file,
+	uint32_t tag);
+
 /*** Component sub-headers ***/
 
 /* Following are component sub-headers for the "standard"
diff --git a/payloads/libpayload/libcbfs/cbfs_core.c b/payloads/libpayload/libcbfs/cbfs_core.c
index 5a46af8..153dc8a 100644
--- a/payloads/libpayload/libcbfs/cbfs_core.c
+++ b/payloads/libpayload/libcbfs/cbfs_core.c
@@ -212,12 +212,8 @@ void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
 
 	void *file_content = (void *)CBFS_SUBHEADER(file);
 
-	struct cbfs_file_attribute *attr = cbfs_file_first_attr(file);
-	while (attr) {
-		if (ntohl(attr->tag) == CBFS_FILE_ATTR_TAG_COMPRESSION)
-			break;
-		attr = cbfs_file_next_attr(file, attr);
-	}
+	struct cbfs_file_attribute *attr =
+		cbfs_file_find_attr(file, CBFS_FILE_ATTR_TAG_COMPRESSION);
 
 	int compression_algo = CBFS_COMPRESS_NONE;
 	if (attr) {
@@ -285,6 +281,19 @@ struct cbfs_file_attribute *cbfs_file_next_attr(struct cbfs_file *file,
 	return next;
 }
 
+struct cbfs_file_attribute *cbfs_file_find_attr(struct cbfs_file *file,
+	uint32_t tag)
+{
+	struct cbfs_file_attribute *attr = cbfs_file_first_attr(file);
+	while (attr) {
+		if (ntohl(attr->tag) == tag)
+			break;
+		attr = cbfs_file_next_attr(file, attr);
+	}
+	return attr;
+
+}
+
 int cbfs_decompress(int algo, void *src, void *dst, int len)
 {
 	switch (algo) {



More information about the coreboot-gerrit mailing list