Commit Graph

57 Commits

Author SHA1 Message Date
Dawid Niedzwiecki f96f176c30 task_set_event: remove the wait argument
There is an option in the task_set_event function which force
the calling task to wait for an event. However, the option is never
used thus remove it.

This also will help in the Zephyr migration process.

BUG=b:172360521
BRANCH=none
TEST=make buildall

Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: Ic152fd3d6862d487bcc0024c48d136556c0b81bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2521599
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
2020-12-14 19:59:09 +00:00
Luis Lozano 0dc8b304f1 Fix use of int const in size of array.
Compiler complains about this use of a GNU extension now.
Replace by a #define.

BUG=chromium:1151317
BRANCH=None
TEST=to be done

Change-Id: Ib7fdd038f761bb4b27e9eeca5de9e3d0ec5f0f79
Signed-off-by: Luis Lozano <llozano@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2553749
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2020-11-23 02:58:48 +00:00
Wai-Hong Tam 1620833b5e tcpm: Change the get_chip_info() to prevent race conditions
The original get_chip_info() returns a point of point to the chip_info.
This way helps to cache the chip_info to a static variable and the
function just returns the pointer to the static variable.

This static variable has a race condition on the PS8805 chip. The PS8805
chip returns a different PID when the firmware is corrupted, i.e. 0x8803
instead of 0x8805. The !live case fixes the PID, by modifying the static
variable directly. When another task calls the same function for the
live case, the static variable is modified and has a race condition.

This change fixes the issue by changing the get_chip_info() parameter to
a point of the chip_info. The caller has to allocate a buffer in the
stack and pass the address to the function. For the !live case, the
function copies the cache value from the static variable to the buffer.
So the static variable doesn't have a race condition.

BRANCH=None
BUG=b:159588335
TEST=Used ectool to check the PD chip PID 0x8805 (was 0x8803).
localhost ~ # ectool pdchipinfo 1
vendor_id: 0x1da0
product_id: 0x8805
device_id: 0x1
fw_version: 0x0
min_req_fw_version: 0x0

Change-Id: Ic24615af77ea58016d286480572d2a282c4fa09a
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2264477
Reviewed-by: Julius Werner <jwerner@chromium.org>
2020-06-25 04:48:11 +00:00
Tom Hughes 99434726be test: Pass commandline arguments to run_test
run_test is called by the "runtest" console command. Console commands
can take arguments, so pass along the arguments to run_test to allow
parameters to be passed to run_test.

The following command was used for automatic replacement:

git grep --name-only 'void run_test(void)' |\
xargs sed -i 's#void run_test(void)#void run_test(int argc, char **argv)##'

BRANCH=none
BUG=b:155897971
TEST=make buildall -j
TEST=Build and flash flash_write_protect test
     > runtest 1

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: Ib20b955d5ec6b98f525c94c24aadefd7a6a320a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2209418
Reviewed-by: Yicheng Li <yichengli@chromium.org>
Commit-Queue: Yicheng Li <yichengli@chromium.org>
Tested-by: Yicheng Li <yichengli@chromium.org>
2020-05-30 05:16:26 +00:00
Sam Hurst 61efe94f1e TCPMv2: Only include PD3.0 functionality when CONFIG_USB_PD_REV30
The TCPMv2 stack defaults to PD2.0 functionality. Defining
CONFIG_USB_PD_REV30 enables PD3.0 functionality.

BUG=b:155879504
BRANCH=none
TEST=make -j buildall
	Manual tests:
	passed FAFT_PD running on kohaku

  Before patch:
  *** 18624 bytes in flash and 29216 bytes in RAM on kohaku RO ****
  *** 18544 bytes in flash and 29216 bytes in RAM on kohaku RW ****

  After patch:
  *** 23320 bytes in flash and 30336 bytes in RAM on kohaku RO ****
  *** 23228 bytes in flash and 30336 bytes in RAM on kohaku RW ****

  Flash savings of 4696 bytest
  Ram savings of 1120

Signed-off-by: Sam Hurst <shurst@google.com>
Change-Id: I082cf62617a91b487d2d3567afd5e340bd52258c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2184547
Reviewed-by: Jett Rink <jettrink@chromium.org>
2020-05-21 04:56:46 +00:00
Denis Brockus 887e071cd0 tcpc: change name of get_vbus_level to check_vbus_level
this is to add near future functionality to allow
not only the current PRESENT range check but to add
Save0V range checking as well, for platforms that
allow for this.  This just lays the framework and
is functionally equivalent.

BUG=none
BRANCH=none
TEST=verify basic USB functionality

