Commit Graph

30 Commits

Author SHA1 Message Date
Simon Glass
8fdf7d5564 flash: Indicate that erase operation is in progress
Erasing the flash can take a while, by which time the host may have timed
out. So pass an in-progress message back to the host before starting, and
when done, stash the result for later collection.

BUG=chrome-os-partner:12685
BRANCH=snow,link
TEST=manual
build and boot to kernel on snow

Change-Id: I5566a5519a1c8b320573b20e1ea7660217b32a5e
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/30471
2012-08-17 07:18:35 -07:00
Louis Yung-Chieh Lo
9d872b724f Snow: WP_RO should be 0x10000 (including pstate).
To reflect the CL 00799d5 that moves the pstate to 0xf000.

BUG=chrome-os-partner:12799
TEST=Build in chroot.
snow:  WP_RO is changed from 0:0xf000 --> 0:0x10000.
daisy: WP_RO is unchanged.
link: WP_RO is unchanged.

Change-Id: I572bae3f624744e60d13a762875211beffc6c516
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/30670
Reviewed-by: Vic Yang <victoryang@chromium.org>
2012-08-17 01:48:30 -07:00
Randall Spangler
371d06bbfd Tidy shared memory module
Adds shmem command to print amount of shared memory.  This is also a
useful indicator of how much IRAM is left, since shared memory will
expand to fill all unused IRAM.

Removes never-implemented wait param to shared_mem_acquire().

BUG=none
TEST=shmem

Change-Id: I798ff644d701dcba52219b70bec99c06a23d03ec
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/29809
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-08-09 17:40:37 -07:00
Vic Yang
00799d5bc1 stm32f: Flash write protect
Implement STM32F write protect to match refactored flash module.
Also move fake write-protect pin to use backup register to preserve
value across reboot.

BUG=chrome-os-partner:11699
TEST=1. 'flashinfo'      -> no flags
     2. 'fakewp 1'       -> 'wp_gpio_asserted'
     3. 'flashwp enable' -> 'wp_gpio_asserted ro_at_boot'
     4. 'reboot'         -> 'wp_gpio_asserted ro_at_boot ro_now'
     5. 'fakewp 0'       -> 'ro_at_boot ro_now'
     6. 'reboot'         -> 'ro_at_boot'
     7. 'fakewp 1'       -> 'wp_gpio_asserted ro_at_boot'
     8. 'flashwp rw'     -> 'wp_gpio_asserted ro_at_boot rw_at_boot'
     9. 'reboot'         -> 'wp_gpio_asserted ro_at_boot ro_now
                             rw_at_boot rw_now'
     10.'flashwp disable'-> error 7
     11.'flashwp norw'   -> 'wp_gpio_asserted ro_at_boot ro_now rw_now'
     12.'reboot'         -> 'wp_gpio_asserted ro_at_boot ro_now'

Change-Id: I40405c266e30b10793ccae2f1d26fb9710ce304b
Reviewed-on: https://gerrit.chromium.org/gerrit/28372
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Ready: Vic Yang <victoryang@chromium.org>
Tested-by: Vic Yang <victoryang@chromium.org>
2012-07-26 18:28:14 -07:00
Randall Spangler
247fdaf13d Change host command params/response pointers to void *
This removes a bunch of unnecessary typecasts, since you can assign
to/from void * without them.  This also uncovered a few cases where
const was being cast away for the input params; now fixed.

BUG=none
TEST=mkbp hash from u-boot console, and/or system boots ok

Change-Id: Ic314b9d2ca06226ea8a09703ef5c1a912eb7146d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28500
2012-07-26 16:25:34 -07:00
Louis Yung-Chieh Lo
3ab8ed4124 Add RW offset query interface (EC_CMD_FLASH_RW_OFFSET).
BUG=chrome-os-partner:11149
TEST=build only.

Originally-Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Change-Id: I35ad1e0a49c95a2d6cffbe49b2013a1b8050aabc
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28166
2012-07-24 17:38:10 -07:00
Randall Spangler
1661f1cef0 Refactor flash module
This is a significant rewrite of the flash module, since it turns out
that much less of the flash logic is actually common between stm32 and
lm4.

BUG=chrome-os-partner:11699
TEST=on link,

