mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 8/8] partition command: optionally do not automatically prepend the device name
Date: Sun, 18 Mar 2012 15:26:44 +0100	[thread overview]
Message-ID: <1332080804-13132-9-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1332080804-13132-1-git-send-email-s.hauer@pengutronix.de>

We used to automatically prepend the device name before the partition
name. So when we added a partition named 'barebox' to a device named
'nor0' the partition was named 'nor0.barebox'.

The Kernel can mount its rootfs based on the mtd name, for example with
root=mtd:root. If for example we have multiple mtd devices (nor and nand)
'root' is a bad name for the partition, it should better be 'nor0.root'

This patch adds an additional commandline switch to addpart to optionally
skip the automatic device name adding. This makes it possible to define
our mtd partitions like this:

nor_parts="512k(nor0.barebox)ro,128k(nor0.bareboxenv),2M(nor0.kernel),-(nor0.root)"

This way the barebox partition names stay the same, but we can now
pass the exact name to the kernel (root=mtd:nor0.root).

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/partition.c |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/commands/partition.c b/commands/partition.c
index acd1609..17e3678 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -40,16 +40,19 @@
 #include <fs.h>
 #include <linux/stat.h>
 #include <libgen.h>
+#include <getopt.h>
 
 #define SIZE_REMAINING ((ulong)-1)
 
+#define PART_ADD_DEVNAME (1 << 0)
+
 static int mtd_part_do_parse_one(char *devname, const char *partstr,
 				 char **endp, unsigned long *offset,
-				 off_t devsize, size_t *retsize)
+				 off_t devsize, size_t *retsize, unsigned int pflags)
 {
 	ulong size;
 	char *end;
-	char buf[PATH_MAX];
+	char buf[PATH_MAX] = {};
 	unsigned long flags = 0;
 	int ret;
 
@@ -78,7 +81,8 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 			return -EINVAL;
 		}
 
-		sprintf(buf, "%s.", devname);
+		if (pflags & PART_ADD_DEVNAME)
+			sprintf(buf, "%s.", devname);
 		memcpy(buf + strlen(buf), partstr, end - partstr);
 
 		end++;
@@ -114,24 +118,35 @@ static int do_addpart(int argc, char *argv[])
 	unsigned long offset = 0;
 	off_t devsize;
 	struct stat s;
+	int opt;
+	unsigned int flags = PART_ADD_DEVNAME;
+
+	while ((opt = getopt(argc, argv, "n")) > 0) {
+		switch (opt) {
+		case 'n':
+			flags &= ~PART_ADD_DEVNAME;
+			break;
+		}
+	}
 
-	if (argc != 3)
+	if (argc != optind + 2)
 		return COMMAND_ERROR_USAGE;
 
-	if (stat(argv[1], &s)) {
+	if (stat(argv[optind], &s)) {
 		perror("addpart");
 		return 1;
 	}
 	devsize = s.st_size;
 
-	devname = basename(argv[1]);
+	devname = basename(argv[optind]);
 
-	endp = argv[2];
+	endp = argv[optind + 1];
 
 	while (1) {
 		size_t size = 0;
 
-		if (mtd_part_do_parse_one(devname, endp, &endp, &offset, devsize, &size))
+		if (mtd_part_do_parse_one(devname, endp, &endp, &offset,
+					devsize, &size, flags))
 			return 1;
 
 		offset += size;
@@ -152,6 +167,8 @@ static int do_addpart(int argc, char *argv[])
 BAREBOX_CMD_HELP_START(addpart)
 BAREBOX_CMD_HELP_USAGE("addpart <device> <part_desc>\n")
 BAREBOX_CMD_HELP_SHORT("Add a partition description to a device.\n")
+BAREBOX_CMD_HELP_OPT  ("-n", "no prefix. Do not prepend the device name as prefix before the partition name\n")
+BAREBOX_CMD_HELP_OPT  ("<device>",    "device being worked on\n")
 BAREBOX_CMD_HELP_OPT  ("<device>",    "device being worked on\n")
 BAREBOX_CMD_HELP_OPT  ("<part_desc>", "size1[@offset1](name1)[ro],size2[@offset2](name2)[ro],...\n")
 BAREBOX_CMD_HELP_END
-- 
1.7.9.1


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

      parent reply	other threads:[~2012-03-18 14:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-18 14:26 [PATCH] automount support Sascha Hauer
2012-03-18 14:26 ` [PATCH 1/8] fs: change get_fs_device_by_path prototype Sascha Hauer
2012-03-18 14:26 ` [PATCH 2/8] fs: drop struct mtab_entry Sascha Hauer
2012-03-18 14:26 ` [PATCH 3/8] Add automount support Sascha Hauer
2012-03-18 14:26 ` [PATCH 4/8] fs open: pass error from stat Sascha Hauer
2012-03-18 14:26 ` [PATCH 5/8] hush source: expand $PATH Sascha Hauer
2012-03-18 14:26 ` [PATCH 6/8] FAT: Fix error path Sascha Hauer
2012-03-18 14:26 ` [PATCH 7/8] usb command: by default scan only once for USB devices Sascha Hauer
2012-03-18 14:26 ` Sascha Hauer [this message]

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=1332080804-13132-9-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --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