Commit Graph

1950 Commits

Author SHA1 Message Date
nagendra modadugu
0bb18fbaac CR50: add support for SHA-384 & 512
This change adds the plumbing for SHA-384 & 512.
The actual hash implementation is software only,
and a part of the third_party/cryptoc library.

BRANCH=none
BUG=none
CQ-DEPEND=CL:418263
TEST=TCG tests pass

Change-Id: Iba7e6d420fd7fa0bce4ad9061e00f9275ecf4d72
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/417888
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2016-12-12 23:28:20 -08:00
Vadim Bendebury
ac4c3020de g: tweak cflush() to wait a bit longer
It turns out that even when the UART status register returns TX_IDLE
bit set, the transmitter is still active - probably working out the
stop sequence.

So, resetting immediately after TX_EMPTY is asserted causes the last
character to be corrupted on the receiving side.

This patch adds a wait for the duration of transmitting 10 bits at
115200 baud, which should be plenty. Wait loop in capped in case timer
is not running for any reason.

BRANCH=none
BUG=chrome-os-partner:60321
TEST=added code to print out a string and then call cflush() and reset
     immediately. The last character is not lost any more, the exact
     string is printed.

Change-Id: If386c515d9d9cc63d161fba73e6ed4e70e465136
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/418487
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2016-12-12 21:03:37 -08:00
li feng
f50b1cec17 ish: correct i2c write operation buffer size
ISH i2c write operation failed due to wrong buffer size passed.

BUG=None
BRANCH=None
TEST=On reef ISH enabled board, verified sensor i2c read/write are
successful.

Change-Id: Icda625ad16e1e60832bb22e3148e23fcb8e6a937
Signed-off-by: li feng <li1.feng@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/418876
Commit-Ready: Li1 Feng <li1.feng@intel.com>
Tested-by: Li1 Feng <li1.feng@intel.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-12-12 18:34:32 -08:00
Mary Ruthven
1b5bb68b8b g: remove the impact of deep sleep resumes from the rolling reboot count
Deep sleep needs to be considered a normal behavior and should not add
to the rollback count. This change subtracts one from the reset count
when the system sees that it just resumed from deep sleep.

Ideally the rollback counter would be able to verify the TPM
functionality and detect rolling reboots. With this change the rollback
counter will only be able to detect rolling reboots, but it fixes the
false positives for rolling reboots we were seeing before.

BUG=chrome-os-partner:60449
BRANCH=none
TEST=manual
	check the reset counter

	turn off the AP

	wait for cr50 to enter deep sleep

	plug in suzyq

	check it resumes from deep sleep and that the reset counter
	still has the same value

Change-Id: Ie8490c29636403b409b2a3f0912a5b312d23bc24
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/418321
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-12-09 21:48:46 -08:00
Mary Ruthven
c7559d4d23 g: make sure usb clocks are enabled before going to deep sleep
This change adds a usb clock enable before trying to write to the usb
registers when preparing for deep sleep.

It is possible that usb has not been initialized, so we need to make
sure that the clock is enabled.

BUG=chrome-os-partner:60555
BRANCH=none
TEST=manual, on both dev and prod fused H1
	run hibernate on the EC

	wait until cr50 enters deep sleep

	plug/unplug the charger

	verify the AP can boot to the kernel

Change-Id: I26359f4224cd25dc57c32d1508e26b133c43d317
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/417771
Tested-by: Vadim Bendebury <vbendeb@chromium.org>
2016-12-08 19:50:33 -08:00
Carl Hamilton
097c2bb04c Cr50: Ensure that trng.h is self-contained.
* Include trng.h from trng.c before any other header to verify that the
  header is self-contained.

* Add inclusion of stdint.h to trng.h to provide definition for uint32_t.

BUG=none
BRANCH=none
TEST=make -j buildall

Change-Id: I78fb6d915c357236ca0fed2a57f093f0eec07fe9
Reviewed-on: https://chromium-review.googlesource.com/417424
Commit-Ready: Carl Hamilton <carlh@chromium.org>
Tested-by: Carl Hamilton <carlh@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-12-08 19:49:53 -08:00
Mary Ruthven
0175c4b812 g: change default idle behavior based on bus obfuscation availability
Set the default idle action based on whether bus obfuscation is enabled.

BUG=none
BRANCH=none
TEST=verify the idle default is sleep on b1 boards and wfi on b2.
     Verify that both types of chips go to sleep and resume
     successfully.

Change-Id: Ib5a11c4060aa411ff36c06c7fcadf0bf4c223bf1
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/410167
2016-12-08 16:38:34 -08:00
CHLin
a0f1cda901 npcx: lpc: Fix KB malfunction after power-key off and then on
The original thought of setting LRESET_PLTRST_MODE to 1 is to remove the
need to reinitialize host module registers whenever LRESET# occurs in
order to save time when boot-up.

However, some of these registers will be reset by core domain reset. It
means every time LRESET is de-asserted, we need to initialize the host
setting again. Therefore, setting LRESET_PLTRST_MODE to 1 is unnecessary
and sometimes dangerous. If BIOS believes LRESET will reset ec's host
state machine to default but ec not, it will cause unexpected behavior.

Modified drivers:
1. lpc.c: allow LRESET/PLTRST generate host domain reset

BUG=chrome-os-partner:60211
BRANCH:none
TEST=make buildall. run "dut-control pwr_button:press; sleep 11; dut-control
pwr_button:release; sleep 7; dut-control pwr_button:press; sleep 1;
dut-control pwr_button:release". Verify keyboard works normally.

Change-Id: I94d428cde69f828468547c44844983f25686ea04
Signed-off-by: CHLin <CHLIN56@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/417745
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2016-12-08 16:38:27 -08:00
Shawn Nematbakhsh
6f8f51012e npcx: watchdog: Log PC on watchdog from exception context
If we watchdog while in exception context, our process PC is not very
useful. Log the actual watchdog PC as our SW panic param, stored in R5.

BUG=chrome-os-partner:60470
BRANCH=gru
TEST=Add "while(1);" in ISR, wait for watchdog, check with 'panicinfo'
that saved R5 is our watchdog PC.

Change-Id: Idbdf1bc3507cc88e7a944c7bbe24ed87a6720eea
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/417061
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 2404a5e7bff4bed278b22260513132a985fa4004)
Reviewed-on: https://chromium-review.googlesource.com/417113
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-12-08 12:32:41 -08:00
Shawn Nematbakhsh
a0bfd989d1 npcx: hwtimer: Fix deadlock close to hwtimer wrap
__hw_clock_event_set() is not reentrant and may be called from both our
event timer ISR and our hwtimer ISR when hwtimer is close to wrapping.
Modify the interrupt priority of our hwtimer int to match our event
timer int so that one cannot preempt the other. Originally the priority
was changed to allow the hwtimer ISR to run first in case both are
pending, but this condition can be handled cleanly and isn't a big
concern.

BUG=chrome-os-partner:60470
BRANCH=gru
TEST=Pass 500 S/R cycles on kevin with hwtimer wrap rate sped up 300x
(roughly equivalent to 150,000 real S/R cycles).

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ied466f14661f04c8662b5db709c0e3770a5bb200
Reviewed-on: https://chromium-review.googlesource.com/417060
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit ac28ec53b63a02c4d25e8a222d13595bc857fef0)
Reviewed-on: https://chromium-review.googlesource.com/417112
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-12-08 12:32:31 -08:00
Vadim Bendebury
515249a7d3 cr50: rename dev mode manifest file
The manifest used for signing in dev mode was originally used for
kevin evt 1, but now it is a common dev mode manifest. Rename the fie
appropriately and modify the makefile using it.

BRANCH=none
BUG=chrome-os-partner:57956
TEST=verified that it is still possible to build cr50 with CR50_DEV=1

Change-Id: If744406a83a7045cd34c76c941fdef209bef51ac
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/417220
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-12-06 19:55:19 -08:00
David Schneider
3d4bb5f649 gru: control LEDs by changing frequency
gru has circuitrythat selects the charge LED color based on the
frequency of the PWM.
By adjusting the PWM frequency instead of just the duty, we gain more
control over the brightness of the charge LED.

BUG=chrome-os-partner:54155
BRANCH=gru
TEST=activate each LED in turn and confirm color and brightness

Change-Id: Ie653125a528595c1ec68aea4d02cb70595a1b151
Signed-off-by: David Schneider <dnschneid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/415517
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-12-05 16:43:18 -08:00
Sam Hurst
22858a07a5 usb pd: Resend request after receiving a WAIT in response to a request
When a WAIT is received in response to a request, wait SinkRequestTime
before resending the request.

BUG=chrome-os-partner:34984
TEST=make -j buildall
BRANCH=none

Change-Id: I5c8429c4a7b9cf06609996f924b8d9d535ab6b5f
Reviewed-on: https://chromium-review.googlesource.com/414533
Commit-Ready: Sam Hurst <shurst@google.com>
Tested-by: Sam Hurst <shurst@google.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2016-12-02 16:52:52 -08:00
Shawn Nematbakhsh
57d8666fa1 npcx: flash: Set SRP0 when enabling RO write protection
HW protection can be overridden unless SRP0 is set with WP asserted.

BUG=chrome-os-partner:60029
BRANCH=gru
TEST=Manual on kevin, deassert WP:
> flashrom -p ec --wp-enable
> flashrom -p ec --wp-disable
SUCCESS

assert WP:
> flashrom -p ec --wp-enable
> flashrom -p ec --wp-disable
FAILED: RO_AT_BOOT is not clear.

Change-Id: I67c1ec086704cd5be4518b6dc3dc87146cbd2d99
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/415465
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit 3025b40df5c7744dde44336cc11f520667a92268)
Reviewed-on: https://chromium-review.googlesource.com/415499
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-12-01 19:59:11 -08:00
Shawn Nematbakhsh
1bdf8584bb npcx: flash: Use common code for SPI flash protect reg translation
Common code is more flexible and supports more parts, so delete the
npcx-only register translation code.

BUG=chrome-os-partner:60029
BRANCH=gru
TEST=Manual on gru, run 'flashrom -p ec --wp-enable' and check that 0x28
gets written to SR1, which matches our desired 'protect botton 128KB',
according to the datasheet. Also run 'flashrom -p ec --erase' then read
back EC SPI contents, verify ROM is erased except for first 128KB
region.

Change-Id: I526401997ff7ec77f2a6047a4a9af74a671ed69a
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/413228
Reviewed-by: David Hendricks <dhendrix@chromium.org>
(cherry picked from commit 43634d36d273887b1f2349c333a7b4b229a83365)
Reviewed-on: https://chromium-review.googlesource.com/415498
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
2016-12-01 19:59:09 -08:00
Shawn Nematbakhsh
d95b9fc18c npcx: flash: Fix SR reg reads during UMA lock
If UMA is locked, read and write access to SR* regs will fail, and we'll
be unable to determine or change our write protect state. Save our SR
regs before enabling UMA lock, and bring down UMA lock for a brief
period when writing SR regs.

BUG=chrome-os-partner:60029
BRANCH=gru
TEST=Manual on kevin with SW sync enabled.
flashrom -p ec --wp-enable -> verify success, check flags:
Flags:   wp_gpio_asserted ro_at_boot ro_now

Reboot host, check flags:
Flags:   wp_gpio_asserted ro_at_boot ro_now all_now

Verify flashrom -p ec --wp-status shows protected, and flashrom -p ec
--wp-disable fails.

Also verify same state after EC reset.

Boot into recovery mode, check flags:
Flags:   wp_gpio_asserted ro_at_boot ro_now

Remove WP screw, reboot EC, check flags:
Flags:   ro_at_boot ro_now

Verify flashrom WP status shows protected, and flashrom WP disable
succeeds and clears all flags.

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I17e32f7305600183e7fcb87f69a3feb88978f94e
Reviewed-on: https://chromium-review.googlesource.com/412977
(cherry picked from commit 6cfc0d0dd030b8b0334f99e99950a52fcf8267af)
Reviewed-on: https://chromium-review.googlesource.com/415497
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-12-01 19:59:07 -08:00
nagendra modadugu
684a4db39c CR50: add support for SHA-384 & 512 PKCS#1 signatures
This change adds support for signing SHA-384 & 512 hashes
when using PKCS#1 padding (CR50 does not support
SHA-384 & 512 at the moment, the actual hashing is to be
done on the host).

BRANCH=none
BUG=chrome-os-partner:59754
TEST=TCG tests pass

Change-Id: I78e774639a7968cbb50e58cdd0bf479e64123630
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/415218
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2016-12-01 14:30:07 -08:00
Mary Ruthven
a285debf1f g: remove sleep disable/enable in rdd
Enabling and disabling sleep in the rdd interrupt is redundant because
USB already takes care of that. When USB is initialized it will disable
sleep. If it is released or suspended then it will re-enable sleep. This
change removes the sleep enable and disable from the rdd interrupt. With
this change now sleep can be enabled while suzyq is still plugged in
using the command 'ccd disable'.

BUG=none
BRANCH=none
TEST=manual
	The consoles still work

	Updating the EC, AP and Cr50 still works

	After running 'reboot ap-off' in the EC console and 'ccd
	disable' in the Cr50 console Cr50 will go to sleep.

Change-Id: Ie8e6201e9fd611c514e93bc70d298d3b0d228611
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/413606
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-28 20:55:02 -08:00
Vadim Bendebury
ed194f7a9a usb_updater: protocol version 6 (vendor commands over usb)
This patch introduces version 6 of the cr50 USB update protocol. This
version allows to multiplex TPM vendor and extension commands over the
same USB endpoint which is used for firmware updates.