Signed-off-by: Denis Brockus <dbrockus@google.com>
Change-Id: I1eb3411bc3aa9b792c9b97799e1721e5cb229f64
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2199036
Tested-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Auto-Submit: Denis Brockus <dbrockus@chromium.org>
2020-05-15 18:05:27 +00:00
Diana Z 1cd2adbbf8 TCPMv2: Configure fuzz test for alternate modes
Configures TCPMv2 fuzz test to build the alternate mode code, and sets
up a usb mux mock for that code to call.

Also removes a duplicate function definition which is no longer
necessary with the alternate mode common code building.

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

Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I4acd72a4a70ed445d4e49b99dbf3e08fe541d063
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2137257
Reviewed-by: Jett Rink <jettrink@chromium.org>
2020-04-16 08:32:21 +00:00
Ayushee d4bc8b52d0 usb_pd: Move cable communication functions to common file
BUG=b:148528713
BRANCH=none
TEST=Verified on TCPMV1 and TCPMv2, able to get correct
     cable characteristics.

Change-Id: I812b21c87661952bf4e86acaa194d4b136371594
Signed-off-by: Ayushee <ayushee.shah@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2051628
Reviewed-by: Diana Z <dzigterman@chromium.org>
Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
2020-03-27 07:59:50 +00:00
Jett Rink 471a3914c3 cleanup: drop the _TYPEC part of USB device config
The three USB device configurations describe more than just the Type-C
layer, so remove the _TYPEC part within the define. This is also in
preparation to change how the usbc build.mk includes files.

This was performed with the following commands:

$ git grep --name-only CONFIG_USB_TYPEC_DRP_ACC_TRYSRC | xargs perl -i
-ple 's/CONFIG_USB_TYPEC_DRP_ACC_TRYSRC/CONFIG_USB_DRP_ACC_TRYSRC/g'
$ git grep --name-only CONFIG_USB_TYPEC_CTVPD | xargs perl -i -ple
's/CONFIG_USB_TYPEC_CTVPD/CONFIG_USB_CTVPD/g'
$ git grep --name-only CONFIG_USB_TYPEC_VPD | xargs perl -i -ple
's/CONFIG_USB_TYPEC_VPD/CONFIG_USB_VPD/g'

BRANCH=none
BUG=none
TEST=builds

Signed-off-by: Jett Rink <jettrink@chromium.org>
Change-Id: I4deab784b7c3479cffd3dee7fb3ea3c8a9d6081c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2121193
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
2020-03-26 00:41:25 +00:00
Namyoon Woo 5ccb5c7cc9 remove cr50 related files
BUG=b:149350081
BRANCH=none
TEST=build all, and emerged ec related packages for host and octopus.
$ make buildall -j

$ cros_workon --host list
chromeos-base/chromeos-cr50-dev
chromeos-base/chromeos-ec
chromeos-base/chromeos-ec-headers
chromeos-base/ec-devutils
chromeos-base/ec-utils
chromeos-base/ec-utils-test
dev-util/hdctools

$ sudo emerge chromeos-cr50-dev -j
$ sudo emerge chromeos-ec -j
$ sudo emerge chromeos-ec-headers -j
$ sudo emerge ec-devutils -j
$ sudo emerge ec-utils -j
$ sudo emerge ec-utils-test -j
$ sudo emerge hdctools -j

$ cros_workon-octopus list
chromeos-base/chromeos-ec
chromeos-base/chromeos-ec-headers
chromeos-base/ec-devutils
chromeos-base/ec-utils
chromeos-base/ec-utils-test
dev-util/hdctools

$ sudo emerge-octopus chromeos-ec -j
$ sudo emerge-octopus chromeos-ec-headers -j
$ sudo emerge-octopus ec-devutils -j
$ sudo emerge-octopus ec-utils -j
$ sudo emerge-octopus ec-utils-test -j
$ sudo emerge-octopus hdctools -j

Signed-off-by: Namyoon Woo <namyoon@chromium.org>
Change-Id: If751b26b0635b0021c077338e96eaa8e8dcf17a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2080631
Reviewed-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2020-03-09 21:48:18 +00:00
Sam Hurst aebb58b990 TCPMV1/2: Make the PD Config Flags more consistent
The current use of the PD Config Flags are a bit confusing and
has been changed to the following:

The CONFIG_USB_POWER_DELIVERY flag is used to enable and disable
the TCPMv1 and TCPMv2 stacks. And when CONFIG_USB_POWER_DELIVERY
is enabled, one of the following must be enabled:
    CONFIG_USB_PD_TCPMV1 - legacy power delivery state machine
    CONFIG_USB_PD_TCPMV2 - current power delivery state machine

BUG=b:149993808
BRANCH=none
TEST=make -j buildall

