summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei-Cheng Xiao <garryxiao@chromium.org>2018-10-17 13:16:34 +0800
committerCommit Bot <commit-bot@chromium.org>2021-01-26 09:45:34 +0000
commitd3e3935cb6e6609987d6dc6b9012987a7bfd43d4 (patch)
tree043437a7779b53a951f810927a587484b5eac338
parent208f366b4b5c31f9ab13d032e8c21ff0ca6fc1eb (diff)
downloadchrome-ec-d3e3935cb6e6609987d6dc6b9012987a7bfd43d4.tar.gz
gsctool: add machine output support (-M) to chip board ID (-i, -O)
Now gsctool can print out GSC board ID in a machine-friendly way. This allows other programs (e.g., debugd) to parse the output. This is the final CL that adds machine output support to gsctool during verify_ro migration. BRANCH=none BUG=None TEST=manually run gsctool -M -i and gsctool -O verify_ro.db -M on a soraka device connected with a naultilus and check the board ID part in the outputs. Sample output (the board ID part is identical in the outputs of both commands): BID_TYPE=5a534b4d BID_TYPE_INV=a5acb4b2 BID_FLAGS=00007f80 Signed-off-by: Wei-Cheng Xiao <garryxiao@chromium.org> Change-Id: Ia275806672c08841c5b5fcc7758d8e0c777b3fc9 Reviewed-on: https://chromium-review.googlesource.com/1286312 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Wei-Cheng Xiao <garryxiao@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2648132 Reviewed-by: Cheng-Han Yang <chenghan@chromium.org> Tested-by: Cheng-Han Yang <chenghan@chromium.org> Commit-Queue: Cheng-Han Yang <chenghan@chromium.org>
-rw-r--r--extra/usb_updater/gsctool.c38
-rw-r--r--extra/usb_updater/gsctool.h7
-rw-r--r--extra/usb_updater/verify_ro.c6
-rw-r--r--extra/usb_updater/verify_ro.h11
4 files changed, 46 insertions, 16 deletions
diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c
index 87af57919e..1a3ca82bac 100644
--- a/extra/usb_updater/gsctool.c
+++ b/extra/usb_updater/gsctool.c
@@ -545,7 +545,7 @@ static void usage(int errs)
"character string.\n"
" -k,--ccd_lock Lock CCD\n"
" -M,--machine Output in a machine-friendly way. "
- "Effective with -f and -b only.\n"
+ "Effective with -b, -f, -i, and -O.\n"
" -m,--tpm_mode [enable|disable]\n"
" Change or query tpm_mode\n"
" -O,--openbox_rma <desc_file>\n"
@@ -1931,7 +1931,8 @@ static void process_wp(struct transfer_descriptor *td)
void process_bid(struct transfer_descriptor *td,
enum board_id_action bid_action,
- struct board_id *bid)
+ struct board_id *bid,
+ bool show_machine_output)
{
size_t response_size;
@@ -1942,16 +1943,31 @@ void process_bid(struct transfer_descriptor *td,
bid, sizeof(*bid),
bid, &response_size);
- if (response_size == sizeof(*bid)) {
+ if (response_size != sizeof(*bid)) {
+ fprintf(stderr,
+ "Error reading board ID: response size %zd, "
+ "first byte %#02x\n",
+ response_size,
+ response_size ? *(uint8_t *)&bid : -1);
+ exit(update_error);
+ }
+
+ if (show_machine_output) {
+ print_machine_output(
+ "BID_TYPE", "%08x", be32toh(bid->type));
+ print_machine_output(
+ "BID_TYPE_INV", "%08x", be32toh(bid->type_inv));
+ print_machine_output(
+ "BID_FLAGS", "%08x", be32toh(bid->flags));
+
+ } else {
printf("Board ID space: %08x:%08x:%08x\n",
- be32toh(bid->type), be32toh(bid->type_inv),
+ be32toh(bid->type),
+ be32toh(bid->type_inv),
be32toh(bid->flags));
- return;
}
- fprintf(stderr, "Error reading board ID: response size %zd,"
- " first byte %#02x\n", response_size,
- response_size ? *(uint8_t *)&bid : -1);
- exit(update_error);
+
+ return;
}
if (bid_action == bid_set) {
@@ -2415,7 +2431,7 @@ int main(int argc, char *argv[])
}
if (openbox_desc_file)
- return verify_ro(&td, openbox_desc_file);
+ return verify_ro(&td, openbox_desc_file, show_machine_output);
if (ccd_unlock || ccd_open || ccd_lock || ccd_info)
process_ccd_state(&td, ccd_unlock, ccd_open,
@@ -2425,7 +2441,7 @@ int main(int argc, char *argv[])
process_password(&td);
if (bid_action != bid_none)
- process_bid(&td, bid_action, &bid);
+ process_bid(&td, bid_action, &bid, show_machine_output);
if (rma)
process_rma(&td, rma_auth_code);
diff --git a/extra/usb_updater/gsctool.h b/extra/usb_updater/gsctool.h
index 707ddfde87..d3ac8f5e85 100644
--- a/extra/usb_updater/gsctool.h
+++ b/extra/usb_updater/gsctool.h
@@ -7,6 +7,7 @@
#ifndef __EXTRA_USB_UPDATER_GSCTOOL_H
#define __EXTRA_USB_UPDATER_GSCTOOL_H
+#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
@@ -84,11 +85,13 @@ enum board_id_action {
/*
* This function allows to retrieve or set (if not initialized) board ID of
- * the H1 chip.
+ * the H1 chip. If bid_action is bid_get and show_machine_output is set,
+ * prints out board ID in a machine-friendly format.
*/
void process_bid(struct transfer_descriptor *td,
enum board_id_action bid_action,
- struct board_id *bid);
+ struct board_id *bid,
+ bool show_machine_output);
/*
* This function can be used to retrieve the current PP status from Cr50 and
diff --git a/extra/usb_updater/verify_ro.c b/extra/usb_updater/verify_ro.c
index f81fab8e67..4a4aea792a 100644
--- a/extra/usb_updater/verify_ro.c
+++ b/extra/usb_updater/verify_ro.c
@@ -5,6 +5,7 @@
*/
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -291,7 +292,8 @@ static int process_descriptor_sections(struct transfer_descriptor *td)
}
int verify_ro(struct transfer_descriptor *td,
- const char *desc_file_name)
+ const char *desc_file_name,
+ bool show_machine_output)
{
/* First find out board ID of the target. */
struct board_id bid;
@@ -303,7 +305,7 @@ int verify_ro(struct transfer_descriptor *td,
* Find out what Board ID is the device we are talking to. This
* function calls exit() on any error.
*/
- process_bid(td, bid_get, &bid);
+ process_bid(td, bid_get, &bid, show_machine_output);
if (bid.type != ~bid.type_inv) {
fprintf(stderr, "Inconsistent board ID: %08x != ~%08x\n",
diff --git a/extra/usb_updater/verify_ro.h b/extra/usb_updater/verify_ro.h
index c37ba3a337..de2443b8b4 100644
--- a/extra/usb_updater/verify_ro.h
+++ b/extra/usb_updater/verify_ro.h
@@ -7,9 +7,18 @@
#ifndef __EXTRA_USB_UPDATER_VERIFY_RO_H
#define __EXTRA_USB_UPDATER_VERIFY_RO_H
+#include <stdbool.h>
+
#include "gsctool.h"
+/*
+ * Runs RO verification on the target specified in td using the description file
+ * desc_file_name. If show_machine_output is set, target's board ID will be
+ * outputted in a machine-friendly format. Returns 0 on success or a negative
+ * value if there is an error.
+ */
int verify_ro(struct transfer_descriptor *td,
- const char *desc_file_name);
+ const char *desc_file_name,
+ bool show_machine_output);
#endif // __EXTRA_USB_UPDATER_VERIFY_RO_H