From fe34d2af28bd81aaa1e23ba38febaa98ec4bb90c Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Fri, 10 Nov 2017 21:10:20 +0100 Subject: spi25: Revise decision when to enter/exit 4BA mode Instead of arbitrarily deciding whether to enter 4BA mode in the flash chip's declaration, advertise that entering 4BA mode is supported and only enter it if the SPI master supports 4-byte addresses. If not, exit 4BA mode (the chip might be in 4BA mode after reset). If we can't assure the state of 4BA mode, we bail out to simplify the code (we'd have to ensure that we don't run any instructions that can usually be switched to 4BA mode otherwise). Two new feature flags are introduced: * FEATURE_4BA_ENTER: Can enter/exit 4BA mode with instructions 0xb7/0xe9 w/o WREN. * FEATURE_4BA_ENTER_WREN Can enter/exit 4BA mode with instructions 0xb7/0xe9 after WREN. FEATURE_4BA_SUPPORT is dropped, it's completely implicit now. Also, draw the with/without WREN distinction into the enter/exit functions to reduce code redundancy. Change-Id: I877fe817f801fc54bd0ee2ce4e3ead324cbb3673 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/22422 Reviewed-by: Stefan Reinauer Tested-by: build bot (Jenkins) Reviewed-by: David Hendricks --- flashrom.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'flashrom.c') diff --git a/flashrom.c b/flashrom.c index 9cc1be66d..ac987fd9b 100644 --- a/flashrom.c +++ b/flashrom.c @@ -42,6 +42,7 @@ #include "flashchips.h" #include "programmer.h" #include "hwaccess.h" +#include "chipdrivers.h" const char flashrom_version[] = FLASHROM_VERSION; const char *chip_to_probe = NULL; @@ -2219,9 +2220,14 @@ int prepare_flash_access(struct flashctx *const flash, flash->in_4ba_mode = false; /* Enable/disable 4-byte addressing mode if flash chip supports it */ - if ((flash->chip->feature_bits & FEATURE_4BA_SUPPORT) && flash->chip->set_4ba) { - if (flash->chip->set_4ba(flash)) { - msg_cerr("Enabling/disabling 4-byte addressing mode failed!\n"); + if (flash->chip->feature_bits & (FEATURE_4BA_ENTER | FEATURE_4BA_ENTER_WREN)) { + int ret; + if (spi_master_4ba(flash)) + ret = spi_enter_4ba(flash); + else + ret = spi_exit_4ba(flash); + if (ret) { + msg_cerr("Failed to set correct 4BA mode! Aborting.\n"); return 1; } } -- cgit v1.2.3