summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-10-14 21:39:26 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-10-18 22:38:01 -0700
commit1f2e477349fd3a14c8821ffc0bc4aa48f63e6dd5 (patch)
treed992a672fe63a3f6cbad9d1ba9553e6dd7701425
parentebd087a925e3b3c62c5b6ba98f951848844ffdf3 (diff)
downloadvboot-1f2e477349fd3a14c8821ffc0bc4aa48f63e6dd5.tar.gz
futility: updater: Change default model name to FWID platform name
For devices not using Unified Build, the firmware updater may contain a single set of firmware images. To make the manifest more consistent for both cases (Unified Build or not), we want to change to model name to be the platform name from FWID if available. This does not make sense because for these devices, usually platform = board = model, and it helps to make sure programs parsing manifest won't try to use the hard coded name 'default' (which does not always work in Unified Build). BUG=chromium:875551 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I6d56336f3b30981e3e936fa63dec7dd45d74b31a Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1278418 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--futility/updater_archive.c29
-rw-r--r--tests/futility/link.manifest.json2
2 files changed, 29 insertions, 2 deletions
diff --git a/futility/updater_archive.c b/futility/updater_archive.c
index 0c866bdb..86d70e75 100644
--- a/futility/updater_archive.c
+++ b/futility/updater_archive.c
@@ -7,6 +7,7 @@
*/
#include <assert.h>
+#include <ctype.h>
#include <fts.h>
#include <string.h>
#include <stdio.h>
@@ -363,6 +364,19 @@ int archive_read_file(struct archive *ar, const char *fname,
* -- End of archive implementations --
*/
+/* Utility function to convert a string to all lowercase. */
+static void str_tolower(char *s)
+{
+ int c;
+
+ for (; *s; s++) {
+ c = *s;
+ if (!isascii(c) || !isalpha(c))
+ continue;
+ *s = tolower(c);
+ }
+}
+
/* Returns 1 if name ends by given pattern, otherwise 0. */
static int str_endswith(const char *name, const char *pattern)
{
@@ -647,6 +661,7 @@ struct manifest *new_manifest_from_archive(struct archive *archive)
manifest.default_model = -1;
archive_walk(archive, &manifest, manifest_scan_entries);
if (manifest.num == 0) {
+ struct firmware_image image = {0};
/* Try to load from current folder. */
if (!archive_has_entry(archive, image_name))
return 0;
@@ -655,7 +670,19 @@ struct manifest *new_manifest_from_archive(struct archive *archive)
model.ec_image = strdup(ec_name);
if (archive_has_entry(archive, pd_name))
model.pd_image = strdup(pd_name);
- model.name = strdup(DEFAULT_MODEL_NAME);
+ /* Extract model name from FWID: $Vendor_$Platform.$Version */
+ if (!load_firmware_image(&image, image_name, archive)) {
+ char *token = NULL;
+ if (strtok(image.ro_version, "_"))
+ token = strtok(NULL, ".");
+ if (token && *token) {
+ str_tolower(token);
+ model.name = strdup(token);
+ }
+ free_firmware_image(&image);
+ }
+ if (!model.name)
+ model.name = strdup(DEFAULT_MODEL_NAME);
manifest_add_model(&manifest, &model);
manifest.default_model = manifest.num - 1;
}
diff --git a/tests/futility/link.manifest.json b/tests/futility/link.manifest.json
index 2e11cd3b..9bd33f52 100644
--- a/tests/futility/link.manifest.json
+++ b/tests/futility/link.manifest.json
@@ -1,5 +1,5 @@
{
- "default": {
+ "link": {
"host": { "versions": { "ro": "Google_Link.2695.1.133", "rw": "Google_Link.2695.1.133" },
"keys": { "root": "7b5c520ceabce86f13e02b7ca363cfb509fc5b98", "recovery": "7e74cd6d66f361da068c0419d2e0946b4d091e1c" },
"image": "bios.bin" }