Commit Graph

185 Commits

Author SHA1 Message Date
Mary Ruthven
b14614b60c gsctool: add factory mode command
We added a cr50 vendor command to control factory mode. This change adds
gsctool support for using the command.

gsctool -F [enable|disable] can be used to set factory mode. You can't
use it to get the factory mode setting, because factory mode is
indistinguishable from other forms of ccd. The regular ccd info can be
used instead gsctool -I.

BUG=b:77543904
BRANCH=cr50
TEST=none

Change-Id: I715e296c323be20bab0b54a2f94a380b61f74cd2
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1069370
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-05-31 16:22:35 -07:00
Mary Ruthven
5a23e3f49a cr50: refactor rma mode into factory mode
We're doing a bit of refactoring to break out factory mode into its own
file. Now factory reset and rma reset will be two methods of entering
factory mode. Factory mode can be disabled with the disable_factory
vendor command.

Factory mode means all ccd capabilities are set to Always and WP is
permanently disabled. When factory mode is disabled, all capabilities
are reset to Default and WP is reset to follow battery presence.

This adds 56 bytes.

BUG=none
BRANCH=cr50
TEST=verify rma reset will enable factory mode.

Change-Id: I21c6f7b4341e3a18e213e438bbd17c67739b85fa
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1069789
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-30 20:38:53 -07:00
Vadim Bendebury
6e364d59c1 rma_reset: add p256 ECC option
This patch adds RMA shared secret generation support using the p256
curve. It is not a simple shoe in replacement for the x25519 because
of a different key representations. This new code uses openssl library
for all calculations.

A new option is being added to indicate that p256 is supposed to be
used, the new server Key ID value is used for p256, which allows to
pick the correct curve when parsing the previously generated
challenge.

BRANCH=none
BUG=b:73296606
TEST=verified that the same secret value is generated on the client
     and server side when using either x25519 or p256 curves.

      ./rma_reset -t
      ./rma_reset -c <challenge generated by the previous command>

      ./rma_reset -t -p
      ./rma_reset -c <challenge generated by the previous command>

Change-Id: I9b21b5ae389480d92f0f663fbb846b0f27b15de1
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1073757
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-28 15:26:29 -07:00
Vadim Bendebury
c50523e1d1 rma_reset: prepare for expanding for p256 support
This is mostly a clean up and refactoring change, which will make it
easier to extend rma_reset to supporting more EC curves.

BRANCH=none
BUG=b:73296606
TEST=verified that the same secret value is generated on the client
     and server side by running

  ./rma_reset -t
  ./rma_reset -c <challenge generated by the previous command>

Change-Id: I15c010a4a62306bfaa56b97936318854b28a4945
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1073756
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-26 00:21:46 -07:00
Vadim Bendebury
99adc6aca7 rma_reset: allow building with debug options
When invoking make with DEBUG=1 add '-g -O0' to the compiler
invocation to facilitate debugging with gdb.

BRANCH=none
BUG=b:73296606
TEST=verified that building with DEBUG=1 adds '-g -O0' to the compiler
     invocation.

Change-Id: Idd80bd481091b91683200c78fe49dc7e9783a730
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1073755
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-05-26 00:21:45 -07:00
Nick Sanders
c20a6da054 servo_updater: add reboot flag
This allows a reboot request regardless of whether update
is required.

BRANCH=servo
BUG=b:69016505
TEST=servo reboots

Change-Id: I2e8651e6ffa95c622aa0a8122d705d9ac8fbdd82
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1066988
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-05-21 21:18:04 -07:00
Nick Sanders
677207d5f0 servo_updater: allow local builds
Updater regex allows local build versions as well.

BRANCH=None
BUG=b:69016431
TEST=update servo v4

Change-Id: I203aefff998ef5c69434187830c27431dbcc7dee
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1066989
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-05-21 21:17:59 -07:00
Nick Sanders
53f61a76b7 servo_updater: support old and new updater
Add support for usb_updater2 in servo_updater.
This allows update back and forth between servo-9040.B
releases and builds from master, although they have
different updater enpoint interfaces.

Also add '-n' no force reboot to usb_updater2 as force reboot
is incompatible with servo_updater's flow.

BRANCH=None
BUG=b:69016431
TEST=update servo v4

Change-Id: I18809590c2e7e1cfcf60c4c97e956dfc22d85856
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1056157
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-05-11 23:22:26 -07:00
Nick Sanders
1356a1a5b7 usb_updater2: match by serial number
Add a serial number match to allow update of servo or
other usb devices, where mutliple devices may be attached
to one system.

