Skip to contentSkip to conversation

ARM: OMAP: xload: Fix compile without CONFIG_MTD

PATCH Applied Alexander Shiyan 3 participants 7 messages Jun 1, 2022 – Jun 3, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: OMAP: xload: Fix compile without CONFIG_MTD

arm-linux-ld: arch/arm/mach-omap/xload.o: in function read_mtd_barebox':
/home/ARM/barebox/arch/arm/mach-omap/xload.c:75: undefined reference to mtd_peb_read_file'

---
 arch/arm/mach-omap/xload.c | 72 ++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 38 deletions(-)
arch/arm/mach-omap/xload.c +34 -38
index 6d3704b8cf..78b2221304 100644
@@ -53,46 +53,44 @@ static void *read_mtd_barebox(const char *part, unsigned int start, unsigned int
 	struct mtd_info *mtd;
 	unsigned int ps, pe;
 
-	if (!IS_ENABLED(CONFIG_MTD)) {
-		printf("Cannot load from nand/nor: MTD support is disabled\n");
-		return NULL;
-	}
+	if (IS_ENABLED(CONFIG_MTD)) {
+		cdev = cdev_open_by_name(part, O_RDONLY);
+		if (!cdev) {
+			printf("failed to open partition\n");
+			return NULL;
+		}
 
-	cdev = cdev_open_by_name(part, O_RDONLY);
-	if (!cdev) {
-		printf("failed to open partition\n");
-		return NULL;
-	}
+		mtd = cdev->mtd;
+		if (!mtd)
+			return NULL;
 
-	mtd = cdev->mtd;
-	if (!mtd)
-		return NULL;
+		if (mtd_mod_by_eb(start, mtd) != 0) {
+			printf("Start must be eraseblock aligned\n");
+			return NULL;
+		}
 
-	if (mtd_mod_by_eb(start, mtd) != 0) {
-		printf("Start must be eraseblock aligned\n");
-		return NULL;
-	}
+		to = xmalloc(size);
 
-	to = xmalloc(size);
+		ps = mtd_div_by_eb(start, mtd);
+		pe = mtd_div_by_eb(start + size, mtd);
+		ret = mtd_peb_read_file(mtd, ps, pe, to, size);
+		if (ret) {
+			printf("Can't read image from %s: %d\n", part, ret);
+			goto err;
+		}
 
-	ps = mtd_div_by_eb(start, mtd);
-	pe = mtd_div_by_eb(start + size, mtd);
-	ret = mtd_peb_read_file(mtd, ps, pe, to, size);
-	if (ret) {
-		printf("Can't read image from %s: %d\n", part, ret);
-		goto err;
-	}
+		size = get_image_size(to);
+		if (!size) {
+			printf("failed to get image size\n");
+			goto err;
+		}
 
-	size = get_image_size(to);
-	if (!size) {
-		printf("failed to get image size\n");
-		goto err;
-	}
+		return to;
 
-	return to;
+		err:
+		free(to);
+	}
 
-err:
-	free(to);
 	return NULL;
 }
 
@@ -292,7 +290,7 @@ static void *am33xx_net_boot(void)
  */
 static __noreturn int omap_xload(void)
 {
-	void *func;
+	void *func = NULL;
 
 	if (!barebox_part)
 		barebox_part = &default_part;
@@ -310,10 +308,8 @@ static __noreturn int omap_xload(void)
 		} else if (IS_ENABLED(CONFIG_FS_OMAP4_USBBOOT)) {
 			printf("booting from USB\n");
 			func = omap4_xload_boot_usb();
-		} else {
+		} else
 			printf("booting from USB not enabled\n");
-			func = NULL;
-		}
 		break;
 	case BOOTSOURCE_NAND:
 		printf("booting from NAND\n");
@@ -327,16 +323,16 @@ static __noreturn int omap_xload(void)
 		if (IS_ENABLED(CONFIG_OMAP_SERIALBOOT)) {
 			printf("booting from serial\n");
 			func = omap_serial_boot();
-			break;
 		}
+		break;
 	case BOOTSOURCE_NET:
 		if (IS_ENABLED(CONFIG_AM33XX_NET_BOOT)) {
 			printf("booting from NET\n");
 			func = am33xx_net_boot();
-			break;
 		} else {
 			printf("booting from network not enabled\n");
 		}