Change-Id: Ie3f8615a75b15b4f1c703f57f3db9e152a471238
Signed-off-by: Sam Hurst <shurst@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2068519
Reviewed-by: Diana Z <dzigterman@chromium.org>
2020-02-22 03:14:27 +00:00
Denis Brockus 4588844d40 usbc: remove tri-state polarity
TCPCIr2 had an issue with setting CC coming out of DRP
that if the polarity was not retained that the connection
dropped back to OPEN. Unfortunately this change broke
many of the other TCPCI implementations.  I am working
on a different method of dealing with coming out of DRP
and this is no longer needed.

BUG=none
BRANCH=none
TEST=verify USB-C is working

Change-Id: Ifa8f26d417df2f5d5f41a23fbf7e6f9129031e94
Signed-off-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2056968
Reviewed-by: Jett Rink <jettrink@chromium.org>
2020-02-15 02:12:59 +00:00
Namyoon Woo d4d347e52e fuzz: remove cr50 or TPM2 library related tests from fuzz and test
This patch removes cr50 or TPM2 related test cases from fuzz and
test directory, so that buildall or chromeos-ec package won't check
them. Those test cases are already moved to cr50_stab branch.

BUG=b:149243259
BRANCH=none
TEST=ran 'make buildall -j' and
'sudo 'FEATURES=test' 'PKGDIR=/build/eve/test-packages' \
-- /mnt/host/source/chromite/bin/parallel_emerge  \
'--sysroot=/build/eve' '--jobs=10' chromeos-ec

Change-Id: Ie6f7c8622fe3e488758a814dc99ddf4587ffd973
Signed-off-by: Namyoon Woo <namyoon@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2047935
Reviewed-by: Allen Webb <allenwebb@google.com>
2020-02-12 05:00:31 +00:00
Vijay Hiremath 1c5d43dd90 TCPMv1/v2: Move dfp_consume_identity() to common file
BUG=b:148528713
BRANCH=none
TEST=make buildall -j

Change-Id: I5b0bbd553cbe4fc76478b1c89b0f3f391f074a27
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2032158
Reviewed-by: Keith Short <keithshort@chromium.org>
2020-02-04 04:07:51 +00:00
Ayushee d3cef73e45 usb_pd: Request Vconn swap to communicating with the cable
Before sending SOP' requests to cable plug, the port checks if
the port is the Vconn source. If the port isn't the Vconn source,
it can't talk to the cable.

From USB PD spec 1.3 sections 2.6.1 and 2.6.2, during an explicit
contract, after the data and power role swaps, if any, source/sink
can initiate or receive a request for exchanging the Vconn source.

Hence, adding support for the port to request Vconn swap, if it
hasn't already been swapped.

BUG=b:147209888
BRANCH=None
TEST=Checked on volteer, able to communicate with the cable plug

Change-Id: I36d896eda6319970b1a0a9bd7cc4efcbc381c8b1
Signed-off-by: Ayushee <ayushee.shah@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1988234
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Diana Z <dzigterman@chromium.org>
2020-01-14 23:22:51 +00:00
Tom Hughes 0b838e162b bloonchipper: Add transport and sensor detection
bloonchipper (aka hatch_fp aka dragonclaw) has a voltage divider that
can be used to select the sensor and the transport type.

Supported designs:
* Dragonclaw rev 0.2 (green with Google logo):
  go/dragonclaw-schematic-rev-0.2
* Hatch reference v3.0:
  go/hatch-schematic-rev-3.0

The selection lines are connected to ADC inputs, so a future change will
use the ADC to allow more than two transports or sensors.

BRANCH=none
BUG=b:147113851
TEST=flash dragonclaw rev 0.2 and view console output

Change-Id: If2e4b150d34cfe41477be528c70e1645043d4d82
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1986322
Reviewed-by: Craig Hesling <hesling@chromium.org>
2020-01-08 00:47:29 +00:00
Sam Hurst 2e2dcb986b TCPMv2: Enable TCPC low power when port is looking for a connection
When the port is in a state where it is looking for a connection,
to save power, we should put the TCPC in its low power mode and
enable auto toggling. Low power mode can happen when DRP auto
toggling, acting as a SNK only, or acting as a SRC only.

