From 8dec5fcaf8d4821103eb66246bee817e987fc7f8 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 24 Jun 2025 10:21:45 +0000 Subject: [PATCH] drivers/spi: Add 4-byte address mode flag to lb_spi_flash Adds a new flags field to the lb_spi_flash coreboot table to indicate if the SPI flash is operating in 4-byte address mode. This allows payloads to query the current address mode directly from the coreboot table, preventing redundant checks or re-enforcement of the mode. The flag is set based on the CONFIG_SPI_FLASH_FORCE_4_BYTE_ADDR_MODE configuration. Important: `erase_cmd` was reduced from uint32_t to uint8_t. Only the least significant byte was ever relevant, so this change ensures accurate type representation, maintains backward compatibility with existing coreboot table structures, and frees up space. BUG=b:417900125 TEST=Able to build google/bluey. Change-Id: I406536432b2a0c7f4108e5b33d5a20c272d917b0 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/88181 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/commonlib/include/commonlib/coreboot_tables.h | 10 +++++++++- src/drivers/spi/spi_flash.c | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/commonlib/include/commonlib/coreboot_tables.h b/src/commonlib/include/commonlib/coreboot_tables.h index 7860a413ce..fefafb87e1 100644 --- a/src/commonlib/include/commonlib/coreboot_tables.h +++ b/src/commonlib/include/commonlib/coreboot_tables.h @@ -359,7 +359,15 @@ struct lb_spi_flash { uint32_t size; uint32_t flash_size; uint32_t sector_size; - uint32_t erase_cmd; + /* + * Note: `erase_cmd` was previously a uint32_t. It's now uint8_t because only + * the lowest byte was used, ensuring backward compatibility with older coreboot + * tables and allowing reuse of the remaining bytes. + */ + uint8_t erase_cmd; +#define LB_SPI_FLASH_FLAG_IN_4BYTE_ADDR_MODE (1 << 0) + uint8_t flags; + uint16_t reserved; /* * Number of mmap windows used by the platform to decode addresses between SPI flash * space and host address space. This determines the number of entries in mmap_table. diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c index 88ed2abda2..dda089e917 100644 --- a/src/drivers/spi/spi_flash.c +++ b/src/drivers/spi/spi_flash.c @@ -768,6 +768,10 @@ void lb_spi_flash(struct lb_header *header) flash->mmap_count = spi_flash_get_mmap_windows(table); flash->size += flash->mmap_count * sizeof(*table); } + + /* Pass 4-byte address mode information to payload */ + if (CONFIG(SPI_FLASH_FORCE_4_BYTE_ADDR_MODE)) + flash->flags = LB_SPI_FLASH_FLAG_IN_4BYTE_ADDR_MODE; } int spi_flash_ctrlr_protect_region(const struct spi_flash *flash,