it8380dev: fix flash module and reset cause.

1. Use flash common code commands for flash erase and write test.
2. Reset cause is "soft" if software reset is triggered by core.
3. Fix EC keeps rebooting after reboot command when write protection is set
   while WP pin is de-asserted.

Signed-off-by: Dino Li <dino.li@ite.com.tw>

BRANCH=none
BUG=none
TEST=1. console commands "flashwrite" and "flasherase" OK.
     2. console "reboot", reset cause is soft.
     3. console command crash "assert", "divzero", and "stack" show
        reboot reason as soft.
     4. manually test with console commands.

flashinfo
Physical: 256 KB
Usable:   256 KB
Write:      4 B (ideal 1024 B)
Erase:   1024 B (to 1-bits)
Protect: 2048 B
Flags:
Protected now:
    ........ ........ ........ ........
    ........ ........ ........ ........
    ........ ........ ........ ........
    ........ ........ ........ ........
> flashwp enable
> flashinfo
Physical: 256 KB
Usable:   256 KB
Write:      4 B (ideal 1024 B)
Erase:   1024 B (to 1-bits)
Protect: 2048 B
Flags:   wp_gpio_asserted ro_at_boot
Protected now:
    ........ ........ ........ ........
    ........ ........ ........ ........
    ........ ........ ........ ........
    ........ ........ ........ ........
> reboot
Rebooting!

--- UART initialized after reboot ---
[Reset cause: soft]

flashinfo
Physical: 256 KB
Usable:   256 KB
Write:      4 B (ideal 1024 B)
Erase:   1024 B (to 1-bits)
Protect: 2048 B
Flags:   wp_gpio_asserted ro_at_boot ro_now
Protected now:
    YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY
    YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY
    ........ ........ ........ ........
    ........ ........ ........ ........
> flashinfo
Physical: 256 KB
Usable:   256 KB
Write:      4 B (ideal 1024 B)
Erase:   1024 B (to 1-bits)
Protect: 2048 B
Flags:   ro_at_boot ro_now
Protected now:
    YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY
    YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY
    ........ ........ ........ ........
    ........ ........ ........ ........
> reboot
Rebooting!

--- UART initialized after reboot ---
[Reset cause: soft]

flashinfo
Physical: 256 KB
Usable:   256 KB
Write:      4 B (ideal 1024 B)
Erase:   1024 B (to 1-bits)
Protect: 2048 B
Flags:   ro_at_boot ro_now INCONSISTENT
Protected now:
    YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY
    YYYYYYYY YYYYYYYY YYYYYYYY YYYYYYYY
    ........ ........ ........ ........
    ........ ........ ........ ........

--- UART initialized after reboot ---
[Reset cause: power-on]

flashinfo
Physical: 256 KB
Usable:   256 KB
Write:      4 B (ideal 1024 B)
Erase:   1024 B (to 1-bits)
Protect: 2048 B
Flags:   ro_at_boot
Protected now:
    ........ ........ ........ ........
    ........ ........ ........ ........
    ........ ........ ........ ........
    ........ ........ ........ ........

Change-Id: Ifad48d190a84326ed3cb4cde497d906b8ab8cd5f
Reviewed-on: https://chromium-review.googlesource.com/297933
Commit-Ready: Dino Li <dino.li@ite.com.tw>
Tested-by: Dino Li <dino.li@ite.com.tw>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Dino Li
2015-09-09 17:55:52 +08:00
committed by chrome-bot
parent f4b09f4f48
commit 72a7796dcb
3 changed files with 25 additions and 146 deletions

View File

@@ -22,6 +22,10 @@
/* Use CS0 of SSPI */
#define CONFIG_SPI_FLASH_PORT 0
/* Optional console commands */
#define CONFIG_CMD_FLASH
#define CONFIG_CMD_STACKOVERFLOW
/* Debug */
#undef CONFIG_KEYBOARD_DEBUG
#undef CONFIG_UART_TX_BUF_SIZE

View File

