From 61d74dc8f7175f004c859e52d37615bc7ae8ad4d Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 24 Jun 2025 10:28:00 +0000 Subject: [PATCH] payloads: Propagate SPI flash address mode flag to libpayload This commit extends libpayload's understanding of SPI flash devices by adding a flags field to both struct cb_spi_flash and struct sysinfo_t.spi_flash. The new CB_SPI_FLASH_FLAG_IN_4BYTE_ADDR_MODE flag will be populated from the coreboot table's lb_spi_flash entry. This allows payloads to reliably determine if the SPI flash is currently configured for 4-byte addressing, enabling more robust flash operations without needing to re-probe or re-enforce the mode. Note: `erase_cmd` type was changed from uint32_t to uint8_t. This is because only the lowest byte of the original uint32_t was ever used. The change ensures proper sizing, maintains compatibility with older coreboot tables, and makes the remaining space available for new fields. BUG=b:417900125 TEST=Able to build google/bluey. Change-Id: I101a50f899e82e9412024a049a9df59c5813313a Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/88182 Reviewed-by: Paul Menzel Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- payloads/libpayload/include/coreboot_tables.h | 10 +++++++++- payloads/libpayload/include/sysinfo.h | 9 ++++++++- payloads/libpayload/libc/coreboot.c | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/payloads/libpayload/include/coreboot_tables.h b/payloads/libpayload/include/coreboot_tables.h index 5b19ca8422..b43a558b49 100644 --- a/payloads/libpayload/include/coreboot_tables.h +++ b/payloads/libpayload/include/coreboot_tables.h @@ -306,7 +306,15 @@ struct cb_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 CB_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/payloads/libpayload/include/sysinfo.h b/payloads/libpayload/include/sysinfo.h index 2eb0da32dd..2db306eba9 100644 --- a/payloads/libpayload/include/sysinfo.h +++ b/payloads/libpayload/include/sysinfo.h @@ -135,7 +135,14 @@ struct sysinfo_t { struct { uint32_t 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; + uint8_t flags; + uint16_t reserved; uint32_t mmap_window_count; struct flash_mmap_window mmap_table[SYSINFO_MAX_MMAP_WINDOWS]; } spi_flash; diff --git a/payloads/libpayload/libc/coreboot.c b/payloads/libpayload/libc/coreboot.c index 7a9f997054..2788f870be 100644 --- a/payloads/libpayload/libc/coreboot.c +++ b/payloads/libpayload/libc/coreboot.c @@ -177,6 +177,7 @@ static void cb_parse_spi_flash(void *ptr, struct sysinfo_t *info) info->spi_flash.size = flash->flash_size; info->spi_flash.sector_size = flash->sector_size; info->spi_flash.erase_cmd = flash->erase_cmd; + info->spi_flash.flags = flash->flags; if (flash->mmap_count == 0) return;