When channeling TPM vendor commands the USB update frame looks as follows:

   4 bytes      4 bytes         4 bytes       2 bytes      variable size
 +-----------+--------------+---------------+-----------+------~~~-------+
 + total size| block digest |    EXT_CMD    | Vend. sub.|      data      |
 +-----------+--------------+---------------+-----------+------~~~-------+

Where 'Vend. sub' is the vendor subcommand, and data field is
subcommand dependent. The target tells between update PDUs and
encapsulated vendor subcommands by looking at the EXT_CMD value - it
is set to 0xbaccd00a and as such is guaranteed not to be a valid
update PDU destination address.

In the previous protocol versions target reset was requested by the
host sending a 4 byte PDU after the target receives the UPGRADE_DONE
message and moves the state machine to the 'awaiting_reset' state.

With the ability to transfer vendor commands, there is no need for the
target to have a special state for reset. The host can send the posted
or immediate reboot request using the appropriate vendor command.

As a result the 'awaiting_reset' state has been removed, the target
accepts vendor commands only when state machine is in the rx_idle
state.

Vendor command response size is not fixed, it is subcommand dependent.
In the current implementation the total size of the vendor command PDU
can not exceed 64 bytes, as there is no reassembly on the target side.

For backwards compatibility in case the target is running protocol
version earlier than 6, the 4 byte PDU is still sent to the target
after UPGRADE_DONE is sent.

BRANCH=none
BUG=chrome-os-partner:60013
TEST=tested updates on Reef and Gru, observed that it is possible to
     update earlier versions of firmware, and that it is possible to
     request immediate and posted reset (depending on the presence of
     the -u flag in the usb_updater invocation).

Change-Id: I6ea9e9f742c96b8ab0670e9cec87a83cd47bb20e
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/414948
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-28 20:53:54 -08:00
Vadim Bendebury
56310c97bf usb_updater: improve debugability
When usb update errors happen it helps a lot to be able to see the
actual error code returned by the target and where the error was
generated.

This patch adds a few printouts to help with debugging.

BRANCH=none
BUG=none
TEST=observed proper error messages generated while debugging
     introduction of extension/vendor commands transfer over USB.

Change-Id: I06c77e7467f7f9547704c88c4b673866fb2e6032
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/414947
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-28 20:53:53 -08:00
Vadim Bendebury
6ac553462e g: update: expose USB PDU verification function
Some upcoming changes will introduce transfer of vendor and extension
commands over the usb updater endpoint.

This patch exposes a function which allows to verify integrity of
received USB PDUs.

BRANCH=none
BUG=chrome-os-partner:60013
TEST=no functional changes, usb_updater still works fine.

Change-Id: I8d9e6746ef0dfbb17bba618410514ca047a59a45
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/414441
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2016-11-28 20:53:47 -08:00
Bruce
ba50aab904 pyro/snappy: Support keyboard factory scanning
Add keyboard factory scanning tool.

BUG=none
BRANCH=none
TEST=check this tool work normal

Signed-off-by: Bruce.Wan <Bruce.Wan@quantatw.com>
Change-Id: Ifd6aa5c03ce668c4a44a5685fa721af11eb7a84e
Reviewed-on: https://chromium-review.googlesource.com/413764
Commit-Ready: Keith Tzeng <keith.tzeng@quantatw.com>
Tested-by: Keith Tzeng <keith.tzeng@quantatw.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-11-27 22:00:51 -08:00
Nicolas Boichat
1b682dd05b chip/stm32/usb_hid: Add USB HID touchpad driver
This describes a 5-finger touchpad. The physical/logical dimensions
of the trackpad are hardcoded for the time being.

BRANCH=none
BUG=chrome-os-partner:59083
TEST=make BOARD=hammer -j && util/flash_ec --board=hammer

Change-Id: I04a0833a28c013395974104ebdd6fcb29e5d6680
Reviewed-on: https://chromium-review.googlesource.com/407742
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2016-11-22 18:36:37 -08:00
Nicolas Boichat
67473cb5b4 chip/stm32/usb: Allow interface handler to reply with more than 64 bytes
For example, when a HID descriptor is longer than 64 bytes, we need
to split it in multiple packets.

BRANCH=none
BUG=chrome-os-partner:59083
TEST=make buildall -j
TEST=make BOARD=hammer -j && util/flash_ec --board=hammer