BUG=chromium:1022217
BRANCH=none
TEST=make -j buildall
	manual tests:
	1: (S0) Nothing plugged in, port is drp and low power mode
	2: (S5/S3/S0ix) Port is SNK only, and low power with nothing plugged in
	3: (S3/S0ix) If TypeC sink was previously plugged in, port remains powered
	4: (S5/S3/S0ix) TypeC source is recognized
	5: (S3->S0) TypeC sink plugged in, port is powered when S0 is reached

	Low power exit test:

	Using this command from the AP console:

	ectool i2cread 8 2 0x16 0x0d
	Transfer failed with status=0x1 # This means the TCPC was asleep.

	On the EC console:

	2019-11-21 09:50:24 [315.235538 TCPC p1 init ready]
	2019-11-21 09:50:24 [315.236048 TCPC p1 Exit Low Power Mode]
	2019-11-21 09:50:24 [315.242837 TCPC p1 init ready]
	2019-11-21 09:50:24 [315.243229 C1: DRPAutoToggle]
	2019-11-21 09:50:24 [315.246471 C1: Unattached.SNK]
	2019-11-21 09:50:24 [315.252504 C1: DRPAutoToggle]
	2019-11-21 09:50:24 [315.362878 C1: LowPowerMode]
	2019-11-21 09:50:24 [315.363314 TCPC p1 Enter Low Power Mode]

Change-Id: I7e853d05e0ece1f6b3031f17a18fcbf0d9a15a51
Signed-off-by: Sam Hurst <shurst@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1904974
Reviewed-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2019-11-21 23:41:16 +00:00
Vadim Bendebury f5b56454cf cr50: remove flash nonvolatile counter space
Counter implementation has been moved to the AP, no need to keep space
for it in the flash.

BUG=b:65253310
BRANCH=cr50, cr50-mp
TEST=generated image uses 2048 bytes less than before this patch.

Change-Id: I8225e9923932ce06ca0a4333c06508cf7d7c70d8
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1753677
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2019-11-21 19:30:28 +00:00
Jett Rink cf54e8664f usbc: fix vbus discharge path for GPIO
Code on Tot assumes that port count was the port to
discharge instead of port parameter

BRANCH=none
BUG=none
TEST=verified with unit test (in this CL)

Change-Id: I17658a0c555f9cea56fa4ec1652e0faf62e3d6cc
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1896125
2019-11-07 23:54:57 +00:00
Karthikeyan Ramasubramanian 9577704f30 Rename CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNT
Certain SKUs of certain boards have lesser number of USB PD ports than
defined by CONFIG_USB_PD_PORT_COUNT. Hence rename
CONFIG_USB_PD_PORT_COUNT as CONFIG_USB_PD_PORT_MAX_COUNT.

BUG=b:140816510, b:143196487
BRANCH=octopus
TEST=make -j buildall; Boot to ChromeOS

Change-Id: I7c33b27150730a1a3b5813b7b4a72fd24ab73c6a
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1879337
Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
2019-11-01 18:43:42 +00:00
Craig Hesling 7eded13a72 fuzz_host_cmd: Add fpsensor task + fp host cmds
This CL enables the fpsensor task and adds the following
remaining fingerprint host commands to the fuzzer:

* EC_CMD_FP_PASSTHRU
* EC_CMD_FP_INFO
* EC_CMD_FP_FRAME
* EC_CMD_FP_STATS
* EC_CMD_FP_TEMPLATE

BRANCH=none
BUG=b:116065496
TEST=make buildall -j
TEST=make run-host_command_fuzz
TEST=# Pull in TEST_COVERAGE fix
     git fetch "https://chromium.googlesource.com/chromiumos/platform/ec" \
     refs/changes/86/1725186/1 && git cherry-pick FETCH_HEAD
     make host-host_command_fuzz TEST_COVERAGE=1
     timeout 5m ./build/host/host_command_fuzz/host_command_fuzz.exe
     llvm-profdata merge -sparse default.profraw -o default.profdata
     llvm-cov show build/host/host_command_fuzz/host_command_fuzz.exe \
     --instr-profile=default.profdata --format=html --output-dir=cov
     # Inspect cov/.../common/fpsensor/fpsensor_state.c.html to verify

Change-Id: Icad9493ba41cd4daa61a30246d01afd1dbe16c56
Signed-off-by: Craig Hesling <hesling@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1682945
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Commit-Queue: Sean Abraham <seanabraham@chromium.org>
2019-10-25 17:58:19 +00:00
Craig Hesling 5866ec2921 mock: Add fp_sensor and mkbp_events mocks
BRANCH=none
BUG=b:116065496
TEST=make buildall -j

Change-Id: Ia723d98354ca027f41f1b3c00d6a2dac500edbf8
Signed-off-by: Craig Hesling <hesling@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1715633
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Commit-Queue: Sean Abraham <seanabraham@chromium.org>
2019-10-25 17:58:18 +00:00
Edward Hill 6e785cd95b usbc: Add missing IS_ENABLED(CONFIG_CHARGE_MANAGER) checks
Remove the need for stubs of charge_manager_set_ceil() by adding a few
missing IS_ENABLED(CONFIG_CHARGE_MANAGER) checks.

