Skip to contentSkip to conversation

Patch for RedBoot Partition Table Parsing

PATCH LOH Chee Tim 2 participants 3 messages Mar 24, 2004 – Mar 26, 2004 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

The attached patch, against mtd-snapshot-20040323, fixes RedBoot Partition Table Parsing for unallocated flash space before the first image.

Also included are minor updates to:
1. include nullname only if it is used
2. add an option for selecting whether unallocated flash space is to be included
3. follow eCos 2.0 by reading partition table from the whole of last erase block instead of just the start
4. force read-only for RedBoot, RedBoot Config and FIS directory images

Please feel free to comment on the patch and its suitability for inclusion into cvs.

Regards,
Chee Tim
Senior Engineer, Product Development
InnoMedia Pte Ltd
DID: +65 65869142
Tel: +65 68720828 ext 142
Fax: +65 68724006
http://www.innomedia.com

drivers/mtd/Config.in +3 -0
diff -ru mtd-snapshot-20040323-orig/drivers/mtd/Config.in mtd-snapshot-20040323/drivers/mtd/Config.in
@@ -14,6 +14,9 @@
    dep_tristate '  MTD partitioning support' CONFIG_MTD_PARTITIONS $CONFIG_MTD
    dep_tristate '  MTD concatenating support' CONFIG_MTD_CONCAT $CONFIG_MTD
    dep_tristate '  RedBoot partition table parsing' CONFIG_MTD_REDBOOT_PARTS $CONFIG_MTD_PARTITIONS
+   if [ "$CONFIG_MTD_REDBOOT_PARTS" = "y" ]; then
+      dep_bool '  Include unallocated flash space' CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED $CONFIG_MTD_REDBOOT_PARTS
+   fi
    dep_tristate '  Command line partition table parsing' CONFIG_MTD_CMDLINE_PARTS $CONFIG_MTD_PARTITIONS
    if [ "$CONFIG_ARM" = "y" ]; then
       dep_tristate '  ARM Firmware Suite partition parsing' CONFIG_MTD_AFS_PARTS $CONFIG_MTD_PARTITIONS
drivers/mtd/redboot.c +24 -11
diff -ru mtd-snapshot-20040323-orig/drivers/mtd/redboot.c mtd-snapshot-20040323/drivers/mtd/redboot.c
@@ -48,21 +48,24 @@
 	char *names;
 	char *nullname;
 	int namelen = 0;
+	int nulllen = 0;
+#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
 	static char nullstring[] = "unallocated";
+#endif
 
-	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	buf = kmalloc(master->erasesize, GFP_KERNEL);
 
 	if (!buf)
 		return -ENOMEM;
 
 	/* Read the start of the last erase block */
 	ret = master->read(master, master->size - master->erasesize,
-			   PAGE_SIZE, &retlen, (void *)buf);
+			   master->erasesize, &retlen, (void *)buf);
 
 	if (ret)
 		goto out;
 
-	if (retlen != PAGE_SIZE) {
+	if (retlen != master->erasesize) {
 		ret = -EIO;
 		goto out;
 	}
@@ -80,7 +83,7 @@
 		goto out;
 	}
 
-	for (i = 0; i < PAGE_SIZE / sizeof(struct fis_image_desc); i++) {
+	for (i = 0; i < master->erasesize / sizeof(struct fis_image_desc); i++) {
 		struct fis_list *new_fl, **prev;
 
 		if (buf[i].name[0] == 0xff)
@@ -112,48 +115,67 @@
 
 		nrparts++;
 	}
-	if (fl->img->flash_base)
+#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
+	if (fl->img->flash_base) {
 		nrparts++;
+		nulllen = sizeof(nullstring);
+	}
 
 	for (tmp_fl = fl; tmp_fl->next; tmp_fl = tmp_fl->next) {
-		if (tmp_fl->img->flash_base + tmp_fl->img->size + master->erasesize < tmp_fl->next->img->flash_base)
+		if (tmp_fl->img->flash_base + tmp_fl->img->size + master->erasesize <= tmp_fl->next->img->flash_base) {
 			nrparts++;
+			nulllen = sizeof(nullstring);
+		}
 	}
-	parts = kmalloc(sizeof(*parts)*nrparts + sizeof(nullstring) + namelen, GFP_KERNEL);
+#endif
+	parts = kmalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL);
 
 	if (!parts) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
-	memset(parts, 0, sizeof(*parts)*nrparts + namelen);
+	memset(parts, 0, sizeof(*parts)*nrparts + nulllen + namelen);
 
-	/* FIXME: Include nullname only if it's used */
 	nullname = (char *)&parts[nrparts];
-	sprintf(nullname, nullstring);
-	names = nullname + sizeof(nullstring);
+#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
+	if (nulllen > 0) {
+		strcpy(nullname, nullstring);
+	}
+#endif
+	names = nullname + nulllen;
 
 	i=0;
 