BRANCH=None
BUG=chromium:718688
TEST=usb_updater2 -d 18d1:501b --serial=[C1706311869|fail]

Signed-off-by: Nick Sanders <nsanders@chromium.org>
Change-Id: Id6ec944139e685948433af703555fd185e91a9d4
Reviewed-on: https://chromium-review.googlesource.com/1050971
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2018-05-10 02:27:11 -07:00
Ruben Rodriguez Buchillon
3db5a829b0 powerlog: allow port & addr in the .board file
Allow board & addr in the board file instead of channel, to make board
file creation and configuration simpler.
This is part of the efforts in the BUG to make sweetberry under chrome
os simpler to use. In that case, we allow now (with crrev.com/c/1051215) to
generate .board files using explicit pin and bank numbers (j2,j3,j4).

BRANCH=None
BUG=chromium:806148
TEST=manual test, works fine.

Change-Id: I6fd3bb1a4a5ffffee08b81625ecb190adceeb2e7
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1051212
Reviewed-by: Nick Sanders <nsanders@chromium.org>
2018-05-10 02:27:09 -07:00
Mary Ruthven
c07167406d cr50_rma_open: add support for testlab mode
Devices going into the testlab should have testlab mode enabled if
possible. Add support for enabling testlab mode on prepvt images.

BUG=none
BRANCH=none
TEST=make sure script complains when testlab mode isn't enabled on
prepvt image and passes ok when testlab mode isn't enabled on prod
images. Run testlab enable to make sure it works.

Change-Id: I623cac192fed31241d08a9d25e46e705cbbeb908
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1040357
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2018-05-04 03:02:59 -07:00
Puthikorn Voravootivat
0a8afe10c2 sweetberry: Make resetting USB interface more forgiving
Currently, sweetberry ocassionally throws Exception when
resetting the USB interface. This CL mitigates that by
- Use linearly back off algorithm with 10ms delay increment
  before next reset attempt to avoid flooding the sweetberry
  hardware with reset requests.
- Increase retry amount from 10 to 100

BUG=chromium:834252
TEST=No "Exception: ('Power', 'Failed to reset')" seen

Change-Id: Iaf039cb82760205d1747fd630387852b7cfd8f83
Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1038788
2018-05-03 21:27:54 -07:00
Mary Ruthven
9d4846a292 cr50_rma_open: add support for checking prepvt and prod versions
RMA support through the cr50 console is only a part images starting with
0.4.5. Check that the prepvt version is greater than or equal to 0.4.5.
Versions 0.4.4 are greater than the prod version 0.3.3, but you can't
use it to do RMA open through the console. It can only be done through
the AP.

BUG=none
BRANCH=none
TEST=none

Change-Id: I7e08cc5dbc9f910686ea5917be755170c0587ee4
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1040356
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2018-05-02 22:21:18 -07:00
Vadim Bendebury
b10c587e7b gsctool: add verbose mode command line option
The new command line option is not used yet, it allows to set a flag
which would allow control verbose debug output in the future.

BRANCH=none
BUG=none
TEST=verified that -V command line option shows up in --help output
     and is accepted.

Change-Id: Ie7becdb9c6964f7bb75e9917a02594d50c3c2693
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1036742
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2018-05-02 22:20:35 -07:00
Vadim Bendebury
e2b45bf508 gsctool: add version command line option
Use the same script the rest of the EC codebase uses to generate the
version string.

BRANCH=none
BUG=none
TEST=built the new image and tried:
  $ ./extra/usb_updater/gsctool  -v
  Version: v1.1.8258+6097a64f0, built on 2018-05-01 17:04:14 by ...

Change-Id: I63d2411872bbd38188f66f51b7ca8508fc74fa8f
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1036741
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2018-05-02 22:20:34 -07:00
Mengqi Guo
a820df3fd6 sweetberry: fix stats_manager and refactor
This CL updates stats_manager to match the new functionalities
in powerlog.py and refactors powerlog.py to more easily find
config files and print timestamps in seconds since epoch.

The unit test for stats_manager is also updated accordingly.

BUG=b:72973433
BRANCH=None
TEST=powerlog -b nami_rev0_loc.board -c nami_rev0_loc.scenario \
--print_stats --save_stats /tmp --save_stats_json /tmp \
--save_raw_data /tmp --mW
and looking at the printed data
python -m unittest stats_manager_unittest
CQ-DEPEND=CL:1003522