(enable hardware wp)
flashinfo -> wp_gpio_asserted
flashwp enable
flashinfo -> wp_gpio_asserted ro_at_boot
reboot
flashinfo -> wp_gpio_asserted ro_at_boot ro_now
flashwp disable -> error 7
flashwp now
flashinfo -> wp_gpio_asserted ro_at_boot ro_now rw_now
reboot
flashinfo -> wp_gpio_asserted ro_at_boot ro_now
(disable hardware wp)
reboot
flashinfo -> ro_at_boot
flashwp disable
flashinfo -> (no flags)

Change-Id: If22b02373946ce1c080d49ccded4f8fa3e380115
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28200
Reviewed-by: Vic Yang <victoryang@chromium.org>
2012-07-23 23:30:33 -07:00
Randall Spangler
93f2e82133 Fix unit tests not compiling for link
BUG=none
TEST=make link tests

Change-Id: I678b927d068bd7f1f43115a4495c16902588faa7
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28140
2012-07-23 11:03:32 -07:00
Vic Yang
c26eb30863 stm32f: Fix some error in flash write protect
And also add a fake write protect pin command for futher development and
testing.

BUG=chrome-os-partner:11595
TEST=Enable pstate read/write for stm32f.
      1. 'flashinfo' -> WP pin deasserted. No blocks protected.
      2. 'flashwp enable' -> Nothing changes.
      3. 'fakewp 1'; 'flashinfo' -> WP pin asserted. No blocks
         protected.
      4. 'flashwp enable'; 'flashinfo' -> RO protected.

Change-Id: Id5b1997442d9104d9cb254a295e0bd2f8c83bc78
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/28062
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2012-07-21 21:47:52 -07:00
Randall Spangler
8137b29125 Add EC flash protect command to ectool
BUG=chrome-os-partner:11150
TEST=manual

Enable WP GPIO.  Then from a root shell

   localhost ~ # ectool flashprotect
   Flash protect flags: 0x00000008 wp_gpio_asserted
   Writable flags:      0x00000005 ro_at_boot rw_now
   localhost ~ # ectool flashprotect enable
   Flash protect flags: 0x0000000b wp_gpio_asserted ro_at_boot ro_now
   Writable flags:      0x00000004 rw_now
   localhost ~ # ectool flashprotect enable
   Flash protect flags: 0x0000000b wp_gpio_asserted ro_at_boot ro_now
   Writable flags:      0x00000004 rw_now
   localhost ~ # ectool flashprotect now
   Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now
   Writable flags:      0x00000000
   localhost ~ # ectool flashprotect now
   Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now
   Writable flags:      0x00000000
   localhost ~ # ectool flashprotect disable
   Flash protect flags: 0x0000000f wp_gpio_asserted ro_at_boot ro_now rw_now
   Writable flags:      0x00000000
   Unable to set requested flags (wanted mask 0x00000001 flags 0x00000000)
   Which is expected, because writable mask is 0x00000000.

Then disable WP GPIO and reboot

   localhost ~ # ectool flashprotect
   Flash protect flags: 0x00000001 ro_at_boot
   Writable flags:      0x00000001 ro_at_boot
   localhost ~ # ectool flashprotect disable
   Flash protect flags: 0x00000000
   Writable flags:      0x00000001 ro_at_boot

Change-Id: Idc5de3b3033521467aca8fb0ba9b7c378d0ad2a1
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27799
2012-07-18 18:15:29 -07:00
Randall Spangler
3dfc336b44 Better handling of corner cases for flash protection
If WP isn't asserted, 'flashwp now' does nothing.
If WP is already enabled, 'flashwp enable' succeeds.

BUG=chrome-os-partner:11150
TEST=manual

(disable physical WP)
flashwp now
flashinfo -> nothing protected
flashwp enable
flashinfo -> ro_at_boot set, nothing protected
(enable physical WP)
reboot
flashinfo -> ro_at_boot ro_now
flashwp enable -> (succeeds)
flashwp disable -> fails
flashinfo -> ro_at_boot ro_now
flashwp now
flashinfo -> ro_at_boot ro_now rw_now
(disable physical WP)
reboot
flashwp disable
flashinfo -> nothing protected

