Skip to contentSkip to conversation

addpart: size and offset not needed for already defined partitions

PATCH In review Carlo Caione 2 participants 2 messages Feb 15, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 addpart: size and offset not needed for already defined partitions

You can use the name of an already defined partition (i.e. hardcoded in board specific files) without specifying size and offset that are automatically obtained

i.e.

$ addpart /dev/nor0 (self)
$ addpart /dev/nor0 (env0)
---
 commands/partition.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
commands/partition.c +14 -1
index fdd6041..8cb50ca 100644
@@ -53,6 +53,7 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 	char buf[PATH_MAX] = {};
 	unsigned long flags = 0;
 	int ret;
+	struct cdev *cdev;
 
 	memset(buf, 0, PATH_MAX);
 
@@ -63,7 +64,7 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 		size = strtoul_suffix(partstr, &end, 0);
 	}
 
-	if (*end == '@')
+	if ((*end == '@') && (size != 0))
 		*offset = strtoul_suffix(end+1, &end, 0);
 
 	if (size == SIZE_REMAINING)
@@ -78,6 +79,18 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 			printf("could not find matching ')'\n");
 			return -EINVAL;
 		}
+		memcpy(buf, partstr, end - partstr);
+
+		if (size == 0) {
+			cdev = cdev_by_name(buf);
+			if (!cdev) {
+				printf("%s: partition not found\n", buf);
+				return -EINVAL;
+			}
+
+			size = cdev->size;
+			*offset = cdev->offset;
+		}
 
 		if (pflags & PART_ADD_DEVNAME)
 			sprintf(buf, "%s.", devname);
Signature · 7 lines
1.8.1.3


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 8 lines · Carlo Caione

You can use the name of an already defined partition (i.e. hardcoded in board specific files) without specifying size and offset that are automatically obtained

i.e.

$ addpart /dev/nor0 (self)
$ addpart /dev/nor0 (env0)

this is dangerous

specialy when you can knwon for sure that (self) will be in the nor flash

as on sama5d3x as we can boot from different media and barebox detect it so the self will spi/nor/nand/mmc/eeprom

Best Regards,
J.

Quoted 54 lines
---
 commands/partition.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
commands/partition.c +14 -1
index fdd6041..8cb50ca 100644
@@ -53,6 +53,7 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 	char buf[PATH_MAX] = {};
 	unsigned long flags = 0;
 	int ret;
+	struct cdev *cdev;
 
 	memset(buf, 0, PATH_MAX);
 
@@ -63,7 +64,7 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 		size = strtoul_suffix(partstr, &end, 0);
 	}
 
-	if (*end == '@')
+	if ((*end == '@') && (size != 0))
 		*offset = strtoul_suffix(end+1, &end, 0);
 
 	if (size == SIZE_REMAINING)
@@ -78,6 +79,18 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 			printf("could not find matching ')'\n");
 			return -EINVAL;
 		}
+		memcpy(buf, partstr, end - partstr);
+
+		if (size == 0) {
+			cdev = cdev_by_name(buf);
+			if (!cdev) {
+				printf("%s: partition not found\n", buf);
+				return -EINVAL;
+			}
+
+			size = cdev->size;
+			*offset = cdev->offset;
+		}
 
 		if (pflags & PART_ADD_DEVNAME)
 			sprintf(buf, "%s.", devname);
Signature · 7 lines
1.8.1.3


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

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