Change-Id: Ic6e4aadfcd3ad245572788094ee3d3a30106044c
Signed-off-by: Mengqi Guo <mqg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1002546
Reviewed-by: Todd Broch <tbroch@chromium.org>
2018-04-27 14:36:54 -07:00
Mary Ruthven
6782985535 cr50_rma_open: add servod support
Add support for finding the cr50 uart given a servo port or being given
a servo console using -d. If servod is using ccd to run, we need to do
ccd_reset after the authcode reboot. Add support for that as well.

BUG=none
BRANCH=none
TEST=none

Change-Id: I972ce60a2e67cc68b604d550579fb2e99db8ac08
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1025267
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2018-04-24 13:31:30 -07:00
Mary Ruthven
d9386134c1 cr50_rma_open: check write protect too
Cr50 RMA Open will disable write protect. Make sure it is disabled. If
it isn't, manually disable write protect after rma_auth. If cr50 reboots
or loses write protect, cr50_rma_open can now be used to force disable
it again with cr50_rma_open -w.

BUG=none
BRANCH=none
TEST=none

Change-Id: I096cff51ae20b8a4cfbfa92892a011ff48f4cc49
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1016023
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2018-04-19 03:37:14 -07:00
Vadim Bendebury
b676f5e0ac gsctool: add support for CCD info
The new option allows to retrieve CCD information from the device. It
is reported similar to the way it is reported on the Cr50 console with
a few deviations:

 - current capability setting is spelled out (instead of stating that
   it is at default);

 - default capability setting is reported only if it is different from
   the current value.

- a bitmap of enabled capabilities is added in the end for ease of
   verifying CCD state during factory process.

BRANCH=cr50, cr50-mp
BUG=b:72718383
TEST=ran the command on a Coral device:

  $ gsctool -a -I
  State: Locked
  Password: None
  Flags: 000000
  Capabilities, current and default:
    UartGscRxAPTx   Y Always
    UartGscTxAPRx   Y Always
    UartGscRxECTx   Y Always
    UartGscTxECRx   - IfOpened
    FlashAP         - IfOpened
    FlashEC         - IfOpened
    OverrideWP      - IfOpened
    RebootECAP      - IfOpened
    GscFullConsole  - IfOpened
    UnlockNoReboot  Y Always
    UnlockNoShortPP Y Always
    OpenNoTPMWipe   - IfOpened
    OpenNoLongPP    - IfOpened
    BatteryBypassPP Y Always
    UpdateNoTPMWipe Y Always
    I2C             - IfOpened
    FlashRead       Y Always
  CCD caps bitmap: 0x16607

  - then took the device through 'ccd open' sequence and tried again,
    observed that all capabilities were set to 'Y' and caps bitmap was
    set to 0x1ffff.

  - then on the Cr50 console modified UnlockNoShortPP capability to be
    set 'UnlessLocked', ran the command again, observed the default
    value (Always) reported.

  - locked the CCD on Cr50 console, ran the command one more time:

  $ gsctool -a -I
  State: Locked
  Password: None
  Flags: 000000
  Capabilities, current and default:
    UartGscRxAPTx   Y Always
    UartGscTxAPRx   Y Always
    UartGscRxECTx   Y Always
    UartGscTxECRx   - IfOpened
    FlashAP         - IfOpened
    FlashEC         - IfOpened
    OverrideWP      - IfOpened
    RebootECAP      - IfOpened
    GscFullConsole  - IfOpened
    UnlockNoReboot  Y Always
    UnlockNoShortPP - UnlessLocked  (Always)
    OpenNoTPMWipe   - IfOpened
    OpenNoLongPP    - IfOpened
    BatteryBypassPP Y Always
    UpdateNoTPMWipe Y Always
    I2C             - IfOpened
    FlashRead       Y Always
  CCD caps bitmap: 0x16207

Change-Id: I0fd5e6bd9402ae518e3f2a3ed82589f8696dfd44
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/999826
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-04-10 16:29:17 -07:00
Mary Ruthven
17536e60cd extra: add cr50 rma open utility
The testlab will be running rma open on a bunch of devices. This change
adds a script for them to use.

The script handles things like finding the cr50 console and converting
the rma_auth output into a full challenge url. The user can click on the
url and generate the authcode. They can input the generated authcode
back into the script. The script will check 'ccd' output to make sure
rma open succeeds.

BUG=none
BRANCH=none
TEST=on a reef and bob running 3.4, run the entire cr50_rma_open
process. Verify RMA open succeeds

Change-Id: I2c9aef565351b65848f29083cd1e2c1f6e77e2a4
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/994417
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2018-04-05 12:30:17 -07:00
Vadim Bendebury
72dd925f10 gsctool: always use BOARD set to cr50
There is no point in allowing the environment to override board name
when building gsctool, it requires BOARD to be set to cr50 to build
properly.

