summaryrefslogtreecommitdiff
path: root/futility/updater.h
diff options
context:
space:
mode:
Diffstat (limited to 'futility/updater.h')
-rw-r--r--futility/updater.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/futility/updater.h b/futility/updater.h
index 85540a90..02c1d8e5 100644
--- a/futility/updater.h
+++ b/futility/updater.h
@@ -8,11 +8,95 @@
#ifndef VBOOT_REFERENCE_FUTILITY_UPDATER_H_
#define VBOOT_REFERENCE_FUTILITY_UPDATER_H_
+#include "fmap.h"
#include "futility.h"
#define DEBUG(format, ...) Debug("%s: " format "\n", __FUNCTION__,##__VA_ARGS__)
#define ERROR(format, ...) Error("%s: " format "\n", __FUNCTION__,##__VA_ARGS__)
+/* FMAP section names. */
+static const char * const FMAP_RO_FRID = "RO_FRID",
+ * const FMAP_RO_SECTION = "RO_SECTION",
+ * const FMAP_RO_GBB = "GBB",
+ * const FMAP_RO_PRESERVE = "RO_PRESERVE",
+ * const FMAP_RO_VPD = "RO_VPD",
+ * const FMAP_RW_VPD = "RW_VPD",
+ * const FMAP_RW_VBLOCK_A = "VBLOCK_A",
+ * const FMAP_RW_SECTION_A = "RW_SECTION_A",
+ * const FMAP_RW_SECTION_B = "RW_SECTION_B",
+ * const FMAP_RW_FWID = "RW_FWID",
+ * const FMAP_RW_FWID_A = "RW_FWID_A",
+ * const FMAP_RW_FWID_B = "RW_FWID_B",
+ * const FMAP_RW_SHARED = "RW_SHARED",
+ * const FMAP_RW_NVRAM = "RW_NVRAM",
+ * const FMAP_RW_ELOG = "RW_ELOG",
+ * const FMAP_RW_PRESERVE = "RW_PRESERVE",
+ * const FMAP_RW_LEGACY = "RW_LEGACY",
+ * const FMAP_SI_DESC = "SI_DESC",
+ * const FMAP_SI_ME = "SI_ME";
+
+struct firmware_image {
+ const char *programmer;
+ uint32_t size;
+ uint8_t *data;
+ char *file_name;
+ char *ro_version, *rw_version_a, *rw_version_b;
+ FmapHeader *fmap_header;
+};
+
+struct firmware_section {
+ uint8_t *data;
+ size_t size;
+};
+
+struct system_property {
+ int (*getter)();
+ int value;
+ int initialized;
+};
+
+enum system_property_type {
+ SYS_PROP_MAINFW_ACT,
+ SYS_PROP_TPM_FWVER,
+ SYS_PROP_FW_VBOOT2,
+ SYS_PROP_PLATFORM_VER,
+ SYS_PROP_WP_HW,
+ SYS_PROP_WP_SW,
+ SYS_PROP_MAX
+};
+
+struct updater_config;
+struct quirk_entry {
+ const char *name;
+ const char *help;
+ int (*apply)(struct updater_config *cfg);
+ int value;
+};
+
+enum quirk_types {
+ QUIRK_ENLARGE_IMAGE,
+ QUIRK_MIN_PLATFORM_VERSION,
+ QUIRK_UNLOCK_ME_FOR_UPDATE,
+ QUIRK_MAX,
+};
+
+struct tempfile {
+ char *filepath;
+ struct tempfile *next;
+};
+
+struct updater_config {
+ struct firmware_image image, image_current;
+ struct firmware_image ec_image, pd_image;
+ struct system_property system_properties[SYS_PROP_MAX];
+ struct quirk_entry quirks[QUIRK_MAX];
+ struct tempfile *tempfiles;
+ int try_update;
+ int force_update;
+ int legacy_update;
+ const char *emulation;
+};
+
enum updater_error_codes {
UPDATE_ERR_DONE,
UPDATE_ERR_NEED_RO_UPDATE,
@@ -71,4 +155,37 @@ int updater_setup_config(struct updater_config *cfg,
/* Prints the name and description from all supported quirks. */
void updater_list_config_quirks(const struct updater_config *cfg);
+/*
+ * Registers known quirks to a updater_config object.
+ */
+void updater_register_quirks(struct updater_config *cfg);
+
+/*
+ * Helper function to create a new temporary file.
+ * Returns the path of new file, or NULL on failure.
+ */
+const char *create_temp_file(struct updater_config *cfg);
+
+/*
+ * Finds a firmware section by given name in the firmware image.
+ * If successful, return zero and *section argument contains the address and
+ * size of the section; otherwise failure.
+ */
+int find_firmware_section(struct firmware_section *section,
+ const struct firmware_image *image,
+ const char *section_name);
+
+/* Loads a firmware image from file. Returns 0 on success, otherwise failure. */
+int load_image(const char *file_name, struct firmware_image *image);
+
+/* Frees the allocated resource from a firmware image object. */
+void free_image(struct firmware_image *image);
+
+/* Gets the value (setting) of specified quirks from updater configuration. */
+int get_config_quirk(enum quirk_types quirk, const struct updater_config *cfg);
+
+/* Gets the system property by given type. Returns the property value. */
+int get_system_property(enum system_property_type property_type,
+ struct updater_config *cfg);
+
#endif /* VBOOT_REFERENCE_FUTILITY_UPDATER_H_ */