summaryrefslogtreecommitdiff
path: root/futility/cmd_update.c
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-08-27 12:50:18 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-09-05 09:15:18 -0700
commit4256ddecd72ce6d2b3e7e10fbc328f57bfdc4ac6 (patch)
treee501a4c2a6781927a6101b6f5d802a6058dc1126 /futility/cmd_update.c
parent1d4e02d8bab3f0aff945dcb6a3d828af53472b64 (diff)
downloadvboot-4256ddecd72ce6d2b3e7e10fbc328f57bfdc4ac6.tar.gz
futility: cmd_update: Check platform compatibility before updating
A safety check so people won't accidentally flashed wrong firmware image and then being not able to boot. The platform is decided by extracting the first component (delimited by dot '.') of firmware ID. For example, platform for "Google_Link.123" is "Google_Link". BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I90a1631f6b3e9a675fe1990cf9c204d763faf54c Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1189248 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility/cmd_update.c')
-rw-r--r--futility/cmd_update.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/futility/cmd_update.c b/futility/cmd_update.c
index 03186cd5..5639497f 100644
--- a/futility/cmd_update.c
+++ b/futility/cmd_update.c
@@ -900,6 +900,30 @@ static int is_write_protection_enabled(struct updater_config *cfg)
return WP_ENABLED;
return wp;
}
+
+/*
+ * Checks if the given firmware images are compatible with current platform.
+ * In current implementation (following Chrome OS style), we assume the platform
+ * is identical to the name before a dot (.) in firmware version.
+ * Returns 0 for success, otherwise failure.
+ */
+static int check_compatible_platform(struct updater_config *cfg)
+{
+ int len;
+ struct firmware_image *image_from = &cfg->image_current,
+ *image_to = &cfg->image;
+ const char *from_dot = strchr(image_from->ro_version, '.'),
+ *to_dot = strchr(image_to->ro_version, '.');
+
+ if (!from_dot || !to_dot) {
+ Debug("%s: Missing dot (from=%p, to=%p)\n", from_dot, to_dot);
+ return -1;
+ }
+ len = from_dot - image_from->ro_version + 1;
+ Debug("%s: Platform: %*.*s\n", __FUNCTION__, len, len,
+ image_from->ro_version);
+ return strncmp(image_from->ro_version, image_to->ro_version, len);
+}
enum updater_error_codes {
UPDATE_ERR_DONE,
UPDATE_ERR_NEED_RO_UPDATE,
@@ -908,6 +932,7 @@ enum updater_error_codes {
UPDATE_ERR_INVALID_IMAGE,
UPDATE_ERR_SET_COOKIES,
UPDATE_ERR_WRITE_FIRMWARE,
+ UPDATE_ERR_PLATFORM,
UPDATE_ERR_TARGET,
UPDATE_ERR_UNKNOWN,
};
@@ -920,6 +945,7 @@ static const char * const updater_error_messages[] = {
[UPDATE_ERR_INVALID_IMAGE] = "The given firmware image is not valid.",
[UPDATE_ERR_SET_COOKIES] = "Failed writing system flags to try update.",
[UPDATE_ERR_WRITE_FIRMWARE] = "Failed writing firmware.",
+ [UPDATE_ERR_PLATFORM] = "Your system platform is not compatible.",
[UPDATE_ERR_TARGET] = "No valid RW target to update. Abort.",
[UPDATE_ERR_UNKNOWN] = "Unknown error.",
};
@@ -1061,6 +1087,9 @@ static enum updater_error_codes update_firmware(struct updater_config *cfg)
image_from->file_name, image_from->ro_version,
image_from->rw_version_a, image_from->rw_version_b);
+ if (check_compatible_platform(cfg))
+ return UPDATE_ERR_PLATFORM;
+
wp_enabled = is_write_protection_enabled(cfg);
printf(">> Write protection: %d (%s; HW=%d, SW=%d).\n", wp_enabled,
wp_enabled ? "enabled" : "disabled",