[PATCH v2] dfu: dfu_sf: Add support for multiple flashes

Marek Vasut marex at denx.de
Tue Oct 5 14:40:20 CEST 2021


Add dfu_alt_info option which allows specifying multiple SPI flashes
as an alt info. The syntax is as follows:

altname sf bus:cs[:speed[:mode]]

Example:
dfu_alt_info=qspi0 sf 0:0;qspi1 sf 0:1

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Lukasz Majewski <lukma at denx.de>
---
V2: Fix device string parsing in all cases
---
 drivers/dfu/dfu_sf.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index b72493ced86..6d33497990a 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -168,30 +168,46 @@ static struct spi_flash *parse_dev(char *devstr)
 int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s)
 {
 	char *st;
-	char *devstr_bkup = strdup(devstr);
-
-	dfu->data.sf.dev = parse_dev(devstr_bkup);
-	free(devstr_bkup);
-	if (!dfu->data.sf.dev)
-		return -ENODEV;
 
 	dfu->dev_type = DFU_DEV_SF;
-	dfu->max_buf_size = dfu->data.sf.dev->sector_size;
 
 	st = strsep(&s, " ");
 	if (!strcmp(st, "raw")) {
+		char *devstr_bkup = strdup(devstr);
+		dfu->data.sf.dev = parse_dev(devstr_bkup);
+		free(devstr_bkup);
+		if (!dfu->data.sf.dev)
+			return -ENODEV;
+
 		dfu->layout = DFU_RAW_ADDR;
+		dfu->max_buf_size = dfu->data.sf.dev->sector_size;
 		dfu->data.sf.start = hextoul(s, &s);
 		s++;
 		dfu->data.sf.size = hextoul(s, &s);
+	} else if (!strcmp(st, "sf")) {
+		st = strsep(&s, " ");
+		dfu->data.sf.dev = parse_dev(st);
+		if (!dfu->data.sf.dev)
+			return -ENODEV;
+
+		dfu->layout = DFU_RAW_ADDR;
+		dfu->max_buf_size = dfu->data.sf.dev->sector_size;
+		dfu->data.sf.start = 0;
+		dfu->data.sf.size = dfu->data.sf.dev->size;
 	} else if (CONFIG_IS_ENABLED(DFU_SF_PART) &&
 		   (!strcmp(st, "part") || !strcmp(st, "partubi"))) {
+		char *devstr_bkup = strdup(devstr);
 		char mtd_id[32];
 		struct mtd_device *mtd_dev;
 		u8 part_num;
 		struct part_info *pi;
 		int ret, dev, part;
 
+		dfu->data.sf.dev = parse_dev(devstr_bkup);
+		free(devstr_bkup);
+		if (!dfu->data.sf.dev)
+			return -ENODEV;
+
 		dfu->layout = DFU_RAW_ADDR;
 
 		dev = dectoul(s, &s);
@@ -208,6 +224,7 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s)
 			printf("Could not locate '%s'\n", mtd_id);
 			return -1;
 		}
+		dfu->max_buf_size = dfu->data.sf.dev->sector_size;
 		dfu->data.sf.start = pi->offset;
 		dfu->data.sf.size = pi->size;
 		if (!strcmp(st, "partubi"))
-- 
2.33.0



More information about the U-Boot mailing list