+#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
 	if (fl->img->flash_base) {
	       parts[0].name = nullname;
	       parts[0].size = fl->img->flash_base;
	       parts[0].offset = 0;

+ i++;
}
+#endif
for ( ; i<nrparts; i++) {
parts[i].size = fl->img->size; parts[i].offset = fl->img->flash_base; parts[i].name = names;

strcpy(names, fl->img->name);
+ if (!memcmp(names, "RedBoot", 8) ||
+ !memcmp(names, "RedBoot config", 15) ||
+ !memcmp(names, "FIS directory", 14)) {
+ parts[i].mask_flags = MTD_WRITEABLE;
+ }
names += strlen(names)+1;

+#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
if(fl->next && fl->img->flash_base + fl->img->size + master->erasesize <= fl->next->img->flash_base) {
i++;
parts[i].offset = parts[i-1].size + parts[i-1].offset;
parts[i].size = fl->next->img->flash_base - parts[i].offset;
parts[i].name = nullname;
}
+#endif
tmp_fl = fl;
fl = fl->next;
kfree(tmp_fl);

#1 lore raw
Quoted 2 lines · LOH Chee Tim

The attached patch, against mtd-snapshot-20040323, fixes RedBoot Partition Table Parsing for unallocated flash space before the first image.

Thanks.

Quoted 4 lines

Also included are minor updates to:
1. include nullname only if it is used
2. add an option for selecting whether unallocated flash space is to be included

OK. I'd be a lot happier if we had already fixed up the partitioning and could get at a 'whole-device' MTD device reliably, but it does make sense.

Quoted 2 lines

3. follow eCos 2.0 by reading partition table from the whole of last erase block instead of just the start

OK.

Quoted 1 line

4. force read-only for RedBoot, RedBoot Config and FIS directory images

I don't like this very much. I habitually update RedBoot from Linux. I have occasionally been known to change the config and FIS directory too.

Perhaps we could make it optional too?

Please update the Kconfig file to match what you've changed in Config.in.

Signature · 1 line
dwmw2
#2 lore raw
Quoted 8 lines · David Woodhouse
Quoted 4 lines

Also included are minor updates to:
1. include nullname only if it is used
2. add an option for selecting whether unallocated flash space is to be included

OK. I'd be a lot happier if we had already fixed up the partitioning and could get at a 'whole-device' MTD device reliably, but it does make sense.

Can you please elaborate more on the issue so that I can try to help?

Quoted 9 lines
Quoted 1 line

4. force read-only for RedBoot, RedBoot Config and FIS directory images

I don't like this very much. I habitually update RedBoot from Linux. I have occasionally been known to change the config and FIS directory too.

Perhaps we could make it optional too?

Please update the Kconfig file to match what you've changed in Config.in.

Please find attached the new patch against mtd-snapshot-20040323 that makes forcing read-only of RedBoot system images optional and the updated Kconfig file to match the changes to Config.in.

Regards,
Chee Tim
Senior Engineer, Product Development
InnoMedia Pte Ltd
DID: +65 65869142
Tel: +65 68720828 ext 142
Fax: +65 68724006
http://www.innomedia.com

drivers/mtd/Config.in +4 -0
diff -ru mtd-snapshot-20040323-orig/drivers/mtd/Config.in mtd-snapshot-20040323/drivers/mtd/Config.in
@@ -14,6 +14,10 @@
    dep_tristate '  MTD partitioning support' CONFIG_MTD_PARTITIONS $CONFIG_MTD
    dep_tristate '  MTD concatenating support' CONFIG_MTD_CONCAT $CONFIG_MTD
    dep_tristate '  RedBoot partition table parsing' CONFIG_MTD_REDBOOT_PARTS $CONFIG_MTD_PARTITIONS
+   if [ "$CONFIG_MTD_REDBOOT_PARTS" = "y" -o "$CONFIG_MTD_REDBOOT_PARTS" = "m" ]; then
+      bool '  Include unallocated flash space' CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
+      bool '  Force read-only for RedBoot system images' CONFIG_MTD_REDBOOT_PARTS_READONLY
+   fi
    dep_tristate '  Command line partition table parsing' CONFIG_MTD_CMDLINE_PARTS $CONFIG_MTD_PARTITIONS
    if [ "$CONFIG_ARM" = "y" ]; then
       dep_tristate '  ARM Firmware Suite partition parsing' CONFIG_MTD_AFS_PARTS $CONFIG_MTD_PARTITIONS
drivers/mtd/Kconfig +14 -0
diff -ru mtd-snapshot-20040323-orig/drivers/mtd/Kconfig mtd-snapshot-20040323/drivers/mtd/Kconfig
@@ -68,6 +68,20 @@
 	  SA1100 map driver (CONFIG_MTD_SA1100) has an option for this, for 
 	  example.
 
+config MTD_REDBOOT_PARTS_UNALLOCATED
+	bool "  Include unallocated flash regions"
+	depends on MTD_REDBOOT_PARTS
+	help
+	  If you need to register each unallocated flash region as a MTD
+	  'partition', enable this option.
+
+config MTD_REDBOOT_PARTS_READONLY
+	bool "  Force read-only for RedBoot system images"
+	depends on MTD_REDBOOT_PARTS
+	help
+	  If you need to force read-only for 'RedBoot', 'RedBoot Config' and
+	  'FIS directory' images, enable this option.
+
 config MTD_CMDLINE_PARTS
 	tristate "Command line partition table parsing"
 	depends on MTD_PARTITIONS
drivers/mtd/redboot.c +35 -11

111 lines not on this page · raw message