drivers: fastboot: Add support for SPI flash memory
PATCH v2 1/1 drivers: fastboot: Add support for SPI flash memory
Fastboot currently supports MMC and NAND flash devices. Similarly, extend the support to SPI flash memories.
Note that in this initial implementation, partitions on the device are not supported yet, but raw partitions can be set in u-boot environment.
To define a raw partition descriptor, add an environment variable similar to the MMC case:
``` fastboot_raw_partition_<raw partition name>=<offset> <size> ```
for example:
``` fastboot_raw_partition_boot=0x0 0x1000000 ```
--- drivers/fastboot/Kconfig | 6 +- drivers/fastboot/Makefile | 1 + drivers/fastboot/fb_command.c | 8 + drivers/fastboot/fb_getvar.c | 6 + drivers/fastboot/fb_spi_flash.c | 249 ++++++++++++++++++++++++++++++++ include/fb_spi_flash.h | 40 +++++ 6 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 drivers/fastboot/fb_spi_flash.c create mode 100644 include/fb_spi_flash.h
drivers/fastboot/Kconfig +5 -1
@@ -91,7 +91,7 @@ config FASTBOOT_USB_DEV config FASTBOOT_FLASH bool "Enable FASTBOOT FLASH command" default y if ARCH_SUNXI || ARCH_ROCKCHIP - depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) + depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) || DM_SPI_FLASH select IMAGE_SPARSE help The fastboot protocol includes a "flash" command for writing
@@ -119,6 +119,10 @@ config FASTBOOT_FLASH_NAND bool "FASTBOOT on NAND" depends on MTD_RAW_NAND && CMD_MTDPARTS +config FASTBOOT_FLASH_SPI + bool "FASTBOOT on SPI flash" + depends on DM_SPI_FLASH + endchoice config FASTBOOT_FLASH_MMC_DEV
drivers/fastboot/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-y += fb_getvar.o obj-y += fb_command.o obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o +obj-$(CONFIG_FASTBOOT_FLASH_SPI) += fb_spi_flash.o
drivers/fastboot/fb_command.c +8 -0
@@ -10,6 +10,7 @@#include <fastboot-internal.h> #include <fb_mmc.h> #include <fb_nand.h> +#include <fb_spi_flash.h> #include <part.h> #include <stdlib.h> #include <vsprintf.h>
@@ -344,6 +345,10 @@ static void __maybe_unused flash(char *cmd_parameter, char *response)if (IS_ENABLED (CONFIG_FASTBOOT_FLASH_NAND ))fastboot_nand_flash_write (cmd_parameter, fastboot_buf_addr, image_size, response); + +if (IS_ENABLED (CONFIG_FASTBOOT_FLASH_SPI )) +fastboot_spi_flash_write (cmd_parameter, fastboot_buf_addr, + image_size, response); }/**
@@ -362,6 +367,9 @@ static void __maybe_unused erase(char *cmd_parameter, char *response)if (IS_ENABLED (CONFIG_FASTBOOT_FLASH_NAND ))fastboot_nand_erase (cmd_parameter, response); + +if (IS_ENABLED (CONFIG_FASTBOOT_FLASH_SPI )) +fastboot_spi_flash_erase (cmd_parameter, response); }/**
drivers/fastboot/fb_getvar.c +6 -0
@@ -8,6 +8,7 @@#include <fastboot-internal.h> #include <fb_mmc.h> #include <fb_nand.h> +#include <fb_spi_flash.h> #include <fs.h> #include <part.h> #include <version.h>
@@ -123,6 +124,11 @@ static int getvar_get_part_info(const char *part_name, char *response, r =fastboot_nand_get_part_info (part_name, &part_info, response);if (r >=0 && size) *size = part_info->size; + }else if (IS_ENABLED (CONFIG_FASTBOOT_FLASH_SPI )) { + r =fastboot_spi_flash_get_part_info (part_name, &disk_part, + response); +if (r >=0 && size) + *size = disk_part.size * disk_part.blksz; }else {fastboot_fail ("this storage is not supported in bootloader" , response); r = -ENODEV ;
drivers/fastboot/fb_spi_flash.c new file +249 -0
249 lines not on this page · raw message
include/fb_spi_flash.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2025 Collabora Ltd. +*/ + +#ifndef _FB_SPI_FLASH_H_ +#define _FB_SPI_FLASH_H_ + +#include <part.h> + +/** +* fastboot_spi_flash_get_part_info() - Lookup SPI flash partition by name +* +* @part_name: Named device to lookup +* @part_info: Pointer to returned struct disk_partition +* @response: Pointer to fastboot response buffer +*/ +int fastboot_spi_flash_get_part_info (const char *part_name, +struct disk_partition *part_info, +char *response); + +/** +* fastboot_spi_flash_write() - Write image to SPI flash for fastboot +* +* @cmd: Named device to write image to +* @download_buffer: Pointer to image data +* @download_bytes: Size of image data +* @response: Pointer to fastboot response buffer +*/ +void fastboot_spi_flash_write (const char *cmd,void *download_buffer, +u32 download_bytes,char *response); + +/** +* fastboot_spi_flash_erase() - Erase SPI flash for fastboot +* +* @cmd: Named device to erase +* @response: Pointer to fastboot response buffer +*/ +void fastboot_spi_flash_erase (const char *cmd,char *response); +#endif
Signature · 1 line
2.50.0
Hi Ariel,
Thank you for the patch.
Quoted 5 lines · Ariel D'Alessandro
Fastboot currently supports MMC and NAND flash devices. Similarly, extend the support to SPI flash memories.
Note that in this initial implementation, partitions on the device are not supported yet, but raw partitions can be set in u-boot environment.
nitpick: u-boot -> U-Boot
Quoted 14 lines
To define a raw partition descriptor, add an environment variable similar to the MMC case:
``` fastboot_raw_partition_<raw partition name>=<offset> <size> ```for example:
``` fastboot_raw_partition_boot=0x0 0x1000000 ```
Quoted 8 lines
Signed-off-by Ariel D'Alessandro <[email protected]>--- drivers/fastboot/Kconfig | 6 +- drivers/fastboot/Makefile | 1 + drivers/fastboot/fb_command.c | 8 + drivers/fastboot/fb_getvar.c | 6 + drivers/fastboot/fb_spi_flash.c | 249 ++++++++++++++++++++++++++++++++ include/fb_spi_flash.h | 40 +++++
Can we also include a doc change to doc/android/fastboot.rst ? The current doc mentions:
"Support for both eMMC and NAND devices is included."
We should add SPI flash to that sentence.
Maybe also mention in the "Raw partition descriptors" that this is supported for SPI flash as well.
Quoted 4 lines
6 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 drivers/fastboot/fb_spi_flash.c create mode 100644 include/fb_spi_flash.h
[...]
include/fb_spi_flash.h line 16
Quoted 7 lines
include/fb_spi_flash.h new file +7
-0+ +/** +* fastboot_spi_flash_get_part_info() - Lookup SPI flash partition by name +* +* @part_name: Named device to lookup +* @part_info: Pointer to returned struct disk_partition +* @response: Pointer to fastboot response buffer
Can we add a Return: line to document the return code?
Quoted 26 lines
+ */
include/fb_spi_flash.h new file +23
-0+int fastboot_spi_flash_get_part_info (const char *part_name, +struct disk_partition *part_info, +char *response); + +/** +* fastboot_spi_flash_write() - Write image to SPI flash for fastboot +* +* @cmd: Named device to write image to +* @download_buffer: Pointer to image data +* @download_bytes: Size of image data +* @response: Pointer to fastboot response buffer +*/ +void fastboot_spi_flash_write (const char *cmd,void *download_buffer, +u32 download_bytes,char *response); + +/** +* fastboot_spi_flash_erase() - Erase SPI flash for fastboot +* +* @cmd: Named device to erase +* @response: Pointer to fastboot response buffer +*/ +void fastboot_spi_flash_erase (const char *cmd,char *response); +#endif 2.50.0
Hi Mattijs,
Quoted 6 lines · Mattijs Korpershoek
Hi Ariel,
Thank you for the patch.
On Tue, Jul 15, 2025 at 16:11, Ariel D'Alessandro <[email protected]> wrote:
Quoted 7 lines
Quoted 5 lines
Fastboot currently supports MMC and NAND flash devices. Similarly, extend the support to SPI flash memories.
Note that in this initial implementation, partitions on the device are not supported yet, but raw partitions can be set in u-boot environment.
nitpick: u-boot -> U-Boot
Ack.
Quoted 24 lines
Quoted 15 lines
To define a raw partition descriptor, add an environment variable similar to the MMC case:
``` fastboot_raw_partition_<raw partition name>=<offset> <size> ```for example:
``` fastboot_raw_partition_boot=0x0 0x1000000 ```Quoted 8 lines
Signed-off-by Ariel D'Alessandro <[email protected]>--- drivers/fastboot/Kconfig | 6 +- drivers/fastboot/Makefile | 1 + drivers/fastboot/fb_command.c | 8 + drivers/fastboot/fb_getvar.c | 6 + drivers/fastboot/fb_spi_flash.c | 249 ++++++++++++++++++++++++++++++++ include/fb_spi_flash.h | 40 +++++
Quoted 5 lines
Can we also include a doc change to
doc/android/fastboot.rst? The current doc mentions:
"Support for both eMMC and NAND devices is included."We should add SPI flash to that sentence.
Sure.
Quoted 3 lines
Maybe also mention in the "Raw partition descriptors" that this is supported for SPI flash as well.
Will do.
Quoted 8 lines
Quoted 5 lines
6 files changed, 309 insertions(+), 1 deletion(-)create mode 100644
drivers/fastboot/fb_spi_flash.ccreate mode 100644include/fb_spi_flash.h[...]
Quoted 9 lines
include/fb_spi_flash.h line 16
Quoted 7 lines
include/fb_spi_flash.h new file +7
-0+ +/** +* fastboot_spi_flash_get_part_info() - Lookup SPI flash partition by name +* +* @part_name: Named device to lookup +* @part_info: Pointer to returned struct disk_partition +* @response: Pointer to fastboot response buffer Can we add a Return: line to document the return code?
Sure, will add it to both source and header files.
Quoted 17 lines
Quoted 17 lines
+ */
include/fb_spi_flash.h new file +15
-0+int fastboot_spi_flash_get_part_info (const char *part_name, +struct disk_partition *part_info, +char *response); + +/** +* fastboot_spi_flash_write() - Write image to SPI flash for fastboot +* +* @cmd: Named device to write image to +* @download_buffer: Pointer to image data +* @download_bytes: Size of image data +* @response: Pointer to fastboot response buffer +*/ +void fastboot_spi_flash_write (const char *cmd,void *download_buffer, +u32 download_bytes,char *response); +
Quoted 8 lines
include/fb_spi_flash.h line 40
Quoted 8 lines
include/fb_spi_flash.h new file +8
-0+/** +* fastboot_spi_flash_erase() - Erase SPI flash for fastboot +* +* @cmd: Named device to erase +* @response: Pointer to fastboot response buffer +*/ +void fastboot_spi_flash_erase (const char *cmd,char *response); +#endif
Thanks a lot for the feedback!
Signature · 5 lines
Ariel D'Alessandro Software Engineer Collabora Ltd. Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK Registered in England & Wales, no. 5513718