u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Ben Gardiner <bengardiner@nanometrics.ca>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 4/5] mtdparts: add new sub-command "spread"
Date: Mon, 30 Aug 2010 13:38:59 -0400	[thread overview]
Message-ID: <b84ec0e7fd378a060c0226d9c8bb38aaf886df82.1283187599.git.bengardiner@nanometrics.ca> (raw)
In-Reply-To: <1281386640-26918-4-git-send-email-bengardiner@nanometrics.ca>

This patch introduces the 'spread' sub-command of the mtdparts command.
This command will modify the existing mtdparts variable by increasing
the size of the partitions such that 1) each partition's net size is at
least as large as the size specified in the mtdparts variable and 2)
each partition starts on a good block.

The new subcommand is implemented by iterating over the mtd device
partitions and collecting a bad blocks count in each -- including any
trailing bad blocks -- and then modifying that partitions's part_info
structure and checking if the modification affects the next partition.

This patch is based on a port of the 'dynnamic partitions' feature by
Harald Welte <laforge@gnumonks.org>; ported from commit
e05835df019027391f58f9d8ce5e1257d6924798 of
git://git.openmoko.org/u-boot.git. Whereas Harald's feature used a
compile-time array to specify partitions, the feature introduced by
this patch uses the mtdparts environment variable.

Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca>
Signed-off-by: Harald Welte <laforge@gnumonks.org>
CC: Wolfgang Denk <wd@denx.de>
CC: Scott Wood <scottwood@freescale.com>

---

V2:
 * formatting: spaces after 'if' and 'for'
 * trailing whitespace removed
 * check for null mtd->block_isbad before dereferencing

V3:
 * rebased to 54841ab50c20d6fa6c9cc3eb826989da3a22d934 of
   git://git.denx.de/u-boot.git
 * fix more checkpatch errors
 * update copyright statement of cmd_mtdparts.c to include openmoko's
   copyright of the 'dynamic partitions' functionality using commit
   e05835df019027391f58f9d8ce5e1257d6924798 of
   git://git.openmoko.org/u-boot.git as reference.

V4:
 * rebased to b417260d871d4d8d336c160d95ed40cc8c0fb0fa of
   git://git.denx.de/u-boot.git
 * fixed multi-line comment style
 * removed changelog and my (C) from file header
 * added source of port to the commit message
 * fixed multi-line comment style
 * indentation only by tabs

V5:
 * rebased to 962ad59e25640e586e2bceabf67a628a27f8f508 of
   git://git.denx.de/u-boot.git
 * renumbered from 3/4 to 4/5
 * use uint64_t for net_size
 * don't push dangling lines to the right
 * offsets to uint64_t
 * fix spelling errors in comments
 * more hanging arguments alignment
 * refactor the spread_partition function so that it delegates the
   bad-block counting to the mtd_get_len_incl_bad function -- as per
   Scott Woods' suggestion.
---
 common/cmd_mtdparts.c |  110 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 109 insertions(+), 1 deletions(-)

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index a8912ed..fb8c77b 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -15,6 +15,9 @@
  *   Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
  *   kernel tree.
  *
+ * (C) Copyright 2008
+ * Harald Welte, OpenMoko, Inc., Harald Welte <laforge@openmoko.org>
+ *
  *   $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
  *   Copyright 2002 SYSGO Real-Time Solutions GmbH
  *