BUG=none
BRANCH=none
TEST=buildall

Change-Id: Ia70434b05107747eb773ae30ee1de5b4bd8cbcea
Signed-off-by: Edward Hill <ecgh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1869401
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
2019-10-18 22:26:51 +00:00
Edward Hill 4cb90db539 fuzz: Add fuzz test for TCPMv2
Add usb_tcpm_v2_fuzz, a TCPMv2 version of usb_pd_fuzz.

This gives some fuzz test coverage of:
  common/usbc/usb_pe_drp_sm.c
  common/usbc/usb_prl_sm.c
  common/usbc/usb_sm.c
  common/usbc/usb_tc_drp_acc_trysrc_sm.c
  common/usbc/usbc_task.c

BRANCH=none
BUG=none
TEST=make run-usb_tcpm_v2_fuzz

Change-Id: Ic129d9ebbe9bb37c2ca2674106e2a6652d08ee2a
Signed-off-by: Edward Hill <ecgh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1865017
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
2019-10-17 19:49:33 +00:00
Evan Green b63e2a87a7 printf: Convert %h to %ph
In order to make printf more standard, use %ph. Pass a pointer to
a struct describing the buffer, including its size. Add a convenience
macro so that conversion between the old style and new style is purely
mechanical. The old style of %h cannot be converted directly to %ph as-is
because the C standard doesn't allow flags, precision, or field width on
%p.

Ultimately the goal is to enable compile-time printf format checking.
This gets us one step closer to that.

BUG=chromium:984041
TEST=make -j buildall
BRANCH=None

Cq-Depend:chrome-internal:1559798,chrome-internal:1560598
Change-Id: I9c0ca124a048314c9b62d64bd55b36be55034e0e
Signed-off-by: Evan Green <evgreen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1730605
2019-10-05 00:47:41 +00:00
Tom Hughes 3c1215dadc fpsensor: Deinit the sensor before clearing the context
The opaque context contains sensor state that we can't nuke from
underneath the sensor library. Calling fp_sensor_deinit will release
this context and allow us to safely clear the context.

BRANCH=none
BUG=b:124773209
TEST="fpenroll" followed by "fpclear" in the FP console
TEST=On nocturne, in the UI, enroll finger, log out, and log in
     => then lock and unlock with finger
TEST=make buildall -j

Change-Id: I3e25bdf7eaaf99f3801547e11a6c524f924f4726
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1647294
Reviewed-by: Nicolas Norvez <norvez@chromium.org>
Commit-Queue: Yicheng Li <yichengli@chromium.org>
Tested-by: Yicheng Li <yichengli@chromium.org>
2019-09-28 17:00:32 +00:00
Craig Hesling d5927cd01e fuzz_host_cmd: Add fuzzing for fpsensor host cmds
This adds the host commands declared in fpsensor_state.c to the
fuzzing mix. They are the following:

EC_CMD_FP_SEED       0x0408
EC_CMD_FP_ENC_STATUS 0x0409
EC_CMD_FP_MODE       0x0402
EC_CMD_FP_CONTEXT    0x0406

This is not the complete fpsensor host command interface.
More host commands will be added in followup CLs.

BRANCH=none
BUG=b:116065496
TEST=# Pull in TEST_COVERAGE fix
     git fetch "https://chromium.googlesource.com/chromiumos/platform/ec" \
     refs/changes/86/1725186/1 && git cherry-pick FETCH_HEAD
     make host-host_command_fuzz TEST_COVERAGE=1
     timeout 5m ./build/host/host_command_fuzz/host_command_fuzz.exe
     llvm-profdata merge -sparse default.profraw -o default.profdata
     llvm-cov show build/host/host_command_fuzz/host_command_fuzz.exe \
     --instr-profile=default.profdata --format=html --output-dir=cov
     # Inspect cov/.../common/fpsensor/fpsensor_state.c.html to verify
TEST=make buildall -j

Change-Id: I69e9833463944a0dfba49e5671987b7fec565bf4
Signed-off-by: Craig Hesling <hesling@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1661122
2019-09-03 23:43:21 +00:00
Louis Collard ba6067286a cr50: Delete non-volatile counter API
This counter was only used by the legacy U2F
implementation, which is no longer required.

This change deletes the code for the counter,
but does not update the flash config to make use
of the pages previously occupied by the counter.

Since this code is already unused, and therefore
already dropped from built firmware images, this
change does not have any impact on image size.

