Commit Graph

33 Commits

Author SHA1 Message Date
Mario Limonciello
8aa5d41eb7 Add external interface messages 2020-10-26 12:05:20 -05:00
Benson Leung
42f2e22dd2 cros-ec: Add support for quiche and gingerbread boards
Add quirks for PID 5048 and 5049, which are cros-ec devices
that update via USB endpoint. Notable about these two are
they support rw_sig, for RW region signature verification.
2020-10-11 07:34:49 +01:00
Benson Leung
343613954b cros-ec: Increase remove delay for reenumeration to 20s. 2020-10-11 07:34:49 +01:00
Benson Leung
e8fd2cdfa4 cros-ec: Restructure to allow RO update first
Our update flow prior to this was:
1. On detach, reboot to RO.
2. From Old RO, Update RW.
3. Reboot to New RW
4. From New RW, Update RO.
5. Reboot to finish

This flow has a flaw, which is that the Old RO may be buggy (especially
during development, before it's actually locked down and actually Read-Only).

This change will do the following instead:
1. On detach, do not reboot to RO if RO is writeable, and we are in RW
2. From old RW, Update RO
3. Reboot to new RO
4. From New RO, update RW
5. Reboot to finish.

This has a speed advantage as well, as we save one reboot cycle (2 vs 3).
2020-10-11 07:34:49 +01:00
Benson Leung
2c5558e51d cros-ec: Log error paths, and trigger flushes
In case of a failure during the bulk transfer sequence, flush out
before trying again.
2020-10-11 07:34:49 +01:00
Benson Leung
af07f32c0f cros-ec: Send a start message after the stay-in-ro
The extra command (stay-in-ro) consumes the start message, so we
need to issue another one before write firmware.
2020-10-11 07:34:49 +01:00
Benson Leung
c516724278 cros-ec: Set another write required if we immediate reset back into RO
As a result of the previous change, where we send an immediate reset to
devices in order to transition back to rw, we will end up reenumerating
as RO briefly, although the destination we wanted to get to was RW.

In that case, basically skip the write firmware step, set another write
required and allow the RO firmware to complete rw_sig and jump to the rw
partition.
2020-10-11 07:34:49 +01:00
Benson Leung
08c396b31c cros-ec: Send an immediate reset after jump to rw
Some devices don't do the jump, so an immediate reset is required to get us
into RW.
2020-10-11 07:34:49 +01:00
Benson Leung
b093de999a cros-ec: Fix reboot to RO sequence
Previously, we sent a 'stay-in-ro' subcommand when we are in
fu_cros_ec_usb_device_reset_to_ro, which is called from the detach phase,
in other words, we are currently sitting in RW.
This is incorrect, since stay-in-ro only interrupts an RO's
rw_sig process if it is in progress.

Instead, 'stay-in-ro' must be issued when the device reenumerates in RO,
immediately before the writing sequence starts. On devices that implement
rw_sig, they will briefly enumerate as RO before self-issuing a jump to RW
on the signature check being valid. In order to stay in RO to perform a RW
partition update, we must interrupt it as soon as we see the RO version
enumerate.
2020-10-11 07:34:49 +01:00
Richard Hughes
9b688d0b73 trivial: Set FWUPD_STATUS_DECOMPRESSING when preparing firmware
This avoids the plugins forgetting to do it themselves.
2020-09-08 14:18:46 +01:00
Benson Leung
72aea1f8ed cros-ec: Save new firmware version on successful write 2020-08-28 10:48:03 -07:00
Benson Leung
a5487d4848 cros-ec: Do RO write as ANOTHER WRITE using custom flags
This implements the following simple state machine:
1. Reboot to RO, Update RW first, set ANOTHER_WRITE_REQUIRED
2. Second time around, don't reboot into RO. Stay in RW.
3. Update RO.
4. Done.
2020-08-28 10:48:03 -07:00
Benson Leung
24f0570e1b cros-ec: Set FWUPD_DEVICE_FLAG_DUAL_IMAGE 2020-08-28 10:48:03 -07:00
Benson Leung
7f3095d9ff cros-ec: Use iConfiguration to determine RO versus RW versions
This requires an API upgrade. libgusb 0.3.5 is required for iConfiguration.
2020-08-28 10:48:03 -07:00
Benson Leung
9832b4138c cros-ec: Restart to RO on detach and to RW on attach
Add external command support and functions to reset to RO and RW.
This will now jump to the RO no matter what, and update the RW, then
jump to RW.
2020-08-28 10:48:03 -07:00
Benson Leung
879b8149c7 cros-ec: Set FWUPD_DEVICE_FLAG_UPDATABLE 2020-08-28 10:48:03 -07:00
Benson Leung
852c6685ff cros-ec: Set protocol for cros-ec-usb-device
Specify "com.google.usb.crosec" to indicate support for Google's
USB endpoint updater protocol.
2020-07-09 07:44:19 +01:00
Benson Leung
8ed9f5f0a1 cros-ec: Write firmware to usb target
Write the firmware to the usb device, first finding which section to
write to, then breaking into blocks (based on maximum pdu size),
and then into chunks, which are transferred to the device using bulk transfers.
2020-07-09 07:44:19 +01:00
Benson Leung
4ed2400cab cros-ec: Store image_idx in section
Makes it a bit easier to retrieve the image later.
2020-07-09 07:44:19 +01:00
Benson Leung
9326e19118 cros-ec: Give cros-ec-firmware a get_sections
Add a getter for the sections.
2020-07-09 07:44:19 +01:00
Benson Leung
d0cd862acf cros-ec: Add fu_cros_ec_firmware_pick_sections
Add this to allow the usb-device to mark which section of the firmware
image is writeable by setting the section's ustatus to FU_CROS_EC_FW_NEEDED.
2020-07-09 07:44:19 +01:00
Benson Leung
befd9a420e cros-ec: Convert cros-ec-firmware's sections to GPtrArray 2020-07-09 07:44:19 +01:00
Benson Leung
6472742bea cros-ec: Add prepare firmware
Prepare firmware by parsing it, which will be of fu_cros_ec_firmware type.
2020-07-09 07:44:19 +01:00
Benson Leung
a989975812 cros-ec: Update documentation to reflect fmap
The file format was added last time around, so update cros-ec's
documentation to reflect that fwupd now supports fmap format
blobs.
2020-07-09 07:44:19 +01:00
Richard Hughes
d9f3bec6d0 trivial: Fix GtkDoc issue with FuFmapFirmware 2020-06-29 15:49:14 +01:00
Benson Leung
53fad4cd6c trivial: cros-ec: Use fu-memcpy-safe 2020-06-20 07:24:32 +01:00
Benson Leung
3a02ad5129 cros-ec: Add cros-ec-firmware
cros-ec firmware are in fmap layout, and have two sections
that this plugin will look for, the EC_RO, and EC_RW sections.

Tested using a servo_micro firmware:
$ fwupdtool firmware-parse servo_micro_v2.4.17-df61092c3.bin
<select fmap option>
FuCrosEcFirmware:
Version:                 2.4.17
  FuFirmwareImage:
  ID:                    EC_RO
  Index:                 0x1
  Version:               servo_micro_v2.4.17-df61092c3
  Data:                  0xf000
  FuFirmwareImage:
  ID:                    FR_MAIN
  Index:                 0x2
  Data:                  0xf000
  FuFirmwareImage:
  ID:                    RO_FRID
  Index:                 0x3
  Address:               0xc4
  Data:                  0x20
  FuFirmwareImage:
  ID:                    FMAP
  Index:                 0x4
  Address:               0x9a40
  Version:               1.0
  Data:                  0x15e
  FuFirmwareImage:
  ID:                    WP_RO
  Index:                 0x5
  Data:                  0x10000
  FuFirmwareImage:
  ID:                    EC_RW
  Index:                 0x6
  Address:               0x10000
  Version:               servo_micro_v2.4.17-df61092c3
  Data:                  0x10000
  FuFirmwareImage:
  ID:                    RW_FWID
  Index:                 0x7
  Address:               0x100c4
  Data:                  0x20
2020-06-20 07:24:32 +01:00
Benson Leung
a22310374e cros-ec: Provide device metadata as a part of to_string
Provide the following metadata:

"Dirty firmware" bit
Protocol version
Header type
Maximum PDU Size
Flash protection status
Raw version string
Key Version
Minimum rollback
2020-05-29 06:55:40 +01:00
Benson Leung
092f87ae0c cros-ec: Add board name as a instance id and hash as metadata
These couple of extra things in the CrOS EC version string
were split off of the triplet, so give them a home.
2020-05-29 06:55:40 +01:00
Benson Leung
086d0c0eb6 cros-ec: Parse version number into triplet
Add fu_cros_ec_parse_version to common, as this will be used to
parse the firmware bundle's version string too.
2020-05-29 06:55:40 +01:00
Benson Leung
00bb3341d2 cros-ec: Add enough infrastructure for setup connection
This should do the bulk transfers using protocol 6.

The output here is now equivalent to the output of
usb_updater2 -d 18d1:501a -f

fwupdtool --plugin-whitelist cros_ec get-devices --verbose
Servo Micro
  DeviceId:             84d0e3f2a0f8b2328f7995767b23ebb40494723f
  Guid:                 8e2f7625-a164-55d7-8f09-f193c8ec33f1 <- USB\VID_18D1&PID_501A&REV_0100
  Guid:                 13564257-c649-586d-b4e4-4f048d480f36 <- USB\VID_18D1&PID_501A
  Serial:               CMO653-00166-040491U00771
  Summary:              Servo Micro (aka "uServo") Debug Board
  Plugin:               cros_ec_usb
  Flags:                registered
  Vendor:               Google Inc.
  VendorId:             USB:0x18D1
  Version:              servo_micro_v2.4.17-df61092c3
  VersionFormat:        plain
  Created:              2020-05-20
  PhysicalId:            usb:03:00:02
2020-05-29 06:55:40 +01:00
Benson Leung
7aa00f6ee8 cros-ec: Add usb_findit functionality
Find the interface and endpoint used for firmware updates.
Note: this change now requires libgusb 0.3.3 or later.
2020-05-29 06:55:40 +01:00
Benson Leung
b483044a8d cros-ec: Initial skeleton
Set it up as a USB device plugin, with the initial device in quirks
being Servo Micro debug board.
2020-05-29 06:55:40 +01:00