Commit Graph

74 Commits

Author SHA1 Message Date
Nicolas Boichat
7ffcd686db whiskers: Enable LM3630A LED driver
Used to control keyboard backlight.

BRANCH=none
BUG=b:68934906
TEST=make BOARD=whiskers -j

Change-Id: Ie793ebe91670965a434896530084561a7f1c57d4
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/892842
Reviewed-by: Benjamin Gordon <bmgordon@chromium.org>
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
2018-01-31 03:36:25 -08:00
Nicolas Boichat
31c1fc6d43 whiskers: Update GPIO for next revision
Looks more similar to original hammer.

BRANCH=none
BUG=b:68934906
TEST=make BOARD=whiskers -j

Change-Id: I0f10240f8c3237b20f60a1217e167ad9539e3953
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/853574
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-01-29 05:24:45 -08:00
Nicolas Boichat
d9f4ce13f2 touchpad_elan: Add retry logic if the touchpad does not respond
After 3 tries, the touchpad is reset by power-cycling it.

BRANCH=none
BUG=b:71688150
TEST=Short SDA/SCL lines, press on touchpad, see that touchpad tasks
     retries transaction, and then resets the touchpad power.
TEST=Do ESD discharge, and see that touchpad always recovers.

Change-Id: If0b5eb936d4d2feb3d34a7ec8748869a1b915c34
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/872131
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2018-01-21 22:20:48 -08:00
Nicolas Boichat
eaaf890188 wand: Enable CONFIG_CHARGE_RAMP_HW
Enable ramping by default. Follow-up CL will have EC-EC master tell
the slave if it's necessary to ramp.

BRANCH=none
BUG=b:71840796
TEST=lux fully charged, in S0ix, wand connected. Connect old
     BC1.2 charger, see that the charger is not browning out anymore.

Change-Id: I5f1052257db4c581bcb700c7f0306f14f792ea03
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/863349
Reviewed-by: Shawn N <shawnn@chromium.org>
2018-01-14 18:38:31 -08:00
Nicolas Boichat
6bbb5adab1 charge_state_v2: Add charge_set_output_current_limit function
This function sets up and enables "OTG" mode on the charger chip
(i.e. use the charger to provide power from the battery).

It also records the output current in curr.output_current, to
make sure that the charger loop is aware that current is provided
externally.

We also add a CONFIG_CHARGER_OTG to remove these functions on
boards that do not require it.

BRANCH=none
BUG=b:65697962
TEST=On wand, when discharging, battery status is updated every
     5 seconds (and not every 60 seconds).

Change-Id: Ibf93933436f3eb24552a8e1eb9d97522fca2ce79
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/842743
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-01-04 21:52:01 -08:00
Nicolas Boichat
41af1bf27c wand: Make sure battery is cut-off when critical
Modify chipset_in_state to always say that the chipset is off,
when we do not actually have a chipset (like on hammer): that
makes sure the battery can actually be cut off (else the EC
would just wait forever for the chipset to turn off).

Also, wake the charger state on "AC" change, that is, when
charging_allowed changes state, to make sure the charging loop
is executed after lux tries to charge it (else the charging loop
would wait until timeout expires, and wand would ask the battery
to be cut off again).

BRANCH=none
BUG=b:65697962
TEST=Deplete wand battery, reboot without providing external power
     to it.
     After 30 seconds, battery is cut off:
[1.354683 Low battery: 2%, 6866mV]
[1.354888 charge warn shutdown due to critical battery]
[31.381410 Low battery: 2%, 6865mV]
[31.381643 charge force battery cut-off due to critical level]
TEST=Upon providing power to wand, charging loop is executed
     regularly, and battery is charging.

Change-Id: I7154b25bd852b8422a0ae3b506675a297a948132
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/842742
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2018-01-04 21:52:00 -08:00
Nicolas Boichat
3ce0b8b924 wand: Increase PWM frequency to 50kHz
RT4531 wants PWM input frequency between 20 and 100 kHz.

BRANCH=none
BUG=b:66575472
TEST=Flash wand, pwm 0 50, check with oscilloscope that frequency
     is around 50kHz, and that duty cycle is 50%.

