diff options
-rw-r--r-- | common/system.c | 169 | ||||
-rw-r--r-- | common/version.c | 8 | ||||
-rw-r--r-- | include/config.h | 5 | ||||
-rw-r--r-- | include/cros_version.h | 5 | ||||
-rw-r--r-- | include/ec_commands.h | 6 | ||||
-rw-r--r-- | include/system.h | 9 | ||||
-rw-r--r-- | include/util.h | 3 | ||||
-rw-r--r-- | test/build.mk | 2 | ||||
-rw-r--r-- | test/version.c | 149 | ||||
-rw-r--r-- | test/version.tasklist | 9 | ||||
-rw-r--r-- | util/ectool.c | 18 | ||||
-rwxr-xr-x | util/getversion.sh | 31 | ||||
-rw-r--r-- | zephyr/Kconfig | 7 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 5 | ||||
-rw-r--r-- | zephyr/zmake/tests/test_version.py | 4 | ||||
-rw-r--r-- | zephyr/zmake/zmake/version.py | 7 |
16 files changed, 367 insertions, 70 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 diff --git a/common/version.c b/common/version.c index 4b42418835..68ec632701 100644 --- a/common/version.c +++ b/common/version.c @@ -26,11 +26,19 @@ const struct image_data __keep current_image_data #endif .rollback_version = CONFIG_ROLLBACK_VERSION, .cookie2 = CROS_EC_IMAGE_DATA_COOKIE2, + .cros_fwid = CROS_FWID32, + .cookie3 = CROS_EC_IMAGE_DATA_COOKIE3, }; BUILD_ASSERT(sizeof(CROS_EC_VERSION32) <= 32); +BUILD_ASSERT(sizeof(CROS_FWID32) <= 32); +#ifdef CONFIG_CROS_FWID_VERSION +const char build_info[] __keep __attribute__((section(".rodata.buildinfo"))) = + VERSION " " CROS_FWID32 " " DATE " " BUILDER; +#else const char build_info[] __keep __attribute__((section(".rodata.buildinfo"))) = VERSION " " DATE " " BUILDER; +#endif static int get_num_commits(const struct image_data *data) { diff --git a/include/config.h b/include/config.h index 63dc4beb62..e555b8a78e 100644 --- a/include/config.h +++ b/include/config.h @@ -5208,6 +5208,11 @@ #undef CONFIG_EXTENDED_VERSION_INFO /* + * Include CROS_FWID in version output. + */ +#define CONFIG_CROS_FWID_VERSION + +/* * Define this to support Cros Board Info from EEPROM. I2C_PORT_EEPROM * and I2C_ADDR_EEPROM_FLAGS must be defined as well. */ diff --git a/include/cros_version.h b/include/cros_version.h index 0d3e777dc5..585c2c1013 100644 --- a/include/cros_version.h +++ b/include/cros_version.h @@ -13,6 +13,9 @@ #define CROS_EC_IMAGE_DATA_COOKIE1 0xce778899 #define CROS_EC_IMAGE_DATA_COOKIE2 0xceaabbdd +#define CROS_EC_IMAGE_DATA_COOKIE3 0xceeeff00 +#define CROS_EC_IMAGE_DATA_COOKIE3_MASK GENMASK(31, 8) +#define CROS_EC_IMAGE_DATA_COOKIE3_VERSION GENMASK(7, 0) struct image_data { uint32_t cookie1; @@ -20,6 +23,8 @@ struct image_data { uint32_t size; int32_t rollback_version; uint32_t cookie2; + char cros_fwid[32]; + uint32_t cookie3; } __packed; extern const struct image_data current_image_data; diff --git a/include/ec_commands.h b/include/ec_commands.h index 9395175e73..6e9c538e5e 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1152,14 +1152,16 @@ enum ec_image { * struct ec_response_get_version - Response to the get version command. * @version_string_ro: Null-terminated RO firmware version string. * @version_string_rw: Null-terminated RW firmware version string. - * @reserved: Unused bytes; was previously RW-B firmware version string. + * @cros_fwid_ro: Null-terminated RO CrOS FWID string. * @current_image: One of ec_image. + * @cros_fwid_rw: Null-terminated RW CrOS FWID string. */ struct ec_response_get_version { char version_string_ro[32]; char version_string_rw[32]; - char reserved[32]; + char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */ uint32_t current_image; + char cros_fwid_rw[32]; /* Added in version 1 */ } __ec_align4; /* Read test */ diff --git a/include/system.h b/include/system.h index 325d76f702..6d46392e38 100644 --- a/include/system.h +++ b/include/system.h @@ -286,6 +286,15 @@ const struct image_data *system_get_image_data(enum ec_image copy); const char *system_get_version(enum ec_image copy); /** + * Get the CrOS fwid string for an image + * + * @param copy Image copy to get version from, or SYSTEM_IMAGE_UNKNOWN + * to get the version for the currently running image. + * @return The fwid string for the image copy, or an empty string if error. + */ +const char *system_get_cros_fwid(enum ec_image copy); + +/** * Get the SKU ID for a device * * @return A value that identifies the SKU variant of a model. Its meaning and diff --git a/include/util.h b/include/util.h index 1b077d0f55..a1c1abb514 100644 --- a/include/util.h +++ b/include/util.h @@ -45,6 +45,9 @@ extern "C" { #define NULL ((void *)0) #endif +/* Returns true if string is not null and not empty */ +#define IS_NONEMPTY_STRING(s) ((s) && (s)[0]) + /** * Ensure that value `v` is between `min` and `max`. * diff --git a/test/build.mk b/test/build.mk index ec9e66ead3..6785024d2e 100644 --- a/test/build.mk +++ b/test/build.mk @@ -105,6 +105,7 @@ test-list-host += usb_pe_drp_noextended test-list-host += utils test-list-host += utils_str test-list-host += vboot +test-list-host += version test-list-host += x25519 test-list-host += stillness_detector endif @@ -242,6 +243,7 @@ usb_tcpmv2_compliance-y=usb_tcpmv2_compliance.o usb_tcpmv2_compliance_common.o \ utils-y=utils.o utils_str-y=utils_str.o vboot-y=vboot.o +version-y += version.o float-y=fp.o fp-y=fp.o x25519-y=x25519.o diff --git a/test/version.c b/test/version.c new file mode 100644 index 0000000000..ad7571d5f6 --- /dev/null +++ b/test/version.c @@ -0,0 +1,149 @@ +/* Copyright 2021 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. + * + * Test ec version + */ + +#include "common.h" +#include "ec_commands.h" +#include "stddef.h" +#include "system.h" +#include "util.h" +#include "test_util.h" + +/* + * Tests that fw version adheres to the expected format. + * Example fw version: host_v2.0.10135+b3e38e380c + */ +static int test_version(void) +{ + const char *fw_version; + size_t board_name_length, major_version_length, minor_version_length, + sub_minor_version_length, hash_length; + const char *major_version_ptr, *minor_version_ptr, + *sub_minor_version_ptr, *hash_ptr; + + fw_version = system_get_version(EC_IMAGE_RO); + + TEST_ASSERT(fw_version != NULL); + + ccprintf("fw_version: %s\n", fw_version); + + TEST_LE(strlen(fw_version), (size_t)32, "%zu"); + + board_name_length = strcspn(fw_version, "_"); + + TEST_GE(board_name_length, (size_t)3, "%zu"); + + major_version_ptr = fw_version + board_name_length + 1; + major_version_length = strcspn(major_version_ptr, "."); + + TEST_GE(major_version_length, (size_t)2, "%zu"); + TEST_EQ(major_version_ptr[0], 'v', "%c"); + for (int i = 1; i < major_version_length; i++) + TEST_ASSERT(isdigit(major_version_ptr[i])); + + minor_version_ptr = major_version_ptr + major_version_length + 1; + minor_version_length = strcspn(minor_version_ptr, "."); + + TEST_GE(minor_version_length, (size_t)1, "%zu"); + for (int i = 0; i < minor_version_length; i++) + TEST_ASSERT(isdigit(minor_version_ptr[i])); + + sub_minor_version_ptr = minor_version_ptr + minor_version_length + 1; + sub_minor_version_length = strcspn(sub_minor_version_ptr, "-+"); + + TEST_GE(sub_minor_version_length, (size_t)1, "%zu"); + for (int i = 0; i < sub_minor_version_length; i++) + TEST_ASSERT(isdigit(sub_minor_version_ptr[i])); + + hash_ptr = sub_minor_version_ptr + sub_minor_version_length + 1; + hash_length = strlen(hash_ptr); + + TEST_GE(hash_length, (size_t)8, "%zu"); + for (int i = 0; i < hash_length; i++) + TEST_ASSERT(isdigit(hash_ptr[i]) || + (hash_ptr[i] >= 'a' && hash_ptr[i] <= 'f')); + + return EC_SUCCESS; +} + +/* + * Tests that cros fwid adheres to the expected format. + * Example cros fwid: host_14175.0.21_08_24 + */ +static int test_fwid(void) +{ + const char *cros_fwid; + size_t board_name_length, major_version_length, minor_version_length, + sub_minor_version_length; + const char *major_version_ptr, *minor_version_ptr, + *sub_minor_version_ptr; + + cros_fwid = system_get_cros_fwid(EC_IMAGE_RO); + + TEST_ASSERT(cros_fwid != NULL); + + ccprintf("cros_fwid: %s\n", cros_fwid); + + TEST_LE(strlen(cros_fwid), (size_t)32, "%zu"); + + board_name_length = strcspn(cros_fwid, "_"); + TEST_GE(board_name_length, (size_t)3, "%zu"); + + major_version_ptr = cros_fwid + board_name_length + 1; + major_version_length = strcspn(major_version_ptr, "."); + TEST_GE(major_version_length, (size_t)5, "%zu"); + + for (int i = 0; i < major_version_length; i++) + TEST_ASSERT(isdigit(major_version_ptr[i])); + + minor_version_ptr = major_version_ptr + major_version_length + 1; + minor_version_length = strcspn(minor_version_ptr, "."); + TEST_GE(minor_version_length, (size_t)1, "%zu"); + + for (int i = 0; i < minor_version_length; i++) + TEST_ASSERT(isdigit(minor_version_ptr[i])); + + sub_minor_version_ptr = minor_version_ptr + minor_version_length + 1; + sub_minor_version_length = strlen(sub_minor_version_ptr); + TEST_GE(sub_minor_version_length, (size_t)1, "%zu"); + + for (int i = 0; i < sub_minor_version_length; i++) + TEST_ASSERT(isdigit(sub_minor_version_ptr[i]) || + sub_minor_version_ptr[i] == '_'); + + return EC_SUCCESS; +} + +/* + * Tests requesting TEST. + * Example fw version: host_v2.0.10135+b3e38e380c + */ +static int test_image_unknown(void) +{ + const char *fw_version; + const char *cros_fwid; + + fw_version = system_get_version(EC_IMAGE_UNKNOWN); + + TEST_ASSERT(fw_version != NULL); + TEST_LE(strlen(fw_version), (size_t)32, "%zu"); + + cros_fwid = system_get_cros_fwid(EC_IMAGE_UNKNOWN); + + TEST_ASSERT(cros_fwid != NULL); + TEST_LE(strlen(cros_fwid), (size_t)32, "%zu"); + + return EC_SUCCESS; +} + +void run_test(int argc, char **argv) +{ + RUN_TEST(test_version); + RUN_TEST(test_fwid); + RUN_TEST(test_image_unknown); + + test_print_result(); +} diff --git a/test/version.tasklist b/test/version.tasklist new file mode 100644 index 0000000000..e54ea001bd --- /dev/null +++ b/test/version.tasklist @@ -0,0 +1,9 @@ +/* Copyright 2021 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. + */ + +/** + * See CONFIG_TASK_LIST in config.h for details. + */ +#define CONFIG_TEST_TASK_LIST /* No test task */ diff --git a/util/ectool.c b/util/ectool.c index 8d2badaa2f..4f983e24f1 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -1071,9 +1071,17 @@ int cmd_version(int argc, char *argv[]) { struct ec_response_get_version r; char *build_string = (char *)ec_inbuf; + int cmdver = 1; int rv; - rv = ec_command(EC_CMD_GET_VERSION, 0, NULL, 0, &r, sizeof(r)); + if (!ec_cmd_version_supported(EC_CMD_GET_VERSION, 1)) { + cmdver = 0; + /* CrOS FWID is not supported. Set it to empty string. */ + r.cros_fwid_ro[0] = '\0'; + r.cros_fwid_rw[0] = '\0'; + } + + rv = ec_command(EC_CMD_GET_VERSION, cmdver, NULL, 0, &r, sizeof(r)); if (rv < 0) { fprintf(stderr, "ERROR: EC_CMD_GET_VERSION failed: %d\n", rv); goto exit; @@ -1085,16 +1093,22 @@ int cmd_version(int argc, char *argv[]) rv); goto exit; } + rv = 0; /* Ensure versions are null-terminated before we print them */ r.version_string_ro[sizeof(r.version_string_ro) - 1] = '\0'; r.version_string_rw[sizeof(r.version_string_rw) - 1] = '\0'; build_string[ec_max_insize - 1] = '\0'; - + r.cros_fwid_ro[sizeof(r.cros_fwid_ro) - 1] = '\0'; + r.cros_fwid_rw[sizeof(r.cros_fwid_rw) - 1] = '\0'; /* Print versions */ printf("RO version: %s\n", r.version_string_ro); + if (cmdver > 0 && strlen(r.cros_fwid_ro)) + printf("RO cros fwid: %s\n", r.cros_fwid_ro); printf("RW version: %s\n", r.version_string_rw); + if (cmdver > 0 && strlen(r.cros_fwid_rw)) + printf("RW cros fwid: %s\n", r.cros_fwid_rw); printf("Firmware copy: %s\n", (r.current_image < ARRAY_SIZE(image_names) ? image_names[r.current_image] : "?")); diff --git a/util/getversion.sh b/util/getversion.sh index 165383d879..3146b29c88 100755 --- a/util/getversion.sh +++ b/util/getversion.sh @@ -21,6 +21,11 @@ dc=$'\001' # Default marker to indicate 'dirty' repositories dirty_marker='+' +# Derive path to chromeos_version.sh script +CHROOT_SOURCE_ROOT="/mnt/host/source" +CHROMIUMOS_OVERLAY="${CHROOT_SOURCE_ROOT}/src/third_party/chromiumos-overlay" +CROS_VERSION_SCRIPT="${CHROMIUMOS_OVERLAY}/chromeos/config/chromeos_version.sh" + # This function examines the state of the current directory and attempts to # extract its version information: the latest tag, if any, how many patches # are there since the latest tag, the top sha1, and if there are local @@ -196,6 +201,32 @@ main() { done | sort | tail -1 | cut -d ' ' -f '2 3')" echo "#define DATE \"${gitdate}\"" fi + + # Use the chromeos_version_string when available. + # This will not work if run from a standalone CrOS EC checkout. + echo "#define CROS_FWID_MISSING_STR \"CROS_FWID_MISSING\"" + if [[ -f "${CROS_VERSION_SCRIPT}" ]]; then + cros_version_output=$("${CROS_VERSION_SCRIPT}") + CHROMEOS_BUILD=$(echo "${cros_version_output}" | \ + grep "^ *CHROMEOS_BUILD=" | cut -d= -f2) + CHROMEOS_BRANCH=$(echo "${cros_version_output}" | \ + grep "^ *CHROMEOS_BRANCH=" | cut -d= -f2) + CHROMEOS_PATCH=$(echo "${cros_version_output}" | \ + grep "^ *CHROMEOS_PATCH=" | cut -d= -f2) + # Official builds must set CHROMEOS_OFFICIAL=1. + if [ "${CHROMEOS_OFFICIAL:-0}" -ne 1 ]; then + # For developer builds, overwrite CHROMEOS_PATCH with the date. + # This date is abbreviated compared to chromeos_version.sh so + # fwid_version will more likely fit in 32 bytes. + CHROMEOS_PATCH=$(date +%y_%m_%d) + fi + fwid="${BOARD}_${CHROMEOS_BUILD}.${CHROMEOS_BRANCH}.${CHROMEOS_PATCH}" + echo "/* CrOS FWID of this build */" + echo "#define CROS_FWID32 \"${fwid:0:31}\"" + else + echo "/* CrOS FWID is not available for this build */" + echo "#define CROS_FWID32 CROS_FWID_MISSING_STR" + fi } main diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 58961630ce..563fddd737 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -281,6 +281,13 @@ config PLATFORM_EC_CONSOLE_CMD_SHMEM used and the maximum number of bytes that have been used since the EC started running. +config PLATFORM_EC_CROS_FWID_VERSION + bool "Include CrOS FWID version" + default y + help + Include Chrome OS FWID in version output. The CrOS FWID will be common + across OS, AP firmware and EC firmware when built together. + config PLATFORM_EC_DEBUG_ASSERT bool "Enable assertion failures" default y diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 0ab812a5b8..f53e4025b7 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -633,6 +633,11 @@ #define CONFIG_CMD_SHMEM #endif +#undef CONFIG_CROS_FWID_VERSION +#ifdef CONFIG_PLATFORM_EC_CROS_FWID_VERSION +#define CONFIG_CROS_FWID_VERSION +#endif + #ifdef CONFIG_PLATFORM_EC_TIMER #define CONFIG_HWTIMER_64BIT #define CONFIG_HW_SPECIFIC_UDELAY diff --git a/zephyr/zmake/tests/test_version.py b/zephyr/zmake/tests/test_version.py index 44997f94da..a238a8ac02 100644 --- a/zephyr/zmake/tests/test_version.py +++ b/zephyr/zmake/tests/test_version.py @@ -124,6 +124,8 @@ EXPECTED_HEADER = ( '#define CROS_EC_VERSION32 "trogdor_v2.6.1004-cmsis:0dead0,"\n' '#define BUILDER "toukmond@pokey"\n' '#define DATE "2021-06-28 03:18:53"\n' + '#define CROS_FWID_MISSING_STR "CROS_FWID_MISSING"\n' + "#define CROS_FWID32 CROS_FWID_MISSING_STR\n" ) HEADER_VERSION_STR_STATIC = "trogdor_v2.6.0-STATIC" EXPECTED_HEADER_STATIC = ( @@ -132,6 +134,8 @@ EXPECTED_HEADER_STATIC = ( '#define CROS_EC_VERSION32 "trogdor_v2.6.0-STATIC"\n' '#define BUILDER "reproducible@build"\n' '#define DATE "STATIC_VERSION_DATE"\n' + '#define CROS_FWID_MISSING_STR "CROS_FWID_MISSING"\n' + "#define CROS_FWID32 CROS_FWID_MISSING_STR\n" ) diff --git a/zephyr/zmake/zmake/version.py b/zephyr/zmake/zmake/version.py index 2d505769f2..47aba6d804 100644 --- a/zephyr/zmake/zmake/version.py +++ b/zephyr/zmake/zmake/version.py @@ -144,6 +144,9 @@ def write_version_header(version_str, output_path, static=False): def add_def(name, value): output.write("#define {} {}\n".format(name, util.c_str(value))) + def add_def_unquoted(name, value): + output.write("#define {} {}\n".format(name, value)) + add_def("VERSION", version_str) add_def("CROS_EC_VERSION32", version_str[:31]) @@ -154,6 +157,10 @@ def write_version_header(version_str, output_path, static=False): add_def("BUILDER", "{}@{}".format(getpass.getuser(), platform.node())) add_def("DATE", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + add_def("CROS_FWID_MISSING_STR", "CROS_FWID_MISSING") + # TODO(b/198475757): Add zmake support for getting CROS_FWID32 + add_def_unquoted("CROS_FWID32", "CROS_FWID_MISSING_STR") + contents = output.getvalue() if not output_path.exists() or output_path.read_text() != contents: output_path.write_text(contents) |