+		break;
 	default:
 		printf("unknown boot source. Fall back to nand\n");
 		func = omap_xload_boot_nand(barebox_part);
Signature · 7 lines
2.32.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 7 lines · Alexander Shiyan

arm-linux-ld: arch/arm/mach-omap/xload.o: in function read_mtd_barebox':
/home/ARM/barebox/arch/arm/mach-omap/xload.c:75: undefined reference to mtd_peb_read_file'

---
 arch/arm/mach-omap/xload.c | 72 ++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 38 deletions(-)

Applied, thanks

Sascha

Quoted 131 lines
arch/arm/mach-omap/xload.c +34 -38
index 6d3704b8cf..78b2221304 100644
@@ -53,46 +53,44 @@ static void *read_mtd_barebox(const char *part, unsigned int start, unsigned int
 	struct mtd_info *mtd;
 	unsigned int ps, pe;
 
-	if (!IS_ENABLED(CONFIG_MTD)) {
-		printf("Cannot load from nand/nor: MTD support is disabled\n");
-		return NULL;
-	}
+	if (IS_ENABLED(CONFIG_MTD)) {
+		cdev = cdev_open_by_name(part, O_RDONLY);
+		if (!cdev) {
+			printf("failed to open partition\n");
+			return NULL;
+		}
 
-	cdev = cdev_open_by_name(part, O_RDONLY);
-	if (!cdev) {
-		printf("failed to open partition\n");
-		return NULL;
-	}
+		mtd = cdev->mtd;
+		if (!mtd)
+			return NULL;
 
-	mtd = cdev->mtd;
-	if (!mtd)
-		return NULL;
+		if (mtd_mod_by_eb(start, mtd) != 0) {
+			printf("Start must be eraseblock aligned\n");
+			return NULL;
+		}
 
-	if (mtd_mod_by_eb(start, mtd) != 0) {
-		printf("Start must be eraseblock aligned\n");
-		return NULL;
-	}
+		to = xmalloc(size);
 
-	to = xmalloc(size);
+		ps = mtd_div_by_eb(start, mtd);
+		pe = mtd_div_by_eb(start + size, mtd);
+		ret = mtd_peb_read_file(mtd, ps, pe, to, size);
+		if (ret) {
+			printf("Can't read image from %s: %d\n", part, ret);
+			goto err;
+		}
 
-	ps = mtd_div_by_eb(start, mtd);
-	pe = mtd_div_by_eb(start + size, mtd);
-	ret = mtd_peb_read_file(mtd, ps, pe, to, size);
-	if (ret) {
-		printf("Can't read image from %s: %d\n", part, ret);
-		goto err;
-	}
+		size = get_image_size(to);
+		if (!size) {
+			printf("failed to get image size\n");
+			goto err;
+		}
 
-	size = get_image_size(to);
-	if (!size) {
-		printf("failed to get image size\n");
-		goto err;
-	}
+		return to;
 
-	return to;
+		err:
+		free(to);
+	}
 
-err:
-	free(to);
 	return NULL;
 }
 
@@ -292,7 +290,7 @@ static void *am33xx_net_boot(void)
  */
 static __noreturn int omap_xload(void)
 {
-	void *func;
+	void *func = NULL;
 
 	if (!barebox_part)
 		barebox_part = &default_part;
@@ -310,10 +308,8 @@ static __noreturn int omap_xload(void)
 		} else if (IS_ENABLED(CONFIG_FS_OMAP4_USBBOOT)) {
 			printf("booting from USB\n");
 			func = omap4_xload_boot_usb();
-		} else {
+		} else
 			printf("booting from USB not enabled\n");
-			func = NULL;
-		}
 		break;
 	case BOOTSOURCE_NAND:
 		printf("booting from NAND\n");
@@ -327,16 +323,16 @@ static __noreturn int omap_xload(void)
 		if (IS_ENABLED(CONFIG_OMAP_SERIALBOOT)) {
 			printf("booting from serial\n");
 			func = omap_serial_boot();
-			break;
 		}
+		break;
 	case BOOTSOURCE_NET:
 		if (IS_ENABLED(CONFIG_AM33XX_NET_BOOT)) {
 			printf("booting from NET\n");
 			func = am33xx_net_boot();
-			break;
 		} else {
 			printf("booting from network not enabled\n");
 		}
