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);
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;
}
return;
}
#endif
+ dev_desc->part_type = PART_TYPE_UNKNOWN;
}
return -1;
}
+
+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;
+}
/* 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);
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; }
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