From: Rob Herring <robherring2@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 3/9] disk/part: introduce get_device_and_partition
Date: Fri, 21 Sep 2012 09:08:17 -0500 [thread overview]
Message-ID: <1348236497-23128-1-git-send-email-robherring2@gmail.com> (raw)
In-Reply-To: <1345757510-6756-4-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 an enhancement over current versions. If no device
or partition is specified on the command line, the bootdevice env variable
will be used (scsiboot does this).
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
v2:
- Keep current behavior removing the bootable partition scanning. This will
be added in follow-up series from Stephen Warren.
disk/part.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
include/part.h | 13 +++++++++--
2 files changed, 78 insertions(+), 4 deletions(-)
diff --git a/disk/part.c b/disk/part.c
index 76f3939..958656c 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -70,7 +70,7 @@ static const struct block_drvr block_drvr[] = {
DECLARE_GLOBAL_DATA_PTR;
-block_dev_desc_t *get_dev(char* ifname, int dev)
+block_dev_desc_t *get_dev(const char *ifname, int dev)
{
const struct block_drvr *drvr = block_drvr;
block_dev_desc_t* (*reloc_get_dev)(int dev);
@@ -97,7 +97,7 @@ block_dev_desc_t *get_dev(char* ifname, int dev)
return NULL;
}
#else
-block_dev_desc_t *get_dev(char* ifname, int dev)
+block_dev_desc_t *get_dev(const char *ifname, int dev)
{
return NULL;
}
@@ -288,6 +288,7 @@ void init_part (block_dev_desc_t * dev_desc)
return;
}
#endif
+ dev_desc->part_type = PART_TYPE_UNKNOWN;
}
@@ -433,3 +434,67 @@ void print_part (block_dev_desc_t * dev_desc)
#endif
#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 = 0;
+ 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) {
+ /* disk doesn't use partition table */
+ if (!desc->lba) {
+ printf("**Bad disk size - %s %d:0 **\n", ifname, dev);
+ return -1;
+ }
+ info->start = 0;
+ info->size = desc->lba;
+ info->blksz = desc->blksz;
+
+ *dev_desc = desc;
+ return 0;
+ }
+
+ part_str = strchr(dev_str, ':');
+ if (part_str)
+ part = (int)simple_strtoul(++part_str, NULL, 16);
+
+ ret = get_partition_info(desc, part, info);
+ if (ret) {
+ printf("** Invalid partition %d, use `dev[:part]' **\n", part);
+ 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;
+}
diff --git a/include/part.h b/include/part.h
index 447f69d..a6d06f3 100644
--- a/include/part.h
+++ b/include/part.h
@@ -98,7 +98,7 @@ typedef struct disk_partition {
/* Misc _get_dev functions */
#ifdef CONFIG_PARTITIONS
-block_dev_desc_t* get_dev(char* ifname, int dev);
+block_dev_desc_t *get_dev(const char *ifname, int dev);
block_dev_desc_t* ide_get_dev(int dev);
block_dev_desc_t* sata_get_dev(int dev);
block_dev_desc_t* scsi_get_dev(int dev);
@@ -112,8 +112,12 @@ int get_partition_info (block_dev_desc_t * dev_desc, int part, disk_partition_t
void print_part (block_dev_desc_t *dev_desc);
void init_part (block_dev_desc_t *dev_desc);
void dev_print(block_dev_desc_t *dev_desc);
+int get_device_and_partition(const char *ifname, const char *dev_str,
+ block_dev_desc_t **dev_desc,
+ disk_partition_t *info);
#else
-static inline block_dev_desc_t* get_dev(char* ifname, int dev) { return NULL; }
+static inline block_dev_desc_t *get_dev(const char *ifname, int dev)
+{ return NULL; }
static inline block_dev_desc_t* ide_get_dev(int dev) { return NULL; }
static inline block_dev_desc_t* sata_get_dev(int dev) { return NULL; }
static inline block_dev_desc_t* scsi_get_dev(int dev) { return NULL; }
@@ -127,6 +131,11 @@ static inline int get_partition_info (block_dev_desc_t * dev_desc, int part,
static inline void print_part (block_dev_desc_t *dev_desc) {}
static inline void init_part (block_dev_desc_t *dev_desc) {}
static inline void dev_print(block_dev_desc_t *dev_desc) {}
+static inline int get_device_and_partition(const char *ifname,
+ const char *dev_str,
+ block_dev_desc_t **dev_desc,
+ disk_partition_t *info)
+{ *dev_desc = NULL; return -1; }
#endif
#ifdef CONFIG_MAC_PARTITION
--
1.7.9.5
next prev parent reply other threads:[~2012-09-21 14:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-23 21:31 [U-Boot] [PATCH 0/9] Auto partition selection and fs partition consolidation Rob Herring
2012-08-23 21:31 ` [U-Boot] [PATCH 1/9] combine block device load commands into common function Rob Herring
2012-09-05 23:36 ` Tom Rini
2012-09-05 23:47 ` Rob Herring
2012-09-05 23:50 ` Tom Rini
2012-09-21 14:02 ` [U-Boot] [PATCH v2 " Rob Herring
2012-09-25 23:17 ` Tom Rini
2012-08-23 21:31 ` [U-Boot] [PATCH 2/9] disk/part: check bootable flag for DOS partitions Rob Herring
2012-08-23 21:31 ` [U-Boot] [PATCH 3/9] disk/part: introduce get_device_and_partition Rob Herring
2012-08-23 22:36 ` Stephen Warren
2012-08-24 1:57 ` Rob Herring
2012-08-24 2:51 ` Stephen Warren
2012-09-05 23:53 ` Tom Rini
2012-09-21 14:08 ` Rob Herring [this message]
2012-08-23 21:31 ` [U-Boot] [PATCH 4/9] ext4: remove init_fs/deinit_fs Rob Herring
2012-08-23 21:31 ` [U-Boot] [PATCH 5/9] cmd_extX: use common get_device_and_partition function Rob Herring
2012-08-23 21:31 ` [U-Boot] [PATCH 6/9] cmd_fat: " Rob Herring
2012-08-23 21:31 ` [U-Boot] [PATCH 7/9] cmd_disk: " Rob Herring
2012-08-23 21:31 ` [U-Boot] [PATCH 8/9] cmd_zfs: " Rob Herring
2012-08-23 21:31 ` [U-Boot] [PATCH 9/9] cmd_reiser: " 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=1348236497-23128-1-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