A follow up change can alter the flash config
to reclaim and repurpose the 2KB per partition
previously used by the counter.

BRANCH=none
BUG=b:138459918
TEST=make buildall -j

Signed-off-by: Louis Collard <louiscollard@chromium.org>
Change-Id: I18892e1eb0224b96caa531293403b0b02f28a32b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1748848
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2019-08-23 09:09:18 +00:00
Jett Rink 85d086a15e usb: convert cc1 from int to enum
Refactor code to use proper type for cc1 and cc2 lines.

BRANCH=none
BUG=none
TEST=builds. No functional change.

Change-Id: Id292db8480920e2b191bac9d9ecc2685f61e4ea9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1744654
Tested-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
2019-08-09 21:50:56 +00:00
Karthikeyan Ramasubramanian 5936367096 ec_commands: Rename 'renew' to 'live' in EC_CMD_USB_PD_CHIP_INFO
Semantics of renew field in EC_CMD_USB_PD_CHIP_INFO is changing as
follows:
0 -> Return hard-coded info for Vendor ID/Product ID and cached info for
the Firmware Version
1 -> Return the live chip info for Vendor ID/Product ID/Firmware Version
Also rename the 'renew' field to 'live' to match the new semantics.

BUG=b:128820536,b:119046668
BRANCH=None
TEST=make -j buildall; Boot to ChromeOS.

Change-Id: Ie3dd022336b0be5c9728bb0ebabef32b7a6b5d57
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1617893
Tested-by: Karthikeyan Ramasubramanian <kramasub@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Karthikeyan Ramasubramanian <kramasub@chromium.org>
Auto-Submit: Karthikeyan Ramasubramanian <kramasub@chromium.org>
2019-07-20 00:49:26 +00:00
Craig Hesling a2139727d7 fuzz: Cleanup test_config.h and fuzz_config.h
This removes the remaining fuzz config that was
left in test_config.h. This section had already been duplicated
in fuzz_config.h, without being removed from test_config.h.

See the original migration CL crrev.com/c/1180179 for more info.

BRANCH=none
BUG=none
TEST=make runtests V=1 -j

Change-Id: Icd7158417ac184d7723828e62b968f7f0aa4bfbc
Signed-off-by: Craig Hesling <hesling@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1660126
Reviewed-by: Allen Webb <allenwebb@google.com>
2019-06-15 04:16:20 +00:00
Nicolas Boichat f88989e751 tcpci/usb_pd_fuzz: Avoid using unitialized data in payload
Found with MSAN fuzzer: usb_pd_protocol.c may use payload data
that is not initialized.

Fix the test by copying over the whole payload, which is what
tcpci.c's version does.

Also, in tcpci.c, clear cached_messages head before using
get_message_raw to fill it up, to make sure that we do not
accidentally use older data in the queue.

BRANCH=none
BUG=chromium:963076
TEST=make TEST_MSAN=y host-usb_pd_fuzz -j
     MSAN_OPTIONS=log_path=stderr:exitcode=0 \
        build/host/usb_pd_fuzz/usb_pd_fuzz.exe \
        clusterfuzz-testcase-minimized-ec_usb_pd_fuzzer-5716775969357824

Change-Id: I74c38538440cb5a01d1714657b9e2d63e5b80cea
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1610163
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2019-05-16 09:04:26 -07:00
Jett Rink bd4012d9ab tasks: convert TASK_EVENT_CUSTOM macro to bit
We should ensure that all custom task definition are non-zero and fit
with the globally defined events. Add compile time check and change
semantics to specify bit number (instead of making all callers use the
BIT macro).

This also fixes an error with TASK_EVENT_PHY_TX_DONE for ITE being 0.
The bug that made that happen hasn't landed on any firmware branches
that use it though.

BRANCH=none
BUG=none
TEST=builds
Cq-Depend:chrome-internal:1178968,chrome-internal:1178952

Change-Id: I5e1d1312382d200280c548e9128e53f4eddd3e61
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1570607
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
2019-04-24 15:51:09 -07:00
Allen Webb fe1f0e960a fuzz: Define HIDE_EC_STDLIB in nvmem_tpm2_mock.
Since nvmem_tpm2_mock is linked outside of libec.a it needs to use the
cstdlib version of memcpy so HIDE_EC_STDLIB needs to be defined prior to
including any of the EC headers.

BRANCH=none
BUG=chromium:950310
TEST=TEST_UBSAN=y make -j host-cr50_fuzz

Change-Id: I2d303ab1e8f493b4d4715c36f6e81592eeca246d
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1566654
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2019-04-19 14:45:37 -07:00
Daisuke Nojiri 6bd030ecd9 ec.tasklist: Consolidate duplicate comments
It's simply a bad idea to describe a macro in multiple locations.
It'll make it hard to change. It'll be difficult to keep all
locations in sync.