And usb_updater2 does not really care about the board at all.

BRANCH=none
BUG=none
TEST='make -C extra/usb_updater now succeeds even if BOARD is set in
     the environment.

Change-Id: I1ed16b8049f4d5936bb29585bb65718ed865d6b5
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/972365
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Nick Vaccaro <nvaccaro@chromium.org>
2018-04-02 16:26:44 -07:00
Nick Sanders
2da18f938d sweetberry: add current and voltage logging
This adds a config to specify whether sweetberry
should measure power, current, voltage per powerlog entry.

The json format is slightly revised to allow data type
per channel. powerlog and sweetberry fw are updated
to handle the new functionality.

BUG=b:72973433
BRANCH=None
TEST=./powerlog.py -b marlin.board -c marlin_a.scenario -s .5

Signed-off-by: Nick Sanders <nsanders@chromium.org>

Change-Id: I231fc6600495146fad30583872bf14c660d5a50b
Reviewed-on: https://chromium-review.googlesource.com/905427
Commit-Ready: Nick Sanders <nsanders@chromium.org>
Tested-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Mengqi Guo <mqg@chromium.org>
2018-03-28 19:34:27 -07:00
Mary Ruthven
6e18f8f981 rma_reset: fix ignored return value error
The fread return value was ignored in rma_reset.c. This caused clang
compilation to fail.

This change checks the return value.

BUG=b:76105747
BRANCH=none
TEST=clang compilation no longer fails

Change-Id: I710b367008b2e17a94c875ea3eae92bcc75546b0
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/976555
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-03-22 20:53:26 -07:00
Mary Ruthven
e33c1d8de0 rma_reset: update Makefile to use different compiliers
BUG=b:76105747
BRANCH=none
TEST=compile for bob and reef. make sure it runs on both

Change-Id: I30004c9794c9619698889fecbf8746778ebbb48c
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/976554
Commit-Ready: Mary Ruthven <mruthven@chromium.org>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-03-22 20:53:25 -07:00
Nicolas Boichat
0cbb4b6f9d stack_analyzer: Add new syntax for function pointer arrays
Makes it far simpler to support hooks, console commands, host
commands.

BRANCH=poppy,fizz
BUG=chromium:648840
TEST=Add new array annotation, run stack_analyzer

Change-Id: I8ed074ba5534661ed59f4f713bb4ba194e712f4e
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/966042
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-03-19 05:43:45 -07:00
Vadim Bendebury
ccbba8f968 gsctool: require exactly two hash sections for every board
The same Chrome OS device could have not only several released
firmware images, but also several variations of the GBB contents. Any
permutation of these two sets is possible, but both areas must match,
as modified GBB is no smaller problem than modified code or RO data.

With this patch the verifier will continue looking for board sections
in the descriptors database until the entire database has been
scanned. Only finding exactly two sections, and each section providing
proper matches will qualify the check as 'pass'.

BRANCH=none
BUG=b:73668125
TEST=verified that both single and dual section descriptions are
     processed properly, and that matching 1 and 3 sections triggers a
     return error.

Change-Id: I181655192246ce245c43e6ce7ba4768ac5c9e51a
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/951864
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2018-03-15 17:58:20 -07:00
Vadim Bendebury
1dfe3193e7 cr50: fix hash database parser to reject misformatted offsets/sizes
Section offsets and sizes are hex numbers which should not be longer
than 8 characters.

BRANCH=none
BUG=b:73668125

TEST=descriptions which miss the size field are properly reported now.
     Before the utility would just terminate with an error without a
     message.

Change-Id: I9bc461b5f848b80e464fecc9b40dcf0ea213c9a7
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/949311
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-03-13 00:57:22 -07:00
Mary Ruthven
52c3a72b73 rma_reset: add server side response
Add support for generating the authcode from cr50's challenge.

BUG=b:74019846
BRANCH=none
TEST=create a cr50 image with test keys. Verify that the output from
rma_reset -c opens cr50.

Change-Id: I85a209e55dc23daa118e0071e868878b6fbfcb69
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/945419
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-03-08 17:01:01 -08:00
Vadim Bendebury
d57e5eb312 gsctool: add open box RMA option
This patch enhances the gsctool utility to allow to verify RO sections
of the target AP and EC flash memory.

The only command line parameter required for the new option ('O') is
the file name of the target descriptors database, containing memory
description sections for one or more Chrome OS devices.

