diff mbox series

[U-Boot,1/2] disk: part: scan the disk if the part_type is unknow

Message ID 1513233549-22018-1-git-send-email-kever.yang@rock-chips.com
State Superseded
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/2] disk: part: scan the disk if the part_type is unknow | expand

Commit Message

Kever Yang Dec. 14, 2017, 6:39 a.m. UTC
We can get the new part table when we write a new partition table to
a blank disk with this patch, or else we have to reset the board
to get new partition table.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
---

 disk/part.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

Comments

Simon Glass Dec. 19, 2017, 3:41 p.m. UTC | #1
Hi Kever,

On 13 December 2017 at 23:39, Kever Yang <kever.yang@rock-chips.com> wrote:
> We can get the new part table when we write a new partition table to
> a blank disk with this patch, or else we have to reset the board
> to get new partition table.
>
> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
> ---
>
>  disk/part.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)

How are you writing the partition table? I wonder if we should rescan
then? Or should we have a flag indicating when we have to scan again?

With your patch, it would not be possible to change the partition type
(e.g. from FAT to EXT4), right?

Regards,
Simon
Kever Yang Dec. 22, 2017, 3:33 a.m. UTC | #2
Hi Simon,


On 12/19/2017 11:41 PM, Simon Glass wrote:
> Hi Kever,
>
> On 13 December 2017 at 23:39, Kever Yang <kever.yang@rock-chips.com> wrote:
>> We can get the new part table when we write a new partition table to
>> a blank disk with this patch, or else we have to reset the board
>> to get new partition table.
>>
>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>> ---
>>
>>   disk/part.c | 24 ++++++++++++++++++------
>>   1 file changed, 18 insertions(+), 6 deletions(-)
> How are you writing the partition table? I wonder if we should rescan
> then? Or should we have a flag indicating when we have to scan again?
>
> With your patch, it would not be possible to change the partition type
> (e.g. from FAT to EXT4), right?

Yes, we are not able to change the partition type runtime now, we have to
reset after we change the partition type.

What I'm doing is a little improve for "blank disk", the old source code
have to reset the board to get the partition table if the disk do not have
any partition info at boot even after I write one with "gpt write" cmd.


Thanks,
- Kever
>
> Regards,
> Simon
>
diff mbox series

Patch

diff --git a/disk/part.c b/disk/part.c
index c04e91a..b007138 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -24,16 +24,28 @@ 
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifdef HAVE_BLOCK_DEVICE
-static struct part_driver *part_driver_lookup_type(int part_type)
+static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv =
 		ll_entry_start(struct part_driver, part_driver);
 	const int n_ents = ll_entry_count(struct part_driver, part_driver);
 	struct part_driver *entry;
 
-	for (entry = drv; entry != drv + n_ents; entry++) {
-		if (part_type == entry->part_type)
-			return entry;
+	if (dev_desc->part_type == PART_TYPE_UNKNOWN) {
+		for (entry = drv; entry != drv + n_ents; entry++) {
+			int ret;
+
+			ret = entry->test(dev_desc);
+			if (!ret) {
+				dev_desc->part_type = entry->part_type;
+				return entry;
+			}
+		}
+	} else {
+		for (entry = drv; entry != drv + n_ents; entry++) {
+			if (dev_desc->part_type == entry->part_type)
+				return entry;
+		}
 	}
 
 	/* Not found */
@@ -286,7 +298,7 @@  void part_print(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv;
 
-	drv = part_driver_lookup_type(dev_desc->part_type);
+	drv = part_driver_lookup_type(dev_desc);
 	if (!drv) {
 		printf("## Unknown partition table type %x\n",
 		       dev_desc->part_type);
@@ -315,7 +327,7 @@  int part_get_info(struct blk_desc *dev_desc, int part,
 	info->type_guid[0] = 0;
 #endif
 
-	drv = part_driver_lookup_type(dev_desc->part_type);
+	drv = part_driver_lookup_type(dev_desc);
 	if (!drv) {
 		debug("## Unknown partition table type %x\n",
 		      dev_desc->part_type);