+		break;
 	default:
 		printf("unknown boot source. Fall back to nand\n");
 		func = omap_xload_boot_nand(barebox_part);
Signature · 7 lines
2.32.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
In reply to Alexander Shiyan
Quoted 2 lines · Alexander Shiyan

arm-linux-ld: arch/arm/mach-omap/xload.o: in function read_mtd_barebox':
/home/ARM/barebox/arch/arm/mach-omap/xload.c:75: undefined reference to mtd_peb_read_file'

Am I missing something or does this patch just change

  if (0) {
    return NULL;
  }

/* something */;
return to;

into

  if (0) {
    /* something */
    return to;
  }
  return NULL;

This shouldn't really make a difference. How old is your GCC?

Cheers,
Ahmad

Quoted 127 lines
---
 arch/arm/mach-omap/xload.c | 72 ++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 38 deletions(-)
arch/arm/mach-omap/xload.c +34 -38
index 6d3704b8cf..78b2221304 100644
@@ -53,46 +53,44 @@ static void *read_mtd_barebox(const char *part, unsigned int start, unsigned int
 	struct mtd_info *mtd;
 	unsigned int ps, pe;
 
-	if (!IS_ENABLED(CONFIG_MTD)) {
-		printf("Cannot load from nand/nor: MTD support is disabled\n");
-		return NULL;
-	}
+	if (IS_ENABLED(CONFIG_MTD)) {
+		cdev = cdev_open_by_name(part, O_RDONLY);
+		if (!cdev) {
+			printf("failed to open partition\n");
+			return NULL;
+		}
 
-	cdev = cdev_open_by_name(part, O_RDONLY);
-	if (!cdev) {
-		printf("failed to open partition\n");
-		return NULL;
-	}
+		mtd = cdev->mtd;
+		if (!mtd)
+			return NULL;
 
-	mtd = cdev->mtd;
-	if (!mtd)
-		return NULL;
+		if (mtd_mod_by_eb(start, mtd) != 0) {
+			printf("Start must be eraseblock aligned\n");
+			return NULL;
+		}
 
-	if (mtd_mod_by_eb(start, mtd) != 0) {
-		printf("Start must be eraseblock aligned\n");
-		return NULL;
-	}
+		to = xmalloc(size);
 
-	to = xmalloc(size);
+		ps = mtd_div_by_eb(start, mtd);
+		pe = mtd_div_by_eb(start + size, mtd);
+		ret = mtd_peb_read_file(mtd, ps, pe, to, size);
+		if (ret) {
+			printf("Can't read image from %s: %d\n", part, ret);
+			goto err;
+		}
 
-	ps = mtd_div_by_eb(start, mtd);
-	pe = mtd_div_by_eb(start + size, mtd);
-	ret = mtd_peb_read_file(mtd, ps, pe, to, size);
-	if (ret) {
-		printf("Can't read image from %s: %d\n", part, ret);
-		goto err;
-	}
+		size = get_image_size(to);
+		if (!size) {
+			printf("failed to get image size\n");
+			goto err;
+		}
 
-	size = get_image_size(to);
-	if (!size) {
-		printf("failed to get image size\n");
-		goto err;
-	}
+		return to;
 
-	return to;
+		err:
+		free(to);
+	}
 
-err:
-	free(to);
 	return NULL;
 }
 
@@ -292,7 +290,7 @@ static void *am33xx_net_boot(void)
  */
 static __noreturn int omap_xload(void)
 {
-	void *func;
+	void *func = NULL;
 
 	if (!barebox_part)
 		barebox_part = &default_part;
@@ -310,10 +308,8 @@ static __noreturn int omap_xload(void)
 		} else if (IS_ENABLED(CONFIG_FS_OMAP4_USBBOOT)) {
 			printf("booting from USB\n");
 			func = omap4_xload_boot_usb();
-		} else {
+		} else
 			printf("booting from USB not enabled\n");
-			func = NULL;
-		}
 		break;
 	case BOOTSOURCE_NAND:
 		printf("booting from NAND\n");
@@ -327,16 +323,16 @@ static __noreturn int omap_xload(void)
 		if (IS_ENABLED(CONFIG_OMAP_SERIALBOOT)) {
 			printf("booting from serial\n");
 			func = omap_serial_boot();
-			break;
 		}