@@ -1428,6 +1431,98 @@ static int delete_partition(const char *id)
 	return 1;
 }
 
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+/**
+ * Increase the size of the given partition so that it's net size is at least
+ * as large as the size member and such that the next partition would start on a
+ * good block if it were adjacent to this partition.
+ *
+ * @param mtd the mtd device
+ * @param part the partition
+ * @param next_offset pointer to the offset of the next partition after this
+ *                    partition's size has been modified (output)
+ */
+static void spread_partition(struct mtd_info *mtd, struct part_info *part,
+			     uint64_t *next_offset)
+{
+	uint64_t net_size, padding_size = 0;
+	int truncated;
+
+	mtd_get_len_incl_bad(mtd, part->offset, part->size, &net_size,
+			     &truncated);
+
+	/*
+	 * Absorb bad blocks immediately following this
+	 * partition also into the partition, such that
+	 * the next partition starts with a good block.
+	 */
+	if (!truncated) {
+		mtd_get_len_incl_bad(mtd, part->offset + net_size,
+				     mtd->erasesize, &padding_size, &truncated);
+		padding_size -= mtd->erasesize;
+	}
+
+	if (truncated) {
+		printf("truncated partition %s to %lld bytes\n", part->name,
+		       (uint64_t) net_size + padding_size);
+	}
+
+	part->size = net_size + padding_size;
+	*next_offset = part->offset + part->size;
+}
+
+/**
+ * Adjust all of the partition sizes, such that all partitions are at least
+ * as big as their mtdparts environment variable sizes and they each start
+ * on a good block.
+ *
+ * @return 0 on success, 1 otherwise
+ */
+static int spread_partitions(void)
+{
+	struct list_head *dentry, *pentry;
+	struct mtd_device *dev;
+	struct part_info *part;
+	struct mtd_info *mtd;
+	int part_num;
+	uint64_t cur_offs;
+
+	list_for_each(dentry, &devices) {
+		dev = list_entry(dentry, struct mtd_device, link);
+
+		if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+			return 1;
+
+		part_num = 0;
+		cur_offs = 0;
+		list_for_each(pentry, &dev->parts) {
+			part = list_entry(pentry, struct part_info, link);
+
+			debug("spread_partitions: device = %s%d, partition %d ="
+				" (%s) 0x%08x at 0x%08x\n",
+				MTD_DEV_TYPE(dev->id->type), dev->id->num,
+				part_num, part->name, part->size,
+				part->offset);
+
+			if (cur_offs > part->offset)
+				part->offset = cur_offs;
+
+			spread_partition(mtd, part, &cur_offs);
+
+			part_num++;
+		}
+	}
+
+	index_partitions();
+
+	if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
+		printf("generated mtdparts too long, reseting to null\n");
+		return 1;
+	}
+	return 0;
+}
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+
 /**
  * Accept character string describing mtd partitions and call device_parse()
  * for each entry. Add created devices to the global devices list.
@@ -1918,6 +2013,11 @@ int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return delete_partition(argv[2]);
 	}
 
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+	if ((argc == 2) && (strcmp(argv[1], "spread") == 0))
+		return spread_partitions();
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
+
 	return cmd_usage(cmdtp);
 }
 
@@ -1941,7 +2041,15 @@ U_BOOT_CMD(
 	"mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
 	"    - add partition\n"
 	"mtdparts default\n"
-	"    - reset partition table to defaults\n\n"
+	"    - reset partition table to defaults\n"
+#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
+	"mtdparts spread\n"
+	"    - adjust the sizes of the partitions so they are\n"
+	"      at least as big as the mtdparts variable specifies\n"
+	"      and they each start on a good block\n\n"
+#else
+	"\n"
+#endif /* CONFIG_CMD_MTDPARTS_SPREAD */
 	"-----\n\n"
 	"this command uses three environment variables:\n\n"
 	"'partition' - keeps current partition identifier\n\n"
-- 
1.7.0.4

  parent reply	other threads:[~2010-08-30 17:38 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-06 16:28 [U-Boot-Users] [PATCH, resend] Support dynamic/patched NAND ENV offset Harald Welte
2008-07-07 18:47 ` Scott Wood
2008-07-08  0:09   ` Harald Welte
2008-07-08 16:05     ` Scott Wood
2008-07-08 21:12       ` Wolfgang Denk
2008-07-09  0:23         ` Harald Welte
2008-07-09  7:05           ` Wolfgang Denk
2008-07-09  7:25             ` Harald Welte
2008-07-09  8:04               ` Wolfgang Denk
2008-07-09 12:13                 ` Harald Welte
2010-06-01 20:23                 ` [U-Boot] mtdparts: add bad-block skipping Ben Gardiner
2010-06-01 22:20                   ` Wolfgang Denk
2010-06-01 22:34                   ` Wolfgang Denk
2010-06-02  5:08                     ` Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 0/4 v2] " Ben Gardiner
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 0/4] " Ben Gardiner
2010-07-12 19:06                       ` Ben Gardiner
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 " Ben Gardiner
2010-08-30 17:38                         ` [U-Boot] [PATCH v5 0/5] " Ben Gardiner
2010-08-30 17:38                           ` [U-Boot] [PATCH v5 2/5] mtd: add an mtd method for get_len_incl_bad() Ben Gardiner
2010-08-30 20:57                             ` Scott Wood
2010-08-31 13:50                               ` Ben Gardiner
2010-08-31 21:48                             ` [U-Boot] [PATCH v6 " Ben Gardiner
     [not found]                           ` <1283185640-0-git-send-email-bengardiner@nanometrics.ca>
2010-08-30 17:38                             ` [U-Boot] [PATCH v5 3/5] mtdparts: show net size in mtdparts list Ben Gardiner
2010-08-30 20:50                               ` Scott Wood
2010-08-31 13:51                                 ` Ben Gardiner
2010-08-31 15:57                                   ` Scott Wood
2010-08-31 21:48                               ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-08-31 21:47                           ` [U-Boot] [PATCH v6 0/5] mtdparts: add bad-block skipping Ben Gardiner
2010-09-09 20:54                             ` Scott Wood
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 1/4] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 2/4] mtdparts: show net size in mtdparts list Ben Gardiner
2010-08-26 18:57                         ` Scott Wood
2010-08-27 13:51                           ` Ben Gardiner
2010-08-27 15:44                           ` Ben Gardiner
2010-08-27 16:02                             ` Scott Wood
2010-08-27 16:45                               ` Ben Gardiner
2010-08-09 20:43                       ` [U-Boot] [PATCH v4 3/4] mtdparts: add new sub-command "spread" Ben Gardiner
2010-08-26 21:12                         ` Scott Wood
2010-08-27 13:51                           ` Ben Gardiner
2010-08-27 21:36                             ` Ben Gardiner
2010-08-27 21:46                               ` Scott Wood
2010-08-27 21:52                                 ` Ben Gardiner
2010-08-27 21:59                                 ` Scott Wood
2010-08-28  3:59                                   ` Ben Gardiner
2010-08-30 20:24                                     ` Scott Wood
2010-08-30 20:30                                       ` Ben Gardiner
2010-08-30 17:38                         ` Ben Gardiner [this message]
2010-08-30 21:01                           ` [U-Boot] [PATCH v5 4/5] " Scott Wood
2010-08-30 21:05                             ` Scott Wood
2010-08-31 13:51                             ` Ben Gardiner
2010-08-31 21:48                           ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-08-09 20:44                       ` [U-Boot] [PATCH v4 4/4] mtdparts: new add.spread: add part skipping bad blocks Ben Gardiner
2010-08-26 22:26                         ` Scott Wood
2010-08-27 13:52                           ` Ben Gardiner
2010-08-30 17:39                         ` [U-Boot] [PATCH v5 5/5] " Ben Gardiner
2010-08-31 21:48                           ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 1/4] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-08-30 17:38                       ` [U-Boot] [PATCH v5 1/5] " Ben Gardiner
2010-08-31 21:48                         ` [U-Boot] [PATCH v6 " Ben Gardiner
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 2/4] mtdparts: show net size in mtdparts list Ben Gardiner
2010-08-07 20:08                       ` Wolfgang Denk
2010-08-08  4:06                         ` Harald Welte
2010-08-08 13:16                           ` Wolfgang Denk
2010-08-09 14:45                         ` Ben Gardiner
2010-09-18 19:42                           ` Wolfgang Denk
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 3/4] mtdparts: add new sub-command "spread" Ben Gardiner
2010-08-07 20:12                       ` Wolfgang Denk
2010-07-05 21:43                     ` [U-Boot] [PATCH v3 4/4] mtdparts: new add.e: add part skipping bad blocks Ben Gardiner
2010-08-07 20:16                       ` Wolfgang Denk
2010-06-02 15:58                   ` [U-Boot] [PATCH 1/4 v2] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 2/4 v2] mtdparts: show net size in mtdparts list Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 3/4 v2] mtdparts: add new sub-command "spread" Ben Gardiner
2010-06-02 15:58                   ` [U-Boot] [PATCH 4/4 v2] mtdparts: new add.e: add part skipping bad blocks Ben Gardiner
2010-08-09 18:25                     ` Scott Wood
2010-08-09 18:39                       ` Ben Gardiner
2010-08-09 18:51                         ` Scott Wood
2010-06-01 20:23                 ` [U-Boot] [PATCH 1/4] mtdparts: regroup calls to get_mtd_device_nm Ben Gardiner
2010-06-02  7:06                   ` Stefan Roese
2010-06-01 20:23                 ` [U-Boot] [PATCH 2/4] mtdparts: show net size in mtdparts list Ben Gardiner
2010-06-02  7:15                   ` Stefan Roese
2010-06-01 20:23                 ` [U-Boot] [PATCH 3/4] mtdparts: add new sub-command "spread" Ben Gardiner
2010-06-01 20:23                 ` [U-Boot] [PATCH 4/4] mtdparts: new add.e: add part skipping bad blocks Ben Gardiner
2008-07-09  0:18       ` [U-Boot-Users] [PATCH, resend] Support dynamic/patched NAND ENV offset Harald Welte
2008-07-09  5:28       ` Harald Welte
2008-07-09  7:07         ` Harald Welte
2008-07-09  8:11       ` [U-Boot-Users] [PATCH] " Harald Welte
2008-07-11 17:28         ` Scott Wood
2010-05-17 21:04           ` [U-Boot] [PATCH] NAND: Support dynamic location of enviromnent (CONFIG_ENV_OFFSET_OOB) Ben Gardiner
2010-05-26 22:58             ` Scott Wood
2010-05-26 23:38               ` Ben Gardiner
2010-05-31 21:29               ` [U-Boot] [PATCH v2] NAND: environment offset in OOB (CONFIG_ENV_OFFSET_OOB) Ben Gardiner
2010-06-30 21:32                 ` [U-Boot] [PATCH v3] " Ben Gardiner
2010-06-30 21:41                   ` Wolfgang Denk
2010-07-01  4:09                     ` Ben Gardiner
2010-07-01  3:37                   ` Vipin KUMAR
2010-07-01  5:29                     ` Ben Gardiner
2010-07-01  7:17                   ` Harald Welte
2010-07-05 13:57                     ` Ben Gardiner
2010-07-05 17:27                     ` [U-Boot] [PATCH v4] " Ben Gardiner
2010-07-12 16:17                       ` Ben Gardiner
2010-07-12 16:19                         ` Scott Wood
2010-07-13 19:26                       ` Scott Wood
2010-07-13 21:17                         ` Ben Gardiner

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=b84ec0e7fd378a060c0226d9c8bb38aaf886df82.1283187599.git.bengardiner@nanometrics.ca \
    --to=bengardiner@nanometrics.ca \
    --cc=u-boot@lists.denx.de \
    /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;
as well as URLs for NNTP newsgroup(s).