summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-09-28 17:01:32 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-10-02 09:17:11 -0700
commitbbe5fda1e8f35bd242ba2e2766a110bada4389e4 (patch)
tree8370f74f178601a85ade29a1a65f1f3b2721a3ae
parent6d211585f519a3ace76b01a372523207fb695a1c (diff)
downloadvboot-bbe5fda1e8f35bd242ba2e2766a110bada4389e4.tar.gz
futility: updater: Support reading main image from stdin
"Can we make futility support stdin like flashrom? I typically flash with: ssh root@DUT flashrom -p host - < foo.bin" Yes we can: ssh root@DUT futility update -i - < foo.bin BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ib1ee5d4c882620e3b6f56fd5e4692b4829cf025a Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1251141 Reviewed-by: Raul E Rangel <rrangel@chromium.org>
-rw-r--r--futility/updater.c31
-rwxr-xr-xtests/futility/test_update.sh4
2 files changed, 34 insertions, 1 deletions
diff --git a/futility/updater.c b/futility/updater.c
index 5480f7e9..7541cdf1 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -1593,6 +1593,28 @@ struct updater_config *updater_new_config()
}
/*
+ * Saves everything from stdin to given output file.
+ * Returns 0 on success, otherwise failure.
+ */
+static int save_from_stdin(const char *output)
+{
+ FILE *in = stdin, *out = fopen(output, "wb");
+ char buffer[4096];
+ size_t sz;
+
+ assert(in);
+ if (!out)
+ return -1;
+
+ while (!feof(in)) {
+ sz = fread(buffer, 1, sizeof(buffer), in);
+ fwrite(buffer, 1, sz, out);
+ }
+ fclose(out);
+ return 0;
+}
+
+/*
* Helper function to setup an allocated updater_config object.
* Returns number of failures, or 0 on success.
*/
@@ -1622,8 +1644,15 @@ int updater_setup_config(struct updater_config *cfg,
if (sys_props)
override_properties_from_list(sys_props, cfg);
- if (image)
+ if (image && strcmp(image, "-") == 0) {
+ fprintf(stderr, "Reading image from stdin...\n");
+ image = create_temp_file(cfg);
+ if (image)
+ errorcnt += !!save_from_stdin(image);
+ }
+ if (image) {
errorcnt += !!load_image(image, &cfg->image);
+ }
if (ec_image)
errorcnt += !!load_image(ec_image, &cfg->ec_image);
if (pd_image)
diff --git a/tests/futility/test_update.sh b/tests/futility/test_update.sh
index d45e114c..655d17dc 100755
--- a/tests/futility/test_update.sh
+++ b/tests/futility/test_update.sh
@@ -170,6 +170,10 @@ test_update "Full update (Skip TPM check with --force)" \
"${FROM_IMAGE}" "${TMP}.expected.full" \
-i "${TO_IMAGE}" --wp=0 --sys_props 0,-1,1 --force
+test_update "Full update (from stdin)" \
+ "${FROM_IMAGE}" "${TMP}.expected.full" \
+ -i - --wp=0 --sys_props 0,-1,1 --force <"${TO_IMAGE}"
+
# Test RW-only update.
test_update "RW update" \
"${FROM_IMAGE}" "${TMP}.expected.rw" \