summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
Diffstat (limited to 'disk')
-rw-r--r--disk/part.c58
-rw-r--r--disk/part_amiga.c1
-rw-r--r--disk/part_dos.c52
-rw-r--r--disk/part_efi.c20
-rw-r--r--disk/part_iso.c26
-rw-r--r--disk/part_mac.c1
6 files changed, 86 insertions, 72 deletions
diff --git a/disk/part.c b/disk/part.c
index 6a1c02d9fa..9f51a07676 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -615,3 +615,61 @@ cleanup:
free(dup_str);
return ret;
}
+
+int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
+ disk_partition_t *info)
+{
+ struct part_driver *first_drv =
+ ll_entry_start(struct part_driver, part_driver);
+ const int n_drvs = ll_entry_count(struct part_driver, part_driver);
+ struct part_driver *part_drv;
+
+ for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) {
+ int ret;
+ int i;
+ for (i = 1; i < part_drv->max_entries; i++) {
+ ret = part_drv->get_info(dev_desc, i, info);
+ if (ret != 0) {
+ /* no more entries in table */
+ break;
+ }
+ if (strcmp(name, (const char *)info->name) == 0) {
+ /* matched */
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
+void part_set_generic_name(const struct blk_desc *dev_desc,
+ int part_num, char *name)
+{
+ char *devtype;
+
+ switch (dev_desc->if_type) {
+ case IF_TYPE_IDE:
+ case IF_TYPE_SATA:
+ case IF_TYPE_ATAPI:
+ devtype = "hd";
+ break;
+ case IF_TYPE_SCSI:
+ devtype = "sd";
+ break;
+ case IF_TYPE_USB:
+ devtype = "usbd";
+ break;
+ case IF_TYPE_DOC:
+ devtype = "docd";
+ break;
+ case IF_TYPE_MMC:
+ case IF_TYPE_SD:
+ devtype = "mmcsd";
+ break;
+ default:
+ devtype = "xx";
+ break;
+ }
+
+ sprintf(name, "%s%c%d", devtype, 'a' + dev_desc->devnum, part_num);
+}
diff --git a/disk/part_amiga.c b/disk/part_amiga.c
index d4316b858c..25fe56ce42 100644
--- a/disk/part_amiga.c
+++ b/disk/part_amiga.c
@@ -381,6 +381,7 @@ static void part_print_amiga(struct blk_desc *dev_desc)
U_BOOT_PART_TYPE(amiga) = {
.name = "AMIGA",
.part_type = PART_TYPE_AMIGA,
+ .max_entries = AMIGA_ENTRY_NUMBERS,
.get_info = part_get_info_amiga,
.print = part_print_amiga,
.test = part_test_amiga,
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 511917a444..ed78334a9d 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -209,35 +209,8 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
info->start = (lbaint_t)(ext_part_sector +
le32_to_int(pt->start4));
info->size = (lbaint_t)le32_to_int(pt->size4);
- switch(dev_desc->if_type) {
- case IF_TYPE_IDE:
- case IF_TYPE_SATA:
- case IF_TYPE_ATAPI:
- sprintf((char *)info->name, "hd%c%d",
- 'a' + dev_desc->devnum,
- part_num);
- break;
- case IF_TYPE_SCSI:
- sprintf((char *)info->name, "sd%c%d",
- 'a' + dev_desc->devnum,
- part_num);
- break;
- case IF_TYPE_USB:
- sprintf((char *)info->name, "usbd%c%d",
- 'a' + dev_desc->devnum,
- part_num);
- break;
- case IF_TYPE_DOC:
- sprintf((char *)info->name, "docd%c%d",
- 'a' + dev_desc->devnum,
- part_num);
- break;
- default:
- sprintf((char *)info->name, "xx%c%d",
- 'a' + dev_desc->devnum,
- part_num);
- break;
- }
+ part_set_generic_name(dev_desc, part_num,
+ (char *)info->name);
/* sprintf(info->type, "%d, pt->sys_ind); */
strcpy((char *)info->type, "U-Boot");
info->bootable = is_bootable(pt);
@@ -297,9 +270,30 @@ int part_get_info_dos(struct blk_desc *dev_desc, int part,
return part_get_info_extended(dev_desc, 0, 0, 1, part, info, 0);
}
+int is_valid_dos_buf(void *buf)
+{
+ return test_block_type(buf) == DOS_MBR ? 0 : -1;
+}
+
+int write_mbr_partition(struct blk_desc *dev_desc, void *buf)
+{
+ if (is_valid_dos_buf(buf))
+ return -1;
+
+ /* write MBR */
+ if (blk_dwrite(dev_desc, 0, 1, buf) != 1) {
+ printf("%s: failed writing '%s' (1 blks at 0x0)\n",
+ __func__, "MBR");
+ return 1;
+ }
+
+ return 0;
+}
+
U_BOOT_PART_TYPE(dos) = {
.name = "DOS",
.part_type = PART_TYPE_DOS,
+ .max_entries = DOS_ENTRY_NUMBERS,
.get_info = part_get_info_ptr(part_get_info_dos),
.print = part_print_ptr(part_print_dos),
.test = part_test_dos,
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 8d67c09a43..19243380da 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -296,25 +296,6 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
return 0;
}
-int part_get_info_efi_by_name(struct blk_desc *dev_desc,
- const char *name, disk_partition_t *info)
-{
- int ret;
- int i;
- for (i = 1; i < GPT_ENTRY_NUMBERS; i++) {
- ret = part_get_info_efi(dev_desc, i, info);
- if (ret != 0) {
- /* no more entries in table */
- return -1;
- }
- if (strcmp(name, (const char *)info->name) == 0) {
- /* matched */
- return 0;
- }
- }
- return -2;
-}
-
static int part_test_efi(struct blk_desc *dev_desc)
{
ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
@@ -958,6 +939,7 @@ static int is_pte_valid(gpt_entry * pte)
U_BOOT_PART_TYPE(a_efi) = {
.name = "EFI",
.part_type = PART_TYPE_EFI,
+ .max_entries = GPT_ENTRY_NUMBERS,
.get_info = part_get_info_ptr(part_get_info_efi),
.print = part_print_ptr(part_print_efi),
.test = part_test_efi,
diff --git a/disk/part_iso.c b/disk/part_iso.c
index f9a741d297..bb8ed658f2 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -137,30 +137,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
entry_num=1;
offset=0x20;
strcpy((char *)info->type, "U-Boot");
- switch(dev_desc->if_type) {
- case IF_TYPE_IDE:
- case IF_TYPE_SATA:
- case IF_TYPE_ATAPI:
- sprintf ((char *)info->name, "hd%c%d",
- 'a' + dev_desc->devnum, part_num);
- break;
- case IF_TYPE_SCSI:
- sprintf ((char *)info->name, "sd%c%d",
- 'a' + dev_desc->devnum, part_num);
- break;
- case IF_TYPE_USB:
- sprintf ((char *)info->name, "usbd%c%d",
- 'a' + dev_desc->devnum, part_num);
- break;
- case IF_TYPE_DOC:
- sprintf ((char *)info->name, "docd%c%d",
- 'a' + dev_desc->devnum, part_num);
- break;
- default:
- sprintf ((char *)info->name, "xx%c%d",
- 'a' + dev_desc->devnum, part_num);
- break;
- }
+ part_set_generic_name(dev_desc, part_num, (char *)info->name);
/* the bootcatalog (including validation Entry) is limited to 2048Bytes
* (63 boot entries + validation entry) */
while(offset<2048) {
@@ -257,6 +234,7 @@ static int part_test_iso(struct blk_desc *dev_desc)
U_BOOT_PART_TYPE(iso) = {
.name = "ISO",
.part_type = PART_TYPE_ISO,
+ .max_entries = ISO_ENTRY_NUMBERS,
.get_info = part_get_info_iso,
.print = part_print_iso,
.test = part_test_iso,
diff --git a/disk/part_mac.c b/disk/part_mac.c
index 3952b8d379..b6c082e7e1 100644
--- a/disk/part_mac.c
+++ b/disk/part_mac.c
@@ -239,6 +239,7 @@ static int part_get_info_mac(struct blk_desc *dev_desc, int part,
U_BOOT_PART_TYPE(mac) = {
.name = "MAC",
.part_type = PART_TYPE_MAC,
+ .max_entries = MAC_ENTRY_NUMBERS,
.get_info = part_get_info_mac,
.print = part_print_mac,
.test = part_test_mac,