All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow
@ 2017-12-14  6:39 Kever Yang
  2017-12-14  6:39 ` [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver Kever Yang
  2017-12-19 15:41 ` [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow Simon Glass
  0 siblings, 2 replies; 7+ messages in thread
From: Kever Yang @ 2017-12-14  6:39 UTC (permalink / raw)
  To: u-boot

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(-)

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);
-- 
1.9.1

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

* [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver
  2017-12-14  6:39 [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow Kever Yang
@ 2017-12-14  6:39 ` Kever Yang
  2017-12-14  9:53   ` Dr. Philipp Tomsich
  2017-12-19 15:41 ` [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow Simon Glass
  1 sibling, 1 reply; 7+ messages in thread
From: Kever Yang @ 2017-12-14  6:39 UTC (permalink / raw)
  To: u-boot

Do not need to scan disk every time when we get part info
by name.

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

 disk/part.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index b007138..96c2858 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -638,26 +638,23 @@ cleanup:
 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;
+	int ret;
+	int i;
 
-	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 i;
-			}
+	part_drv = part_driver_lookup_type(dev_desc);
+	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 i;
 		}
 	}
+
 	return -1;
 }
 
-- 
1.9.1

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

* [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver
  2017-12-14  6:39 ` [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver Kever Yang
@ 2017-12-14  9:53   ` Dr. Philipp Tomsich
  2017-12-15  2:34     ` Kever Yang
  0 siblings, 1 reply; 7+ messages in thread
From: Dr. Philipp Tomsich @ 2017-12-14  9:53 UTC (permalink / raw)
  To: u-boot

Kever,

> On 14 Dec 2017, at 07:39, Kever Yang <kever.yang@rock-chips.com> wrote:
> 
> Do not need to scan disk every time when we get part info
> by name.

How does this interact with USB devices?
I.e.: what happens, when you get the partition-info for a usb drive, then change
the attached usb drive (with only a single one attached, but a different one) and
do a ‘usb rescan’?

Regards,
Philipp.

> 
> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
> ---
> 
> disk/part.c | 29 +++++++++++++----------------
> 1 file changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/disk/part.c b/disk/part.c
> index b007138..96c2858 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -638,26 +638,23 @@ cleanup:
> 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;
> +	int ret;
> +	int i;
> 
> -	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 i;
> -			}
> +	part_drv = part_driver_lookup_type(dev_desc);
> +	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 i;
> 		}
> 	}
> +
> 	return -1;
> }
> 
> -- 
> 1.9.1
> 

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