+		break;
 	case BOOTSOURCE_NET:
 		if (IS_ENABLED(CONFIG_AM33XX_NET_BOOT)) {
 			printf("booting from NET\n");
 			func = am33xx_net_boot();
-			break;
 		} else {
 			printf("booting from network not enabled\n");
 		}
+		break;
 	default:
 		printf("unknown boot source. Fall back to nand\n");
 		func = omap_xload_boot_nand(barebox_part);
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Hello.

It's just the result of the my master branch not being updated from remote before I made the changes... Sorry :)

чт, 2 июн. 2022 г. в 11:07, Ahmad Fatoum <[email protected]>:

Quoted 15 lines · Alexander Shiyan
Quoted 2 lines

arm-linux-ld: arch/arm/mach-omap/xload.o: in function read_mtd_barebox':
/home/ARM/barebox/arch/arm/mach-omap/xload.c:75: undefined reference to mtd_peb_read_file'

Am I missing something or does this patch just change

  if (0) {
    return NULL;
  }

/* something */;
return to;

into

Quoted 8 lines
  if (0) {
    /* something */
    return to;
  }
  return NULL;

This shouldn't really make a difference. How old is your GCC?

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw
Quoted 13 lines · Alexander Shiyan

Hello.

It's just the result of the my master branch not being updated from remote before I made the changes... Sorry :)

чт, 2 июн. 2022 г. в 11:07, Ahmad Fatoum <[email protected]>:

Quoted 7 lines · Alexander Shiyan
Quoted 2 lines

arm-linux-ld: arch/arm/mach-omap/xload.o: in function read_mtd_barebox':
/home/ARM/barebox/arch/arm/mach-omap/xload.c:75: undefined reference to mtd_peb_read_file'

Am I missing something or does this patch just change

  if (0) {

Typo: if (1)

Quoted 8 lines
Quoted 8 lines
    return NULL;

}

/* something */;
return to;

into

Quoted 8 lines
Quoted 8 lines
  if (0) {
    /* something */
    return to;
  }
  return NULL;

This shouldn't really make a difference. How old is your GCC?

i.e. this patch can be dropped again?

Quoted 1 line
Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

чт, 2 июн. 2022 г. в 12:01, Ahmad Fatoum <[email protected]>:

Quoted 5 lines · Alexander Shiyan
Quoted 4 lines

Hello.

It's just the result of the my master branch not being updated from remote before I made the changes... Sorry :)

...

Quoted 1 line

i.e. this patch can be dropped again?

The logic doesn't change with or without a patch, but yes, we can drop it.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw
In reply to Alexander Shiyan
Quoted 33 lines · Alexander Shiyan

arm-linux-ld: arch/arm/mach-omap/xload.o: in function read_mtd_barebox':
/home/ARM/barebox/arch/arm/mach-omap/xload.c:75: undefined reference to mtd_peb_read_file'

---
 arch/arm/mach-omap/xload.c | 72 ++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 38 deletions(-)

static __noreturn int omap_xload(void)
{

arch/arm/mach-omap/xload.c +2 -5
-	void *func;
+	void *func = NULL;
 
 	if (!barebox_part)
 		barebox_part = &default_part;
@@ -310,10 +308,8 @@ static __noreturn int omap_xload(void)
 		} else if (IS_ENABLED(CONFIG_FS_OMAP4_USBBOOT)) {
 			printf("booting from USB\n");
 			func = omap4_xload_boot_usb();
-		} else {
+		} else
 			printf("booting from USB not enabled\n");
-			func = NULL;
-		}
 		break;
 	case BOOTSOURCE_NAND:
 		printf("booting from NAND\n");
@@ -327,16 +323,16 @@ static __noreturn int omap_xload(void)
 		if (IS_ENABLED(CONFIG_OMAP_SERIALBOOT)) {
 			printf("booting from serial\n");
 			func = omap_serial_boot();
-			break;
 		}

arch/arm/mach-omap/xload.c static __noreturn int omap_xload(void) · line 335

Quoted 10 lines
arch/arm/mach-omap/xload.c +2 -1
+		break;
 	case BOOTSOURCE_NET:
 		if (IS_ENABLED(CONFIG_AM33XX_NET_BOOT)) {
 			printf("booting from NET\n");
 			func = am33xx_net_boot();
-			break;
 		} else {
 			printf("booting from network not enabled\n");
 		}
+		break;

Despite being the first hunk a no-op, these ones look quite useful. Should we make a separate patch from it?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox