summaryrefslogtreecommitdiff
path: root/common/system.c
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2021-05-13 12:27:56 -0600
committerCommit Bot <commit-bot@chromium.org>2021-09-14 12:18:02 +0000
commit5d157c8679880b8c86bb3944daa35ba25aece58b (patch)
treec8285384008e6ee38b16d88e13f8f258298f3808 /common/system.c
parentda4711d25c547f760efd1b2e8df1af2957972eae (diff)
downloadchrome-ec-5d157c8679880b8c86bb3944daa35ba25aece58b.tar.gz
system: Add CrOS FWID to version output
EC version does not follow the the AP and OS version. This causes confusion during development. This change augments the EC version output to include the CrOS FWID when available. The CrOS FWID will be missing when the CrOS EC is built outside of cros_sdk. When CrOS FWID is missing 'CROS_FWID_MISSING' will be used. Zephyr/zmake support will be added later, CROS_FWID32 is set to 'CROS_FWID_MISSING' in zephyr builds until then. BUG=b:188073399 TEST=version 21-05-20 16:43:18.627 Chip: Nuvoton NPCX993F A.00160101 21-05-20 16:43:18.631 Board: 1 21-05-20 16:43:18.631 RO: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.634 guybrush_13983.0.21_05_20 21-05-20 16:43:18.639 RW_A: * guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.641 * guybrush_13983.0.21_05_20 21-05-20 16:43:18.644 RW_B: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.644 guybrush_13983.0.21_05_20 21-05-20 16:43:18.647 Build: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.651 guybrush_13983.0.21_05_20 2021-05-20 21-05-20 16:43:18.657 16:31:19 robbarnes@robbarnes0 ectool version RO version: guybrush_v2.0.8770+f47439f75 RO cros fwid: guybrush_13983.0.21_05_20 RW version: guybrush_v2.0.8770+f47439f75 RW cros fwid: guybrush_13983.0.21_05_20 Firmware copy: RO Build info: guybrush_v2.0.8770+f47439f75 guybrush_13983.0.21_05_20 2021-05-20 16:31:19 robbarnes@robbarnes0 Tool version: 1.1.9999-f47439f @robbarnes0 BRANCH=None Signed-off-by: Rob Barnes <robbarnes@google.com> Change-Id: Ief0a0c6e9d35edc72ac2d4780ee203be41d7305f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2894145 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/system.c')
-rw-r--r--common/system.c169
1 files changed, 103 insertions, 66 deletions
diff --git a/common/system.c b/common/system.c
index c8212bb422..985d64752e 100644
--- a/common/system.c
+++ b/common/system.c
@@ -12,6 +12,7 @@
#include "console.h"
#include "cpu.h"
#include "cros_board_info.h"
+#include "ec_version.h"
#include "dma.h"
#include "extpower.h"
#include "flash.h"
@@ -809,6 +810,23 @@ const char *system_get_version(enum ec_image copy)
return data ? data->version : "";
}
+
+const char *system_get_cros_fwid(enum ec_image copy)
+{
+ const struct image_data *data;
+
+ if (IS_ENABLED(CONFIG_CROS_FWID_VERSION)) {
+ data = system_get_image_data(copy);
+ if (data &&
+ (data->cookie3 & CROS_EC_IMAGE_DATA_COOKIE3_MASK) ==
+ CROS_EC_IMAGE_DATA_COOKIE3)
+ return data->cros_fwid;
+ else
+ return CROS_FWID_MISSING_STR;
+ }
+ return "";
+}
+
#ifdef CONFIG_ROLLBACK
int32_t system_get_rollback_version(enum ec_image copy)
{
@@ -1246,47 +1264,32 @@ DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate,
*
* cr50_v1.1.4979-0061603+ private-cr51:v0.0.66-bd9a0fe tpm2:v0.0.259-2b...
*
- * Each subcomponent in this case includes the ":v" substring. For these
- * combined version strings this function prints each version or subcomponent
- * version on a different line.
*/
static void print_build_string(void)
{
const char *full_build_string;
const char *p;
- char symbol;
- int seen_colonv;
+ size_t next_token_len;
+ size_t line_len = 0;
+ const size_t max_line_len = 50;
- ccprintf("Build: ");
+ ccprintf("Build:\t");
full_build_string = system_get_build_info();
-
- /* 50 characters or less, will fit into the terminal line. */
- if (strlen(full_build_string) < 50) {
- ccprintf("%s\n", full_build_string);
- return;
- }
-
- /*
- * Build version string needs splitting, let's split it at the first
- * space (this is where the main version ends), and then on each space
- * after the ":v" substring, this is where subcomponent versions are
- * separated.
- */
p = full_build_string;
- seen_colonv = 1;
-
- symbol = *p++;
- while (symbol) {
- if ((symbol == ' ') && seen_colonv) {
- seen_colonv = 0;
- /* Indent each line under 'Build: ' */
- ccprintf("\n ");
- } else {
- if ((symbol == ':') && (*p == 'v'))
- seen_colonv = 1;
- ccprintf("%c", symbol);
+
+ while (*p) {
+ /* Print first token */
+ if (*p == ' ') {
+ next_token_len = strcspn(p + 1, " \0");
+ if (next_token_len + line_len > max_line_len) {
+ line_len = 0;
+ p++;
+ ccprintf("\n\t\t");
+ continue;
+ }
}
- symbol = *p++;
+ ccprintf("%c", *p++);
+ line_len++;
}
ccprintf("\n");
}
@@ -1294,46 +1297,66 @@ static void print_build_string(void)
static int command_version(int argc, char **argv)
{
int board_version;
+ const char *fw_version;
+ const char *cros_fwid;
+ bool __maybe_unused is_active;
- ccprintf("Chip: %s %s %s\n", system_get_chip_vendor(),
+ ccprintf("Chip:\t%s %s %s\n", system_get_chip_vendor(),
system_get_chip_name(), system_get_chip_revision());
board_version = system_get_board_version();
if (board_version < 0)
- ccprintf("Board: Error %d\n", -board_version);
+ ccprintf("Board:\tError %d\n", -board_version);
else
- ccprintf("Board: %d\n", board_version);
-
-#ifdef CHIP_HAS_RO_B
- {
- enum ec_image active;
-
- active = system_get_ro_image_copy();
- ccprintf("RO_A: %c %s\n",
- (active == EC_IMAGE_RO ? '*' : ' '),
- system_get_version(EC_IMAGE_RO));
- ccprintf("RO_B: %c %s\n",
- (active == EC_IMAGE_RO_B ? '*' : ' '),
- system_get_version(EC_IMAGE_RO_B));
+ ccprintf("Board:\t%d\n", board_version);
+
+ fw_version = system_get_version(EC_IMAGE_RO);
+ cros_fwid = system_get_cros_fwid(EC_IMAGE_RO);
+ if (IS_ENABLED(CHIP_HAS_RO_B)) {
+ is_active = system_get_ro_image_copy() == EC_IMAGE_RO;
+
+ ccprintf("RO_A:\t%s%s\n", is_active ? "* " : "", fw_version);
+ if (IS_NONEMPTY_STRING(cros_fwid))
+ ccprintf("\t\t%s%s\n", is_active ? "* " : "",
+ cros_fwid);
+
+ is_active = system_get_ro_image_copy() == EC_IMAGE_RO_B;
+ fw_version = system_get_version(EC_IMAGE_RO_B);
+ cros_fwid = system_get_cros_fwid(EC_IMAGE_RO_B);
+
+ ccprintf("RO_B:\t%s%s\n", is_active ? "* " : "", fw_version);
+ if (IS_NONEMPTY_STRING(cros_fwid))
+ ccprintf("\t\t%s%s\n", is_active ? "* " : "",
+ cros_fwid);
+ } else {
+ ccprintf("RO:\t%s\n", fw_version);
+ if (IS_NONEMPTY_STRING(cros_fwid))
+ ccprintf("\t\t%s\n", cros_fwid);
}
-#else
- ccprintf("RO: %s\n", system_get_version(EC_IMAGE_RO));
-#endif
-#ifdef CONFIG_RW_B
- {
- enum ec_image active;
-
- active = system_get_image_copy();
- ccprintf("RW_A: %c %s\n",
- (active == EC_IMAGE_RW ? '*' : ' '),
- system_get_version(EC_IMAGE_RW));
- ccprintf("RW_B: %c %s\n",
- (active == EC_IMAGE_RW_B ? '*' : ' '),
- system_get_version(EC_IMAGE_RW_B));
+
+ fw_version = system_get_version(EC_IMAGE_RW);
+ cros_fwid = system_get_cros_fwid(EC_IMAGE_RW);
+ if (IS_ENABLED(CONFIG_RW_B)) {
+ is_active = system_get_active_copy() == EC_IMAGE_RW;
+
+ ccprintf("RW_A:\t%s%s\n", is_active ? "* " : "", fw_version);
+ if (IS_NONEMPTY_STRING(cros_fwid))
+ ccprintf("\t\t%s%s\n", is_active ? "* " : "",
+ cros_fwid);
+
+ fw_version = system_get_version(EC_IMAGE_RW_B);
+ cros_fwid = system_get_cros_fwid(EC_IMAGE_RW_B);
+ is_active = system_get_active_copy() == EC_IMAGE_RW_B;
+
+ ccprintf("RW_B:\t%s%s\n", is_active ? "* " : "", fw_version);
+ if (IS_NONEMPTY_STRING(cros_fwid))
+ ccprintf("\t\t%s%s\n", is_active ? "* " : "",
+ cros_fwid);
+ } else {
+ ccprintf("RW:\t%s\n", fw_version);
+ if (IS_NONEMPTY_STRING(cros_fwid))
+ ccprintf("\t\t%s\n", cros_fwid);
}
-#else
- ccprintf("RW: %s\n", system_get_version(EC_IMAGE_RW));
-#endif
system_print_extended_version_info();
print_build_string();
@@ -1548,6 +1571,9 @@ host_command_get_version(struct host_cmd_handler_args *args)
struct ec_response_get_version *r = args->response;
enum ec_image active_slot = system_get_active_copy();
+ /* Clear optional fields (i.e. cros_fwid). */
+ memset(r, 0, sizeof(*r));
+
strzcpy(r->version_string_ro, system_get_version(EC_IMAGE_RO),
sizeof(r->version_string_ro));
strzcpy(r->version_string_rw,
@@ -1567,13 +1593,24 @@ host_command_get_version(struct host_cmd_handler_args *args)
break;
}
- args->response_size = sizeof(*r);
+ if (args->version > 0 && IS_ENABLED(CONFIG_CROS_FWID_VERSION)) {
+ strzcpy(r->cros_fwid_ro, system_get_cros_fwid(EC_IMAGE_RO),
+ sizeof(r->cros_fwid_ro));
+ strzcpy(r->cros_fwid_rw, system_get_cros_fwid(EC_IMAGE_RW),
+ sizeof(r->cros_fwid_rw));
+ }
+ if (args->version == 0)
+ /* cros_fwid_rw[32] is not present in version 0 */
+ args->response_size =
+ offsetof(struct ec_response_get_version, cros_fwid_rw);
+ else
+ args->response_size = sizeof(struct ec_response_get_version);
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_GET_VERSION,
host_command_get_version,
- EC_VER_MASK(0));
+ EC_VER_MASK(0) | EC_VER_MASK(1));
#ifdef CONFIG_HOSTCMD_SKUID
static enum ec_status