From: Rob Herring <robherring2@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 2/5] disk/part: introduce get_device_and_partition
Date: Tue, 6 Mar 2012 17:41:09 -0600 [thread overview]
Message-ID: <1331077272-25215-3-git-send-email-robherring2@gmail.com> (raw)
In-Reply-To: <1331077272-25215-1-git-send-email-robherring2@gmail.com>
From: Rob Herring <rob.herring@calxeda.com>
All block device related commands (scsiboot, fatload, ext2ls, etc.) have
simliar duplicated device and partition parsing and selection code. This
adds a common function to replace various implementations.
The new function has some enhancements over current versions. If no device
or partition is specified on the command line, the bootdevice env variable
will be used (scsiboot does this). If the partition is not specified and
the device has partitions, then the first bootable partition will be used.
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
disk/part.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/part.h | 4 +++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/disk/part.c b/disk/part.c
index f07a17f..e892c8d 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -291,6 +291,7 @@ void init_part (block_dev_desc_t * dev_desc)
return;
}
#endif
+ dev_desc->part_type = PART_TYPE_UNKNOWN;
}
@@ -435,4 +436,63 @@ void print_part (block_dev_desc_t * dev_desc)
# error nor CONFIG_EFI_PARTITION configured!
#endif
+int get_device_and_partition(const char *ifname, const char *dev_str,
+ block_dev_desc_t **dev_desc,
+ disk_partition_t *info)
+{
+ int ret;
+ char *ep;
+ int dev;
+ block_dev_desc_t *desc;
+ int part = 1;
+ int do_scan_part = 1;
+ char *part_str;
+
+ if (dev_str)
+ dev = simple_strtoul(dev_str, &ep, 16);
+
+ if (!dev_str || (dev_str == ep)) {
+ dev_str = getenv("bootdevice");
+ if (dev_str)
+ dev = simple_strtoul(dev_str, &ep, 16);
+ if (!dev_str || dev_str == ep)
+ goto err;
+ }
+
+ desc = get_dev(ifname, dev);
+ if (!desc || (desc->type == DEV_TYPE_UNKNOWN))
+ goto err;
+
+ if (desc->part_type == PART_TYPE_UNKNOWN)
+ return 0;
+
+ part_str = strchr(dev_str, ':');
+ if (part_str) {
+ part = (int)simple_strtoul(++part_str, NULL, 16);
+ do_scan_part = 0;
+ }
+
+ while ((ret = get_partition_info(desc, part, info)) == 0 &&
+ !info->bootable && do_scan_part)
+ part++;
+
+ if (ret) {
+ puts("** Invalid partition, use `dev[:part]' **\n");
+ return -1;
+ }
+ if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) {
+ printf("** Invalid partition type \"%.32s\""
+ " (expect \"" BOOT_PART_TYPE "\")\n",
+ info->type);
+ return -1;
+ }
+
+ *dev_desc = desc;
+ return part;
+
+ err:
+ puts("** Invalid boot device, use `dev[:part]' **\n");
+ return -1;
+}
+
#endif
diff --git a/include/part.h b/include/part.h
index 79a3493..e44ca49 100644
--- a/include/part.h
+++ b/include/part.h
@@ -129,6 +129,10 @@ static inline void init_part (block_dev_desc_t *dev_desc) {}
static inline void dev_print(block_dev_desc_t *dev_desc) {}
#endif
+int get_device_and_partition(const char *ifname, const char *dev_str,
+ block_dev_desc_t **dev_desc,
+ disk_partition_t *info);
+
#ifdef CONFIG_MAC_PARTITION
/* disk/part_mac.c */
int get_partition_info_mac (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
--
1.7.5.4
next prev parent reply other threads:[~2012-03-06 23:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-06 23:41 [U-Boot] [RFC PATCH 0/5] add bootable partition support Rob Herring
2012-03-06 23:41 ` [U-Boot] [RFC PATCH 1/5] disk/part: check bootable flag for DOS partitions Rob Herring
2012-03-06 23:41 ` Rob Herring [this message]
2012-03-06 23:41 ` [U-Boot] [RFC PATCH 3/5] cmd_ext2: use common get_device_and_partition function Rob Herring
2012-03-06 23:41 ` [U-Boot] [RFC PATCH 4/5] cmd_fat: " Rob Herring
2012-03-06 23:41 ` [U-Boot] [RFC PATCH 5/5] cmd_scsi: " Rob Herring
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=1331077272-25215-3-git-send-email-robherring2@gmail.com \
--to=robherring2@gmail.com \
--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