Skip to contentSkip to conversation

dfu: Call backend specific dfu_fill_*() only if enabled

PATCH In review Marek Vasut 3 participants 4 messages Nov 28, 2022 – Nov 30, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dfu: Call backend specific dfu_fill_*() only if enabled

The dfu_fill_*() functions are available only if the matching backend is enabled. Add missing CONFIG_IS_ENABLED() guard for each backend to prevent build errors, in case such a backend is enabled in U-Boot and not in SPL or vice versa.

---
Cc: Lukasz Majewski <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>

---
 drivers/dfu/dfu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dfu/dfu.c +6 -6
index 516dda61796..f9679d5ee52 100644
@@ -529,22 +529,22 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
 	dfu->free_entity = NULL;
 
 	/* Specific for mmc device */
-	if (strcmp(interface, "mmc") == 0) {
+	if (CONFIG_IS_ENABLED(DFU_MMC) && !strcmp(interface, "mmc")) {
 		if (dfu_fill_entity_mmc(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "mtd") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_MTD) && !strcmp(interface, "mtd")) {
 		if (dfu_fill_entity_mtd(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "nand") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_NAND) && !strcmp(interface, "nand")) {
 		if (dfu_fill_entity_nand(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "ram") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_RAM) && !strcmp(interface, "ram")) {
 		if (dfu_fill_entity_ram(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "sf") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_SF) && !strcmp(interface, "sf")) {
 		if (dfu_fill_entity_sf(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "virt") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_VIRT) && !strcmp(interface, "virt")) {
 		if (dfu_fill_entity_virt(dfu, devstr, argv, argc))
 			return -1;
 	} else {
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Marek

Quoted 37 lines · Marek Vasut

The dfu_fill_*() functions are available only if the matching backend is enabled. Add missing CONFIG_IS_ENABLED() guard for each backend to prevent build errors, in case such a backend is enabled in U-Boot and not in SPL or vice versa.

---
Cc: Lukasz Majewski <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>

---
 drivers/dfu/dfu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dfu/dfu.c +4 -4
index 516dda61796..f9679d5ee52 100644
@@ -529,22 +529,22 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
 	dfu->free_entity = NULL;
 
 	/* Specific for mmc device */
-	if (strcmp(interface, "mmc") == 0) {
+	if (CONFIG_IS_ENABLED(DFU_MMC) && !strcmp(interface, "mmc")) {
 		if (dfu_fill_entity_mmc(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "mtd") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_MTD) && !strcmp(interface, "mtd")) {
 		if (dfu_fill_entity_mtd(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "nand") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_NAND) && !strcmp(interface, "nand")) {
 		if (dfu_fill_entity_nand(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "ram") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_RAM) && !strcmp(interface, "ram")) {
 		if (dfu_fill_entity_ram(dfu, devstr, argv, argc))

drivers/dfu/dfu.c static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, · line 550

Quoted 10 lines
drivers/dfu/dfu.c +2 -2
 			return -1;
-	} else if (strcmp(interface, "sf") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_SF) && !strcmp(interface, "sf")) {
 		if (dfu_fill_entity_sf(dfu, devstr, argv, argc))
 			return -1;
-	} else if (strcmp(interface, "virt") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_VIRT) && !strcmp(interface, "virt")) {
 		if (dfu_fill_entity_virt(dfu, devstr, argv, argc))
 			return -1;
 	} else {

Thanks
Patrice

#2 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 37 lines · Marek Vasut

The dfu_fill_*() functions are available only if the matching backend is enabled. Add missing CONFIG_IS_ENABLED() guard for each backend to prevent build errors, in case such a backend is enabled in U-Boot and not in SPL or vice versa.

---
Cc: Lukasz Majewski <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>

---
  drivers/dfu/dfu.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dfu/dfu.c +4 -4
index 516dda61796..f9679d5ee52 100644
@@ -529,22 +529,22 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
  	dfu->free_entity = NULL;
 
  	/* Specific for mmc device */
-	if (strcmp(interface, "mmc") == 0) {
+	if (CONFIG_IS_ENABLED(DFU_MMC) && !strcmp(interface, "mmc")) {
  		if (dfu_fill_entity_mmc(dfu, devstr, argv, argc))
  			return -1;
-	} else if (strcmp(interface, "mtd") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_MTD) && !strcmp(interface, "mtd")) {
  		if (dfu_fill_entity_mtd(dfu, devstr, argv, argc))
  			return -1;
-	} else if (strcmp(interface, "nand") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_NAND) && !strcmp(interface, "nand")) {
  		if (dfu_fill_entity_nand(dfu, devstr, argv, argc))
  			return -1;
-	} else if (strcmp(interface, "ram") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_RAM) && !strcmp(interface, "ram")) {
  		if (dfu_fill_entity_ram(dfu, devstr, argv, argc))

drivers/dfu/dfu.c static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, · line 550

Quoted 10 lines
drivers/dfu/dfu.c +2 -2
  			return -1;
-	} else if (strcmp(interface, "sf") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_SF) && !strcmp(interface, "sf")) {
  		if (dfu_fill_entity_sf(dfu, devstr, argv, argc))
  			return -1;
-	} else if (strcmp(interface, "virt") == 0) {
+	} else if (CONFIG_IS_ENABLED(DFU_VIRT) && !strcmp(interface, "virt")) {
  		if (dfu_fill_entity_virt(dfu, devstr, argv, argc))
  			return -1;
  	} else {

All these DFU backend functions are stubbed in API = include/dfu.h

for example:

#if CONFIG_IS_ENABLED(DFU_MMC)
extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char **argv, int argc);
#else
static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char **argv, int argc)
{
    puts("MMC support not available!\n");
    return -1;
}
#endif

I think the only issue here is the test for CONFIG_DFU_VIRT

=> my patch which add this backend is not SPL friendly

-  #ifdef CONFIG_DFU_VIRT

+ #if CONFIG_IS_ENABLED(DFU_VIRT)

it is a fixes for commit ec44cace4b8d2 ("dfu: add DFU virtual backend")

I just pushed this correction...

"dfu: Make DFU virtual backend SPL friendly"

http://patchwork.ozlabs.org/project/uboot/patch/20221130114146.1.I1944fc560e894329a83e9cf8f50cab3610f4f334@changeid/

Regards

Patrick

#3 lore raw
Quoted 83 lines · Patrick DELAUNAY

Hi Marek,

Quoted 47 lines · Marek Vasut

The dfu_fill_*() functions are available only if the matching backend is enabled. Add missing CONFIG_IS_ENABLED() guard for each backend to prevent build errors, in case such a backend is enabled in U-Boot and not in SPL or vice versa.

---
Cc: Lukasz Majewski <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
---
  drivers/dfu/dfu.c | 12 ++++++------

  1 file changed, 6 insertions(+), 6 deletions(-)
drivers/dfu/dfu.c +6 -6
index 516dda61796..f9679d5ee52 100644
@@ -529,22 +529,22 @@ static int dfu_fill_entity(struct dfu_entity 
 *dfu, char *s, int alt,
       dfu->free_entity = NULL;
       /* Specific for mmc device */
-    if (strcmp(interface, "mmc") == 0) {
+    if (CONFIG_IS_ENABLED(DFU_MMC) && !strcmp(interface, "mmc")) {
           if (dfu_fill_entity_mmc(dfu, devstr, argv, argc))
               return -1;
-    } else if (strcmp(interface, "mtd") == 0) {
+    } else if (CONFIG_IS_ENABLED(DFU_MTD) && !strcmp(interface, 
 "mtd")) {
           if (dfu_fill_entity_mtd(dfu, devstr, argv, argc))
               return -1;
-    } else if (strcmp(interface, "nand") == 0) {
+    } else if (CONFIG_IS_ENABLED(DFU_NAND) && !strcmp(interface, 
 "nand")) {
           if (dfu_fill_entity_nand(dfu, devstr, argv, argc))
               return -1;
-    } else if (strcmp(interface, "ram") == 0) {
+    } else if (CONFIG_IS_ENABLED(DFU_RAM) && !strcmp(interface, 
 "ram")) {
           if (dfu_fill_entity_ram(dfu, devstr, argv, argc))
               return -1;
-    } else if (strcmp(interface, "sf") == 0) {
+    } else if (CONFIG_IS_ENABLED(DFU_SF) && !strcmp(interface, "sf")) {
           if (dfu_fill_entity_sf(dfu, devstr, argv, argc))
               return -1;
-    } else if (strcmp(interface, "virt") == 0) {
+    } else if (CONFIG_IS_ENABLED(DFU_VIRT) && !strcmp(interface, 
Quoted 4 lines

"virt")) {
          if (dfu_fill_entity_virt(dfu, devstr, argv, argc)) return -1;
      } else {

All these DFU backend functions are stubbed in API = include/dfu.h

for example:

#if CONFIG_IS_ENABLED(DFU_MMC)
extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr,
                   char **argv, int argc);
#else
static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr,
                      char **argv, int argc)
{
    puts("MMC support not available!\n");
    return -1;
}
#endif

I think the only issue here is the test for CONFIG_DFU_VIRT

=> my patch which add this backend is not SPL friendly

-  #ifdef CONFIG_DFU_VIRT

+ #if CONFIG_IS_ENABLED(DFU_VIRT)

Quoted 8 lines

it is a fixes for commit ec44cace4b8d2 ("dfu: add DFU virtual backend")

I just pushed this correction...

"dfu: Make DFU virtual backend SPL friendly"

http://patchwork.ozlabs.org/project/uboot/patch/20221130114146.1.I1944fc560e894329a83e9cf8f50cab3610f4f334@changeid/

That's even better, I'll review the other patch ... shortly ... sorry for the massive delays.