Commit Graph

46 Commits

Author SHA1 Message Date
Shawn Nematbakhsh
dedd0ab913 gru: Remove flashinfo command for RAM savings
BUG=None
TEST=`make buildall -j`
BRANCH=None

Change-Id: Ibfbb6875327dfc13dcba57933d39fd207f382ac1
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/761299
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
2017-11-09 19:16:33 -08:00
Daisuke Nojiri
729a4ba2bd EFS: Switch active slot when current slot is invalid
When EFS finds the active slot is invalid, it tries the other slot.
This patch makes the other slot active so that the following boots
will try the other slot first.

This patch also replaces enum flash_rw_slot with system_image_copy_t.
The new APIs are therefore renamed from *_slot to *_copy. Basically,
this makes vboot see slots as a conceptual place instead of physical
spaces bound to flash storage.

BUG=b:65028930
BRANCH=none
TEST=On Fizz, verify:
1. RW_B is old and updated by soft sync. RW_B is activated and
   executed after reboot. System continues to boot to OS.
2. RW_A is old and updated by soft sync. RW_A is activated and
   executed after reboot. System continues to boot to OS.

Change-Id: Icf97da13e651e7a931b9d507052b9422566eb16c
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/648449
2017-09-21 01:07:55 -07:00
Daisuke Nojiri
4dcee1c545 EFS: Add support for early firmware selection
Chromebox ECs performs EFS: verifying firmware before the AP boots.
This patch updates host commands which are required for the EFS.

The change includes:
* Update EC_CMD_FLASH_REGION_INFO to accept EC_FLASH_REGION_UPDATE
* Update EC_CMD_VBOOT_HASH to accept EC_VBOOT_HASH_OFFSET_UPDATE

When EC_FLASHS_REGION_UPDATE is specified, EC_CMD_FLASH_REGION_INFO
returns the slot which currently is not hosting a running RW copy.

When EC_VBOOT_HASH_OFFSET_UPDATE is specified, EC_CMD_VBOOT_HASH
computs the hash of the update slot. This hash covers the entire
region, including the signature at the end.

This patch undefines CONFIG_CMD_USBMUX and CONFIG_CMD_TYPEC
for gru to create space.

BUG=b:65028930
BRANCH=none
CQ-DEPEND=CL:648071
TEST=On Fizz, verify:
1. RW_B is old and updated by soft sync. RW_B is activated and
   executed after reboot. System continues to boot to OS.
2. RW_A is old and updated by soft sync. RW_A is activated and
   executed after reboot. System continues to boot to OS.

Change-Id: I9ece907b764d07ce94054ba27996e048c665a80a
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/648448
2017-09-12 01:11:59 -07:00
Daisuke Nojiri
5da63f4ea2 Treat SYSTEM_IMAGE_RW_B also as RW copy
SYSTEM_IMAGE_RW_B hasn't been globally treated as a RW copy.
This change makes EC treat it also as a RW copy.

BUG=none
BRANCH=none
TEST=make buildall

Change-Id: Iae5a9090cdf30f980014daca44cdf8f2a65ea1f2
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/656337
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-09-09 02:26:16 -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
Wei-Ning Huang
b9c8dcb9f6 flash: add flash selection support
Some chips require special operations before flash can be accessed
(read, write, erase), without it the flash operations could be
corrupted.  The chip that requires this should enable the
CONFIG_FLASH_SELECT_REQUIRED config, which exposes
EC_FLASH_INFO_SELECT_REQUIRED in flashinfo flags. Before any flash
operations is executed on the chip, EC_CMD_FLASH_SELECT should be issued
to notify the chip to prepare for the flash operations.

BRANCH=none
BUG=b:63685022
TEST=with depended CLs, touchpad interrupt should be disabled when
     flashrom is in progress.
CQ-DEPEND=CL:*416548

Change-Id: I96455adbe739d5f924edf382a2752404a7c5ad04
Signed-off-by: Wei-Ning Huang <wnhuang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/582374
Commit-Ready: Wei-Ning Huang <wnhuang@chromium.org>
Tested-by: Wei-Ning Huang <wnhuang@chromium.org>
Reviewed-by: Wei-Ning Huang <wnhuang@chromium.org>
2017-07-27 04:22:42 -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
Wei-Ning Huang
f534936ca5 common: delay flash_erase deferred task so EC_CMD_FLASH_ERASE can complete
Add a delay before flash_erase deferred started so the task does not halt
CPU,  and cause the response of EC_CMD_FLASH_ERASE to not be delivered.
When the above situation happens the host I2C controller will timeout.
A 100ms delay should be long enough on any board to allow the response
to be sent.