Change-Id: I25a05eabaf9413e332fe3cd70695a0d53639713d
Reviewed-on: https://chromium-review.googlesource.com/409316
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2016-11-22 18:36:36 -08:00
Nicolas Boichat
f940d4f516 chip/stm32/usb_hid_keyboard: Add functions for keyscan
This first cleans up the code:
 - Define report as a structure.
 - Fix USB interval from 40 ms to 32 ms (Linux kernel complains
   otherwise).

Then, this removes the old set_keyboard_report interface, and
replaces it by the interface used by the keyboard scanner
(i.e. keyboard_state_changed and keyboard_clear_buffer).

This also means we need a keycode table to translate from
row/column to USB HID keycode.

BRANCH=none
BUG=chrome-os-partner:59083
TEST=make buildall -j
TEST=make BOARD=hammer -j && util/flash_ec --board=hammer
     With evtest and "hid 0-7" in console, check that key are
     reported correctly.

Change-Id: I5d526db1568c29c7f28fc5e962e213e44303cc16
Reviewed-on: https://chromium-review.googlesource.com/411571
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2016-11-22 14:52:40 -08:00
Vadim Bendebury
481fede513 g: do not consider valid headers with the 'magic' field corrupted
When cr50 rollback happens, the newer header's magic field is set to
zero to prevent it from ever running again.

Take this into consideration when displaying versions of the inactive
RW image.

BRANCH=none
BUG=none

TEST=loaded two versions of the new code on a cr50 and then modified
     the fallback counter to force it to boot the older version and
     reboot a Reef. Once Reef fully boots to chrome os examine CR50
     version report:

     Before:

   > vers
   ...
   RW_A:    0.0.9/DEV/cr50_v1.1.5654-2228b76+
   RW_B:  * 0.0.11/DEV/cr50_v1.1.5654-2228b76+
   ...

    After:

   > vers
   ...
   RW_A:  * 0.0.9/DEV/cr50_v1.1.5654-2228b76+
   RW_B:    Error

Change-Id: I2a9ee13117a0bc91710226cd733c5c484c6d0595
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/413089
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-22 11:52:10 -08:00
Mulin Chao
50fbfc5040 npcx: hwtimer: Add consecutive reading for ITCNT32
The mux for selecting source clock of ITIM will introduce a delay
and have a chance to make ITIM's source clock and core clock are
asynchronous. We need consecutive reading for ITCNT32 no matter source
clock is APB2 or 32k.

Modified sources:
1. hwtimer.c: Add consecutive reading for ITCNT32

BRANCH=none
BUG=chrome-os-partner:34346,chrome-os-partner:59240
TEST=No time stamp symptoms occur on wheatley for 30 hours.

Change-Id: I8b54e93b320e3ea74fc3d6ea13f0d178f9c449cd
Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-on: https://chromium-review.googlesource.com/412505
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-11-22 11:51:56 -08:00
Vadim Bendebury
14421571ca g: fix reboot request posting bug
When the host requests the uploader to post a reboot request, the
uploader should exit right away once the request is posted.

BRANCH=none
BUG=chrome-os-partner:59911
TEST=verified that cr50 gets successfully updated from this image to a
     newer one on both reef and gru: the reboot happens under upstart
     control, not by cr50 rebooting on its own.

Change-Id: I9e4a2da686fe512b633daa05c675871e5946926f
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/412348
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2016-11-18 20:07:23 -08:00
Shawn Nematbakhsh
e97073a20d clock: Fix clock_wait_cycles() asm
The 'cycles' register will be clobbered by our macro, so it must be
specified as an output operand that may also be used as input.

BUG=chrome-os-partner:60000
BRANCH=gru,strago,glados
TEST=Build + burn wheatley, verify alignment exception is not
encountered on boot. Also verify produced assembly is still correct:

100a89a6:       2303            movs    r3, #3
100a89a8:       3b01            subs    r3, #1
100a89aa:       d1fd            bne.n   100a89a8

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I1be03a006967aed6970dbac5d98a19a31e0b7d49
Reviewed-on: https://chromium-review.googlesource.com/412441
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Mulin Chao <mlchao@nuvoton.com>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2016-11-18 20:07:08 -08:00
Mary Ruthven
7c6d8d40f1 g: fix error rbox debug term override
The KEY_IN is used twice. One of these should be KEY_OUT. This change
fixes it.

BUG=none
BRANCH=none
TEST=make buildall

