mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Carlo Caione <carlo.caione@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH] addpart: size and offset not needed for already defined partitions
Date: Fri, 15 Feb 2013 19:09:01 +0100	[thread overview]
Message-ID: <1360951741-7911-1-git-send-email-carlo.caione@gmail.com> (raw)

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)

Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
 commands/partition.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/commands/partition.c b/commands/partition.c
index fdd6041..8cb50ca 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -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);
-- 
1.8.1.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2013-02-15 18:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15 18:09 Carlo Caione [this message]
2013-02-15 18:28 ` Jean-Christophe PLAGNIOL-VILLARD

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=1360951741-7911-1-git-send-email-carlo.caione@gmail.com \
    --to=carlo.caione@gmail.com \
    --cc=barebox@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