Change-Id: I6a37ef435a51cf730805ef57a0e3ebd05f9820a3
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/845541
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2018-01-02 21:32:23 -08:00
Nicolas Boichat
7eacce9720 ec_ec_comm_slave: Define extpower_is_present
On dual-battery slave, we use the charging allowed signal from
master to indicate whether external power is present.

In most cases, this actually matches the external power status
of the master (slave battery charging when AC is connected, or
discharging when slave battery still has enough capacity), with
one exception: when we do master to slave battery charging (in
this case the "external" power is the master).

BRANCH=none
BUG=b:65697962
TEST=Deplete wand battery to 5%, see that lux still provides power
     to it but the battery does not charge.

Change-Id: I8bd9f52c386a0a9edfae3837ba33725b3101a008
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
2017-12-21 22:50:34 -08:00
Nicolas Boichat
9a284576a8 wand: Add wand board
hammer derivative, with a battery.

BRANCH=none
BUG=b:66575472
TEST=make BOARD=wand -j, flash to reworked hammer board,
     battery charging works.

Change-Id: I42366f4738b35c352b9be0c44a17ebeb323adfd1
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/678756
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-12-20 05:49:34 -08:00
Nicolas Boichat
2f4fd74df5 hammer: Detect backlight circuitry
Pull-down means backlight is present, pull-up means backlight
is absent.

After detection, we still apply internal pull-down on the GPIO,
to make sure old boards with both pull-up and pull-down stuffed
do not always keep backlight on.

BRANCH=none
BUG=b:67722756
TEST=On reworked board with pull-down on backlight pin,
     backlight works, and "Backlight present" shown in console.
TEST=On old board with both pull-up and pull-down, backlight is
     off by default, and "Backlight not present" shown in console.

Change-Id: I6988c6ef8f4d155a08967db34f72d7ea4c835306
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/538458
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-12-12 03:57:19 -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
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
Nicolas Boichat
cd1f377f16 usb_i2c: Remove usb_i2c_board_enable/disable
These functions are not used by usb_i2c.c on chip/stm32, let's
move them to board/cr50 which is the only place where they are
used.

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

Change-Id: I8c1b292838b8dbee9a9001add9332e0add80c342
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/778749
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-11-20 23:25:45 -08:00
Nicolas Boichat
4cb524de67 touchpad_elan: Rename task/interrupts functions
Change the names to generic touchpad_* functions, instead of
vendor-specific names. Makes it a little easier to add drivers
for other touchpads.

Also fix console_channel.inc to add the channel whenever any
touchpad is used.

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

Change-Id: I6d268db5ebd53db272fb2ee7bbf06bbe80845734
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/778750
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-11-20 04:53:20 -08:00
Nicolas Boichat
fe69abf6c3 board: Add support for whiskers board
A hammer derivative.

BRANCH=none
BUG=b:68934906
TEST=make BOARD=whiskers -j

Change-Id: I8df5156d622bf518f647addf2fcea6342b2d6f2b
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/754078
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-11-09 16:43:54 -08:00
Nicolas Boichat
254174085a hammer: Enable CONFIG_SHA256_UNROLLED in RO region
Makes RW verification a little faster (268ms vs 294ms), at no
cost since RO still has enough space. Doesn't make any difference
in time to active USB, as USB enumeration is still the bottleneck.

BRANCH=none
BUG=b:35647963
TEST=Boot hammer, check that [0.267707 RW verify OK] is better
     than without this patch ([0.294128 RW verify OK]).

Change-Id: I7d6564226616bfa807a636198d53ca7b2ea7081a
Signed-off-by: Nicolas Boichat <drinkcat@google.com>
Reviewed-on: https://chromium-review.googlesource.com/744297
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-10-30 18:47:45 -07:00
Nicolas Boichat
b6547eda9b staff: Adjust touchpad dimensions
BRANCH=none
BUG=b:67982128
TEST=Flash staff, no more *** TP mismatch error.

Change-Id: I8f9aee68bc81a550eae176b9903add2a4f26b700
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/727390
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-10-19 05:15:30 -07:00
Nicolas Boichat
4bb651b27b hammer: Include hashes in EC image (CONFIG_TOUCHPAD_HASH_FW)
BRANCH=none
BUG=b:63993173
TEST=make TOUCHPAD_FW=SA459C-1211_ForGoogleHammer_3.0.bin \
          BOARD=hammer -j
CQ-DEPEND=CL:641736