Change-Id: I923e0e2a1a0c4428a06ab486bf5ad9e49cf3d9b0
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/412902
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-11-18 20:07:06 -08:00
Nicolas Boichat
dfc9b86c82 chip/stm32/usb_hid_keyboard: Fix set_keyboard_report race
We always want set_keyboard_report to send the freshest possible
data. For this purpose, we use double-buffering on the USB
endpoint.

When the endpoint is currently busy, we sneak in an address change,
hoping that the hardware will pick it up. There is no guarantee
about which buffer was transferred, so we queue another transfer
anyway. This means that the code will send a duplicate (harmless)
report in that case.

BRANCH=none
BUG=chrome-os-partner:59083
TEST=make buildall -j
TEST=make BOARD=hammer -j && util/flash_ec --board=hammer

Change-Id: I9d14541b8b05017c1d5051b9a315db381a89dcea
Reviewed-on: https://chromium-review.googlesource.com/411741
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2016-11-17 07:08:23 -08:00
Nicolas Boichat
64f1823a74 chip/stm32/usb_hid: Separate HID keyboard support
In the future, we'd like to have different HID devices on different
endpoints (keyboard, trackpad, etc.), so we'd like to separate the
keyboard handling.

For other chip implementing usb_hid.c (namely, chip/g), we, for now
just rename the config option and endpoint/interface definitions.
Making the code more generic can be done at a later stage.

BRANCH=none
BUG=chrome-os-partner:59083
TEST=make buildall -j
TEST=make BOARD=hammer -j && util/flash_ec --board=hammer

Change-Id: Iad1b00fa226f7635c0f34aae6a435dc53a3ea555
Reviewed-on: https://chromium-review.googlesource.com/409256
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2016-11-16 19:04:47 -08:00
Martin Roth
0e0a9589ec upgrade_fw.c: Initialize variable before using it.
block offset was being used in a printf before it was being
initialized.  Initialize it earlier to fix the problem.

This does not change the size of any ec.*.flat file.

BRANCH=none
BUG=none
TEST=build succeeds under GCC 4.9.2, 5.3 and 6.2

Change-Id: I3233ca3b10d35a6f61036c2e30224dc3747618fd
Signed-off-by: Martin Roth <martinroth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/403501
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-11-16 19:04:33 -08:00
Archana Patni
edaedfaab4 npcx: set and clear wake masks in S0 <-> S0ix transitions
In the S0 <-> S3 transition, Coreboot sends EC messages to set/clear
the wake masks when the SMI is invoked. For S0ix, EC sets and clears
the wake mask via this patch.

These functions are directly invoked from the state machine transition
states. During S0ix entry, the wake mask for lid open is enabled.
During S0ix exit, the wake mask for lid open is cleared. All pending
events are also cleared.

BRANCH=none
BUG=chrome-os-partner:58740
TEST=test lidopen in S0ix

Change-Id: I398fdba2b9bba1f6caef46f8dc71c7de3b669d08
Signed-off-by: Archana Patni <archana.patni@intel.com>
Signed-off-by: Subramony Sesha <subramony.sesha@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/401070
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2016-11-16 07:10:03 -08:00
Aseda Aboagye
703d134977 mec1322: Place idlestats behind config option.
The `idlestats` command was not behind the CONFIG_CMD_IDLE_STATS option;
this commit fixes that.

BUG=None
BRANCH=glados
TEST=build a board that uses mec1322.  Undef CONFIG_CMD_IDLE_STATS;
verify that the command isn't present in the build.

Change-Id: Id17c8377f812ee2a63dc4507766c1c557704dcb1
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/411518
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2016-11-15 17:42:41 -08:00
Martin Roth
651f8b9acd chip/g to chip/lm4: fix more misspellings in comments
No functional changes.

BUG=none
BRANCH=none
TEST=make buildall passes

Change-Id: I0c4fcc900ec0326d6904aa14f298206e62be0fda
Signed-off-by: Martin Roth <martinroth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/403418
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
2016-11-15 17:41:55 -08:00
Martin Roth
897ce78bdd Fix various misspellings in comments
No functional changes.

BUG=none
BRANCH=none
TEST=make buildall passes

Change-Id: Ie852feb8e3951975d99dce5a49c17f5f0e8bc791
Signed-off-by: Martin Roth <martinroth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/403417
Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
2016-11-15 17:41:53 -08:00
Nick Sanders
bb3ab2fbc4 sweetberry: add usb power logging interface
This allows logging of power data over sweetberry

BUG=chromium:608039
TEST=log power data
BRANCH=None