Memory description sections are of two types (both types could be
referring AP or EC memory):

 - hash descriptor, this section includes the address range of the
   memory and one or more hash values for the contents of that address
   range. Multiple hashes are needed in case when the same device has
   mnore than one RO firmware releases in circulation.

 - dump descriptor, this is a request for this utility to display on
   the console the contents of the certain area of flash memory on the
   target.

When this utility starts the process, the target might request that
the operator confirms physical presence, in this case the utility
keeps prompting the operator to press the physical presence button
until DUT is satisfied,

BRANCH=none
BUG=b:73668125
TEST=created a descriptor database for a Robo device feeding it with
     values retrieved on the device by locally running spihash command
     on the device.

     Then ran this utility to verify successful hash and dump
     retrievals, comparing dump values with values obtained through
     Cr50 console directly.

     Created additional dummy hash variants and verified that the
     utility succeeds only if all matches happen at the same variant
     index in different hash sections.

Change-Id: Ib43cf4eb642d141b7cd7f129ef412e14bd59f30b
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933545
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2018-02-23 23:12:58 -08:00
Vadim Bendebury
52b93ce19d gsctool: move common objects and definitions into a .h file
This is a lateral move allowing to share some data structures and
functions previously limited to the gsctool.c scope.

This will allow adding new functionality in a separate .c file, and
further refactor gsctool.c which little by little became quite
unwieldy.

BRANCH=none
BUG=b:73668125
TEST=gsctool utility still works for uploading Cr50 images.

Change-Id: Ib56db3e0b983c53a228a658467a3059abcf2166e
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933543
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-02-23 23:12:57 -08:00
Vadim Bendebury
9a6de75ebf gsctool: add RO descriptor parser
This patch adds code which would parse the RO hash/dump descriptor
file including a database listing expected values of hashes for
various ranges of target SPI flash devices, or areas which need to be
printed out (hex dumped) for operator inspection.

Lines starting with '#' are completely ignored. The rest of the
logical lines could actually split into multiple text lines in the
file, so to separate one logical line from another at least one empty
line is required.

Hash descriptor database file consists of sections for various Chrome
OS boards. Each board description section starts with a logical line
of 4 characters which is the board ID (the same as the board's RLZ
code).

Each board description section includes variable number of range
descriptor entries, each entry being a logical line, potentially split
into multiple text lines.

Each entry consists of semicolon separated fields:

 {a|e|g}:{h|d}:base_addr:size[:value[:value[:value...]]]]

 Where

  - the first sindgle character field defines the way the range is
    accessed:
     a - AP flash
     e - EC flash
     g - EC flash requiring gang programming mode
  - the second single character field defines the range type
     h - Cr50 returns the hash of the range
     d - Cr50 returns actual contents of the range (hex dump)
   - the third and and forth fields are base address and size of the range
   - ranges of type 'h' include one or more values for the hash of the
     range, each hash is a 64 byte hex string. Ranges of type 'd' do
     not include any data.

All values are expressed in hex.

The parser API provides functions to open the passed in hash
descriptor file and find there the section for a particular board, a
function to advance to the next entry in the board's section, and a
function to close the file when board entries scanning is completed.

When scanning the entries, the parser verifies their sanity, i.e.
conformance with the above described format, that all hashes are of
the right size, that there are no hashes attached to 'dump' entries
and there is at least one hash attached to the 'hash' entries, and
that there are no invalid characters in the hashes and address range
definitions.

The parser is not yet used by the gsctool, but when the new module is
compiled stand alone with -DTEST_PARSER passed to the compiler, it
becomes an executable which can be given the test hash database (the
new file, sample_descriptor) to interpret and report success or
failure.

BRANCH=none
BUG=chromium:812880
TEST=ran the following commands:

  $ gcc -DTEST_PARSER desc_parser.c -o dp
  $ ./dp sample_descriptor
  Section 1, rv 0
  Section 2, rv 0
  Section 3, rv 0
  Unexpected data in section 4
  Section 4, rv -22
  Invalid hash 1 size 0 in section 5
  Section 5, rv -22
  Invalid hash 1 size 0 in section 6
  Section 6, rv -22
  Invalid hash 1 size 63 in section 7
  Section 7, rv -22
  Invalid hash 1 size 65 in section 8
  Section 8, rv -22
  Invalid hash 1 value in section 9
  Section 9, rv -22
  Unexpected number of variants in section 10
  Section 10, rv -22
  Invalid hex value 10x in section 11
  Section 11, rv -22
  Section 12, rv -61
  $

Change-Id: I14b2754a5f6ba26b3c56ddc26d45cb4574514b69
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/923419
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2018-02-23 23:12:56 -08:00
Vadim Bendebury
1850d5908a gsctool: refactor PP polling into a function
Both CCD and SPI_HASH commands need to enforce physical presence. This
patch separates PP polling into a function which can be used by both
commands.