Change-Id: Ib9eadfb6be8022f774b770a03480cf8c319a8a5a
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/664501
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-09-15 23:39:26 -07:00
Chun-Ta Lin
e18d9dd530 hammer: Support different IC types in touchpad FW update
Some Elan touchpad ICs have a different firmware sizes (48, 56, or 64
KB). We use CONFIG_TOUCHPAD_VIRTUAL_SIZE, set in the board file, to
determine the appropriate size, and, at runtime, we sanity check the
firmware size according to the IC type reported by the touchpad.

BRANCH=none
BUG=b:65188846
TEST=Manually modify the CONFIG_TOUCHPAD_VIRTUAL_SIZE in hammer,
     executed and verified both (1) "EC_ERROR_UNKNOWN" returned
     (2) ic_type shows 0x09 on EC console
TEST=Successfully flashing 48k firmware using CL:658920 on hammer and
     56k firmware on staff. With success here, we specifically test
     with different firmware version and make sure it reflected in
     hammerd's touchpad info.

Change-Id: Ib30917d8376d4a2e8b6137daabad2341ac48d1f8
Signed-off-by: Chun-Ta Lin <itspeter@google.com>
Reviewed-on: https://chromium-review.googlesource.com/664937
Commit-Ready: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2017-09-14 22:25:02 -07:00
Nicolas Boichat
fe5cebf1d9 hammer: Enable touchpad FW update over USB updater
We use address 0x80000000, which is not mapped to anything in
STM32F0 address space.

BRANCH=none
BUG=b:63993173, b:65188846
TEST=./usb_updater2 -p 144.0_2.0.bin
CQ-DEPEND=CL:601814

Change-Id: I9a9044d29ebe058d3792dc984cac4051a005cf8f
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/597468
Commit-Ready: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
2017-09-12 06:38:08 -07:00
Wei-Ning Huang
af00619b1e hammer: enable keyboard backlight support
Enable keyboard backlight support through HID output report.

BRANCH=none
BUG=b:37971411,b:63364143
TEST=with stacked CLs
     1. `make BOARD=hammer -j`
     2. `echo 10 > /sys/class/leds/hammer\:\:kbd_backlight/brightness`
        console shows 'Keyboard backlight set to 10%'

Change-Id: Icd08c2c48ab2f0a6ea6ecbc45bad8dd2c743931d
Reviewed-on: https://chromium-review.googlesource.com/586349
Commit-Ready: Wei-Ning Huang <wnhuang@chromium.org>
Tested-by: Wei-Ning Huang <wnhuang@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-09-01 12:39:19 -07:00
Nicolas Boichat
9ea128966b hammer: Pull down PWM output pin
Some staff boards were accidentally built with both pull-up and
pull-down stuffed, leaving the backlight output always on when
the EC is not driving the pin.

This "fixes" the issue by adding an internal pull-down on the pin,
so that the pin is pulled low whenever the PWM is disabled.

BRANCH=none
BUG=b:64845198
TEST=staff EC console:
     pwm 0 -1 => backlight is off
     pwm 0 0 => backlight still off
     pwm 0 100 => backlight full intensity
TEST=Power consumption with PWM disabled (pwm 0 -1) and always 0
     (pwm 0 0) are comparable.

Change-Id: I32549bfc037a6506470408f8e98cae5ae56006e2
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/627345
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2017-08-23 00:04:09 -07:00
Nicolas Boichat
e525e1af8a usb_update: Add a way to fetch touchpad information
We'd like to know touchpad vendor/product id, as well as currently
running FW version. This CL does that by adding a new
UPDATE_EXTRA_CMD_TOUCHPAD_INFO command.

We also make the interface more generic by adding a CONFIG_TOUCHPAD
configuration option, even though we only support Elan touchpads
currently.

BRANCH=none
BUG=b:63418037
TEST=Flash hammer, ./usb_updater -t

Change-Id: Icce3c785eb3235bcc50b2ae7c0227ce11cbc9f2b
Signed-off-by: Nicolas Boichat <drinkcat@google.com>
Reviewed-on: https://chromium-review.googlesource.com/593000
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Chun-ta Lin <itspeter@chromium.org>
2017-08-03 00:32:05 -07:00
Nicolas Boichat
a6ce030a84 hammer: Disable USB I2C passthrough when system is locked
Leaving the I2C passthrough to the trackpad open causes security
issues, let's make sure we disable that in the field, whenever
the WP screw is on (and system is locked, which will be synonymous
for production firmwares).