Change-Id: I6f642384cbf223959294c7bd99bca0f9206775b8
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/385540
Reviewed-by: Todd Broch <tbroch@chromium.org>
2016-11-11 17:20:19 -08:00
nagendra modadugu
d7222a4956 CR50: add a constant time buffer equals implementation
Various cryptographic operations leak timing
information if comparisons are not executed
in constant time.  This change adds DCRYPTO_equals(),
a constant runtime comparator.

Also replace crypto related callsites that used
memcmp() as a binary comparator.

BUG=none
BRANCH=none
TEST=tcg tests pass

Change-Id: I3d3da3c0524c3a349d60675902d1f2d338ad455f
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/410163
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-11 14:27:23 -08:00
Kyoung Kim
fa1cec0b60 ISH: fix UART reference clock
UART reference clock is 100KHz for ISH4 and 120MHz for ISH3

BUG=none
BRANCH=None
TEST=`make buildall -j`

Change-Id: Ie33e0bd33e0a0c8e56a58fcf4a48677d38c9d61e
Signed-off-by: Kyoung Kim <kyoung.il.kim@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/409594
Commit-Ready: Kyoung Il Kim <kyoung.il.kim@intel.com>
Tested-by: Kyoung Il Kim <kyoung.il.kim@intel.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-11-11 00:12:33 -08:00
Mary Ruthven
5edf3f5a8c cr50: disable sleep
When bus obfuscation is enabled we have the chance of doing a security
reset when resuming from sleep. Since we cannot disable bus obfuscation
on current boards, we need to disable sleep.

BUG=chrome-os-partner:57994
BRANCH=none
TEST=make buildall

Change-Id: I6f49278a9b41c1d15c646838044e34f03b979479
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/409576
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-10 18:34:21 -08:00
Shawn Nematbakhsh
92d91adbdb npcx: hwtimer: Fix 'slow' timer count just before overflow
If our 32-bit usec timer is close to overflow, we may deep sleep several
times in succession without making any adjustment to our count, causing
deadlines on the other side (eg. HOOK_TICK expiration) to be reached much
slower than expected. Avoid this by not entering deep sleep if our timer
is about to overflow. This will result in a <= HOOK_TICK_INTERVAL (200ms
interval) period of not entering deep sleep, every ~4300 seconds.

BUG=chrome-os-partner:59240
BRANCH=gru
TEST=Verify 3x kevin units survive 16 hours in S3 without EC watchdog.

Change-Id: I2126458be8820f78212e19c2bb79242ff1194f6f
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/409673
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-11-09 21:14:09 -08:00
Shawn Nematbakhsh
ebdb6a62aa npcx: Fix hwtimers
- Wait for ITEN bit to be set / cleared, since writing this bit just
  sets a 'request'.
- Ensure ITIM_EVENT_NO reg is set with minimum value 1, per the
  datasheet.
- Don't dsleep if our wake event is in the past (eg. wake event will
  occur any time now)

BUG=chrome-os-partner:59240
BRANCH=gru
TEST=Manual on kevin, verify that dsleep period never exceeds expected
wait period. Also verify that EC watchdog doesn't occur after 5 hours in
S3.

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Iedb2723c3f12b74dea66082b1d8b8ce1b6e7d945
Reviewed-on: https://chromium-review.googlesource.com/409672
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-11-09 21:14:08 -08:00
Daisuke Nojiri
5e8a2255ab stm32f0: Allow change of external int priorities
This change allows each board to customize external interrupt
priorities.

BUG=none
BRANCH=none
TEST=make buildall

Change-Id: I5941f368ea70a069b34ce1d98508a1fad1ac22da
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/408796
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-11-09 18:40:00 -08:00
Scott
3405c79584 Cr50: I2CS TPM: Ensure HW read fifo is empty for register reads
This change is a safegaurd to ensure that TPM register data is always
placed in the correct location in the HW read I2CS fifo. It is only
checked for 1 or 4 byte regsiter reads. Because of the way in which a
TPM command is sent and the response is read, there are multiple reads
of the STS register prior to reading the TPM fifo register. Therefore
ensuring the fifo has zero depth when 1 or 4 byte regsiter reads,
improves the robustness of the design.

Added a counter to track the number of times the fifo is adjusted and
a new console command 'i2cs disp|rst' to display the count and reset
it to 0 if desired.

Removed section in code for TPM fifo register reads intended to handle
the case where there was a mismatch between how many bytes were copied
into the fifo and the number read by the host. Since the burstcount
field in the status register always contains a valid amount of data
that can be read by the host, there should not be cases where the
host reads less data than was copied from the TPM fifo register. In
the unexpected cases where the host may not drain all of the I2CS read
fifo data during a TPM register read, the I2CS fifo depth will be
corrected the next time that it reads either the access or STS
register which happens prior to the start of any TPM transaction.