Change-Id: I4660d822886635e71ab1636c737611214852f58c
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27798
2012-07-18 18:15:18 -07:00
Randall Spangler
c7b4a30a53 Use config values for flash protect/erase/write sizes
Since they're config values anyway.  Gets rid of an unneeded layer of
function call.

BUG=chrome-os-partner:11150
TEST=build link, snow, daisy; flashinfo returns same values

Change-Id: I27fa007f64a446f1ec0fe22ae16c5c1ac667f8e9
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27797
2012-07-18 18:15:00 -07:00
Randall Spangler
9a8223a8db Remove flash_read()
Everything now uses flash_dataptr() to get at flash memory rather than
calling the read function, since the read function adds a needless memcpy().

BUG=chrome-os-partner:11150
TEST=manual

flashwp enable
reboot
flashinfo -> should show ro_at_boot
flashwp disable
reboot
flashinfo -> should no longer show ro_at_boot

Change-Id: I1830e2f036cf6777115c782c1737335ff2eb4ce0
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27796
2012-07-18 18:14:47 -07:00
Randall Spangler
1a76325fa8 Continue refactoring flash write protect
Now properly detects partially-protected flash banks.

Also renames 'flashwp lock/unlock' to 'flashwp enable/disable'

BUG=chrome-os-partner:11150
TEST=manual

ww 0x400fe400 0x7fffffff
flashinfo -> ro_now PARTIAL
reboot
ww 0x400fe404 0x7fffffff
flashinfo -> rw_now PARTIAL
flashwp now
flashinfo -> ro_now rw_now (and NOT partial)

Change-Id: I9266a024eee6d75af052cd47e3f54468ad959a12
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27795
2012-07-18 18:14:36 -07:00
Randall Spangler
2223179cbc Move looking at write protect GPIO to button/switches module
Since that already monitors the WP signal for reporting it as a
switch.  And if we have that code in two places and the WP signal
polarity changes, we'll inevitably forget to change it in the other
place...

BUG=chrome-os-partner:11150
TEST=manual

flashinfo -> WP pin asserted
remove WP screw
flashinfo -> WP pin deasserted

Change-Id: I6091c8bb470c357e02ede8a5b184b2a76b70dc60
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27720
2012-07-18 15:51:36 -07:00
Randall Spangler
3f492b471b Continue simplifying flash write protect
Now that read-only code is protected iff the persistent state is
locked, we don't need to track per-block in the persistent state.

BUG=chrome-os-partner:11150
TEST=if it builds and boots, it's fine

Change-Id: I80e6a85c0c72136b7ed8964ce02c8abdbaafe637
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27719
2012-07-18 13:49:11 -07:00
Randall Spangler
aabe50f0d5 Move flash commands into flash_common.c
In preparation for more flash refactoring.

BUG=chrome-os-partner:11150
TEST=build link, snow

Change-Id: If877e5ebee5af0f9b167ec7b28fd9d718d0108ec
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27718
2012-07-18 13:48:56 -07:00
Randall Spangler
ad2268e739 Simplify flash protection, part 1
1. If the flash protection state is locked, RO firmware is explicitly locked.
2. Protecting flash now locks the entire flash.

BUG=chrome-os-partner:11150
TEST=manual

flashinfo -> nothing protected
flashwp now
flashinfo -> unlocked,applied; everything protected
reboot
flashinfo -> nothing protected
flashwp lock ->
flashinfo -> locked,applied; now has 40 Y's at start and 1 at end
reboot
flashinfo -> locked,applied; now has 40 Y's at start and 1 at end
remove WP screw
reboot
flashinfo -> locked, not applied; nothing protected
flashwp unlock
flashinfo -> nothing protected

Change-Id: I2cf0e8bfe82ab7a5bf88b9161b7a05b889cae71a
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27717
2012-07-18 13:48:46 -07:00
Louis Yung-Chieh Lo
9c289eda9f Enable Lucas EC WP again.
Uncomment back the old code and fix the bug of WRP bit definition and
also write_opt().