BRANCH=none
BUG=b:38018926
TEST=on eve units where flashrom always fail:
     `flashrom -p ec:type=tp -w ec.bin` succeeds.

Change-Id: I399a60064392da41a3e27f8630175ab427047ab7
Signed-off-by: Wei-Ning Huang <wnhuang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/547375
Commit-Ready: Wei-Ning Huang <wnhuang@chromium.org>
Tested-by: Wei-Ning Huang <wnhuang@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@google.com>
2017-06-27 17:56:12 -07:00
Gwendal Grignou
92ea78398b common: Add deferred erase support
Some device has large pages that take up to 2s to erase.
Add support to send a deferred erase command, that willi
be processed on HOOK task.

It can leave the other tasks (HOST_CMD) responsive.
If the whole EC can stall on flash erase, like the STM32F4 do,
at least the command FLASH_ERASE_GET_RESULT can be retried when it times
out.

BRANCH=none
TEST=Check with flashrom doing a loop of overwrites.
BUG=b:38018926

Change-Id: I8ce8e901172843d00aac0d8d59a84cbd13f58a10
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/510012
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
2017-06-02 18:39:37 -07:00
Rong Chang
9ca4586129 common: Add support for flash with regions of different size
Add support to handle devices with flash regions of different sizes.

BRANCH=none
TEST=compile
BUG=b:38018926

Change-Id: I8f842abaa50de724df60dd7e19f9e97cb9660367
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/264031
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
2017-06-02 16:59:36 -07:00
Vincent Palatin
d9afaba9b4 flash: ensure proper pstate alignment
The pstate structure is written using the low-level
flash_physical_write() function. As a consequence, it is supposed to
meet the CONFIG_FLASH_WRITE_SIZE alignment constraint.
Add a build-time assertion to avoid silent failures.

Slightly decrease the maximum size of the serial number string, so the
structure has a natural 32-byte alignment which is compatible with a
large number of platforms (including STM32L4 which requires 64-bit
alignment).
Of course, this change is not fully backward-compatible.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=none
BUG=chromium:571477 b:35648258
TEST=on STM32L442, build and run 'flashrom --wp-enable' without failure.

Change-Id: Ia8f82790a61a6c7d2cf9bfeb95bfdaf7b8c52d11
Reviewed-on: https://chromium-review.googlesource.com/458201
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
2017-03-24 09:32:53 -07:00
Nicolas Boichat
2dcfd2446c flash: Add ROLLBACK flash region, that can be protected separately
ROLLBACK region will be used to store rollback information, and
can be protected independently of RW (it can only be protected when
RO is protected, though).

This is only supported on stm32f0 currently.

BRANCH=none
BUG=chrome-os-partner:61671
TEST=on hammer (stm32f072)
     flashinfo => RO+RW not protected
     flashwp true; reboot => only RO protected
     flashwp all; reboot => RO+RW+RB protected
     flashwp noall; reboot => only RO protected
     flashwp rw; reboot => only RO+RW protected
     flashwp rb; reboot => RO+RW+RB protected
     flashwp norb; reboot => RO+RW protected
     flashwp all; reboot => RO+RW+RB protected
     flashwp norw; reboot => RO+RB protected
TEST=on reef, rb/norb commands not available

Change-Id: I45ffc66d91cf3699ecff025e5114c59a73dc8274
Reviewed-on: https://chromium-review.googlesource.com/430519
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-02-25 08:36:41 -08:00
Nicolas Boichat
83cf8d0a7a flash: Add EC_FLASH_PROTECT_RW_[AT_BOOT|NOW] flags
The idea of this flag is to be able to protect/unprotect only the
RW portion of the flash. In the (usual) case where ALL=RO+RW, with
no other region, this makes no difference compared to the existing
EC_FLASH_PROTECT_ALL_* flag, and this flag may not be supported.

This is necessary for futher work, where a ROLLBACK region is added,
so that RW/ROLLBACK can be protected/unprotected individually.

Only support for stm32f0 is added, as this is the target for hammer.

BRANCH=none
BUG=chrome-os-partner:61671
TEST=build and flash hammer (stm32f072)
     flashinfo => RO+RW not protected
     flashwp true; reboot => only RO protected
     flashwp all; reboot => RO+RW protected
     flashwp noall; reboot => only RO protected
     flashwp rw/norw not available
TEST=enable CONFIG_FLASH_PROTECT_RW
     build and flash hammer (stm32f072)
     flashinfo => RO+RW not protected
     flashwp true; reboot => only RO protected
     flashwp all; reboot => RO+RW protected
     flashwp noall; reboot => only RO protected
     flashwp rw; reboot => RO+RW protected
     flashwp norw; reboot => only RO protected