BRANCH=none
BUG=b:37926507
TEST=- In board/hammer/board.h, uncomment CONFIG_SYSTEM_UNLOCKED
     - Flash hammer (both RO and RW)
     - Trackpad updating still works (touchpad_updater on DUT)
     - Make sure WP is on
       dut-control -p 9000 fw_wp_vref:pp3300 fw_wp_en:on fw_wp:on
     - hammer console: flashwp true; reboot
     - Trackpad updating fails (cannot read iap password.)

Change-Id: I247bb9c62ea00d6cb3631c919d27305f4d291d68
Signed-off-by: Nicolas Boichat <drinkcat@google.com>
Reviewed-on: https://chromium-review.googlesource.com/595290
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2017-08-03 00:32:04 -07:00
Randall Spangler
00ea73ab16 usb_i2c: Fail if board I2C bridge is disabled
Add usb_i2c_board_is_enabled().

On Cr50, this is now also connected to the I2C CCD capability.  The
USB-I2C bridge can only be used when the capability is available.

On other platforms (Servo V4, etc.) where usb_i2c_board_enable() is
a no-op, add a dummy implementation which always returns true.

See go/cr50-ccd-wp for more information.

BUG=b:62537474
BRANCH=cr50
TEST=manual with CR50_DEV=1
	Connect host PC to dev board USB port
	On host PC:
		sudo servod -c ccd_cr50.xml -c reef_r1_inas.xml
		dut-control pp3300_ec_shv_reg --> fail, error 0x8001

	ccdoops --> reset I2C config
	ccd i2c disable --> I2C disabled

	On host PC:
		sudo servod -c ccd_cr50.xml -c reef_r1_inas.xml
		dut-control pp3300_ec_shv_reg --> fail, error 0x0006

	ccd i2c enable --> I2C enabled
	ccdunlock --> I2C disabled
	ccdoops --> I2C enabled
	ccdset i2c unlesslocked
	ccdlock --> I2C disabled
	ccdunlock --> I2C enabled

Change-Id: Ia3df32e239a5f7c5915bc6c7e408ce0dc8b26c89
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/590577
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
2017-07-31 21:39:39 -07:00
Gwendal Grignou
1b25735b73 Add OTP support
One Time Programmable memory can be used to store permanent data like
serial numbers.
Reorganize the code to support writing serial number to OTP, in
addition to pstate (if using its own memory bank) or autogenerate from
unique id (hammer).

+ Add CONFIG_OTP to enable OTP code
+ Add CONFIG_SERIALNO_LEN to indicate the size of the serial number
string.  Currently set to 28, when USB serial number is needed.
+ Expose flash_read|write_pstate_serial and add otp_read|write_serail,
remove more generic flash_read|write_serial.
+ Make board_read|write_serial generic, declared outside of USB subsystem.

Priority order to read|write serial string:
- board definition (like hammer)
- pstate location, if stored in its private memory bank
- otp area
If none of these methods are available, a compilation error is raised.

BUG=chromium:746471
BRANCH=none
TEST=compile

Change-Id: I3d16125a6c0f424fb30e38123e63cf074b3cb2d3
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/580289
Reviewed-by: Nick Sanders <nsanders@chromium.org>
2017-07-28 17:45:13 -07:00
Nicolas Boichat
74d1a312e7 poppy/hammer: Increase sideband wake pulse to 500us
100us is hard to measure reliably on poppy side, let's increase to
500us, and widen the range.

BRANCH=none
BUG=b:63818321
TEST=Flash staff and soraka EC, check that pulses are detected
     correctly.

Change-Id: I1c29a42c70da0efa0318a619bb83e451b9f168f4
Reviewed-on: https://chromium-review.googlesource.com/581572
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2017-07-25 20:08:34 -07:00
Chun-Ta Lin
8288cea242 hammer: adjust stack size for trackpad task
Current stack size is so well-calculated that printing debug message
will cause stack overflow and triger reboots.

BRANCH=none
BUG=none
TEST=make BOARD=hammer