This patch replaces the comment duplicated in all ec.tasklist with
a pointer to the CONFIG_TASK_LIST definition. The macro will be
described in a single place (just like all/most other macros).

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

BUG=none
BRANCH=none
TEST=buildall

Change-Id: Id658b9d68e742e4334c692b804d9c98c8de21313
Reviewed-on: https://chromium-review.googlesource.com/1551579
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
2019-04-08 22:30:32 -07:00
Vadim Bendebury 1d6c7bb977 nvmem: test modifications to support the new scheme
This patch includes changes to support testing of the new nvmem
implementation.

Making fizz compatible required duplicating a lot of functionality
available in the test/ directory (fuzz/nvmem_tpm2_mock.c is very
similar to test/nvmem_tpm2_mock.c), but I could not find an easy way
to avoid it.

BRANCH=cr50, cr50-mp
BUG=b:69907320, b:129710256
CQ-DEPEND=CL:1496607
TEST=with the rest of the patches applied 'make buildall -j' succeeds,
     which confirms both test and fuzz success.

Change-Id: Ife999b04d22f8ddbe9ea5d35f4c3e21f57592754
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1450278
Reviewed-by: Andrey Pronin <apronin@chromium.org>
2019-04-05 09:21:44 -07:00
Allen Webb 5079009d35 cr50_fuzz: Add owners files for fuzz target.
This adds owners files for the fuzz target so that bugs are correctly
assigned.

BRANCH=None
BUG=None
TEST=USE="ubsan asan fuzzer" ./build_packages \
  --board=amd64-generic --skip_chroot_upgrade chromeos-ec

Change-Id: I53867fcb09bdf306a2a01e50a4c2faa647e2efe8
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1361980
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2019-01-08 01:59:10 -08:00
Allen Webb 7a071bca73 stdlib cleanup.
This cleanups some header includes to avoid conflicts between the ec
headers and the standard c headers.

BRANCH=None
BUG=None
TEST=make -j buildall && ./build_packages --board=veyron_minnie \
  chromeos-ec && FEATURES=test emerge-veyron_minnie chromeos-ec

Change-Id: Icf9022d688fd9c749f7a5f8673755188741b40e1
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1378906
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2019-01-03 15:04:38 -08:00
Allen Webb 934c1103a2 cr50_fuzz: Re-enable this fuzz target now that chromeos-ec is fixed.
A new symbol was added to third_party/tpm2 that needed a mock
implementation in cr50_fuzz to fix compilation.

CQ-DEPEND=CL:1370404,CL:1377383
BRANCH=None
BUG=chromium:911310
TEST=USE="ubsan asan fuzzer" ./build_packages \
  --board=amd64-generic --skip_chroot_upgrade chromeos-ec

Change-Id: I3e2546829646e89361bfa2a8b4084c95b346f78f
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1370747
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2019-01-02 18:14:04 -08:00
Allen Webb 9df27e27ad cr50_fuzz: Fix build errors related to nvmem_wipe_cache.
The declaration of nvmem_wipe_cache is now inside the extern "C"
section and a definition was added to cr50_fuzz.

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

Change-Id: Ie7401d8880e7982c84fa6a5df5015cbd145fc6d1
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1370746
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-12-20 13:49:43 -08:00
Allen Webb a6f0a7e96c Makefile.rules: Add buildfuzztests to buildall.
This incorporates the fuzz targets into buildall and adds a quick
sanity check to each fuzz target to make sure it exits successfully for
an empty input.

This adds roughly 5.88 seconds to "make -j buildall" (This includes an
addtionally target that will be enabled in a later CL).

time make -j buildall # BEFORE
real    1m19.519s
user    23m9.220s
sys     5m1.690s

time make -j buildall # AFTER
real    1m25.399s
user    23m35.753s
sys     5m12.609s

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

Change-Id: Ib77a57297ee896569c509d0c8c998552d2a3a76c
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1370934
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2018-12-19 01:12:52 -08:00
Allen Webb 7f325f2e91 cr50_fuzz: Disable this target. It is breaking the chromeos-ec build.
BRANCH=None
BUG=chromium:911310
TEST=USE="ubsan asan fuzzer" ./build_packages \
  --board=amd64-generic --skip_chroot_upgrade chromeos-ec