Note that to make this functional, wp_pin_asserted() always returns true.

Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Change-Id: Ic09d3346ca68a2700697ff863f0fa08525129b11
BUG=chrome-os-partner:9849
TEST=run on lucas.
> flashwp set 0 0x1f000
> flashwp lock
> flashinfo  # ensure the setting is right.
stm32mon -r to read the firmware.
stm32mon -w to write a different image.
stm32mon -r to read again and compare the firmware is non-changed.
> flashwp unlock
Command returned error 1
stm32mon -u to unlock write protection.
Reviewed-on: https://gerrit.chromium.org/gerrit/27503
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Commit-Ready: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com>
Tested-by: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com>
2012-07-18 00:56:45 -07:00
Randall Spangler
acf6f963a1 Flash pre-init reboots if it needs to clear protection registers
BUG=chrome-os-partner:11171
TEST=manual

1. Clear some of the writable-bits in the flash registers
> ww 0x400fe40c 0xffff1234
write 0x400fe40c = 0xffff1234
> rw 0x400fe40c
read 0x400fe40c = 0xffff1234
2. Reset using power+refresh
3. Register should be clear again
> rw 0x400fe40c
read 0x400fe40c = 0xffffffff
4. Sysinfo should indicate reset-pin reason AND hard-reset reason
> sysinfo
Reset flags: 0x0000000a (reset-pin power-on)
5. Reset using power+refresh
6. Sysinfo should indicate reset-pin reason only
> sysinfo
Reset flags: 0x00000002 (reset-pin)
7. Clear writable-bits again
> ww 0x400fe40c 0xffff1234
write 0x400fe40c = 0xffff1234
8. Jump to another image.  This should NOT trigger a hard reset.
> sysjump A
> sysinfo
Reset flags: 0x00000402 (reset-pin sysjump)

Change-Id: Ie1d6af2acc68217bb82faae464798ee85d63d1ea
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27540
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2012-07-16 17:49:10 -07:00
Rong Chang
63368620c5 CHERRY-PICK: stm32: de-activate all flash accesses for pstate
Cherry-picked from factory-2475.B.

This feature is not implemented and accessing random flash
addresses.

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

BUG=chrome-os-partner:10237
TEST=on Snow, run flashrom -p internal:bus=lpc --wp-status

Reviewed-on: https://gerrit.chromium.org/gerrit/25979
Reviewed-by: Katie Roberts-Hoffman <katierh@chromium.org>
Tested-by: David Hendricks <dhendrix@chromium.org>

Change-Id: Idce19f4e2af37faa5fde9d6561779d981772c9ac
Reviewed-on: https://gerrit.chromium.org/gerrit/26666
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Commit-Ready: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
2012-07-03 23:51:19 -07:00
Simon Glass
a60fdbdfcb Fix flash_dataptr() to support flash at zero
If flash starts at zero, then flash_dataptr() will return NULL for a valid
region. Change the function around so that it can be used in this case.

BUG=chrome-os-partner:10146
TEST=manual:
Modify code it print out parameters and problems, then:
Writing 256 bytes to 0x0...
0 256 64
ok 131072
Command returned error 1
> flashwrite 0 256
Writing 256 bytes to 0x0...
0 256 64
ok 131072
Command returned error 1
> flashwrite 0 255
Writing 255 bytes to 0x0...
0 255 64
Command usage/param invalid.
Usage: flashwrite offset [size]

Change-Id: I5683fc181ef780310ceff50f120735659e973784
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26749
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Reviewed-by: Rong Chang <rongchang@chromium.org>
2012-07-03 23:51:09 -07:00
Simon Glass
9a4eff992f flash: Provide direct flash access with flash_dataptr()
Sometimes it is useful to get access to the flash directly, without using
flash_read(). Add a function to do this.

Since the range checking is done in every function in flash_common,
use the new function to do it for us. That way we get a slight (64 byte)
code size reduction.

BUG=chrome-os-partner:10146
TEST=manual:
build and boot on snow with SPI flash emulation, in U-Boot:

See that the 32KB of flash has been provided correctly.

Change-Id: I6622a24234edaed371dd5b9bf43d1f3974d55e39
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26174
2012-07-02 22:35:51 -07:00
Vincent Palatin
15854fa680 Add FMAP even if VBOOT is not activated
This simplifies the re-flashing for stm32 based platforms.

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

BUG=chrome-os-partner:8865
TEST=On Daisy, flashrom -p internal:bus=lpc -w ec.bin

