summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--futility/updater.c23
-rw-r--r--futility/updater.h1
-rwxr-xr-xtests/futility/test_update.sh12
3 files changed, 26 insertions, 10 deletions
diff --git a/futility/updater.c b/futility/updater.c
index 39daf9b4..5cd29f4a 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -898,12 +898,13 @@ const struct vb2_gbb_header *find_gbb(const struct firmware_image *image)
/*
* Preserve the GBB contents from image_from to image_to.
- * Currently only GBB flags and HWID are preserved.
+ * HWID is always preserved, and flags are preserved only if preserve_flags set.
* Returns 0 if success, otherwise -1 if GBB header can't be found or if HWID is
* too large.
*/
static int preserve_gbb(const struct firmware_image *image_from,
- struct firmware_image *image_to)
+ struct firmware_image *image_to,
+ int preserve_flags)
{
int len;
uint8_t *hwid_to, *hwid_from;
@@ -917,8 +918,10 @@ static int preserve_gbb(const struct firmware_image *image_from,
if (!gbb_from || !gbb_to)
return -1;
- /* Preserve flags. */
- gbb_to->flags = gbb_from->flags;
+ /* Preserve flags (for non-factory mode). */
+ if (preserve_flags)
+ gbb_to->flags = gbb_from->flags;
+
hwid_to = (uint8_t *)gbb_to + gbb_to->hwid_offset;
hwid_from = (uint8_t *)gbb_from + gbb_from->hwid_offset;
@@ -979,7 +982,7 @@ static int preserve_images(struct updater_config *cfg)
"RO_FSG",
};
- errcnt += preserve_gbb(from, to);
+ errcnt += preserve_gbb(from, to, !cfg->factory_update);
errcnt += preserve_management_engine(cfg, from, to);
errcnt += preserve_firmware_section(from, to, FMAP_RO_VPD);
errcnt += preserve_firmware_section(from, to, FMAP_RW_VPD);
@@ -1378,7 +1381,7 @@ static enum updater_error_codes update_try_rw_firmware(
int has_update = 1;
int is_vboot2 = get_system_property(SYS_PROP_FW_VBOOT2, cfg);
- preserve_gbb(image_from, image_to);
+ preserve_gbb(image_from, image_to, 1);
if (!wp_enabled && section_needs_update(
image_from, image_to, FMAP_RO_SECTION))
return UPDATE_ERR_NEED_RO_UPDATE;
@@ -1673,12 +1676,12 @@ int updater_setup_config(struct updater_config *cfg,
int errorcnt = 0;
int check_single_image = 0, check_wp_disabled = 0;
const char *default_quirks = NULL;
- int is_factory = arg->is_factory;
const char *archive_path = arg->archive;
struct manifest *manifest = NULL;
/* Setup values that may change output or decision of other argument. */
cfg->verbosity = arg->verbosity;
+ cfg->factory_update = arg->is_factory;
if (arg->force_update)
cfg->force_update = 1;
@@ -1700,14 +1703,14 @@ int updater_setup_config(struct updater_config *cfg,
cfg->legacy_update = 1;
} else if (strcmp(arg->mode, "factory") == 0 ||
strcmp(arg->mode, "factory_install") == 0) {
- is_factory = 1;
+ cfg->factory_update = 1;
} else {
errorcnt++;
ERROR("Invalid mode: %s", arg->mode);
}
}
- if (is_factory) {
- /* is_factory must be processed after arg->mode. */
+ if (cfg->factory_update) {
+ /* factory_update must be processed after arg->mode. */
check_wp_disabled = 1;
cfg->try_update = 0;
}
diff --git a/futility/updater.h b/futility/updater.h
index 3971c4e6..21bdbdb5 100644
--- a/futility/updater.h
+++ b/futility/updater.h
@@ -106,6 +106,7 @@ struct updater_config {
int try_update;
int force_update;
int legacy_update;
+ int factory_update;
int verbosity;
const char *emulation;
};
diff --git a/tests/futility/test_update.sh b/tests/futility/test_update.sh
index c7880486..6bb627c8 100755
--- a/tests/futility/test_update.sh
+++ b/tests/futility/test_update.sh
@@ -112,6 +112,10 @@ cp -f "${FROM_IMAGE}" "${TMP}.expected.legacy"
RW_SECTION_B:${TMP}.to/RW_SECTION_B
"${FUTILITY}" load_fmap "${TMP}.expected.legacy" \
RW_LEGACY:${TMP}.to/RW_LEGACY
+cp -f "${TMP}.expected.full" "${TMP}.expected.full.gbb0"
+"${FUTILITY}" gbb -s --flags=0 "${TMP}.expected.full.gbb0"
+cp -f "${FROM_IMAGE}" "${FROM_IMAGE}.gbb0"
+"${FUTILITY}" gbb -s --flags=0 "${FROM_IMAGE}.gbb0"
cp -f "${TMP}.expected.full" "${TMP}.expected.large"
dd if=/dev/zero bs=8388608 count=1 | tr '\000' '\377' >>"${TMP}.expected.large"
cp -f "${TMP}.expected.full" "${TMP}.expected.me_unlocked"
@@ -174,6 +178,10 @@ test_update "Full update (from stdin)" \
"${FROM_IMAGE}" "${TMP}.expected.full" \
-i - --wp=0 --sys_props 0,-1,1 --force <"${TO_IMAGE}"
+test_update "Full update (GBB=0 -> 0)" \
+ "${FROM_IMAGE}.gbb0" "${TMP}.expected.full.gbb0" \
+ -i "${TO_IMAGE}" --wp=0 --sys_props 0,0x10001,1
+
# Test RW-only update.
test_update "RW update" \
"${FROM_IMAGE}" "${TMP}.expected.rw" \
@@ -253,6 +261,10 @@ test_update "Factory mode update (WP=1)" \
"${FROM_IMAGE}" "!needs WP disabled" \
--factory -i "${TO_IMAGE}" --wp=1 --sys_props 0,0x10001,1
+test_update "Factory mode update (GBB=0 -> 39)" \
+ "${FROM_IMAGE}.gbb0" "${TMP}.expected.full" \
+ --factory -i "${TO_IMAGE}" --wp=0 --sys_props 0,0x10001,1
+
# Test legacy update
test_update "Legacy update" \
"${FROM_IMAGE}" "${TMP}.expected.legacy" \