Change-Id: If90a4d99181e1e08b7ff69e12b5d54a19455cea9
Signed-off-by: Chun-Ta Lin <itspeter@google.com>
Reviewed-on: https://chromium-review.googlesource.com/575116
Commit-Ready: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
Reviewed-by: Che-yu Wu <cheyuw@google.com>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2017-07-19 14:41:23 -07:00
Nicolas Boichat
cc6662135d hammer: Enable Link-Time-Optimization CONFIG_LTO
We need to add __keep to the USB descriptors, otherwise they
get thrown away.

Also, for some reason the optimized RWSIG task uses a little bit
more stack space, so account for that:
   1   RWSIG            00000000    0.264350  1096/2048

BRANCH=none
BUG=b:63610290
TEST=make BOARD=hammer -j
     make newsizes
build/hammer/RO/ec.RO.flat shrank by 2052 bytes: (37336 to 35284)
build/hammer/RW/ec.RW.flat shrank by 3172 bytes: (50508 to 47336)
     Flash hammer, touchpad, keyboard, update all still work fine.

Change-Id: I39ffd320dae883596ce481efc4adec6e3c23000b
Reviewed-on: https://chromium-review.googlesource.com/567909
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-07-17 21:27:14 -07:00
Nicolas Boichat
74d09422e9 common/flash: Add option to set PSTATE to be locked by default
For hammer, we do not want to require finalization in factory, so
we just protect RO whenever WP GPIO is set.

BRANCH=none
BUG=b:63378217
TEST=Enable CONFIG_FLASH_PSTATE_LOCKED, flash hammer,
     check with flashinfo that RO protection matches WP status.

Change-Id: I902ee478c00a3c932277d2a7d0622c070654a5eb
Reviewed-on: https://chromium-review.googlesource.com/563217
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-07-08 03:49:53 -07:00
Nicolas Boichat
1442cbdebb hammer: Adjust trackpad dimensions
BRANCH=none
BUG=b:35582031
TEST=Flash and boot hammer, no more trackpad dimension mismatch error.

Change-Id: If4bd9db456617a52d1890543e7cae34a563122dd
Reviewed-on: https://chromium-review.googlesource.com/523502
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-06-19 21:03:33 -07:00
Nicolas Boichat
a9364ca5d4 hammer: Add support for base pairing
x25519 requires quite a bit more stack size (1696/2048), so
increase its size.

BRANCH=none
BUG=b:38486828
TEST=Flash hammer, ./usb_updater2 -c always reports the same
     device public key, and authenticator is correct.

Change-Id: I51dff9f10167d654561ef7f199b9b9206511b7e9
Reviewed-on: https://chromium-review.googlesource.com/532476
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-06-15 09:37:57 -07:00
Nicolas Boichat
d5bb8390a8 hammer: Use unique board ID to generate USB serial number
BRANCH=none
BUG=b:62280271
TEST=Flash hammer
     lsusb -d 18d1:5022 -v -v | grep iSerial
     shows different chip IDs on different boards.

Change-Id: I249967df133a8aa8a2b5c570fb940dd03fae4169
Reviewed-on: https://chromium-review.googlesource.com/523046
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-06-13 21:23:56 -07:00
Nicolas Boichat
6d05a31a44 rollback: Include board-generated entropy when adding entropy
Mix in board-generated entropy with the externally provided one,
which should help make the per-device secret stronger.

BRANCH=none
BUG=b:38486828
TEST=reboot; rollbackaddent Hello => works fine when USB is connected,
     fails otherwise, as board-generated entropy relies on USB timing.

Change-Id: I314f44759c5f8b859913a748db95e9d42b5cdd11
Reviewed-on: https://chromium-review.googlesource.com/518609
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Mattias Nissler <mnissler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-06-06 08:52:16 -07:00
Nicolas Boichat
39db721f9a hammer: Add board_get_entropy function (and test)
This function will be used to generate some entropy using the
Clock Recovery System.

BRANCH=none
BUG=b:38486828
TEST=make BOARD=hammer -j tests
     ./util/flash_ec --board=hammer --image=build/hammer/test-entropy.bin
     EC console: runtest
TEST=Test fails when no USB connection is active
TEST=Test passes when USB connection is active
TEST=Pasting the values into:
     tr ';' '\n' | awk 'BEGIN { e = 0; tot=16384.0 }
                  { p = $1/tot; if (p > 0) { e -= p*log(p)/log(2) } }
                  END { print e }'
     shows an entropy > 4 bits per sample.