BRANCH=none
BUG=chrome-os-partner:57338,chrome-os-partner:59191
TEST=manual
Booted Reef and verfied that TPM functionality is working.

Change-Id: I065a55e64bbcc0cb3357a2bd83447a05400b8899
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/382689
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2016-11-04 18:31:46 -07:00
Mary Ruthven
f16d6e43d3 g: add permission level checks
The jittery clock and trng security features require high permissions to
be initialized. In the future these initializations and the permission
level drop may be moved to RO.

This change adds permission level checks before trying to access any
registers that require high permission, so when we update RO to change
the permission RW can still function fine.

BUG=chrome-os-partner:59107
BRANCH=none
TEST=Move the permission drop to the beginning of main and verify the
system still boots.

Change-Id: I5b7cb856decd0640288ad3476f875ec9edc42635
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/405840
2016-11-04 18:31:44 -07:00
Jaiber John
d7b938f857 ish: Add support for ISH chip
This patch adds the initial support for ISH chip to enable the EC
firmware to boot on Intel Integrated Sensor Hub (ISH). The following are
enabled:

1. Inter-Processor Communication (IPC) driver that enables the ISH to
communicate with the host Operating system via shared registers.
2. High Precision Event Timer (HPET) driver that provides configurable
timers for the FW to use in task scheduling.
3. I2C bus driver for accessing sensors.
4. UART console driver with TX support only.

BUG=chrome-os-partner:51851
BRANCH=None
TEST=`make buildall -j`

Change-Id: I15d4c201b799cfa79bed220ee573b75f5cd7b1f7
Signed-off-by: Jaiber John <jaiber.j.john@intel.com>
Signed-off-by: Alex Brill <alexander.brill@intel.com>
Signed-off-by: Gomathi Kumar <gomathi.kumar@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/336710
Commit-Ready: Raj Mojumder <raj.mojumder@intel.com>
Tested-by: Jaiber J John <jaiber.j.john@intel.com>
Tested-by: Raj Mojumder <raj.mojumder@intel.com>
Reviewed-by: Jaiber J John <jaiber.j.john@intel.com>
Reviewed-by: Raj Mojumder <raj.mojumder@intel.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-11-04 18:31:29 -07:00
Marius Schilder
b8c1ce6700 bn_div and faster modular inverse.
We previously used binary extended Euclid. That does not perform well
when inverting a small public exponent.
We also abused that routine to perform the division of n by one of its
factors. Really did not perform well there either.

This CL introduces a classic Knuth long division and a normal extended
Euclid based on that.

This drops the execution time of the common inversions into the single
msec range (vs. multiple seconds before..)

TEST=tcg_tests pass the usual 381/391; test/tpm_test/bn_test passes.
BUG=chrome-os-partner:57422
BRANCH=none
Change-Id: Ic9b4aecd0356fcab3e823dbd60c5b228a87447d3
Reviewed-on: https://chromium-review.googlesource.com/406940
Commit-Ready: Marius Schilder <mschilder@chromium.org>
Tested-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2016-11-03 14:44:27 -07:00
Nick Sanders
a04fc68e72 usb_i2c: refactor into common
This combines stm32 and chip/g usb_i2c interfaces so they
will not diverge. Note that this fixes the chip/g implementation
to use 8-bit i2c addresses.

BUG=chrome-os-partner:57059
BRANCH=none
TEST=servod interacts with servo_micro and servo_v4

Change-Id: Ibff217d84b132556202c8a71e3d42c07d546c634
Reviewed-on: https://chromium-review.googlesource.com/405108
Commit-Ready: Nick Sanders <nsanders@chromium.org>
Tested-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2016-11-02 17:39:56 -07:00
Scott
dd652accd0 g: i2cm: Changed the slave address assumption to 8 bits
The i2c_xfer API assumes it's getting an 8 bit slave address, but the
driver was assuming a 7 bit slave address was being passed in. Fixed
the location where this is used to shift it back to 7 bits.

BRANCH=none
BUG=chrome-os-partner:57059
TEST=manual
Cr50 console 'ccd i2c on' then
> i2cxfer r16 0 0x40 0
Unknown error
Usage: i2cxfer r/r16/rlen/w/w16 port addr offset [value | len]
> i2cxfer r16 0 0x80 0
0x2771 [10097]
Shows that it's now assuming an 8 bit address

Change-Id: I791b7c136a741856749c281dd4c8166b5cf97ef9
Signed-off-by: Scott <scollyer@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/405780
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2016-11-02 04:23:21 -07:00