BRANCH=none
BUG=b:73668125
TEST=verified that running 'gsctool -a -o' on a Robo device still
     allows to unlock CCD with PP enforced.

Change-Id: I49abb0e56ad37664eaad7cc34de44e1ac06e2d1b
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/930567
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-02-23 03:36:30 -08:00
Vadim Bendebury
58759f5fbb cr50: use single __packed definition
Various parts of Cr50 code and Cr50 related utilities duplicate
definition of __packed available in include/common.h. Let's use the
same definition everywhere.

BRANCH=cr50, cr50-mp
BUG=none
TEST=make buildall succeeds
     verified that linker generated map files for Cr50 RW are the same
     before and after this change.

     built and used gsctoo and rma_reset

Change-Id: Ib91f9bbad1f6822b347f32b393630f592df80d60
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/931929
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-02-22 20:17:14 -08:00
Vadim Bendebury
cd76cde217 gsctool: fix Board ID retrieval function
The function used to read or write Board ID value, when invoked for
reading, reports the value on the console, but does not save the read
value in the passed in structure.

Let's always save it in the structure so that the caller of this
function has access to the retrieved value.

BRANCH=none
BUG=chromium:812880
TEST=verified that 'gsctool -i' still operates as expected.

Change-Id: I9bc713386758ca6701e6b853e042652e2f392871
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/925692
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-02-21 14:19:50 -08:00
Vadim Bendebury
77fe675d75 gsctool: allow multiple source files
With the upcoming extensions it would be beneficial to be able to keep
gsctool functionality spread among multiple source files. The current
Makefile is also not generating proper dependencies, which was fine
when gsctool utility was first introduced, but is not adequate any
more, and would be even more noticeable when more source files are
added.

In preparation let's just convert the build scheme into separately
compiling .c files, generating .d files while at it, and then linking
the .o files together in a separate link operation.

BRANCH=none
BUG=chromium:812880
TEST=verified that gsctool still builds fine and allows to update Cr50
     image.

Change-Id: I537bbe6bf76ac71e8d30040b276b78513d390bbf
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/923418
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-02-21 14:19:49 -08:00
Vadim Bendebury
a41c59598d gsctool: add options to control ccd
The user needs to be able to unlock/open/lock CCD in addition to
setting the CCD password.

This patch adds command line options for these three CCD subcommands.
They all are communicated to the TPM using the same vendor command.
'open' and 'unlock' subcommands could require the user to enter the
password. This is indicated by the appropriate vendor command return
code.

If return code of 'open' or 'unlock' subcommand indicates the need for
physical presence, the utility starts polling the Cr50 prompting the
user to press the power button when the chip expects it.

Some input parameters sanity checks are added to make sure that the
user does not request mutually exclusive actions.

BRANCH=none
BUG=b:62537474
TEST=verified that CCD can be unlocked and opend with and without
     password, with and without PP required.

Change-Id: Iea229a220e9f3d2f5d07cebdaebcb9b297939310
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/861209
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-01-12 03:27:10 -08:00
Vadim Bendebury
d9831e6015 gsctool: allow password handling function to run on different subcommands
With the upcoming addition of ability to manage CCD using gsctool, it
is necessary to send user password in several CC_CCD subcommands. This
patch modifies the password handler to allow the user to specify the
subcommand code to use.

VENDOR_RC_IN_PROGRESS is added to the list of acceptable return codes,
as this is what could be returned in response to 'ccd unlock' or 'ccd
open'.

BRANCH=none
BUG=b:62537474
TEST=verified that password still could be set and cleared from the
     CLI and gsctool

Change-Id: Ic58f344a728897fb535cd9b7bedd47d28b30f5f8
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/861207
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-01-12 03:27:10 -08:00
Vadim Bendebury
877e5909b4 ccd: prepare for handling crucial CCD commands through TPM task context
We want CCD commands lock, open, password, and unlock (at least to
start with) to be available over both CLI and through crosh (i.e.
coming over /dev/tpm0).

Let's allocate a TPM vendor command for handling all CCD subcommands,
and move to this new framework the 'ccd password' command, which
already is available over vendor command.

BRANCH=cr50
BUG=b:62537474
TEST=verified that 'ccd password' still works both over Suzy-Q CLI and
     using gsctool on the target.

Change-Id: I2d06230b762f47af7e580b188a587bc5678ca169
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/853280
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-01-10 15:44:29 -08:00
Vadim Bendebury
0b9a068894 gsctool: use full path when invoking trunks_send
The gsctool utility sometimes is used in environments where path to
trunks_send is not set. As a result 'gsctool -t' invocations fail.

