summaryrefslogtreecommitdiff
path: root/utility/include
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2010-05-28 10:32:02 -0700
committerHung-Te Lin <hungte@chromium.org>2010-05-28 10:32:02 -0700
commit262668fcf3d66595947527d0bb34c1b4e0bc250e (patch)
tree90d7b7e69ad3cc3804be19d9c7080749d92ea79a /utility/include
parent3c6f7a09a482dc200eac00bd210876faf0e45a99 (diff)
downloadvboot-262668fcf3d66595947527d0bb34c1b4e0bc250e.tar.gz
Added gbb_utility (tool for Google Binary Block)
Review URL: http://codereview.chromium.org/2346001
Diffstat (limited to 'utility/include')
-rw-r--r--utility/include/gbb_utility.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/utility/include/gbb_utility.h b/utility/include/gbb_utility.h
new file mode 100644
index 00000000..70a45275
--- /dev/null
+++ b/utility/include/gbb_utility.h
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+#ifndef VBOOT_REFERENCE_GBB_UTILITY_H_
+#define VBOOT_REFERENCE_GBB_UTILITY_H_
+
+#include <string>
+#include "gbb_header.h"
+
+namespace vboot_reference {
+
+class GoogleBinaryBlockUtil {
+ public:
+ GoogleBinaryBlockUtil();
+ ~GoogleBinaryBlockUtil();
+
+ // load GBB from a BIOS image file.
+ // return true if a valid GBB was retrieved.
+ bool load_from_file(const char *filename);
+
+ // save loaded (and modified) GBB with BIOS image to new file
+ // return true on success.
+ bool save_to_file(const char *filename);
+
+ // getters and setters of properties in GBB
+ bool set_hwid(const char *hwid); // hwid is NUL-terminated.
+ bool set_rootkey(const std::string &value);
+ bool set_bmpfv(const std::string &value);
+ std::string get_hwid() const { return get_property(PROP_HWID); }
+ std::string get_rootkey() const { return get_property(PROP_ROOTKEY); }
+ std::string get_bmpfv() const { return get_property(PROP_BMPFV); }
+
+ private:
+ // enumerate of available data fields
+ enum PROPINDEX {
+ PROP_HWID, // hardware id
+ PROP_ROOTKEY, // root key
+ PROP_BMPFV, // bitmap FV
+ };
+
+ // clear all cached data and initialize to original state
+ void initialize();
+
+ // search and count for GBB signatures in loaded image.
+ // return the number of signatures found.
+ int search_header_signatures(const std::string &image, long *poffset) const;
+
+ // load and check header structure from image by given offset.
+ // return true if a valid GBB header is loaded into *phdr.
+ bool load_gbb_header(const std::string &image, long offset,
+ GoogleBinaryBlockHeader *phdr) const;
+
+ // retrieve a property from GBB data.
+ // return the property value.
+ std::string get_property(PROPINDEX i) const;
+
+ // overwrite a property in GBB data.
+ // return true on success.
+ bool set_property(PROPINDEX i, const std::string &value);
+
+ // find the size and offset information for given property
+ // return true if the offset and size are assign to *poffset and *psize.
+ bool find_property(PROPINDEX i, uint32_t *poffset, uint32_t *psize) const;
+
+ GoogleBinaryBlockHeader header_; // copy of GBB header from image
+ std::string file_content_; // complete image file content
+ long header_offset_; // offset to GBB header in file_content_
+ bool is_valid_gbb; // if we are holding a valid GBB
+
+ bool verbose; // provide verbose messages
+};
+
+} // namespace vboot_reference
+
+#endif // VBOOT_REFERENCE_GBB_UTILITY_H_
+