TEST=build and flash reef (npcx)
     flashinfo => RO+RW not protected
     flashwp true => RO protected
     flashwp all; flashinfo => all_now displayed
     reboot => RO protected
     flashwp rw/norw not available

Change-Id: Ica6f499cf2e8a9345b08ef52c915655a983ffe3c
Reviewed-on: https://chromium-review.googlesource.com/442265
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-02-23 19:06:16 -08:00
Nicolas Boichat
ed396c5efb common/flash.c: Remove redundant code
Saves a little bit of flash size:
Compared 167 of 167 files.
77 files changed.
Total size change: -3240 bytes.
Average size change: -42 bytes.

BRANCH=none
BUG=chrome-os-partner:61671
TEST=make buildall -j
TEST=hammer: 'flashwp true' works as expected
TEST=hammer+CONFIG_FLASH_PSTATE_BANK: 'flashwp true' still works
TEST=reef: 'flashwp now' sets all_now flag in flashinfo

Change-Id: Ic2fe8f0c67520afea276369fdf8c59e75e95208e
Reviewed-on: https://chromium-review.googlesource.com/444488
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-02-23 19:06:16 -08:00
Nicolas Boichat
9761bf2ba1 common/flash.c: Rename flashwp parameter from [no]rw to [no]all
Saying that 'flashwp rw' was protecting RW region was not really
accurate: it was actually protecting the whole flash (which,
well, is actually equivalent as the RW can't be protected without
the RO).

Let's fix that in anticipation for adding a new flag that will
_really_ set the RW protection (and only that).

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

Change-Id: Ic1c585622330b4976e71150f3a71b74a031a7694
Reviewed-on: https://chromium-review.googlesource.com/442264
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
2017-02-17 04:09:38 -08:00
Nicolas Boichat
8c12f0a53f flash: Pass more precise parameter to flash_[physical_]protect_at_boot
In preparation for adding the rollback protection block, pass
EC_FLASH_PROTECT_RO/ALL_AT_BOOT to flash_[physical_]protect_at_boot,
instead of an enumeration no protection/RO/ALL.

This will later allow us to protect/unprotect the rollback region only,
by adding a EC_FLASH_PROTECT_ROLLBACK_AT_BOOT flag.

BRANCH=none
BUG=chrome-os-partner:61671
TEST=Build hammer with CONFIG_CMD_FLASH command, so that write protection
     can be checked with flasherase/flashwrite.
TEST=On hammer (stm32f072):
     flashinfo => RO+RW not protected
     flashwp true; reboot => only RO protected
     flashwp rw; reboot => RO+RW protected
     flashwp norw; reboot => only RO protected
TEST=On reef (npcx):
     deassert WP, flashwp false; flashinfo => RO+RW not protected
     flashwp true => only RO protected
     reboot => only RO protected
     flashwp rw => RO+RW protected
     reboot => only RO protected

Change-Id: Iec96a7377baabc9100fc59de0a31505095a3499f
Reviewed-on: https://chromium-review.googlesource.com/430518
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2017-02-12 21:05:11 -08:00
Nicolas Boichat
09fca7bddb flash: Fix ccprintf parameters in flasherase/write
Both these functions had a superfluous offset parameter.

BRANCH=none
BUG=chrome-os-partner:61671
TEST=flasherase/write

Change-Id: I2973490e472c2e658440b56a0b76ec9f2aab749a
Reviewed-on: https://chromium-review.googlesource.com/432176
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-01-25 10:50:58 -08:00
Shawn Nematbakhsh
fd41823595 flash: Call lock function prior to mapped external read
Mapped read access to external flash may conflict with direct access
through SPI commands, so call a chip-level function to lock access prior
to doing such reads.

BUG=chrome-os-partner:55781
BRANCH=Gru
TEST=Verify 'ver' still works fine on kevin, and vboot hashing completes
successfully.

Change-Id: I009d6d5ee61c83260fb49ad4ee137fa3f4cd625a
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/385165
Tested-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
(cherry picked from commit a7f3e3fa376731709f4823a0c1d464b4d1deae14)
Reviewed-on: https://chromium-review.googlesource.com/386446
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2016-09-16 21:59:08 -07:00
Bill Richardson
8c4421759d Cr50: Mark several console commands as safe
Even when CONFIG_RESTRICTED_CONSOLE_COMMANDS is enabled, there
are many commands that can't do anything dangerous. This marks
some of those commands as safe to use, even when restrictions are
enforced.

I'm only marking commands that are used by the Cr50, since that's
the only board that has restrictions.

BUG=chrome-os-partner:55322
BRANCH=none
TEST=make buildall, test on Cr50 hardware