Let's make sure PATH includes /usr/sbin before trunsk_send is invoked.

BRANCH=none
BUG=none
TEST=verified that gsctool invocations in crosh started in a tab and
     in a linux shell ran under user 'chronos' do not fail.

Change-Id: Ib8af365dc5707cfec19acda9aa0228d33eb4573f
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/851266
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2018-01-05 12:10:05 -08:00
Hung-Te Lin
9de2d245cf gsctool: Add option '--any' to auto-detect -s/-t availability.
For partners and developers, it's usually better to have a single simple
instruction to invoke commands. Currently gsctool needs either -s (if
/dev/tpm is not locked) or -t (if trunksd is running) and partners have
to either try both commands (-s or -t) or read the error messages and
try to figure out which option to use.

For example, see the extra logic in CL:831787.

Instead of putting the check everywhere in scripting, it seems easier
and more convenient to have a simple switch - "--any (-a)" that
automatically selects between -s and -t.

BUG=b:70184153
TEST=gsctool -f -a; stop trunksd; gsctool -f -a

Change-Id: Ie1590b0b8fef882178465ceee64a7150eda6b0dd
Reviewed-on: https://chromium-review.googlesource.com/851612
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-01-05 03:14:37 -08:00
Nicolas Boichat
27c01992fc usb_updater2: Increase touchpad debug buffer length to 50 bytes.
We would like to use all 64-bytes of the buffer as parameter to
UPDATE_EXTRA_CMD_TOUCHPAD_DEBUG (12 bytes for update_frame_header,
2 bytes for the extra command type, leaving 50 bytes of payload).

BRANCH=none
BUG=b:63993891
TEST=./usb_updater2 -g 00 -d 18d1:502b

Change-Id: I023aa760f1a4cf9cacf9262a758cba1120d4f380
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/780372
Reviewed-by: Chun-ta Lin <itspeter@chromium.org>
2017-12-14 04:22:40 -08:00
Mengqi Guo
fec861cd49 sweetberry: add microsecond to sweetberry timestamp
This CL adds microsecond to sweetberry timestamp, for more
accuracy in timing sweetberry runs.

This CL is part of the effort to start sweetberry measurements
while running power autotests.

BRANCH=None
BUG=b:68956240
TEST=./powerlog.py -b xxx.board -c xxx.scenario \
--save_stats_json [directory to store it]

Change-Id: I68c40d5be6d684205b49428c4e5cb6e69af6dfdf
Signed-off-by: Mengqi Guo <mqg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/812502
Reviewed-by: Puthikorn Voravootivat <puthik@chromium.org>
2017-12-07 15:22:49 -08:00
Chun-Ta Lin
ab238235f8 i2c: support large reading in i2c_xfer()
There might be more than one place that will use very similar codes in
CL:542716 (usb_i2c.c). To avoid unnecessary duplication of code, we fold
the logic into i2c_xfer(). With config enabled (illustrated in this CL),
i2c_xfer() will support large reading. An early prototype of potential
usage is demostrated in CL:781300.

BRANCH=none
TEST=For CONFIG_I2C_XFER_LARGE_READ:
     With proprietary software on slave: ./touchpad_updater -d
TEST=For usb_i2c regression:
     ./touchpad_updater still works (where the reading is less than 255)
TEST=For generic EC regression test:
     On poppy EC (With CONFIG_I2C_XFER_LARGE_READ defined)
     (1) Prevent override of update
       /usr/share/vboot/bin/set_gbb_flags.sh 0xa39
     (2) flashrom -p ec -w ec_binary_contains_this_CL.bin
     (3) ectool reboot_ec cold
     (4) "ectool version" verified that both RO/RW/Build info is local.
     (5) Test with a type-C DP dongle on DELL 2408WFP.
     (6) Plug-in type-C charger and external display still works.
     (7) Confirmed that battery is charging.
     (7) "ectool battery" reads same data (for fixed field) as before.
     (8) "ectool usbpdpower", confirmed charger info displayed as before.
     (9) "ectool usbpd 0", confirmed content exactly as before.
     (10) For Gyro. Verify under Arc++
          Using App: com.gamma.bubblelevel, works the same as before.
     (11) For Accelerometers. Verify under Arc++
          Using App: com.innoventions.sensorkinetics,
          small movement's charts looks as expected.
TEST=For generic EC regression test:
     On Caroline EC (Without CONFIG_I2C_XFER_LARGE_READ defined).
     Details in CL:810332
