summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-08-22 22:29:27 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-09-05 09:15:18 -0700
commit1d4e02d8bab3f0aff945dcb6a3d828af53472b64 (patch)
tree966001f2f720243bfe0d0012ec61c5a3a9aa494d
parent48e48b777a8e8ec7603829805b3939b8d771f0c8 (diff)
downloadvboot-1d4e02d8bab3f0aff945dcb6a3d828af53472b64.tar.gz
futility: cmd_update: Add vboot1 updater logic
There are still many devices running vboot1 and we need to support them as well. There is no way to determine if a firmware is vboot2 or not, so we can only rely on the system property "fw_vboot2". If fw_vboot2 is 0, then we should always update section B and compare content with section A. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Iefdcb81099914c2183c627a33eb73678d1269bc1 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1184952 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--futility/cmd_update.c42
-rwxr-xr-xtests/futility/test_update.sh17
2 files changed, 47 insertions, 12 deletions
diff --git a/futility/cmd_update.c b/futility/cmd_update.c
index 95832a72..03186cd5 100644
--- a/futility/cmd_update.c
+++ b/futility/cmd_update.c
@@ -96,6 +96,7 @@ struct system_property {
enum system_property_type {
SYS_PROP_MAINFW_ACT,
+ SYS_PROP_FW_VBOOT2,
SYS_PROP_WP_HW,
SYS_PROP_WP_SW,
SYS_PROP_MAX
@@ -192,6 +193,12 @@ static int host_get_wp_hw()
return v;
}
+/* A helper function to return "fw_vboot2" system property. */
+static int host_get_fw_vboot2()
+{
+ return VbGetSystemPropertyInt("fw_vboot2");
+}
+
/*
* A helper function to invoke flashrom(8) command.
* Returns 0 if success, non-zero if error.
@@ -545,11 +552,16 @@ static void free_image(struct firmware_image *image)
* Returns the section name if success, otherwise NULL.
*/
static const char *decide_rw_target(struct updater_config *cfg,
- enum target_type target)
+ enum target_type target,
+ int is_vboot2)
{
const char *a = FMAP_RW_SECTION_A, *b = FMAP_RW_SECTION_B;
int slot = get_system_property(SYS_PROP_MAINFW_ACT, cfg);
+ /* In vboot1, always update B and check content with A. */
+ if (!is_vboot2)
+ return target == TARGET_UPDATE ? b : a;
+
switch (slot) {
case SLOT_A:
return target == TARGET_UPDATE ? b : a;
@@ -567,7 +579,8 @@ static const char *decide_rw_target(struct updater_config *cfg,
* The `target` argument is an FMAP section name indicating which to try.
* Returns 0 if success, non-zero if error.
*/
-static int set_try_cookies(struct updater_config *cfg, const char *target)
+static int set_try_cookies(struct updater_config *cfg, const char *target,
+ int is_vboot2)
{
int tries = 6;
const char *slot;
@@ -592,8 +605,14 @@ static int set_try_cookies(struct updater_config *cfg, const char *target)
return 0;
}
- RETURN_ON_FAILURE(VbSetSystemPropertyString("fw_try_next", slot));
- RETURN_ON_FAILURE(VbSetSystemPropertyInt("fw_try_count", tries));
+ if (is_vboot2 && VbSetSystemPropertyString("fw_try_next", slot)) {
+ Error("Failed to set fw_try_next to %s.\n", slot);
+ return -1;
+ }
+ if (VbSetSystemPropertyInt("fw_try_count", tries)) {
+ Error("Failed to set fw_try_count to %d.\n", tries);
+ return -1;
+ }
return 0;
}
@@ -919,14 +938,16 @@ static enum updater_error_codes update_try_rw_firmware(
{
const char *target;
int has_update = 1;
+ int is_vboot2 = get_system_property(SYS_PROP_FW_VBOOT2, cfg);
preserve_gbb(image_from, image_to);
if (!wp_enabled && section_needs_update(
image_from, image_to, FMAP_RO_SECTION))
return UPDATE_ERR_NEED_RO_UPDATE;
- /* TODO(hungte): Support vboot1. */
- target = decide_rw_target(cfg, TARGET_SELF);
+ Debug("%s: Firmware %s vboot2.\n", __FUNCTION__,
+ is_vboot2 ? "is" : "is NOT");
+ target = decide_rw_target(cfg, TARGET_SELF, is_vboot2);
if (target == NULL) {
Error("TRY-RW update needs system to boot in RW firmware.\n");
return UPDATE_ERR_TARGET;
@@ -942,14 +963,18 @@ static enum updater_error_codes update_try_rw_firmware(
has_update = section_needs_update(image_from, image_to, target);
if (has_update) {
- target = decide_rw_target(cfg, TARGET_UPDATE);
+ target = decide_rw_target(cfg, TARGET_UPDATE, is_vboot2);
printf(">> TRY-RW UPDATE: Updating %s to try on reboot.\n",
target);
if (write_firmware(cfg, image_to, target))
return UPDATE_ERR_WRITE_FIRMWARE;
- if (set_try_cookies(cfg, target))
+ if (set_try_cookies(cfg, target, is_vboot2))
return UPDATE_ERR_SET_COOKIES;
+ } else {
+ /* Clear trial cookies for vboot1. */
+ if (!is_vboot2 && !cfg->emulate)
+ VbSetSystemPropertyInt("fwb_tries", 0);
}
/* TODO(hungte): Add optional checks here that may change has_update. */
@@ -1128,6 +1153,7 @@ static int do_update(int argc, char *argv[])
.emulate = 0,
.system_properties = {
[SYS_PROP_MAINFW_ACT] = {.getter = host_get_mainfw_act},
+ [SYS_PROP_FW_VBOOT2] = {.getter = host_get_fw_vboot2},
[SYS_PROP_WP_HW] = {.getter = host_get_wp_hw},
[SYS_PROP_WP_SW] = {.getter = host_get_wp_sw},
},
diff --git a/tests/futility/test_update.sh b/tests/futility/test_update.sh
index bc2a2ec9..3093e25d 100755
--- a/tests/futility/test_update.sh
+++ b/tests/futility/test_update.sh
@@ -79,7 +79,7 @@ test_update() {
cmp "${TMP}.emu" "${expected}"
}
-# --sys_props: mainfw_act, [wp_hw, wp_sw]
+# --sys_props: mainfw_act, is_vboot2, [wp_hw, wp_sw]
# Test Full update.
test_update "Full update" \
@@ -94,12 +94,21 @@ test_update "RW update" \
# Test Try-RW update (vboot2).
test_update "RW update (A->B)" \
"${FROM_IMAGE}" "${TMP}.expected.b" \
- -i "${TO_IMAGE}" -t --wp=1 --sys_props 0
+ -i "${TO_IMAGE}" -t --wp=1 --sys_props 0,1
test_update "RW update (B->A)" \
"${FROM_IMAGE}" "${TMP}.expected.a" \
- -i "${TO_IMAGE}" -t --wp=1 --sys_props 1
+ -i "${TO_IMAGE}" -t --wp=1 --sys_props 1,1
test_update "RW update -> fallback to RO+RW Full update" \
"${FROM_IMAGE}" "${TMP}.expected.full" \
- -i "${TO_IMAGE}" -t --wp=0 --sys_props 1
+ -i "${TO_IMAGE}" -t --wp=0 --sys_props 1,1
+
+# Test Try-RW update (vboot1).
+test_update "RW update (vboot1, A->B)" \
+ "${FROM_IMAGE}" "${TMP}.expected.b" \
+ -i "${TO_IMAGE}" -t --wp=1 --sys_props 0,0
+
+test_update "RW update (vboot1, B->B)" \
+ "${FROM_IMAGE}" "${TMP}.expected.b" \
+ -i "${TO_IMAGE}" -t --wp=1 --sys_props 1,0