Change-Id: I66860383c34110b1edf852929c244a2b682bc105
2012-05-22 15:04:13 +00:00
Bill Richardson
add419009f Clean up linker scripts; detect out-of-flash problem.
The VMA of the .data segment is in RAM, but we actually put it into FLASH.
The linker doesn't notice if it runs out of flash, so it creates an invalid
image.

This adds an explicit check to be sure it all fits. It also refactors the
region declarations to be more explicit. For vboot-enabled configurations,

  CONFIG_SECTION_*      - describes the extent of flash for one entire image
  CONFIG_FW_*           - the region within the SECTION for the firmware only
  CONFIG_VBLOCK_*       - the region within the RW SECTIONs for the vblocks
  CONFIG_VBOOT_ROOTKEY  - the region within the RO SECTION for the root key

Look at chip/lm4/config.h for the best example.

BUG=chrome-os-partner:9839
TEST=manual

Build it, run it.

Change-Id: I3c652e82d58a5328115cc750c80ecba6a3fd99a3
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
2012-05-21 14:20:02 -07:00
Vincent Palatin
71c86b38c3 stm32: add flash programming support
Implements the on-chip flash erasing and writing functions.

The actual writing is done from a routine in internal RAM (using the
special .iram.text section) with interrupt disabled as we cannot read
flash during the writing process.

The write-protect feature is only lightly tested.

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

BUG=chrome-os-partner:8865
TEST=run on Daisy, from the EC console, use flasherase and flashwrite
commands and observe the results using rw command.

Change-Id: I4c64cf28b23df52b18500b42a32a7d3668d45ba6
2012-05-09 01:13:26 +00:00
Randall Spangler
5cd6f3cf7f Remove unused uart.h includes
Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=none
TEST=none

Change-Id: I8f9c6e67427a5c7f2c42754b421db44504f9c10d
2012-04-25 15:56:10 -07:00
Randall Spangler
bae507a2da Invert write protect signal
Write protect is active-high, not active-low.

Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=chrome-os-partner:8580
TEST=manual

From chroot:
  dut-control fw_wp_en:on
  dut-control mfg_mode:on
From console:
  gpioget WRITE_PROTECT
  0  WRITE_PROTECT

From chroot:
  dut-control fw_wp_en:on
  dut-control mfg_mode:off
From console:
  gpioget WRITE_PROTECT
  1  WRITE_PROTECT

Change-Id: I81c7858cac43c6c9b8630bf7f5aa0f491e6554ad
2012-04-04 15:26:25 -07:00
Randall Spangler
cb214ee8d8 Remove write protect -> recovery signal hack
Servo2 can set the write protect signal

Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=chrome-os-partner:8580
TEST=manual

From chroot:
  dut-control fw_wp_en:on
  dut-control mfg_mode:on

Then from EC console:
  gpioget WRITE_PROTECTn
  0  WRITE_PROTECTn

From chroot:
  dut-control fw_wp_en:on
  dut-control mfg_mode:off

Then from EC console:
  gpioget WRITE_PROTECTn
  1* WRITE_PROTECTn

Change-Id: I9976cd6f114c8dae75434adf99d9409107b6ada0
2012-04-03 15:58:11 -07:00
Randall Spangler
b70183a9bd Implement persistent flash write protect settings
This uses the last bank of flash to hold persistent settings, and
looks at the write protect GPIO to decide whether to protect the chip
at boot (chrome-os-partner:7453).

For ease of debugging, I've temporarily hacked this so flash uses the
RECOVERYn signal (dut-control goog_rec_mode:on) to enable WP instead
of the write protect signal; this works around chrome-os-partner:8580.

Also note that if you write protect any blocks even temporarily,
you'll need to do a power-on reset to clear them before you can
reprogram the flash.  See chrome-os-partner:8632.  At the EC console,
"hibernate 1" will do that, or you can just yank the power.

This also fixes a bug in the flash write and erase commands, where
they weren't properly detecting failure if you attempted to modify a
protected block (missed an interrupt reason...)

New "flashwp" console commands work.  LPC commands need reworking.

Signed-off-by: Randall Spangler <rspangler@chromium.org>

BUG=chrome-os-partner:8448
TEST=manual

Change-Id: I49c38cc25c793094ae3331a4586fda0761b4bac6
2012-04-02 10:57:03 -07:00