futility: updater: Report EC and PD images on emulation

When testing updater behavior with emulation (--emulate), there was no
way to know if EC and PD images were correctly found from archive and
expected to be flashed (for example if we want to test the difference
between modes).

Since we do flash EC/PD in recovery and factory modes, it is better
to still allow loading EC/PD images, and simply not writing them
(and print some messages as indication) in emulation.

BUG=chromium:965092
TEST=make runfutiltests
BRANCH=None

Change-Id: I3bbbd75cb8adf2e238a593d3dee0b2491abe7719
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1626190
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Dana Goyette <dgoyette@chromium.org>
diff --git a/futility/updater.c b/futility/updater.c
index 0a7a3d5..82ee4a4 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -887,7 +887,8 @@
 static int write_optional_firmware(struct updater_config *cfg,
 				   const struct firmware_image *image,
 				   const char *section_name,
-				   int check_programmer_wp)
+				   int check_programmer_wp,
+				   int is_host)
 {
 	if (!image->data) {
 		VB2_DEBUG("No data in <%s> image.\n", image->programmer);
@@ -898,6 +899,14 @@
 			  image->file_name, image->programmer, section_name);
 		return 0;
 	}
+	/* Currently only host emulation is supported. */
+	if (cfg->emulation && !is_host) {
+		INFO("(emulation) Update %s from %s to %s (%d bytes), "
+		     "skipped for non-host targets in emulation.\n",
+		     section_name ? section_name : "whole image",
+		     image->file_name, image->programmer, image->size);
+		return 0;
+	}
 
 	/*
 	 * EC & PD may have different WP settings and we want to write
@@ -1577,7 +1586,7 @@
 	if (write_firmware(cfg, image_to, FMAP_RW_SECTION_A) ||
 	    write_firmware(cfg, image_to, FMAP_RW_SECTION_B) ||
 	    write_firmware(cfg, image_to, FMAP_RW_SHARED) ||
-	    write_optional_firmware(cfg, image_to, FMAP_RW_LEGACY, 0))
+	    write_optional_firmware(cfg, image_to, FMAP_RW_LEGACY, 0, 1))
 		return UPDATE_ERR_WRITE_FIRMWARE;
 
 	return UPDATE_ERR_DONE;
@@ -1648,8 +1657,8 @@
 
 	/* FMAP may be different so we should just update all. */
 	if (write_firmware(cfg, image_to, NULL) ||
-	    write_optional_firmware(cfg, &cfg->ec_image, NULL, 1) ||
-	    write_optional_firmware(cfg, &cfg->pd_image, NULL, 1))
+	    write_optional_firmware(cfg, &cfg->ec_image, NULL, 1, 0) ||
+	    write_optional_firmware(cfg, &cfg->pd_image, NULL, 1, 0))
 		return UPDATE_ERR_WRITE_FIRMWARE;
 
 	return UPDATE_ERR_DONE;
@@ -1833,7 +1842,7 @@
 		if (!errorcnt)
 			errorcnt += updater_setup_quirks(cfg, arg);
 	}
-	if (cfg->emulation || arg->host_only)
+	if (arg->host_only)
 		return errorcnt;
 
 	if (!cfg->ec_image.data && ec_image)
@@ -2049,7 +2058,6 @@
 	/* Set up archive and load images. */
 	if (arg->emulation) {
 		/* Process emulation file first. */
-		check_single_image = 1;
 		cfg->emulation = arg->emulation;
 		VB2_DEBUG("Using file %s for emulation.\n", arg->emulation);
 		errorcnt += !!load_firmware_image(