Change-Id: I6289d332830175b6adcb6b20cb4c21d01d27a25e
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/376188
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-08-31 17:20:26 +00:00
Bill Richardson
bb15561db5 cleanup: DECLARE_CONSOLE_COMMAND only needs 4 args
Since pretty much always, we've declared console commands to take
a "longhelp" argument with detailed explanations of what the
command does. But since almost as long, we've never actually used
that argument for anything - we just silently throw it away in
the macro. There's only one command (usbchargemode) that even
thinks it defines that argument.

We're never going to use this, let's just get rid of it.

BUG=none
BRANCH=none
CQ-DEPEND=CL:*279060
CQ-DEPEND=CL:*279158
CQ-DEPEND=CL:*279037
TEST=make buildall; tested on Cr50 hardware

Everything builds. Since we never used this arg anyway, there had
better not be any difference in the result.

Change-Id: Id3f71a53d02e3dc625cfcc12aa71ecb50e35eb9f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/374163
Reviewed-by: Myles Watson <mylesgw@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-08-24 16:30:10 +00:00
Bill Richardson
8f080f795b Cr50: Use parse_bool() for boolean args
The parse_bool() function exists so we don't have to litter our
console commands with stuff like this:

  if (!strncasecmp(argv[1], "on") ||
     !strncasecmp(argv[1], "enable" ||
     !strncasecmp(argv[1], "true" ||
     [...]

This CL uses parse_bool instead of that kind of thing so I don't
have to remember which commands use "enable" and which use "on"
and so forth.

I only changed the commands that Cr50 uses.

BUG=none
BRANCH=none
TEST=make buildall; test on Cr50 hardware

I tested all the affected commands to ensure that they still work
correctly: usb, ccd, flashwp (which doesn't do anything anyway).

Change-Id: I7d875ab22934fb4b500e3d0f62ebe3e04101272d
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/373658
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-08-22 23:27:24 -07:00
Shawn Nematbakhsh
8cda422254 gru: Align images sizes to flash block erase size
Image sizes must be aligned to block erase size to ensure that the host
can erase the entire image and nothing but the image.

BUG=chrome-os-partner:55828
BRANCH=None
TEST=Manual on kevin, rebuild FW with new EC, rebuild + flash EC once
again, verify that SW sync completes and unit boots to OS.

Change-Id: If6110f39869d6421038a3fe7afdc7d918323249e
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/365142
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-08-01 22:20:29 -07:00
Nick Sanders
56ee8aefc3 servo_micro: add programmable serial number
This change provides a console command for setting,
and loading a usb serial number from flash. This
feature adds CONFIG_USB_SERIALNO, and currently only
has a useful implementation when PSTATE is present.

BUG=chromium:571477
TEST=serialno set abcdef; serialno load; reboot
BRANCH=none

Change-Id: I3b24cfa2d52d54118bc3fd54b276e3d95412d245
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/337359
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-05-26 16:17:26 -07:00
Bill Richardson
e9000b22cb cleanup: Remove superfluous #defines
This just removes a couple places where a perfectly good CONFIG
macro is simply renamed to something else.

BUG=none
BRANCH=none
TEST=make buildall

Change-Id: I97a4abe95736504fe97c468336426d0ecc48d62c
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/302597
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-09-25 18:05:27 -07:00
Shawn Nematbakhsh
fe77303bec cleanup: Remove redundant FLASH_SIZE CONFIGs
Since there is no more concept of a flash region belonging only to the
EC, we only need one FLASH_SIZE config, which represents the actual
physical size of flash.

BRANCH=None
BUG=chrome-os-partner:23796
TEST=With entire patch series, on both Samus and Glados:
- Verify 'version' EC console command is correct
- Verify 'flashrom -p ec -r read.bin' reads back EC image
- Verify software sync correctly flashes both EC and PD RW images

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I18a34a943e02c8a029f330f213a8634a2ca418b6
Reviewed-on: https://chromium-review.googlesource.com/297824
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Mulin Chao <mlchao@nuvoton.com>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-09-16 14:49:33 -07:00
Shawn Nematbakhsh
1167cad6a8 cleanup: Change meaning of storage offset CONFIGs
In order to support architectures with non-contiguous writable and
protected regions, change storage offsets to be relative to writable and
protected regions, rather than relative to "the start of the region of
storage belonging to the EC".

Spec doc available at https://goo.gl/fnzTvr.

BRANCH=None
BUG=chrome-os-partner:23796
TEST=With entire patch series, on both Samus and Glados:
- Verify 'version' EC console command is correct
- Verify 'flashrom -p ec -r read.bin' reads back EC image
- Verify software sync correctly flashes both EC and PD RW images

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I796f8e7305a6336495bd256a78774595cb16a2e4
Reviewed-on: https://chromium-review.googlesource.com/297823
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-09-16 14:49:32 -07:00
Shawn Nematbakhsh
558c465165 cleanup: Remove CDRAM / CODERAM CONFIGs
CDRAM / CODERAM configs were previously used for chips which copied code
from external SPI to program memory prior to execution, and were used
inconsistently between npcx and mec1322.

These CONFIGs are now completely redundant given new configs like
CONFIG_MAPPED_STORAGE_BASE and CONFIG_EXTERNAL_STORAGE.

BRANCH=None
BUG=chrome-os-partner:23796
TEST=With entire patch series, on both Samus and Glados:
- Verify 'version' EC console command is correct
- Verify 'flashrom -p ec -r read.bin' reads back EC image
- Verify software sync correctly flashes both EC and PD RW images

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I0e054ab4c939f9dcf54abee8e5ebd9b2e42fe9c4
Reviewed-on: https://chromium-review.googlesource.com/297804
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-09-16 14:49:32 -07:00
Shawn Nematbakhsh
d58e54730c cleanup: Rename geometry constants
Rename and add geometry constants to match spec doc -
https://goo.gl/fnzTvr.

CONFIG_FLASH_BASE becomes CONFIG_PROGRAM_MEMORY_BASE
CONFIG_FLASH_MAPPED becomes CONFIG_MAPPED_STORAGE

Add CONFIG_INTERNAL_STORAGE, CONFIG_EXTERNAL_STORAGE and
CONFIG_MAPPED_STORAGE_BASE where appropriate.

This CL leaves chip/npcx in a broken state -- it's fixed in a follow-up
CL.

BRANCH=None
BUG=chrome-os-partner:23796
TEST=With entire patch series, on both Samus and Glados:
- Verify 'version' EC console command is correct
- Verify 'flashrom -p ec -r read.bin' reads back EC image
- Verify software sync correctly flashes both EC and PD RW images

Change-Id: Idb3c4ed9f7f6edd0a6d49ad11753eba713e67a80
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/297484
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-09-16 14:49:31 -07:00
Divya Jyothi
b4c205bf51 vboot_hash: Abort hash calculation on flash write
If flash is being written, any pending hash calculation is likely to
be invalid.

BRANCH=None
BUG=chrome-os-partner:38103
TEST=on Cyan, run hundreds of flashrom cycles to make sure there are no
read, erase or write errors

Change-Id: I915f8db7998c56fc12e7d85173232882fb7ed80d
Signed-off-by: Divya Jyothi <divya.jyothi@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/282211
Reviewed-by: Shawn N <shawnn@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
2015-07-01 03:49:00 +00:00
Shawn Nematbakhsh
e3dce49334 cleanup: Use appropriate image geometry CONFIGs
- Use CONFIG_*_MEM when dealing with images in program memory.
- Use CONFIG_*_STORAGE when dealing with images on storage.
- Use CONFIG_WP when dealing with the entire WP RO region.

BUG=chrome-os-partner:39741,chrome-os-partner:23796
TEST=Manual on Cyan with subsequent commit. Verify that FMAP matches
actual layout of image. Verify flashrom succeeds flashing + verifying EC
image using host command interface.
BRANCH=None

Change-Id: Iadc02daa89fe3bf07b083ed0f7be2e60702a1867
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/270269
2015-05-15 06:42:30 +00:00
Shawn Nematbakhsh
39bd18b890 cleanup: Rename image geometry CONFIGs
Rename image geometry configs with a uniform naming scheme to make their
purposes more clear.

CONFIG_RO_MEM_OFF (was CONFIG_FW_RO_OFF) - RO image offset in program memory
CONFIG_RO_STORAGE_OFF (was CONFIG_RO_SPI_OFF) - RO image offset on storage
CONFIG_RO_SIZE (was CONFIG_FW_RO_SIZE) - Size of RO image

CONFIG_RW_MEM_OFF (was CONFIG_FW_RW_OFF) - RW image offset in program memory
CONFIG_RW_STORAGE_OFF (was CONFIG_RW_SPI_OFF) - RW image offset on storage
CONFIG_RW_SIZE (was CONFIG_FW_RW_SIZE) - Size of RW image

CONFIG_WP_OFF (was CONFIG_FW_WP_RO_OFF) - Offset of WP region on storage
CONFIG_WP_SIZE (was CONFIG_FW_WP_RO_SIZE) - Size of WP region on storage

BUG=chrome-os-partner:39741,chrome-os-partner:23796
TEST=Set date / version strings to constants then `make buildall -j`.
Verify that each ec.bin image is identical pre- and post-change.
BRANCH=None

Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I6ea0a4e456dae71c266fa917a309b9f6fa4b50cd
Reviewed-on: https://chromium-review.googlesource.com/270189
Reviewed-by: Anton Staaf <robotboy@chromium.org>
2015-05-12 20:54:37 +00:00
Randall Spangler
932eb3ddca flash: Add option to move pstate inside RO image
Currently, ECs with internal flash store the write protect state for
RO in a separate write/erase block of flash.  This is wasteful on
chips where there are not many blocks of flash.

Add a new CONFIG_FLASH_PSTATE_IN_BANK option which is defined by
default.  This is the old behavior, for compatibility.  (And we're
calling it 'bank' because that's what the existing code does, even if
the terminology is somewhat etymologically... bankrupt.)

If that config is #undef'd, then store the write protect flag directly
inside the RO image.  This uses only 4 bytes of the RO image, instead
of an entire erase block.  The magic numbers for the pstate values are
chosen such that when protecting RO, bits are only transitioned away
from their erased state.  Unprotecting RO once it's protected requires
reflashing RO; it's no longer possible to 'flashwp disable'.  But
that's ok, because realistically, the only reason to unprotect RO is
if you're about to flash the RO firmware anyway.

BUG=chromium:476659
BRANCH=none
TEST=Without undefining CONFIG_FLASH_PSTATE_IN_BANK, make sure everything
     still works on samus and samus_pd.  This ensures we didn't break the
     existing functionality:
         flashinfo -> no flags
         flashwp enable
         flashinfo -> ro_at_boot
         reboot
         flashinfo -> ro_at_boot
         flashwp disable
         flashinfo -> no flags
     Then recompile with #undef CONFIG_FLASH_PSTATE_IN_BANK and test:
         flashinfo -> no flags
         flashwp enable
         flashinfo -> ro_at_boot
         reboot
         flashinfo -> ro_at_boot
         flashwp disable -> fails with access denied
         flashinfo -> ro_at_boot
     Then reflash to verify that clears the ro_at_boot flag:
         flashinfo -> no flags

Change-Id: Ie794b8cfed2a10c50b0e36dcf185884070b04666
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/266095
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
2015-04-17 19:38:17 +00:00
Randall Spangler
6aebf13a6b Add CONFIG_FLASH_PSTATE option to enable persistent flash WP state
Previously, the flash module assumed it needed to emulate a SPI write
protect register using a bank of flash to hold the persistent flash
write protect state.  This is not true for mec and ncpx chips under
development, which use external SPI flash.  So, gate that code with
CONFIG_FLASH_PSTATE.  For compatibility, leave it on by default (as we
do with CONFIG_FLASH_MAPPED).

There is no change to the behavior of currently supported chips, since
all of them already assume pstate is present.  Removing this feature
from npcx will be done in a subsequent change.

BUG=chrome-os-partner:34346
BRANCH=strago
TEST=make buildall -j; verify flash wp and flashinfo work properly on samus

Change-Id: Ie044eb042863e4a7359ea540166ffd8d0089589d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/253632
Reviewed-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Mulin Chao <mlchao@nuvoton.com>
2015-02-26 20:31:51 +00:00
Randall Spangler
f8af89c40d Support vboot hash and system version if flash isn't memory-mapped
Some EC chips (mec1322) use external SPI flash which is not mapped
into the EC CPU's address space.  These must explicitly read data from
flash when calculating the vboot hash or reading the version string of
the image which isn't currently loaded into code RAM.

To test this bug, I used a board with known working mapped flash, and
temporarily patched it to act like it didn't have mapped flash.

Also add a flashread console command, useful for manually testing.

BUG=chrome-os-partner:35308
BRANCH=glower,strago
TEST=manual
	1. Apply this patch to samus
	2. Check result for 'vboot hash RW'
	3. Check result for 'version'

	4a. In board/samus/board.h, #undef CONFIG_FLASH_MAPPED and
            #define CONFIG_CMD_FLASH
	4b. In chip/lm4/flash.c, add the following:

	int flash_physical_read(int offset, int size, char *data)
	{
		const char *src;
		if (offset > CONFIG_FLASH_SIZE ||
		    offset + size > CONFIG_FLASH_SIZE)
		return EC_ERROR_INVAL;

		src = (const char *)((uintptr_t)CONFIG_FLASH_BASE + offset);
		memcpy(data, src, size);
		return EC_SUCCESS;
	}

	Steps 4a,4b will make the LM4 chip act like it doesn't have
	memory-mapped flash.

	5. From the dev system, util/flash_ec --board=samus --ro
	6. Check result for 'vboot hash RW'.  Should be same as 2.
	7. Check result for 'version' for RW version.  Should be same as in 3.
	8. From the dev system, util/flash_ec --board=samus
	9. sysjump rw
	10. Check result for 'version' for RO version.  Should be same as in 3.
	11. Compare 'flashread 0x100 0x100' with 'md 0x100 0x40'.  The results
            should be the same (but endian-swapped, since flashread is byte
	    ordered and md is 32-bit ordered).
	12. Revert changes from steps 4a-4b.

Change-Id: I951d6f5603a84e326740936e4e84dfe6296a0f59
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/246200
Reviewed-by: Shawn N <shawnn@chromium.org>
2015-02-05 21:03:01 +00:00
Vincent Palatin
cca794d2fe pd: dingdong/hoho: Enable flash write-protection
These USB type-C accessories don't have a write-protect GPIO.
Add a configure flag (CONFIG_WP_ALWAYS) to force the flash
write-protection on the dongles.

Also set the read protection (by elevating RDP to level 1),
so trying to unprotect the flash will trigger a full erase.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=samus
BUG=chrome-os-partner:35088
TEST=boot Hoho,
check the flash OBR and WRPR registers:
"rw 0x4002201c" / "rw 0x40022020"
and the option bytes write-protect bits: "rw 0x1FFFF808"
dump the logical state with "flashinfo" command.
> rw 0x4002201c
read 0x40022020 = 0xffff0002
> rw 0x40022020
read 0x40022020 = 0xffff0000
> rw 0x1FFFF808
read 0x1ffff808 = 0xff00ff00
> flashinfo
Physical: 128 KB
Usable:   128 KB
Write:      2 B (ideal 2 B)
Erase:   2048 B (to 1-bits)
Protect: 4096 B
Flags:   wp_gpio_asserted ro_at_boot ro_now
Protected now:
    YYYYYYYY YYYYYYYY ........ ........

Change-Id: I45bbc0bce40ecc174b6b8a1ebacf4f53d2fd372d
Reviewed-on: https://chromium-review.googlesource.com/238893
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
2015-01-08 00:38:17 +00:00
Vic Yang
f8fd63f135 Fix incorrect valid and writable flash flags
The valid and writable flags the EC sends back to the AP are incorrect.
They are a little bit different on differnt chips, so let's move it to
flash physical layer. This is not any causing problem, but we should fix
this.

BUG=chrome-os-partner:32745
TEST=make buildall
BRANCH=samus

Change-Id: Ibcda5ae770f5ea02cde094490997a5bc447df88f
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222661
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-15 23:56:27 +00:00
Vic Yang
82915c2502 Write protect support for STM32F0
On STM32F0, we cannot work around the hard fault triggered when trying
to protect the whole flash. Therefore, we need to go with the
ALL_AT_BOOT approach. When write protect is enabled, instead of setting
ALL_NOW flag to immediately lock down the entire flash, we need to set
ALL_AT_BOOT and then reboot to have the protection take effect.

BUG=chrome-os-partner:32745
TEST=Along with the next CL. On Ryu:
  1. Enable HW WP. Check the output of 'ectool flashprotect' and see
     correct flags.
  2. 'flashrom -p ec --wp-range 0 0x10000'. Check RO_AT_BOOT is set.
  3. Reboot EC and check RO_NOW is enabled.
  4. Boot the system and check ALL_NOW is set.
  5. Update BIOS and reboot. Check software sync updates EC-RW.
  6. 'flashrom -p ec --wp-disable' and check it fails.
  7. Disable HW WP and reboot EC. Check RO_NOW and ALL_NOW are cleared.
  8. 'flashrom -p ec --wp-disable' and check RO_AT_BOOT is cleared.
TEST=Enable/disable WP on Spring. Check RO_AT_BOOT/ALL_NOW can be set
properly.
BRANCH=samus

Change-Id: I1c7c4f98f2535f1c8a1c7daaa88d47412d015977
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222622
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-15 23:55:55 +00:00
Vic Yang
4a9cabc3f9 Factor out common flash code for STM32F and STM32F0
This is a preparatory work for the following change for write protection
support on STM32F0.

BUG=chrome-os-partner:32745
TEST=make buildall
BRANCH=samus

Change-Id: Ic4deea06e26c4a6ac024a5388e1a5783b40e9876
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222660
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-10-15 20:49:35 +00:00
Randall Spangler
2c4432f609 flash: Fix bad check for flash_is_erased()
This caused all platforms to check only the first 25% of each page to
see if it's already erased.  Fortunately, we tend to fill flash pages
from the beginning, so in normal usage we don't hit this bug.

BUG=chrome-os-partner:30281
BRANCH=all (if convenient)
TEST=Make sure CONFIG_CMD_FLASH is defined.  Then at the EC console:
  flasherase 0x1f000 0x400
  rw 0x1f3e0 -> 0xffffffff
  flashwrite 0x1f3e0 0x20
  rw 0x1f3e0 -> 0x03020100
  flasherase 0x1f000 0x400
  rw 0x1f3e0 -> 0x03020100 (bad!) or 0xffffffff (good)

Change-Id: If78b08b5e0414993a440bc8cd707b5ce70eb1a0a
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/206891
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-07-08 02:14:32 +00:00
Dominic Chen
bc50751dbe flash: add config option to exclude building console commands by default
some commands, e.g. flashwrite, are never used on the final product and also increase
the size of the flash image.

BRANCH=none
BUG=none
TEST=make buildall

Change-Id: I2a2a0a749b8eee16db5bae6a1dc92c430570e928
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/202993
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-06-12 01:44:31 +00:00
Dominic Chen
d414c89a61 util: move console command argument parsing to util.c
move parse_offset_size() from flash.c to util.c for SPI flash driver usage

BRANCH=none
BUG=none
TEST=make buildall

Change-Id: Ib4824d2a7e2f5b8c3e4b918d6507c072ded8837d
Signed-off-by: Dominic Chen <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/202530
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2014-06-11 00:17:06 +00:00
Randall Spangler
72481572aa Convert vboot hash calculation from task to deferred function
Vboot hash calculation takes ~350 ms during EC boot.  Since the hash
task is higher priority than the hook task, this starves all the hooks
during boot.

We could, in theory, fix that simply by swapping the priority of the
hook and hash tasks.  But then watchdog detection (in the hook task)
wouldn't detect hangs in the hash task.

A better fix (implemented here) is to convert the hashing operation to
a series of deferred function calls.  This gets rid of the hash task
entirely, and allows all pending hooks and other deferred function
calls to take place between each chunk of hashing.

On STM32-based boards, we need to bump up the hook task stack size,
since hashing is called from several layers deep in the hook task
instead of at the top of its own task, but this is still a net win of
several hundred bytes of SRAM.

BUG=chrome-os-partner:24892
BRANCH=rambi
TEST=Boot EC; look for "hash start" and "hash done" debug output.
     'taskinfo' shows at least 32 bytes of unused stack for HOOKS task.
     'hash ro' runs properly from EC console.

Change-Id: I9e580dc10fc0bc8e44896d84451218ef67578bbe
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/181954
2014-01-09 20:25:11 +00:00
Vic (Chun-Ju) Yang
143763421c Ignore all-now flag if WP GPIO is deasserted
On early snow boards, WP GPIO is not wired to the EC. Now that we have
properly fixed hardware, we should drop workaround for those boards.

BUG=chrome-os-partner:23762
TEST=Build all boards
BRANCH=None

Change-Id: I5dcfaf5497fc36d6b8d7bc5d8975aa18b2d36a1d
Signed-off-by: Vic (Chun-Ju) Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/181090
Reviewed-by: Yung-chieh Lo <yjlou@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2014-01-06 12:40:54 +00:00
Randall Spangler
05bd0cdec7 Rename mixed-case config constants
This renames constants used in compiler conditionals to uppercase.
   BOARD_foo
   CHIP_foo
   CHIP_FAMILY_foo
   CHIP_VARIANT_foo
   CORE_foo

Mixed-case constants are still defined by the makefile, but are now no
longer used.  I will make one more pass in a week or so to catch any
that are part of someone else's CL, since otherwise this change might
silently merge correctly but result in incorrect compilation.  Then I
will remove defining the mixed-case constants.

BUG=chromium:322144
BRANCH=none
TEST=Build all boards.  Also, "git grep 'BOARD_[a-z]'" should return no
     results (similarly for CHIP, CORE, etc.)

Change-Id: I6418412e9f7ec604a35c2d426d12475dd83e7076
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/179206
Reviewed-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-12-16 20:28:32 +00:00
Randall Spangler
760ace07a5 cleanup: Improve / remove more TODO comments
Add bug references.  Remove one assert that can no longer be triggered.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I3f4d2e4f2f3343a8d0531cb0715d151eaa4d0b50
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/175293
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-11-01 17:13:07 +00:00
Randall Spangler
8cf03ac056 Move source files to driver/ and power/ subdirs
The common/ subdir was getting cluttered.  Move drivers for external
components to a new driver/ tree, and move what used to be called
chipset_*.c to a new power/ directory.

This does not move/rename header files or CONFIG options.  That will
be done in subsequent steps, since moving and modifying .c files in
the same CL is harder to review.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I67a3003dc8564783a320335cf0e9620a21982d5e
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/173601
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Tested-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
2013-10-23 20:07:25 +00:00