mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 07:23:43 +02:00
4BA: Allow disabling 4-byte address mode for SPI flash
This allows us to support flash chips in any of the following configurations, regardless of whether the chip powers up in 3-byte or 4-byte address mode. - standard commands with extended address register (*_4ba_ereg) or direct commands (*_4ba_direct) in 3-byte address mode (.set_4ba = spi_exit_4ba_*) - standard commands (*_4ba) or direct commands (*_4ba_direct) in 4-byte address mode (.set_4ba = spi_enter_4ba_*) - direct commands (*_4ba_direct) in either address mode (.set_4ba = NULL) Change-Id: I0b25309d731426940fc50956b744b681ab599e87 Signed-off-by: Ed Swierk <eswierk@skyportsystems.com> Reviewed-on: https://review.coreboot.org/20510 Reviewed-by: David Hendricks <david.hendricks@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
d94d254262
commit
cc20a9b08e
11
flash.h
11
flash.h
@ -119,14 +119,7 @@ enum write_granularity {
|
|||||||
#define FEATURE_WRSR_EITHER (FEATURE_WRSR_EWSR | FEATURE_WRSR_WREN)
|
#define FEATURE_WRSR_EITHER (FEATURE_WRSR_EWSR | FEATURE_WRSR_WREN)
|
||||||
#define FEATURE_OTP (1 << 8)
|
#define FEATURE_OTP (1 << 8)
|
||||||
#define FEATURE_QPI (1 << 9)
|
#define FEATURE_QPI (1 << 9)
|
||||||
/* Feature bits used for 4-bytes addressing mode */
|
#define FEATURE_4BA_SUPPORT (1 << 10)
|
||||||
#define FEATURE_4BA_SUPPORT (1 << 10)
|
|
||||||
#define FEATURE_4BA_ONLY (1 << 11)
|
|
||||||
#define FEATURE_4BA_EXTENDED_ADDR_REG (1 << 12)
|
|
||||||
#define FEATURE_4BA_DIRECT_READ (1 << 13)
|
|
||||||
#define FEATURE_4BA_DIRECT_WRITE (1 << 14)
|
|
||||||
#define FEATURE_4BA_ALL_ERASERS_DIRECT (1 << 15)
|
|
||||||
#define FEATURE_4BA_ALL_DIRECT (FEATURE_4BA_DIRECT_READ | FEATURE_4BA_DIRECT_WRITE | FEATURE_4BA_ALL_ERASERS_DIRECT)
|
|
||||||
|
|
||||||
enum test_state {
|
enum test_state {
|
||||||
OK = 0,
|
OK = 0,
|
||||||
@ -174,7 +167,7 @@ struct flashchip {
|
|||||||
|
|
||||||
/* set of function pointers to use in 4-bytes addressing mode */
|
/* set of function pointers to use in 4-bytes addressing mode */
|
||||||
struct four_bytes_addr_funcs_set {
|
struct four_bytes_addr_funcs_set {
|
||||||
int (*enter_4ba) (struct flashctx *flash);
|
int (*set_4ba) (struct flashctx *flash);
|
||||||
int (*read_nbyte) (struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
|
int (*read_nbyte) (struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
|
||||||
int (*program_byte) (struct flashctx *flash, unsigned int addr, const uint8_t databyte);
|
int (*program_byte) (struct flashctx *flash, unsigned int addr, const uint8_t databyte);
|
||||||
int (*program_nbyte) (struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len);
|
int (*program_nbyte) (struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len);
|
||||||
|
@ -14597,10 +14597,10 @@ const struct flashchip flashchips[] = {
|
|||||||
/* supports SFDP */
|
/* supports SFDP */
|
||||||
/* OTP: 1024B total, 256B reserved; read 0x48; write 0x42, erase 0x44, read ID 0x4B */
|
/* OTP: 1024B total, 256B reserved; read 0x48; write 0x42, erase 0x44, read ID 0x4B */
|
||||||
/* FOUR_BYTE_ADDR: supports 4-bytes addressing mode */
|
/* FOUR_BYTE_ADDR: supports 4-bytes addressing mode */
|
||||||
.feature_bits = FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_4BA_SUPPORT | FEATURE_4BA_DIRECT_READ,
|
.feature_bits = FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_4BA_SUPPORT,
|
||||||
.four_bytes_addr_funcs =
|
.four_bytes_addr_funcs =
|
||||||
{
|
{
|
||||||
.enter_4ba = spi_enter_4ba_b7_we, /* enter 4-bytes addressing mode by CMD B7 + WREN */
|
.set_4ba = spi_enter_4ba_b7_we, /* enter 4-bytes addressing mode by CMD B7 + WREN */
|
||||||
.read_nbyte = spi_nbyte_read_4ba_direct, /* read directly from any mode, no need to enter 4ba */
|
.read_nbyte = spi_nbyte_read_4ba_direct, /* read directly from any mode, no need to enter 4ba */
|
||||||
.program_byte = spi_byte_program_4ba, /* write from 4-bytes addressing mode */
|
.program_byte = spi_byte_program_4ba, /* write from 4-bytes addressing mode */
|
||||||
.program_nbyte = spi_nbyte_program_4ba /* write from 4-bytes addressing mode */
|
.program_nbyte = spi_nbyte_program_4ba /* write from 4-bytes addressing mode */
|
||||||
|
41
flashrom.c
41
flashrom.c
@ -2223,41 +2223,12 @@ int prepare_flash_access(struct flashctx *const flash,
|
|||||||
if (flash->chip->unlock)
|
if (flash->chip->unlock)
|
||||||
flash->chip->unlock(flash);
|
flash->chip->unlock(flash);
|
||||||
|
|
||||||
/* Switching to 4-Bytes Addressing mode if flash chip supports it */
|
/* Enable/disable 4-byte addressing mode if flash chip supports it */
|
||||||
if(flash->chip->feature_bits & FEATURE_4BA_SUPPORT) {
|
if ((flash->chip->feature_bits & FEATURE_4BA_SUPPORT) &&
|
||||||
/* Do not switch if chip is already in 4-bytes addressing mode */
|
flash->chip->four_bytes_addr_funcs.set_4ba) {
|
||||||
if (flash->chip->feature_bits & FEATURE_4BA_ONLY) {
|
if (flash->chip->four_bytes_addr_funcs.set_4ba(flash)) {
|
||||||
msg_cdbg("Flash chip is already in 4-bytes addressing mode.\n");
|
msg_cerr("Enabling/disabling 4-byte addressing mode failed!\n");
|
||||||
}
|
return 1;
|
||||||
/* Do not switch to 4-Bytes Addressing mode if using Extended Address Register */
|
|
||||||
else if(flash->chip->feature_bits & FEATURE_4BA_EXTENDED_ADDR_REG) {
|
|
||||||
msg_cdbg("Using 4-bytes addressing with extended address register.\n");
|
|
||||||
}
|
|
||||||
/* Go to 4-Bytes Addressing mode if selected
|
|
||||||
operation requires 4-Bytes Addressing mode
|
|
||||||
(no need if functions are direct-4BA) */
|
|
||||||
else if(((read_it || verify_it)
|
|
||||||
&& (!(flash->chip->feature_bits & FEATURE_4BA_DIRECT_READ)))
|
|
||||||
|| ((erase_it || write_it)
|
|
||||||
&& ((flash->chip->feature_bits & FEATURE_4BA_ALL_DIRECT) != FEATURE_4BA_ALL_DIRECT))) {
|
|
||||||
|
|
||||||
if (!flash->chip->four_bytes_addr_funcs.enter_4ba) {
|
|
||||||
msg_cerr("No function for Enter 4-bytes addressing mode for this flash chip.\n"
|
|
||||||
"Please report to flashrom@flashrom.org\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(flash->chip->four_bytes_addr_funcs.enter_4ba(flash)) {
|
|
||||||
msg_cerr("Switching to 4-bytes addressing mode failed!\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_cdbg("Switched to 4-bytes addressing mode.\n");
|
|
||||||
}
|
|
||||||
/* Do not switch to 4-Bytes Addressing mode if all instructions are direct-4BA
|
|
||||||
or if the flash chip is 4-Bytes Addressing Only and always in 4BA-mode */
|
|
||||||
else {
|
|
||||||
msg_cdbg2("No need to switch to 4-bytes addressing mode.\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user