All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support
@ 2016-09-07 13:06 Petr Kulhavy
  2016-09-07 13:06 ` [U-Boot] [PATCH 1/3] disk: part: implement generic function part_get_info_by_name() Petr Kulhavy
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Petr Kulhavy @ 2016-09-07 13:06 UTC (permalink / raw)
  To: u-boot

This set extends the Fastboot implementation from GPT-only to any partition
support.  Further it adds a special target "mbr" (configurable) to write the
DOS MBR.

Petr Kulhavy (3):
  disk: part: implement generic function part_get_info_by_name()
  fastboot: add support for writing MBR
  disk: part: refactor generic name creation for DOS and ISO

 README                      |  7 +++++
 common/fb_mmc.c             | 44 +++++++++++++++++++++++------
 disk/part.c                 | 58 +++++++++++++++++++++++++++++++++++++
 disk/part_amiga.c           |  1 +
 disk/part_dos.c             | 52 +++++++++++++++-------------------
 disk/part_efi.c             | 20 +------------
 disk/part_iso.c             | 26 ++---------------
 disk/part_mac.c             |  1 +
 doc/README.android-fastboot | 38 +++++++++++++++++++++++++
 include/part.h              | 69 +++++++++++++++++++++++++++++++++++++--------
 10 files changed, 224 insertions(+), 92 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/3] disk: part: implement generic function part_get_info_by_name()
  2016-09-07 13:06 [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Petr Kulhavy
@ 2016-09-07 13:06 ` Petr Kulhavy
  2016-09-08 18:13   ` Tom Rini
  2016-09-07 13:06 ` [U-Boot] [PATCH 2/3] fastboot: add support for writing MBR Petr Kulhavy
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Petr Kulhavy @ 2016-09-07 13:06 UTC (permalink / raw)
  To: u-boot

So far partition search by name has been supported only on the EFI partition
table. This patch extends the search to all partition tables.

Rename part_get_info_efi_by_name() to part_get_info_by_name(), move it from
part_efi.c into part.c and make it a generic function which traverses all part
drivers and searches all partitions (in the order given by the linked list).

For this a new variable struct part_driver.max_entries is added, which limits
the number of partitions searched. For EFI this was GPT_ENTRY_NUMBERS.
Similarly the limit is defined for DOS, ISO, MAC and AMIGA partition tables.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
---
 common/fb_mmc.c   |  4 ++--
 disk/part.c       | 26 ++++++++++++++++++++++++++
 disk/part_amiga.c |  1 +
 disk/part_dos.c   |  1 +
 disk/part_efi.c   | 20 +-------------------
 disk/part_iso.c   |  1 +
 disk/part_mac.c   |  1 +
 include/part.h    | 32 ++++++++++++++++++++------------
 8 files changed, 53 insertions(+), 33 deletions(-)

diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index 8d0524d..a0a4a83 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -27,7 +27,7 @@ static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc,
 {
 	int ret;
 
-	ret = part_get_info_efi_by_name(dev_desc, name, info);
+	ret = part_get_info_by_name(dev_desc, name, info);
 	if (ret) {
 		/* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */
 		char env_alias_name[25 + 32 + 1];
@@ -38,7 +38,7 @@ static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc,
 		strncat(env_alias_name, name, 32);
 		aliased_part_name = getenv(env_alias_name);
 		if (aliased_part_name != NULL)
-			ret = part_get_info_efi_by_name(dev_desc,
+			ret = part_get_info_by_name(dev_desc,
 					aliased_part_name, info);
 	}
 	return ret;
diff --git a/disk/part.c b/disk/part.c
index 6a1c02d..8317e80 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -615,3 +615,29 @@ 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;
+}
diff --git a/disk/part_amiga.c b/disk/part_amiga.c
index d4316b8..25fe56c 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 511917a..8226601 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -300,6 +300,7 @@ int part_get_info_dos(struct blk_desc *dev_desc, int part,
 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 8d67c09..1924338 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 f9a741d..78fc97e 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -257,6 +257,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 3952b8d..b6c082e 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,
diff --git a/include/part.h b/include/part.h
index 226b5be..bd8fd49 100644
--- a/include/part.h
+++ b/include/part.h
@@ -28,6 +28,11 @@ struct block_drvr {
 #define PART_TYPE_AMIGA		0x04
 #define PART_TYPE_EFI		0x05
 
+/* maximum number of partition entries supported by search */
+#define DOS_ENTRY_NUMBERS	8
+#define ISO_ENTRY_NUMBERS	64
+#define MAC_ENTRY_NUMBERS	64
+#define AMIGA_ENTRY_NUMBERS	8
 /*
  * Type string for U-Boot bootable partitions
  */
@@ -146,6 +151,20 @@ int blk_get_device_by_str(const char *ifname, const char *dev_str,
 int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 			    struct blk_desc **dev_desc,
 			    disk_partition_t *info, int allow_whole_dev);
+
+/**
+ * part_get_info_by_name() - Search for a partition by name
+ *                           among all available registered partitions
+ *
+ * @param dev_desc - block device descriptor
+ * @param gpt_name - the specified table entry name
+ * @param info - returns the disk partition info
+ *
+ * @return - '0' on match, '-1' on no match, otherwise error
+ */
+int part_get_info_by_name(struct blk_desc *dev_desc,
+			      const char *name, disk_partition_t *info);
+
 extern const struct block_drvr block_drvr[];
 #else
 static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
@@ -189,6 +208,7 @@ static inline int blk_get_device_part_str(const char *ifname,
 struct part_driver {
 	const char *name;
 	int part_type;
+	const int max_entries;	/* maximum number of entries to search */
 
 	/**
 	 * get_info() - Get information about a partition
@@ -225,18 +245,6 @@ struct part_driver {
 #include <part_efi.h>
 /* disk/part_efi.c */
 /**
- * part_get_info_efi_by_name() - Find the specified GPT partition table entry
- *
- * @param dev_desc - block device descriptor
- * @param gpt_name - the specified table entry name
- * @param info - returns the disk partition info
- *
- * @return - '0' on match, '-1' on no match, otherwise error
- */
-int part_get_info_efi_by_name(struct blk_desc *dev_desc,
-			      const char *name, disk_partition_t *info);
-
-/**
  * write_gpt_table() - Write the GUID Partition Table to disk
  *
  * @param dev_desc - block device descriptor
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 2/3] fastboot: add support for writing MBR
  2016-09-07 13:06 [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Petr Kulhavy
  2016-09-07 13:06 ` [U-Boot] [PATCH 1/3] disk: part: implement generic function part_get_info_by_name() Petr Kulhavy
@ 2016-09-07 13:06 ` Petr Kulhavy
  2016-09-08 18:13   ` Tom Rini
  2016-09-07 13:06 ` [U-Boot] [PATCH 3/3] disk: part: refactor generic name creation for DOS and ISO Petr Kulhavy
  2016-09-08 18:14 ` [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Tom Rini
  3 siblings, 1 reply; 8+ messages in thread
From: Petr Kulhavy @ 2016-09-07 13:06 UTC (permalink / raw)
  To: u-boot

Add special target "mbr" (otherwise configurable via CONFIG_FASTBOOT_MBR_NAME)
to write MBR partition table.
Partitions are now searched using the generic function which finds any
partiiton by name. For MBR the partition names hda1, sda1, etc. are used.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
---
 README                      |  7 +++++++
 common/fb_mmc.c             | 40 ++++++++++++++++++++++++++++++++++------
 disk/part_dos.c             | 20 ++++++++++++++++++++
 doc/README.android-fastboot | 37 +++++++++++++++++++++++++++++++++++++
 include/part.h              | 23 +++++++++++++++++++++++
 5 files changed, 121 insertions(+), 6 deletions(-)

diff --git a/README b/README
index 30d7ee3..f6ef8b8 100644
--- a/README
+++ b/README
@@ -1682,6 +1682,13 @@ The following options need to be configured:
 		"fastboot flash" command line matches this value.
 		Default is GPT_ENTRY_NAME (currently "gpt") if undefined.
 
+		CONFIG_FASTBOOT_MBR_NAME
+		The fastboot "flash" command supports writing the downloaded
+		image to DOS MBR.
+		This occurs when the "partition name" specified on the
+		"fastboot flash" command line matches this value.
+		If not defined the default value "mbr" is used.
+
 - Journaling Flash filesystem support:
 		CONFIG_JFFS2_NAND, CONFIG_JFFS2_NAND_OFF, CONFIG_JFFS2_NAND_SIZE,
 		CONFIG_JFFS2_NAND_DEV
diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index a0a4a83..4bc68a7 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -14,15 +14,20 @@
 #include <mmc.h>
 #include <div64.h>
 
-#ifndef CONFIG_FASTBOOT_GPT_NAME
+#if defined(CONFIG_EFI_PARTITION) && !defined(CONFIG_FASTBOOT_GPT_NAME)
 #define CONFIG_FASTBOOT_GPT_NAME GPT_ENTRY_NAME
 #endif
 
+
+#if defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_FASTBOOT_MBR_NAME)
+#define CONFIG_FASTBOOT_MBR_NAME "mbr"
+#endif
+
 struct fb_mmc_sparse {
 	struct blk_desc	*dev_desc;
 };
 
-static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc,
+static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
 		const char *name, disk_partition_t *info)
 {
 	int ret;
@@ -103,6 +108,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 		return;
 	}
 
+#ifdef CONFIG_EFI_PARTITION
 	if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
 		printf("%s: updating MBR, Primary and Backup GPT(s)\n",
 		       __func__);
@@ -114,14 +120,36 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 		}
 		if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
 			printf("%s: writing GPT partitions failed\n", __func__);
-			fastboot_fail(
-				      "writing GPT partitions failed");
+			fastboot_fail("writing GPT partitions failed");
 			return;
 		}
 		printf("........ success\n");
 		fastboot_okay("");
 		return;
-	} else if (part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info)) {
+	}
+#endif
+
+#ifdef CONFIG_DOS_PARTITION
+	if (strcmp(cmd, CONFIG_FASTBOOT_MBR_NAME) == 0) {
+		printf("%s: updating MBR\n", __func__);
+		if (is_valid_dos_buf(download_buffer)) {
+			printf("%s: invalid MBR - refusing to write to flash\n",
+			       __func__);
+			fastboot_fail("invalid MBR partition");
+			return;
+		}
+		if (write_mbr_partition(dev_desc, download_buffer)) {
+			printf("%s: writing MBR partition failed\n", __func__);
+			fastboot_fail("writing MBR partition failed");
+			return;
+		}
+		printf("........ success\n");
+		fastboot_okay("");
+		return;
+	}
+#endif
+
+	if (part_get_info_by_name_or_alias(dev_desc, cmd, &info)) {
 		error("cannot find partition: '%s'\n", cmd);
 		fastboot_fail("cannot find partition");
 		return;
@@ -172,7 +200,7 @@ void fb_mmc_erase(const char *cmd)
 		return;
 	}
 
-	ret = part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info);
+	ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
 	if (ret) {
 		error("cannot find partition: '%s'", cmd);
 		fastboot_fail("cannot find partition");
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 8226601..8e6aae5 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -297,6 +297,26 @@ 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,
diff --git a/doc/README.android-fastboot b/doc/README.android-fastboot
index ce12bc5..dea7066 100644
--- a/doc/README.android-fastboot
+++ b/doc/README.android-fastboot
@@ -59,6 +59,43 @@ To define a partition alias add an environment variable similar to:
 fastboot_partition_alias_<alias partition name>=<actual partition name>
 Example: fastboot_partition_alias_boot=LNX
 
+Partition Names
+===============
+The Fastboot implementation in U-boot allows to write images into disk
+partitions (currently on eMMC). Target partitions are referred on the host
+computer by their names.
+
+For GPT/EFI the respective partition name is used.
+
+For MBR the partitions are referred by generic names according to the
+following schema:
+
+  <device type> <device index letter> <partition index>
+
+Example: hda3, sdb1, usbda1
+
+The device type is as follows:
+
+  * IDE, ATAPI and SATA disks: hd
+  * SCSI disks: sd
+  * USB media: usbd
+  * Disk on chip: docd
+  * other: xx
+
+The device index starts from 'a' and refers to the interface (e.g. USB
+controller, SD/MMC controller) or disk index. The partition index starts
+from 1 and describes the partition number on the particular device.
+
+Writing Partition Table
+=======================
+Fastboot also allows to write the partition table to the media. This can be
+done by writing the respective partition table image to a special target
+"gpt" or "mbr". These names can be customized by defining the following
+configuration options:
+
+CONFIG_FASTBOOT_GPT_NAME
+CONFIG_FASTBOOT_MBR_NAME
+
 In Action
 =========
 Enter into fastboot by executing the fastboot command in u-boot and you
diff --git a/include/part.h b/include/part.h
index bd8fd49..b17c219 100644
--- a/include/part.h
+++ b/include/part.h
@@ -351,4 +351,27 @@ int gpt_verify_partitions(struct blk_desc *dev_desc,
 			  gpt_header *gpt_head, gpt_entry **gpt_pte);
 #endif
 
+#ifdef CONFIG_DOS_PARTITION
+/**
+ * is_valid_dos_buf() - Ensure that a DOS MBR image is valid
+ *
+ * @param buf - buffer which contains the MBR
+ *
+ * @return - '0' on success, otherwise error
+ */
+int is_valid_dos_buf(void *buf);
+
+/**
+ * write_mbr_partition() - write DOS MBR
+ *
+ * @param dev_desc - block device descriptor
+ * @param buf - buffer which contains the MBR
+ *
+ * @return - '0' on success, otherwise error
+ */
+int write_mbr_partition(struct blk_desc *dev_desc, void *buf);
+
+#endif
+
+
 #endif /* _PART_H */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 3/3] disk: part: refactor generic name creation for DOS and ISO
  2016-09-07 13:06 [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Petr Kulhavy
  2016-09-07 13:06 ` [U-Boot] [PATCH 1/3] disk: part: implement generic function part_get_info_by_name() Petr Kulhavy
  2016-09-07 13:06 ` [U-Boot] [PATCH 2/3] fastboot: add support for writing MBR Petr Kulhavy
@ 2016-09-07 13:06 ` Petr Kulhavy
  2016-09-08 18:13   ` Tom Rini
  2016-09-08 18:14 ` [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Tom Rini
  3 siblings, 1 reply; 8+ messages in thread
From: Petr Kulhavy @ 2016-09-07 13:06 UTC (permalink / raw)
  To: u-boot

In both DOS and ISO partition tables the same code to create partition name
like "hda1" was repeated.

Code moved to into a new function part_set_generic_name() in part.c and optimized.
Added recognition of MMC and SD types, name is like "mmcsda1".

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
---
 disk/part.c                 | 32 ++++++++++++++++++++++++++++++++
 disk/part_dos.c             | 31 ++-----------------------------
 disk/part_iso.c             | 25 +------------------------
 doc/README.android-fastboot |  1 +
 include/part.h              | 14 ++++++++++++++
 5 files changed, 50 insertions(+), 53 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 8317e80..9f51a07 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -641,3 +641,35 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
 	}
 	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_dos.c b/disk/part_dos.c
index 8e6aae5..ed78334 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);
diff --git a/disk/part_iso.c b/disk/part_iso.c
index 78fc97e..bb8ed65 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) {
diff --git a/doc/README.android-fastboot b/doc/README.android-fastboot
index dea7066..b8afa15 100644
--- a/doc/README.android-fastboot
+++ b/doc/README.android-fastboot
@@ -79,6 +79,7 @@ The device type is as follows:
   * IDE, ATAPI and SATA disks: hd
   * SCSI disks: sd
   * USB media: usbd
+  * MMC and SD cards: mmcsd
   * Disk on chip: docd
   * other: xx
 
diff --git a/include/part.h b/include/part.h
index b17c219..0979005 100644
--- a/include/part.h
+++ b/include/part.h
@@ -165,6 +165,20 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 int part_get_info_by_name(struct blk_desc *dev_desc,
 			      const char *name, disk_partition_t *info);
 
+/**
+ * part_set_generic_name() - create generic partition like hda1 or sdb2
+ *
+ * Helper function for partition tables, which don't hold partition names
+ * (DOS, ISO). Generates partition name out of the device type and partition
+ * number.
+ *
+ * @dev_desc:	pointer to the block device
+ * @part_num:	partition number for which the name is generated
+ * @name:	buffer where the name is written
+ */
+void part_set_generic_name(const struct blk_desc *dev_desc,
+	int part_num, char *name);
+
 extern const struct block_drvr block_drvr[];
 #else
 static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/3] disk: part: implement generic function part_get_info_by_name()
  2016-09-07 13:06 ` [U-Boot] [PATCH 1/3] disk: part: implement generic function part_get_info_by_name() Petr Kulhavy
@ 2016-09-08 18:13   ` Tom Rini
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2016-09-08 18:13 UTC (permalink / raw)
  To: u-boot

On Wed, Sep 07, 2016 at 03:06:42PM +0200, Petr Kulhavy wrote:

> So far partition search by name has been supported only on the EFI partition
> table. This patch extends the search to all partition tables.
> 
> Rename part_get_info_efi_by_name() to part_get_info_by_name(), move it from
> part_efi.c into part.c and make it a generic function which traverses all part
> drivers and searches all partitions (in the order given by the linked list).
> 
> For this a new variable struct part_driver.max_entries is added, which limits
> the number of partitions searched. For EFI this was GPT_ENTRY_NUMBERS.
> Similarly the limit is defined for DOS, ISO, MAC and AMIGA partition tables.
> 
> Signed-off-by: Petr Kulhavy <brain@jikos.cz>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160908/e6098c76/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 2/3] fastboot: add support for writing MBR
  2016-09-07 13:06 ` [U-Boot] [PATCH 2/3] fastboot: add support for writing MBR Petr Kulhavy
@ 2016-09-08 18:13   ` Tom Rini
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2016-09-08 18:13 UTC (permalink / raw)
  To: u-boot

On Wed, Sep 07, 2016 at 03:06:43PM +0200, Petr Kulhavy wrote:

> Add special target "mbr" (otherwise configurable via CONFIG_FASTBOOT_MBR_NAME)
> to write MBR partition table.
> Partitions are now searched using the generic function which finds any
> partiiton by name. For MBR the partition names hda1, sda1, etc. are used.
> 
> Signed-off-by: Petr Kulhavy <brain@jikos.cz>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160908/1327d0ae/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 3/3] disk: part: refactor generic name creation for DOS and ISO
  2016-09-07 13:06 ` [U-Boot] [PATCH 3/3] disk: part: refactor generic name creation for DOS and ISO Petr Kulhavy
@ 2016-09-08 18:13   ` Tom Rini
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2016-09-08 18:13 UTC (permalink / raw)
  To: u-boot

On Wed, Sep 07, 2016 at 03:06:44PM +0200, Petr Kulhavy wrote:

> In both DOS and ISO partition tables the same code to create partition name
> like "hda1" was repeated.
> 
> Code moved to into a new function part_set_generic_name() in part.c and optimized.
> Added recognition of MMC and SD types, name is like "mmcsda1".
> 
> Signed-off-by: Petr Kulhavy <brain@jikos.cz>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160908/57af040f/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support
  2016-09-07 13:06 [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Petr Kulhavy
                   ` (2 preceding siblings ...)
  2016-09-07 13:06 ` [U-Boot] [PATCH 3/3] disk: part: refactor generic name creation for DOS and ISO Petr Kulhavy
@ 2016-09-08 18:14 ` Tom Rini
  3 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2016-09-08 18:14 UTC (permalink / raw)
  To: u-boot

On Wed, Sep 07, 2016 at 03:06:41PM +0200, Petr Kulhavy wrote:

> This set extends the Fastboot implementation from GPT-only to any partition
> support.  Further it adds a special target "mbr" (configurable) to write the
> DOS MBR.
> 
> Petr Kulhavy (3):
>   disk: part: implement generic function part_get_info_by_name()
>   fastboot: add support for writing MBR
>   disk: part: refactor generic name creation for DOS and ISO
> 
>  README                      |  7 +++++
>  common/fb_mmc.c             | 44 +++++++++++++++++++++++------
>  disk/part.c                 | 58 +++++++++++++++++++++++++++++++++++++
>  disk/part_amiga.c           |  1 +
>  disk/part_dos.c             | 52 +++++++++++++++-------------------
>  disk/part_efi.c             | 20 +------------
>  disk/part_iso.c             | 26 ++---------------
>  disk/part_mac.c             |  1 +
>  doc/README.android-fastboot | 38 +++++++++++++++++++++++++
>  include/part.h              | 69 +++++++++++++++++++++++++++++++++++++--------
>  10 files changed, 224 insertions(+), 92 deletions(-)

Can you please do a follow up patch where you move both
CONFIG_FASTBOOT_GPT_NAME and CONFIG_FASTBOOT_MBR_NAME in to
cmd/fastboot/Kconfig ?  And then clean up the code since a name will
always be set.  Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160908/07fd8c5a/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-09-08 18:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-07 13:06 [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Petr Kulhavy
2016-09-07 13:06 ` [U-Boot] [PATCH 1/3] disk: part: implement generic function part_get_info_by_name() Petr Kulhavy
2016-09-08 18:13   ` Tom Rini
2016-09-07 13:06 ` [U-Boot] [PATCH 2/3] fastboot: add support for writing MBR Petr Kulhavy
2016-09-08 18:13   ` Tom Rini
2016-09-07 13:06 ` [U-Boot] [PATCH 3/3] disk: part: refactor generic name creation for DOS and ISO Petr Kulhavy
2016-09-08 18:13   ` Tom Rini
2016-09-08 18:14 ` [U-Boot] [PATCH 0/3] Fastboot MBR and generic partition support Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.