* [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver
  2017-12-14  9:53   ` Dr. Philipp Tomsich
@ 2017-12-15  2:34     ` Kever Yang
  2017-12-15  9:08       ` Dr. Philipp Tomsich
  0 siblings, 1 reply; 7+ messages in thread
From: Kever Yang @ 2017-12-15  2:34 UTC (permalink / raw)
  To: u-boot

Hi Philipp,


On 12/14/2017 05:53 PM, Dr. Philipp Tomsich wrote:
> Kever,
>
>> On 14 Dec 2017, at 07:39, Kever Yang <kever.yang@rock-chips.com> wrote:
>>
>> Do not need to scan disk every time when we get part info
>> by name.
> How does this interact with USB devices?
> I.e.: what happens, when you get the partition-info for a usb drive, then change
> the attached usb drive (with only a single one attached, but a different one) and
> do a ‘usb rescan’?

I don't understand your question here, the part driver is using block api,
no matter its from usb or emmc, it's the same for part driver.
USB msc driver should always call part_init() for a new device.

This patch does not change the functionality of the origin implement, 
but with
a better api, and do not need to scan the disk if the disk already have 
a known type.

Thanks,
- Kever
>
> Regards,
> Philipp.
>
>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>> ---
>>
>> disk/part.c | 29 +++++++++++++----------------
>> 1 file changed, 13 insertions(+), 16 deletions(-)
>>
>> diff --git a/disk/part.c b/disk/part.c
>> index b007138..96c2858 100644
>> --- a/disk/part.c
>> +++ b/disk/part.c
>> @@ -638,26 +638,23 @@ cleanup:
>> 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;
>> +	int ret;
>> +	int i;
>>
>> -	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 i;
>> -			}
>> +	part_drv = part_driver_lookup_type(dev_desc);
>> +	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 i;
>> 		}
>> 	}
>> +
>> 	return -1;
>> }
>>
>> -- 
>> 1.9.1
>>
>

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

* [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver
  2017-12-15  2:34     ` Kever Yang
@ 2017-12-15  9:08       ` Dr. Philipp Tomsich
  0 siblings, 0 replies; 7+ messages in thread
From: Dr. Philipp Tomsich @ 2017-12-15  9:08 UTC (permalink / raw)
  To: u-boot


> On 15 Dec 2017, at 03:34, Kever Yang <kever.yang@rock-chips.com> wrote:
> 
> Hi Philipp,
> 
> 
> On 12/14/2017 05:53 PM, Dr. Philipp Tomsich wrote:
>> Kever,
>> 
>>> On 14 Dec 2017, at 07:39, Kever Yang <kever.yang@rock-chips.com> wrote:
>>> 
>>> Do not need to scan disk every time when we get part info
>>> by name.
>> How does this interact with USB devices?
>> I.e.: what happens, when you get the partition-info for a usb drive, then change
>> the attached usb drive (with only a single one attached, but a different one) and
>> do a ‘usb rescan’?
> 
> I don't understand your question here, the part driver is using block api,
> no matter its from usb or emmc, it's the same for part driver.
> USB msc driver should always call part_init() for a new device.

Thanks, this answers it: part_init() will always be called for new devices.

> This patch does not change the functionality of the origin implement, but with
> a better api, and do not need to scan the disk if the disk already have a known type.
> 
> Thanks,
> - Kever
>> 
>> Regards,
>> Philipp.
>> 
>>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>>> ---
>>> 
>>> disk/part.c | 29 +++++++++++++----------------
>>> 1 file changed, 13 insertions(+), 16 deletions(-)
>>> 
>>> diff --git a/disk/part.c b/disk/part.c
>>> index b007138..96c2858 100644
>>> --- a/disk/part.c
>>> +++ b/disk/part.c
>>> @@ -638,26 +638,23 @@ cleanup:
>>> 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;
>>> +	int ret;
>>> +	int i;
>>> 
>>> -	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 i;
>>> -			}
>>> +	part_drv = part_driver_lookup_type(dev_desc);
>>> +	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 i;
>>> 		}
>>> 	}
>>> +
>>> 	return -1;
>>> }
>>> 
>>> -- 
>>> 1.9.1
>>> 
>> 
> 
> 

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

* [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow
  2017-12-14  6:39 [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow Kever Yang
  2017-12-14  6:39 ` [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver Kever Yang
@ 2017-12-19 15:41 ` Simon Glass
  2017-12-22  3:33   ` Kever Yang
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Glass @ 2017-12-19 15:41 UTC (permalink / raw)
  To: u-boot

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

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

* [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow
  2017-12-19 15:41 ` [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow Simon Glass
@ 2017-12-22  3:33   ` Kever Yang
  0 siblings, 0 replies; 7+ messages in thread
From: Kever Yang @ 2017-12-22  3:33 UTC (permalink / raw)
  To: u-boot

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
>

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

end of thread, other threads:[~2017-12-22  3:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-14  6:39 [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow Kever Yang
2017-12-14  6:39 ` [U-Boot] [PATCH 2/2] disk: part: use common api to lookup part driver Kever Yang
2017-12-14  9:53   ` Dr. Philipp Tomsich
2017-12-15  2:34     ` Kever Yang
2017-12-15  9:08       ` Dr. Philipp Tomsich
2017-12-19 15:41 ` [U-Boot] [PATCH 1/2] disk: part: scan the disk if the part_type is unknow Simon Glass
2017-12-22  3:33   ` Kever Yang

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.