Change-Id: I2363c7bce42c72c33ef0bf3f099d709ee9c13d13
Reviewed-on: https://chromium-review.googlesource.com/518608
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-06-06 08:52:16 -07:00
Chun-Ta Lin
d5c08763e1 usb_i2c: extend the protocol to support larger payload
The default USB packet has a maximum size of 64 bytes, however, we need
to support some USB over I2C write transaction that exceed this default.

To support so with protocol backwards-compatible in mind, we enable a
config option CONFIG_USB_I2C_MAX_WRITE_COUNT that will enlarge the USB
RX queue.

BRANCH=none
BUG=b:35587174
TEST=Complete presubmit test.
TEST=Manually update elan trackpad firmware with interrupt disabled.

Change-Id: Ia8983b036b7297f7ca673459ae34b7e5ecd2ee01
Reviewed-on: https://chromium-review.googlesource.com/513642
Commit-Ready: Chun-ta Lin <itspeter@chromium.org>
Tested-by: Chun-ta Lin <itspeter@chromium.org>
Reviewed-by: Chun-ta Lin <itspeter@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2017-06-05 07:55:32 -07:00
Nicolas Boichat
5c9118b311 hammer: Add support for new key
There is a new keyboard matrix layout:
 - We can map the search key to both KSO1, KSI0 and KSO0, KSI3
   (old layout will only use the former, new layout will use the latter).
 - There is a new key on KSO0, KSI5, which we can map to HID page 0xffd1
   code 0x0018.

BRANCH=none
BUG=b:62004286
TEST=Flash hammer
     kbpress 0 3 1; kbpress 0 3 0 reports KEY_LEFTMETA as expected
     kbpress 0 5 1; kbpress 0 5 0 reports "BTN_0", which is probably
     incorrect, and needs to be fixed.

Change-Id: I9fb428805ff756b6d63f50cc5b061c6a0e1defbc
Reviewed-on: https://chromium-review.googlesource.com/512502
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
2017-06-02 23:59:05 -07:00
Nicolas Boichat
6bbcf5b3f8 hammer: Prefix configuration descriptor with RO/RW section
It is useful for the updater to be able to determine which region
is active without having to use the update interface.

BRANCH=none
BUG=b:35587171
TEST=lsusb -d 18d1:5022 -v -v | grep hammer shows either:
     RO:hammer_v1.1.6441-e58472daf+ or
     RW:hammer_v1.1.6441-e58472daf+
     depending on the image used

Change-Id: I8e1acfbc546330e10ba650b743e3a4c9986b0c30
Reviewed-on: https://chromium-review.googlesource.com/515242
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
2017-05-25 18:58:49 -07:00
Nicolas Boichat
95a986ecad hammer: Increase hook stack size
Adding entropy takes up to 1028 bytes of stack, let's increase
the stack size to 1280 bytes.

BRANCH=none
BUG=b:38487027
TEST=Flash hammer. On host, reboot hammer to RO:
     usb_updater2 -r; sleep 0.5; usb_updater2 -s
     usb_updater2 -e (adds entropy)
     EC console: check that rollbackinfo shows secret is updated

Change-Id: I7e2d506e0fcc3152d27ac1796db95df6b1a931d1
Reviewed-on: https://chromium-review.googlesource.com/513808
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-05-25 18:58:47 -07:00
Nicolas Boichat
4fd6f23101 hammer: Store secret in rollback block
Also, increase console task stack size, as adding entropy
requires 780 bytes of stack.

BRANCH=none
BUG=b:38486828
TEST=Flash hammer
     rollbackinfo => 1 version 0 block, 1 empty block, RW verifies
           correctly.
     rollbackupdate 0; rollbackinfo => No change
     rollbackupdate 1; reboot => RO refuses to jump to RW
     rollbackinfo => Secret is [00..00] on both block (so the data
                     was copied correctly)
     rollbackupdate 2, 3, 4; rollbackinfo => Writes alternate
           between the 2 blocks.
     rollbackupdate 2 => Refuses to downgrade version