Change-Id: I15ac87b14a0f28a62e257bb155f1862753053eb4
Reviewed-on: https://chromium-review.googlesource.com/c/1368010
Tested-by: Allen Webb <allenwebb@google.com>
Trybot-Ready: Allen Webb <allenwebb@google.com>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2018-12-07 18:34:25 +00:00
Vadim Bendebury a45e42da1a cr50: provide DCRYPTO_ladder_is_enabled() for test and fuzz builds
This function is called from common/nvmem.c, it should be available
when compiling for tests, the stub could be filled up later when new
tests are added.

BRANCH=cr50, cr50-mp
BUG=b:119221935
TEST=make buildall -j still succeeds.

Change-Id: I082292818c7f2b10336c9a7c49e0a9195e25a12b
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1363816
Reviewed-by: Allen Webb <allenwebb@google.com>
2018-12-06 22:06:26 -08:00
Nicolas Boichat d260241836 test/usb_pd_fuzz: Fuzzing of USB PD data
Setup CC lines, then send up to 8 PD messages, in an attempt to
cause errors while parsing PDO and other messages.

BRANCH=none
BUG=chromium:854975
TEST=make -j buildfuzztests && \
     ./build/host/usb_pd_fuzz/usb_pd_fuzz.exe > /dev/null

Change-Id: Ibb575ea8d464945390d1663dd6fff279bd9d77ea
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1116626
Reviewed-by: Jonathan Metzman <metzman@chromium.org>
2018-12-05 01:13:38 -08:00
Allen Webb 1caaa593b1 cr50_fuzz: Re-enable this fuzz target now that chromeos-ec is fixed.
'mem_hash_tree.h' was missing '#define HIDE_EC_STDLIB' before
'dcrypto.h'. This problem was only apparent when -O2 is set.

CQ-DEPEND=CL:1358746
BRANCH=None
BUG=chromium:911310
TEST=USE="ubsan asan fuzzer" ./build_packages \
  --board=amd64-generic --skip_chroot_upgrade chromeos-ec

Change-Id: I19d00c165764f80cfa385fb3bed64efc67bfc3f9
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1361680
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2018-12-04 17:40:11 -08:00
Allen Webb cc31a63016 cr50_fuzz: Fix missing dependencies.
This fixes a dependency problem that was introduced in CL:1184107.

BRANCH=None
BUG=chromium:911310
TEST=USE="ubsan asan fuzzer" ./build_packages \
  --board=amd64-generic --skip_chroot_upgrade chromeos-ec

Change-Id: Ib4795d6a716fe3fcb7a88bf6a165f96ffe10640a
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1358746
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
2018-12-04 14:00:04 -08:00
Allen Webb 5f4f729f2f cr50_fuzz: Disable this fuzz target until chromeos-ec is fixed.
BRANCH=None
BUG=chromium:911310
TEST=USE="ubsan asan fuzzer" ./build_packages \
  --board=amd64-generic --skip_chroot_upgrade chromeos-ec

Change-Id: Ib2ffc7035d0f6912834709bb8a5f6b3c11a2c67a
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1359652
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2018-12-04 00:11:31 -08:00
Allen Webb c60f9f37ab cr50_fuzz: Add self test.
This adds an initialization step that sanity checks the fuzz target to
make sure the model is working as intended.

BRANCH=None
BUG=chromium:876582
TEST=sudo emerge libprotobuf-mutator &&
  make -j buildfuzztests && ./build/host/cr50_fuzz/cr50_fuzz.exe

Change-Id: I3961a7ff05b4876992af447a2104bcfa0a496562
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1347012
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
2018-12-03 12:43:23 -08:00
Allen Webb a5e1a639e5 cr50_fuzz: Add libprotobuf-mutator support.
This uses protocol buffers to model what actions can be taken with
pinweaver at a higher level of abstraction than the raw requests to
greatly increase the coverage that can be achieved by fuzzing, while
still allowing for invalid inputs to be checked.

BRANCH=none
BUG=chromium:876582
TEST=sudo emerge libprotobuf-mutator &&
  make -j buildfuzztests && ./build/host/cr50_fuzz/cr50_fuzz.exe

Change-Id: Ie7ce569650ca06866f277f36eae61df2684de60c
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1184107
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2018-12-03 12:43:22 -08:00
Allen Webb 90f4c546b3 cr50_fuzz: fix nvmem_vars user number.
The CONFIG_FLASH_NVMEM_VARS_USER_NUM constant was incorrectly defined,
so nvmem_vars was failing with EC_OVERFLOW.

BRANCH=None
BUG=None
TEST=make -j buildfuzztests && ./build/host/cr50_fuzz/cr50_fuzz.exe

Change-Id: I52facfd44423bb69284b54e6831e5e777cf35a05
Signed-off-by: Allen Webb <allenwebb@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1344800
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
2018-11-21 01:25:22 -08:00