usb_updater: allow symbolic Board IDs

When specifying board ID to program, it is convenient to be able to
specify the ID as a string, as reported by the RLZ stored in the VPD.

With this patch the first component of the board_id command line
option is considered a string if it is no longer than 4 bytes.

BRANCH=cr50
BUG=b:35587387,b:35587053

TEST=ran the following commands (interleaved with erasing INFO1 on the
     target):

  localhost ~ # usb_updater -s -i
  Board ID space: ffffffff:ffffffff:ffffffff
  localhost ~ # usb_updater -s -i ABCD
  localhost ~ # usb_updater -s -i
  Board ID space: 41424344:bebdbcbb:0000ff00
  localhost ~ # usb_updater -s -i
  Board ID space: ffffffff:ffffffff:ffffffff
  localhost ~ # usb_updater -s -i 0x41424344:0x1234
  localhost ~ # usb_updater -s -i
  Board ID space: 41424344:bebdbcbb:00001234
  localhost ~ # usb_updater -s -i
  Board ID space: ffffffff:ffffffff:ffffffff
  localhost ~ # usb_updater -s -i ABCD:0x1234
  localhost ~ # usb_updater -s -i
  Board ID space: 41424344:bebdbcbb:00001234

Change-Id: Ied8b240d60ea50f6fc8633f919ce4bc81ac17727
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/528440
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Vadim Bendebury
2017-06-08 13:54:42 -07:00
committed by chrome-bot
parent 2a783457a9
commit bdbb45b14a

View File

@@ -366,7 +366,9 @@ static void usage(int errs)
" -f,--fwver Report running firmware versions.\n"
" -h,--help Show this message\n"
" -i,--board_id [ID[:FLAGS]]\n"
" Get or set Info1 board ID fields\n"
" Get or set Info1 board ID fields.\n"
" ID could be 32 bit hex or 4 "
"character string.\n"
" -p,--post_reset Request post reset after transfer\n"
" -s,--systemdev Use /dev/tpm0 (-d is ignored)\n"
" -u,--upstart "
@@ -1263,27 +1265,56 @@ static int parse_bid(const char *opt,
enum board_id_action *bid_action)
{
char *e;
const char *param2;
size_t param1_length;
if (!opt) {
*bid_action = bid_get;
return 1;
}
bid->type = (uint32_t)strtoul(opt, &e, 0);
/* Set it here to make bailing out easier later. */
bid->flags = DEFAULT_BOARD_ID_FLAG;
*bid_action = bid_set; /* Ignored by caller on errors. */
if (!e || !*e) {
bid->flags = DEFAULT_BOARD_ID_FLAG;
return 1;
/*
* Pointer to the optional second component of the command line
* parameter, when present - separated by a colon.
*/
param2 = strchr(opt, ':');
if (param2) {
param1_length = param2 - opt;
param2++;
if (!*param2)
return 0; /* Empty second parameter. */
} else {
param1_length = strlen(opt);
}
if (*e == ':') {
bid->flags = (uint32_t)strtoul(e + 1, &e, 0);
if (!e || !*e)
return 1;
if (!param1_length)
return 0; /* Colon is the first character of the string? */
if (param1_length <= 4) {
unsigned i;
/* Input must be a symbolic board name. */
bid->type = 0;
for (i = 0; i < param1_length; i++)
bid->type = (bid->type << 8) | opt[i];
} else {
bid->type = (uint32_t)strtoul(opt, &e, 0);
if ((param2 && (*e != ':')) || (!param2 && *e))
return 0;
}
return 0;
if (param2) {
bid->flags = (uint32_t)strtoul(param2, &e, 0);
if (*e)
return 0;
}
return 1;
}
static void process_bid(struct transfer_descriptor *td,