TEST=From blank secret [00..00], 'rollbackaddent Hello' updates it
         to [ba..fa], which matches the output of:
         (dd if=/dev/zero bs=1 count=32; echo -n Hello) | sha256sum

Change-Id: If63346dfab0a28aa82a7b4c2e46ca89fde3eb990
Reviewed-on: https://chromium-review.googlesource.com/511986
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-25 04:27:41 -07:00
Nicolas Boichat
e58472daf8 hammer: Better RO/RB/RW split: 44/4/80 kB
Let's future proof hammer a bit: current flash usage, after
applying uncommmited patches, is about 36/50 kB for RO/RW respectively.

Let's change the RO/RB/RW layout from 64/4/60 kB to 44/4/80 kB.

BRANCH=none
BUG=b:38489464
TEST=Enable CONFIG_CMD_FLASH and force WP_L low.
TEST=flashwrite 0xa000 0x100 => ok
     flashwp true; reboot
     flashinfo => ro_at_boot ro_now
     YYYYYYYY YYY..... ........ ........
     flashread 0xa000 0x100 => Incrementing numbers 0->255
     flasherase 0xa000 0x800 => error
     flashread 0xa000 0x800 => Incrementing numbers 0->255
TEST=(rollback)
     rollbackupdate 2 => works, rollbackinfo is correct
     flashwp rb; reboot
     flashread 0xb000 0x100 => Rollback info followed by 0xff
     flasherase 0xb000 0x800 => error
     flashread 0xb000 0x800 => Unchanged
     rollbackupdate 3 => fails
TEST=(rw)
     flashwp rw; reboot
     flashinfo => all_at_boot all_now
     flashread 0x0c000 0x100
     flasherase 0x0c000 0x800 => Access denied
     flashread 0x0c000 0x100
     flashread 0x1f800 0x100 => 0xff
     flashwrite 0x1f800 0x100 => Access denied
     flashread 0x1f800 0x100
TEST=(norw)
     flashwp norw; reboot
     flasherase 0x0c000 0x800 => ok
     flashread 0x0c000 0x100 => 0xff
     flashwrite 0x0c000 0x100
     flashread 0x0c000 0x100 => Incrementing numbers 0->255
     reboot => RW does not verify anymore
TEST=(norb)
     flashwp norb
     flasherase 0xb000 0x800
     flashwrite 0xb000 0x100
     rollbackinfo => block 0 shows incorrect values.

Change-Id: I915ffe3032e6a70f761c5f7ea2940feaae58366b
Reviewed-on: https://chromium-review.googlesource.com/510413
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-23 21:59:45 -07:00
Nicolas Boichat
0ce33d0e87 hammer: Do not define CONFIG_ROLLBACK_UPDATE for RW section
BRANCH=none
BUG=b:35586219
TEST=make newsizes saves ~420 bytes on hammer and staff.

Change-Id: I69a757cc8eb0545cfbb73df04ac36ea6e68ae933
Reviewed-on: https://chromium-review.googlesource.com/511984
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-23 05:57:13 -07:00
Nicolas Boichat
11237d5e91 hammer: Make keyboard work at firmware screen
First, libpayload expects the keyboard interface index to be 0.

Then, hid_iface_request needs to reply to USB_HID_DT_HID request
with the content of struct usb_hid_descriptor. With current code,
the variable name is generated (and therefore hard to guess), so
we create a new set of macros so that we can use a specific
variable name.

Also, add support for HID Get_Protocol and Set_Protocol, as they
are compulsory for devices supporting boot protocol, even though
those are mostly no-op for now.

Finally, add a note regarding USB HID keyboard boot protocol, to
make sure that we do not accidentally change the report format.

BRANCH=none
BUG=b:36538963
TEST=Keyboard works in FW screen, both trackpad and keyboard
     still work when AP has booted.
TEST=hammer/staff can still be updated (both RO from RW, and RW
     from RO)

Change-Id: Ibea4888385909c9ce3b430464e5805c039d4b9ed
Reviewed-on: https://chromium-review.googlesource.com/505796
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-18 06:03:52 -07:00
Nicolas Boichat
12a8ab8a5c usb_hid_touchpad: Add config options to set dimensions
In principle, trackpad dimensions (logical and physical), can be
probed from the trackpad at runtime, but this would slow down setup
time, as we need to wait for the trackpad to be initialized to read
those. Also, we do not have a framework to generate HID report
at runtime, and a new base with new trackpad would probably require
a new overlay anyway.

