diff options
author | Hung-Te Lin <hungte@chromium.org> | 2018-08-21 17:32:44 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-31 05:22:44 -0700 |
commit | d5e8445e3fd4694802e2246dd7e4c0df55ef0adc (patch) | |
tree | 64fc3e5c82005611edd123437a85a132271bf0ab | |
parent | fdbb87b113897d08cc0c8b9c4c460d02b47063f7 (diff) | |
download | vboot-d5e8445e3fd4694802e2246dd7e4c0df55ef0adc.tar.gz |
futility: Add 'update' command for updating firmware
A reference firmware updater for all systems running vboot using FMAP for
layout. The updater is currently a dummy implementation and will be completed
with incoming changes.
BUG=chromium:875551
TEST=make futil; build/futility/futility update;
tests/futility/run_test_scripts.sh $(pwd)/build/futility
BRANCH=None
Change-Id: I57bec91c178749b79a19789f9599f5f9048fced8
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1182701
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | futility/cmd_update.c | 104 | ||||
-rwxr-xr-x | tests/futility/run_test_scripts.sh | 1 | ||||
-rwxr-xr-x | tests/futility/test_update.sh | 13 |
4 files changed, 119 insertions, 0 deletions
@@ -667,6 +667,7 @@ FUTIL_STATIC_SRCS = \ futility/futility.c \ futility/cmd_dump_fmap.c \ futility/cmd_gbb_utility.c \ + futility/cmd_update.c \ futility/cmd_vbutil_firmware.c \ futility/cmd_vbutil_key.c \ futility/misc.c \ diff --git a/futility/cmd_update.c b/futility/cmd_update.c new file mode 100644 index 00000000..ac1246e4 --- /dev/null +++ b/futility/cmd_update.c @@ -0,0 +1,104 @@ +/* + * Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * A reference implementation for AP (and supporting images) firmware updater. + */ + +#include <getopt.h> +#include <stdio.h> +#include <stdlib.h> + +#include "futility.h" +#include "utility.h" + +struct updater_config { +}; + +enum updater_error_codes { + UPDATE_ERR_DONE, + UPDATE_ERR_UNKNOWN, +}; + +static const char * const updater_error_messages[] = { + [UPDATE_ERR_DONE] = "Done (no error)", + [UPDATE_ERR_UNKNOWN] = "Unknown error.", +}; + +/* + * The main updater to update system firmware using the configuration parameter. + * Returns UPDATE_ERR_DONE if success, otherwise failure. + */ +static enum updater_error_codes update_firmware(struct updater_config *cfg) +{ + return UPDATE_ERR_DONE; +} + +/* Command line options */ +static struct option const long_opts[] = { + /* name has_arg *flag val */ + {"help", 0, NULL, 'h'}, + {NULL, 0, NULL, 0}, +}; + +static const char * const short_opts = "h"; + +static void print_help(int argc, char *argv[]) +{ + printf("\n" + "Usage: " MYNAME " %s [OPTIONS]\n" + "\n" + "", + argv[0]); +} + +static int do_update(int argc, char *argv[]) +{ + int i, errorcnt = 0; + struct updater_config cfg = {}; + + printf(">> Firmware updater started.\n"); + + opterr = 0; + while ((i = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) { + switch (i) { + case 'h': + print_help(argc, argv); + return !!errorcnt; + case '?': + errorcnt++; + if (optopt) + Error("Unrecognized option: -%c\n", optopt); + else if (argv[optind - 1]) + Error("Unrecognized option (possibly '%s')\n", + argv[optind - 1]); + else + Error("Unrecognized option.\n"); + break; + default: + errorcnt++; + Error("Failed parsing options.\n"); + } + } + if (optind < argc) { + errorcnt++; + Error("Unexpected arguments.\n"); + } + if (!errorcnt) { + int r = update_firmware(&cfg); + if (r != UPDATE_ERR_DONE) { + r = Min(r, UPDATE_ERR_UNKNOWN); + Error("%s\n", updater_error_messages[r]); + errorcnt++; + } + } + printf(">> %s: Firmware updater %s.\n", + errorcnt ? "FAILED": "DONE", + errorcnt ? "stopped due to error" : "exited successfully"); + + return !!errorcnt; +} + +DECLARE_FUTIL_COMMAND(update, do_update, VBOOT_VERSION_ALL, + "Update system firmware"); diff --git a/tests/futility/run_test_scripts.sh b/tests/futility/run_test_scripts.sh index 15a2580c..7171b483 100755 --- a/tests/futility/run_test_scripts.sh +++ b/tests/futility/run_test_scripts.sh @@ -56,6 +56,7 @@ ${SCRIPTDIR}/test_sign_fw_main.sh ${SCRIPTDIR}/test_sign_kernel.sh ${SCRIPTDIR}/test_sign_keyblocks.sh ${SCRIPTDIR}/test_sign_usbpd1.sh +${SCRIPTDIR}/test_update.sh ${SCRIPTDIR}/test_file_types.sh " diff --git a/tests/futility/test_update.sh b/tests/futility/test_update.sh new file mode 100755 index 00000000..7f747c61 --- /dev/null +++ b/tests/futility/test_update.sh @@ -0,0 +1,13 @@ +#!/bin/bash -eux +# Copyright 2018 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +me=${0##*/} +TMP="$me.tmp" + +# Work in scratch directory +cd "$OUTDIR" + +# Test command execution. +"${FUTILITY}" update |