@@ -36,6 +36,7 @@ const char __flash_dma_start;
#define FLASH_CMD_AAI_WORD 0xAD
static int stuck_locked;
static int inconsistent_locked;
static int all_protected;
static int flash_dma_code_enabled;
@@ -472,6 +473,10 @@ uint32_t flash_physical_get_protect_flags(void)
if (stuck_locked)
flags |= EC_FLASH_PROTECT_ERROR_STUCK;
/* Check if flash protection is in inconsistent state at pre-init */
if (inconsistent_locked)
flags |= EC_FLASH_PROTECT_ERROR_INCONSISTENT;
return flags;
}
@@ -609,154 +614,15 @@ int flash_pre_init(void)
if (reset_flags & RESET_FLAG_POWER_ON) {
stuck_locked = 1;
return EC_ERROR_ACCESS_DENIED;
} else {
/*
* Set inconsistent flag, because there is no software
* reset can clear write-protect.
*/
inconsistent_locked = 1;
return EC_ERROR_ACCESS_DENIED;
}
/* Otherwise, do a hard boot to clear the flash protection registers */
system_reset(SYSTEM_RESET_HARD | SYSTEM_RESET_PRESERVE_FLAGS);
/* That doesn't return, so if we're still here that's an error */
return EC_ERROR_UNKNOWN;
}
static int eflash_test_erase(int addr, int size)
{
int rv, i, rvr;
uint8_t *rdata;
/* Acquire the shared memory buffer */
rv = shared_mem_acquire(FLASH_SECTOR_ERASE_SIZE, (char **)&rdata);
if (rv) {
ccputs("Can't get shared mem\n");
return rv;
}
for (; size > 0; size -= FLASH_SECTOR_ERASE_SIZE) {
rv = flash_physical_erase(addr, FLASH_SECTOR_ERASE_SIZE);
if (rv) {
/* Free the buffer */
shared_mem_release(rdata);
ccputs("Flash erase error\n");
return rv;
}
rvr = flash_read(addr, FLASH_SECTOR_ERASE_SIZE, rdata);
if (rvr) {
/* Free the buffer */
shared_mem_release(rdata);
ccputs("Flash read error\n");
return rvr;
}
for (i = 0; i < FLASH_SECTOR_ERASE_SIZE; i++) {
if (rdata[i] != 0xff) {
ccprintf("Addr %Xh should be FFh but %Xh\n",
(addr+i), rdata[i]);
ccprintf("Erase %Xh ~ %Xh fail\n", addr,
(addr + FLASH_SECTOR_ERASE_SIZE - 1));
/* Free the buffer */
shared_mem_release(rdata);
return rv;
}
}
ccprintf("Verify %Xh ~ %Xh OK\n", addr,
(addr + FLASH_SECTOR_ERASE_SIZE - 1));
addr += FLASH_SECTOR_ERASE_SIZE;
}
/* Free the buffer */
shared_mem_release(rdata);
return rv;
}
static int eflash_test_write(int addr, int size)
{
int rv, i, rvr;
uint8_t *rwdata;
/* Acquire the shared memory buffer */
rv = shared_mem_acquire((size * 2), (char **)&rwdata);
if (rv) {
ccputs("Can't get shared mem\n");
return rv;
}
for (i = 0; i < size; i++)
rwdata[i] = i;
rv = flash_physical_write(addr, size, rwdata);
if (rv) {
/* Free the buffer */
shared_mem_release(rwdata);
ccputs("Flash write error\n");
return rv;
}
rvr = flash_read(addr, size, &rwdata[size]);
if (rvr) {
/* Free the buffer */
shared_mem_release(rwdata);
ccputs("Flash read error\n");
return rvr;
}
rvr = 0;
for (i = 0; i < size; i++) {
if (rwdata[i] != rwdata[i+size]) {
ccprintf("%Xh should be %Xh but %Xh\n",
(addr+i), rwdata[i], rwdata[i+size]);
rvr++;
}
}
if (rvr)
ccprintf("Verify %d bytes fail\n", rvr);
else
ccprintf("Verify %Xh ~ %Xh OK\n", addr, (addr + size - 1));
/* Free the buffer */
shared_mem_release(rwdata);
return rv;
}
static int eflash_test(int argc, char **argv)
{
char *e;
int addr, size;
int rv;
if (argc != 4)
return EC_ERROR_PARAM_COUNT;
addr = strtoi(argv[2], &e, 0);
if (*e)
return EC_ERROR_PARAM2;
size = strtoi(argv[3], &e, 0);
if (*e)
return EC_ERROR_PARAM3;
/* erase */
if (strcasecmp(argv[1], "e") == 0) {
rv = eflash_test_erase(addr, size);
/* write */
} else if (strcasecmp(argv[1], "w") == 0) {
if (size > CONFIG_FLASH_WRITE_IDEAL_SIZE) {
ccprintf("size need <=%d\n",
CONFIG_FLASH_WRITE_IDEAL_SIZE);
return EC_ERROR_PARAM3;
}
rv = eflash_test_write(addr, size);
} else {
return EC_ERROR_PARAM1;
}
return rv;
}
DECLARE_CONSOLE_COMMAND(eflash, eflash_test,
"e/w addr size",
"erase/write internal eflash",
NULL);

View File

@@ -59,6 +59,10 @@ static void check_reset_cause(void)
flags |= REG8(addr + 1) << 16;
flags |= REG8(addr + 2) << 8;
flags |= REG8(addr + 3);
/* watchdog module triggers these reset */
if (flags & (RESET_FLAG_HARD | RESET_FLAG_SOFT))
flags &= ~RESET_FLAG_WATCHDOG;
}
REG8(IT83XX_BRAM_BASE+BRAM_INDEX_SAVED_RESET_FLAGS) = 0;
@@ -110,6 +114,11 @@ void system_reset(int flags)
if (flags & SYSTEM_RESET_LEAVE_AP_OFF)
save_flags |= RESET_FLAG_AP_OFF;
if (flags & SYSTEM_RESET_HARD)
save_flags |= RESET_FLAG_HARD;
else
save_flags |= RESET_FLAG_SOFT;
/* Store flags to battery backed RAM. */
REG8(IT83XX_BRAM_BASE+BRAM_INDEX_SAVED_RESET_FLAGS) = save_flags >> 24;
REG8(IT83XX_BRAM_BASE+BRAM_INDEX_SAVED_RESET_FLAGS+1) =