Also, set appropriate (temporary) values for both hammer and staff.

BRANCH=none
BUG=b:38277869
TEST=Connect hammer/staff to host, correct logical dimensions are
     shown in evtest, and resolution is always 32.

Change-Id: I39b84274d71ca2f4e285f3324c0841331aae9bc1
Reviewed-on: https://chromium-review.googlesource.com/505856
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-18 02:26:08 -07:00
Nicolas Boichat
cb9bd66ec6 hammer: Add staff board
hammer corresponds to poppy, and staff corresponds to soraka.

Current differences (hammer/staff):
 - USB id (5022/502b)
 - PWM frequency (10kHz/100Hz):
   - On staff, driving PWM at 10kHz leads to an actual duty cycle
     around 30-40%, with a PWM output at 1% (long rise/fall time).
     100Hz looks better, we get ~1.45% duty with 1% PWM output.

BRANCH=none
BUG=b:38277869
TEST=Flash staff, boots fine.
TEST=pwm 0 1 shows quite dim backlight on staff.

Change-Id: I66ba2adf89fbee8578ee473afb28e3e242b4d111
Reviewed-on: https://chromium-review.googlesource.com/505855
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-16 07:47:05 -07:00
Nicolas Boichat
f660c8e5b0 hammer: Add pull-up on write protect pin
We don't have an external pull-up on WP_L, so let's use an internal
one instead.

BRANCH=none
BUG=b:35582031
TEST=gpioget WP_L shows 1 as default value, servo can control
     value, and when servo is not driving the pin, value goes back
     to 1.

Change-Id: I75148cde9ab89c1dfb05f3182608894a3e1390fa
Reviewed-on: https://chromium-review.googlesource.com/502849
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-15 03:56:41 -07:00
Nicolas Boichat
8c980fc5af hammer: Disable boot keys and runtime keys
Those keys aren't very useful on hammer.

BRANCH=none
BUG=b:37422577
TEST=Flash hammer
TEST=make newsizes shows 280 bytes size decrease on hammer/RW.

Change-Id: I859c999ce796af53b9290cc5215f9b28a815b638
Reviewed-on: https://chromium-review.googlesource.com/495969
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-08 07:04:07 -07:00
Nicolas Boichat
7fb0338cbd hammer: Pulse detection pin on USB wake event
When usb_wake is called (key press, trackpad event), pulse
detection pin for 100us. This allows Lid EC to wake the AP
even when it is in deep S3 mode, where normal wake using USB
lines does not work.

BRANCH=none
BUG=b:35775062
TEST=Flash hammer, looks at poppy console: base power is not
     disconnected, but events appear in the console.

Change-Id: I7b8ee407046d4caa1ce75190c30d693b71b00d2e
Reviewed-on: https://chromium-review.googlesource.com/448380
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-05-02 22:50:32 -07:00
Nicolas Boichat
be294d4efb hammer: Only define required options for RO and RW
RO does not need touchpad/keyboard driver or I2C passthru, RW does
not need RW verification, let's shrink both images by only including
required config options.

BRANCH=none
BUG=b:35582031
TEST=Build and flash hammer: still functional.
   build/hammer/RO/ec.RO.flat shrank by 10144 bytes: (45868 to 35724)
   build/hammer/RW/ec.RW.flat shrank by 2764 bytes: (45332 to 42568)

Change-Id: Iff0feb4e8446cc9f2e32103cd383fddae3234fec
Reviewed-on: https://chromium-review.googlesource.com/479492
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-04-25 05:52:34 -07:00
Nicolas Boichat
2b460c9830 common/update_fw: Remove board-specific rw_sections
rw_sections is defined in the exact same way on all common code
boards, let's remove it, and hard-code the values in update_fw.c
instead.

Take this as an opportunity to fold set_valid_section in
fw_update_start (this will be useful later on, as we also
want to return the inactive region version).

BRANCH=none
BUG=b:35587171
TEST=make buildall -j
TEST=Can update hammer over USB using usb_updater2

Change-Id: I4dd3224f17f89c1851c379255f1195dc54528b3d
Reviewed-on: https://chromium-review.googlesource.com/476451
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
2017-04-15 04:08:07 -07:00