BUG=b:63993891

Change-Id: I654868945fa535e784800177d54eb2d9803f5249
Signed-off-by: Chun-Ta Lin <itspeter@google.com>
Reviewed-on: https://chromium-review.googlesource.com/788479
Commit-Ready: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-12-07 05:09:28 -08:00
Nick Sanders
5ab0c9fcef servo_updater: add version checks
This adds a check for the current and new versions,
and will not update if they are matched.

BUG=b:69016431
BRANCH=None
TEST=sudo ./servo_updater.py -b servo_micro

Change-Id: I3462099a086278dc1589609d76facf11a64bd3bc
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/804716
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2017-12-06 14:28:58 -08:00
Mengqi Guo
aaf0169b11 sweetberry: print MEAN in json format
This CL adds the flag --save_stats_json which prints the MEAN
of sweetberry readings into json format. Corresponding unit
test has been added too. Printing just the MEAN in json format
makes it easier to read it back in power_telemetry_logger,
which uploads the stats to the dashboard.

This CL is part of the effort to start sweetberry measurements
while running power autotests.

BRANCH=None
BUG=b:68956240
TEST=./powerlog.py -b xxx.board -c xxx.scenario \
--save_stats_json [directory to store it]
python -m  unittest -v stats_manager_unittest

Change-Id: I8274bcac21175f6c53184ced79b6ffe5e7d7a72a
Signed-off-by: Mengqi Guo <mqg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/807636
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Puthikorn Voravootivat <puthik@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
2017-12-05 22:43:45 -08:00
Vadim Bendebury
3bb08ed694 gsctool: fix error processing logic
The error processing logic is reversed, which results in missing error
values when errors actually happen.

BRANCH=none
BUG=none
TEST=verified that errors values are now reported properly.

Change-Id: I282920d35e978a704e8c2728a8aa71a5f1da9a00
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/802994
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2017-12-01 12:28:37 -08:00
Nick Sanders
3cf217eae9 servo_updater: add better default args
Let servo_updater look for configs and firmwares
in the default installed locations.

BUG=b:69016431
BRANCH=None
TEST=sudo servo_updater -b servo_v4

Change-Id: I069b96044ce17992e41a8fc66931477823eef986
Signed-off-by: Nick Sanders <nsanders@google.com>
Reviewed-on: https://chromium-review.googlesource.com/792603
Commit-Ready: Nick Sanders <nsanders@chromium.org>
Tested-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2017-11-28 17:56:31 -08:00
Vadim Bendebury
84b20f9225 gsctool: add option to disable RMA mode
The --rma_auth command line option is being extended to treat the
auth_code of value of 'disable' as a user request to cancel CCD RMA
mode on the device.

BRANCH=none
BUG=b:68213540
TEST=verified that passing '-f disable' to gsctool causes CCD state on
     the Cr50 changed to 'Locked'

Change-Id: I8764e0207977a6290d3d10dc4678f98631be0360
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/784354
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-11-28 15:44:16 -08:00
Chun-Ta Lin
f326fb05b5 hammer: enable large block reading on usb i2c passthru.
Originally, i2c passthru is limited to use I2C_XFER_SINGLE flag where
it can only read at most 255 bytes at a time.  For application that
requires larger i2c bus reading, we change the flag setting and the
command protocol.

TEST=old ./touchpad_updater still works (previous protocol)
TEST=new ./touchpad_updater can get more than 500 bytes per transaction
TEST=Debug message only print when -d assigned.
     ./touchpad_updater -d
TEST=Manually change #define CONFIG_USB_I2C_MAX_READ_COUNT (1024 - 6)
     to #define CONFIG_USB_I2C_MAX_READ_COUNT (1024 - 4) and trigger
     POWER_OF_TWO assertion.
BRANCH=none
BUG=b:35587174, b:63993891

Change-Id: Id75b11ea49ba89bab8e18af24d47219030c778c5
Signed-off-by: Chun-Ta Lin <itspeter@google.com>
Reviewed-on: https://chromium-review.googlesource.com/542716
Commit-Ready: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2017-11-24 02:39:04 -08:00
Vadim Bendebury
88011d8ea5 gsctool: clean up error processing
The gsctool utility is inconsistent in using stdio channels when
reporting errors. All error messages should go into stderr.

Also, to avoid confusion, this patch makes options -s and -t mutually
exclusive.

BRANCH=none
BUG=b:68213540
TEST=verified that passing both -t and -s command line options causes
     an error.

Change-Id: Ieb50cf08314aa37594964ef4bbfa4a850741da2f
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/784353
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-11-21 23:55:30 -08:00