public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: "LOH Chee Tim" <cheetim_loh@innomedia.com.sg>
To: <linux-mtd@lists.infradead.org>
Subject: Patch for RedBoot Partition Table Parsing
Date: Wed, 24 Mar 2004 12:00:46 +0800	[thread overview]
Message-ID: <002101c41154$a6339560$0b00a8c0@PIII1200MHzM> (raw)

[-- Attachment #1: Type: text/plain, Size: 725 bytes --]

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

[-- Attachment #2: mtd-snapshot-20040323.diff --]
[-- Type: application/octet-stream, Size: 4353 bytes --]

diff -ru mtd-snapshot-20040323-orig/drivers/mtd/Config.in mtd-snapshot-20040323/drivers/mtd/Config.in
--- mtd-snapshot-20040323-orig/drivers/mtd/Config.in	Sat May 24 06:00:06 2003
+++ mtd-snapshot-20040323/drivers/mtd/Config.in	Fri Mar 19 10:23:29 2004
@@ -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
diff -ru mtd-snapshot-20040323-orig/drivers/mtd/redboot.c mtd-snapshot-20040323/drivers/mtd/redboot.c
--- mtd-snapshot-20040323-orig/drivers/mtd/redboot.c	Thu Jun 26 06:00:07 2003
+++ mtd-snapshot-20040323/drivers/mtd/redboot.c	Thu Mar 18 16:29:00 2004
@@ -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);

             reply	other threads:[~2004-03-24  3:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-24  4:00 LOH Chee Tim [this message]
2004-03-24  9:15 ` Patch for RedBoot Partition Table Parsing David Woodhouse
2004-03-26  2:01   ` LOH Chee Tim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='002101c41154$a6339560$0b00a8c0@PIII1200MHzM' \
    --to=cheetim_loh@innomedia.com.sg \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox