aboutsummaryrefslogtreecommitdiff
path: root/src/commonlib/include
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2015-12-15 13:33:51 -0600
committerAaron Durbin <adurbin@chromium.org>2016-01-06 01:11:19 +0100
commit295d58bda85ce30724a3fff87d60b323373f6e5f (patch)
tree7bdd1cf6a886bc11ab313d9b235aa5cb00bdaf8d /src/commonlib/include
parent990ab7efe5d0eddb96542042bf5106811365e34a (diff)
commonlib: Add common cbfs parsing logic to coreboot and cbfstool.
To continue sharing more code between the tools and coreboot proper provide cbfs parsing logic in commonlib. A cbfs_for_each_file() function was added to allow one to act on each file found within a cbfs. cbfs_locate() was updated to use that logic. BUG=chrome-os-partner:48412 BUG=chromium:445938 BRANCH=None TEST=Utilized and booted on glados. Change-Id: I1f23841583e78dc3686f106de9eafe1adbef8c9f Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/12783 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth <martinroth@google.com> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/commonlib/include')
-rw-r--r--src/commonlib/include/commonlib/cbfs.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/commonlib/include/commonlib/cbfs.h b/src/commonlib/include/commonlib/cbfs.h
new file mode 100644
index 0000000000..b0a468cdc9
--- /dev/null
+++ b/src/commonlib/include/commonlib/cbfs.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _COMMONLIB_CBFS_H_
+#define _COMMONLIB_CBFS_H_
+
+#include <commonlib/cbfs_serialized.h>
+#include <commonlib/region.h>
+
+/* Object representing cbfs files. */
+struct cbfsf {
+ struct region_device metadata;
+ struct region_device data;
+};
+
+/* Locate file by name and optional type. Returns 0 on succcess else < 0 on
+ * error.*/
+int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs,
+ const char *name, uint32_t *type);
+
+static inline void cbfs_file_data(struct region_device *data,
+ const struct cbfsf *file)
+{
+ rdev_chain(data, &file->data, 0, region_device_sz(&file->data));
+}
+
+static inline void cbfs_file_metadata(struct region_device *metadata,
+ const struct cbfsf *file)
+{
+ rdev_chain(metadata, &file->metadata, 0,
+ region_device_sz(&file->metadata));
+}
+
+/*
+ * Provide a handle to each cbfs file within a cbfs. The prev pointer represents
+ * the previous file (NULL on first invocation). The next object gets filled
+ * out with the next file. This returns < 0 on error, 0 on finding the next
+ * file, and > 0 at end of cbfs.
+ */
+int cbfs_for_each_file(const struct region_device *cbfs,
+ const struct cbfsf *prev, struct cbfsf *fh);
+
+#endif