All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size
@ 2015-02-18 19:52 Dileep Katta
  2015-02-20 14:54 ` Rob Herring
  0 siblings, 1 reply; 6+ messages in thread
From: Dileep Katta @ 2015-02-18 19:52 UTC (permalink / raw)
  To: u-boot

This patch adds functionality to getvar command to get the userdata partition
size.

Signed-off-by: Dileep Katta <dileep.katta@linaro.org>
---
 common/fb_mmc.c                 | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c |  2 ++
 include/fb_mmc.h                |  2 ++
 3 files changed, 42 insertions(+)

diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index 6ea3938..1bb6335 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -32,6 +32,44 @@ void fastboot_okay(const char *s)
 	strncat(response_str, s, RESPONSE_LEN - 4 - 1);
 }
 
+void fb_mmc_get_ptn_size(const char *cmd, char *response)
+{
+	int ret;
+	block_dev_desc_t *dev_desc;
+	disk_partition_t info;
+	u32 sz_mb;
+	u64 sz = 0;
+	char buf[RESPONSE_LEN];
+
+	/* initialize the response buffer */
+	response_str = response;
+
+	dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
+	if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
+		error("invalid mmc device");
+		fastboot_fail("invalid mmc device");
+		return;
+	}
+
+	ret = get_partition_info_efi_by_name(dev_desc, cmd, &info);
+	if (ret) {
+		error("cannot find partition: '%s'", cmd);
+		fastboot_fail("cannot find partition");
+		return;
+	}
+
+	sz = (info.size * (u64)info.blksz) >> 10;
+
+	if (sz >= 0xFFFFFFFF) {
+		sz_mb = (u32)(sz >> 10);
+		sprintf(buf, "0x%d MB", sz_mb);
+		fastboot_okay(buf);
+	} else {
+		sprintf(buf, "%d KB", (u32)sz);
+		fastboot_okay(buf);
+	}
+}
+
 static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
 		const char *part_name, void *buffer,
 		unsigned int download_bytes)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 310175a..17b64ef 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -363,6 +363,8 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
 			strncat(response, s, chars_left);
 		else
 			strcpy(response, "FAILValue not set");
+	} else if (!strcmp_l1("userdata_size", cmd)) {
+		fb_mmc_get_ptn_size("userdata", response);
 	} else {
 		error("unknown variable: %s\n", cmd);
 		strcpy(response, "FAILVariable not implemented");
diff --git a/include/fb_mmc.h b/include/fb_mmc.h
index 1ad1d13..353f325 100644
--- a/include/fb_mmc.h
+++ b/include/fb_mmc.h
@@ -4,5 +4,7 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
+void fb_mmc_get_ptn_size(const char *cmd, char *response);
+
 void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 			unsigned int download_bytes, char *response);
-- 
1.8.3.2

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

* [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size
  2015-02-18 19:52 [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size Dileep Katta
@ 2015-02-20 14:54 ` Rob Herring
  2015-02-25 21:45   ` Dileep Katta
  2016-03-16 12:51   ` Boris Brezillon
  0 siblings, 2 replies; 6+ messages in thread
From: Rob Herring @ 2015-02-20 14:54 UTC (permalink / raw)
  To: u-boot

On Wed, Feb 18, 2015 at 1:52 PM, Dileep Katta <dileep.katta@linaro.org> wrote:
> This patch adds functionality to getvar command to get the userdata partition
> size.

This is non-standard and doesn't scale to other partitions. There is
already a standard var "partition-size:<part name>". There is also
"partition-type:<part name>" which probably needs to be supported as
well. It would probably be good to have generic code to retrieve
fastboot variables from a u-boot environment variables. Something like
this:

    fastboot: allow retrieving fastboot variables from env

    Signed-off-by: Rob Herring <robh@kernel.org>

diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 310175a..31e1063 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -364,8 +364,15 @@ static void cb_getvar(struct usb_ep *ep, struct
usb_request *req)
                else
                        strcpy(response, "FAILValue not set");
        } else {
-               error("unknown variable: %s\n", cmd);
-               strcpy(response, "FAILVariable not implemented");
+               char envstr[32];
+               snprintf(envstr, sizeof(envstr) - 1, "fastboot.%s", cmd);
+               s = getenv(envstr);
+               if (s) {
+                       strncat(response, s, chars_left);
+               } else {
+                       error("unknown variable: %s\n", cmd);
+                       strcpy(response, "FAILVariable not implemented");
+               }
        }
        fastboot_tx_write_str(response);
 }

Rob

> Signed-off-by: Dileep Katta <dileep.katta@linaro.org>
> ---
>  common/fb_mmc.c                 | 38 ++++++++++++++++++++++++++++++++++++++
>  drivers/usb/gadget/f_fastboot.c |  2 ++
>  include/fb_mmc.h                |  2 ++
>  3 files changed, 42 insertions(+)
>
> diff --git a/common/fb_mmc.c b/common/fb_mmc.c
> index 6ea3938..1bb6335 100644
> --- a/common/fb_mmc.c
> +++ b/common/fb_mmc.c
> @@ -32,6 +32,44 @@ void fastboot_okay(const char *s)
>         strncat(response_str, s, RESPONSE_LEN - 4 - 1);
>  }
>
> +void fb_mmc_get_ptn_size(const char *cmd, char *response)
> +{
> +       int ret;
> +       block_dev_desc_t *dev_desc;
> +       disk_partition_t info;
> +       u32 sz_mb;
> +       u64 sz = 0;
> +       char buf[RESPONSE_LEN];
> +
> +       /* initialize the response buffer */
> +       response_str = response;
> +
> +       dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
> +       if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
> +               error("invalid mmc device");
> +               fastboot_fail("invalid mmc device");
> +               return;
> +       }
> +
> +       ret = get_partition_info_efi_by_name(dev_desc, cmd, &info);
> +       if (ret) {
> +               error("cannot find partition: '%s'", cmd);
> +               fastboot_fail("cannot find partition");
> +               return;
> +       }
> +
> +       sz = (info.size * (u64)info.blksz) >> 10;
> +
> +       if (sz >= 0xFFFFFFFF) {
> +               sz_mb = (u32)(sz >> 10);
> +               sprintf(buf, "0x%d MB", sz_mb);
> +               fastboot_okay(buf);
> +       } else {
> +               sprintf(buf, "%d KB", (u32)sz);
> +               fastboot_okay(buf);
> +       }
> +}
> +
>  static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
>                 const char *part_name, void *buffer,
>                 unsigned int download_bytes)
> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> index 310175a..17b64ef 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -363,6 +363,8 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
>                         strncat(response, s, chars_left);
>                 else
>                         strcpy(response, "FAILValue not set");
> +       } else if (!strcmp_l1("userdata_size", cmd)) {
> +               fb_mmc_get_ptn_size("userdata", response);
>         } else {
>                 error("unknown variable: %s\n", cmd);
>                 strcpy(response, "FAILVariable not implemented");
> diff --git a/include/fb_mmc.h b/include/fb_mmc.h
> index 1ad1d13..353f325 100644
> --- a/include/fb_mmc.h
> +++ b/include/fb_mmc.h
> @@ -4,5 +4,7 @@
>   * SPDX-License-Identifier:    GPL-2.0+
>   */
>
> +void fb_mmc_get_ptn_size(const char *cmd, char *response);
> +
>  void fb_mmc_flash_write(const char *cmd, void *download_buffer,
>                         unsigned int download_bytes, char *response);
> --
> 1.8.3.2
>

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

* [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size
  2015-02-20 14:54 ` Rob Herring
@ 2015-02-25 21:45   ` Dileep Katta
  2015-02-26  0:38     ` Rob Herring
  2016-03-16 12:51   ` Boris Brezillon
  1 sibling, 1 reply; 6+ messages in thread
From: Dileep Katta @ 2015-02-25 21:45 UTC (permalink / raw)
  To: u-boot

Hi Rob,


On 20 February 2015 at 20:24, Rob Herring <rob.herring@linaro.org> wrote:

> On Wed, Feb 18, 2015 at 1:52 PM, Dileep Katta <dileep.katta@linaro.org>
> wrote:
> > This patch adds functionality to getvar command to get the userdata
> partition
> > size.
>
> This is non-standard and doesn't scale to other partitions. There is
>

Is there a way to add support for retrieving some non-standard variables,
such as cpu_type or
board specific information in getvar or other command(oem!) in fastboot?

already a standard var "partition-size:<part name>". There is also
> "partition-type:<part name>" which probably needs to be supported as
> well. It would probably be good to have generic code to retrieve
> fastboot variables from a u-boot environment variables. Something like
> this:
>
>     fastboot: allow retrieving fastboot variables from env
>
>     Signed-off-by: Rob Herring <robh@kernel.org>
>
> Thanks for the suggestion.
Is it fine to extend fb_mmc_get_ptn_size() in this patch to to support standard
var "partition-size:<part name>"
and similar functionality for partition-type?
or using "mtdparts" environment variable to get partition-type or
partition-size is preferable? Please advise.

Regards, Dileep

diff --git a/drivers/usb/gadget/f_fastboot.c
> b/drivers/usb/gadget/f_fastboot.c
> index 310175a..31e1063 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -364,8 +364,15 @@ static void cb_getvar(struct usb_ep *ep, struct
> usb_request *req)
>                 else
>                         strcpy(response, "FAILValue not set");
>         } else {
> -               error("unknown variable: %s\n", cmd);
> -               strcpy(response, "FAILVariable not implemented");
> +               char envstr[32];
> +               snprintf(envstr, sizeof(envstr) - 1, "fastboot.%s", cmd);
> +               s = getenv(envstr);
> +               if (s) {
> +                       strncat(response, s, chars_left);
> +               } else {
> +                       error("unknown variable: %s\n", cmd);
> +                       strcpy(response, "FAILVariable not implemented");
> +               }
>         }
>         fastboot_tx_write_str(response);
>  }
>
> Rob
>
> > Signed-off-by: Dileep Katta <dileep.katta@linaro.org>
> > ---
> >  common/fb_mmc.c                 | 38
> ++++++++++++++++++++++++++++++++++++++
> >  drivers/usb/gadget/f_fastboot.c |  2 ++
> >  include/fb_mmc.h                |  2 ++
> >  3 files changed, 42 insertions(+)
> >
> > diff --git a/common/fb_mmc.c b/common/fb_mmc.c
> > index 6ea3938..1bb6335 100644
> > --- a/common/fb_mmc.c
> > +++ b/common/fb_mmc.c
> > @@ -32,6 +32,44 @@ void fastboot_okay(const char *s)
> >         strncat(response_str, s, RESPONSE_LEN - 4 - 1);
> >  }
> >
> > +void fb_mmc_get_ptn_size(const char *cmd, char *response)
> > +{
> > +       int ret;
> > +       block_dev_desc_t *dev_desc;
> > +       disk_partition_t info;
> > +       u32 sz_mb;
> > +       u64 sz = 0;
> > +       char buf[RESPONSE_LEN];
> > +
> > +       /* initialize the response buffer */
> > +       response_str = response;
> > +
> > +       dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
> > +       if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
> > +               error("invalid mmc device");
> > +               fastboot_fail("invalid mmc device");
> > +               return;
> > +       }
> > +
> > +       ret = get_partition_info_efi_by_name(dev_desc, cmd, &info);
> > +       if (ret) {
> > +               error("cannot find partition: '%s'", cmd);
> > +               fastboot_fail("cannot find partition");
> > +               return;
> > +       }
> > +
> > +       sz = (info.size * (u64)info.blksz) >> 10;
> > +
> > +       if (sz >= 0xFFFFFFFF) {
> > +               sz_mb = (u32)(sz >> 10);
> > +               sprintf(buf, "0x%d MB", sz_mb);
> > +               fastboot_okay(buf);
> > +       } else {
> > +               sprintf(buf, "%d KB", (u32)sz);
> > +               fastboot_okay(buf);
> > +       }
> > +}
> > +
> >  static void write_raw_image(block_dev_desc_t *dev_desc,
> disk_partition_t *info,
> >                 const char *part_name, void *buffer,
> >                 unsigned int download_bytes)
> > diff --git a/drivers/usb/gadget/f_fastboot.c
> b/drivers/usb/gadget/f_fastboot.c
> > index 310175a..17b64ef 100644
> > --- a/drivers/usb/gadget/f_fastboot.c
> > +++ b/drivers/usb/gadget/f_fastboot.c
> > @@ -363,6 +363,8 @@ static void cb_getvar(struct usb_ep *ep, struct
> usb_request *req)
> >                         strncat(response, s, chars_left);
> >                 else
> >                         strcpy(response, "FAILValue not set");
> > +       } else if (!strcmp_l1("userdata_size", cmd)) {
> > +               fb_mmc_get_ptn_size("userdata", response);
> >         } else {
> >                 error("unknown variable: %s\n", cmd);
> >                 strcpy(response, "FAILVariable not implemented");
> > diff --git a/include/fb_mmc.h b/include/fb_mmc.h
> > index 1ad1d13..353f325 100644
> > --- a/include/fb_mmc.h
> > +++ b/include/fb_mmc.h
> > @@ -4,5 +4,7 @@
> >   * SPDX-License-Identifier:    GPL-2.0+
> >   */
> >
> > +void fb_mmc_get_ptn_size(const char *cmd, char *response);
> > +
> >  void fb_mmc_flash_write(const char *cmd, void *download_buffer,
> >                         unsigned int download_bytes, char *response);
> > --
> > 1.8.3.2
> >
>

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

* [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size
  2015-02-25 21:45   ` Dileep Katta
@ 2015-02-26  0:38     ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2015-02-26  0:38 UTC (permalink / raw)
  To: u-boot

On Wed, Feb 25, 2015 at 3:45 PM, Dileep Katta <dileep.katta@linaro.org> wrote:
> Hi Rob,
>
>
> On 20 February 2015 at 20:24, Rob Herring <rob.herring@linaro.org> wrote:
>>
>> On Wed, Feb 18, 2015 at 1:52 PM, Dileep Katta <dileep.katta@linaro.org>
>> wrote:
>> > This patch adds functionality to getvar command to get the userdata
>> > partition
>> > size.
>>
>> This is non-standard and doesn't scale to other partitions. There is
>
>
> Is there a way to add support for retrieving some non-standard variables,
> such as cpu_type or
> board specific information in getvar or other command(oem!) in fastboot?

That is what my patch does. You just have to create the env variable
on your board.

>> already a standard var "partition-size:<part name>". There is also
>> "partition-type:<part name>" which probably needs to be supported as
>> well. It would probably be good to have generic code to retrieve
>> fastboot variables from a u-boot environment variables. Something like
>> this:
>>
>>     fastboot: allow retrieving fastboot variables from env
>>
>>     Signed-off-by: Rob Herring <robh@kernel.org>
>>
> Thanks for the suggestion.
> Is it fine to extend fb_mmc_get_ptn_size() in this patch to to support
> standard var "partition-size:<part name>"
> and similar functionality for partition-type?

That's probably ok, but it would not work on an un-formatted device
(perhaps that is okay).

Also, I'd rather not see more MMC specific code. Soon as I want to
support a device with SATA, then we've got to go generalize
everything.

> or using "mtdparts" environment variable to get partition-type or
> partition-size is preferable? Please advise.

The partitioning/formatting code needs to know the sizes of
partitions, so keeping them in env vars could be reused by both.

Rob

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

* [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size
  2015-02-20 14:54 ` Rob Herring
  2015-02-25 21:45   ` Dileep Katta
@ 2016-03-16 12:51   ` Boris Brezillon
  2016-03-17 12:12     ` Rob Herring
  1 sibling, 1 reply; 6+ messages in thread
From: Boris Brezillon @ 2016-03-16 12:51 UTC (permalink / raw)
  To: u-boot

Hi Rob,

On Fri, 20 Feb 2015 08:54:56 -0600
Rob Herring <rob.herring@linaro.org> wrote:

> On Wed, Feb 18, 2015 at 1:52 PM, Dileep Katta <dileep.katta@linaro.org> wrote:
> > This patch adds functionality to getvar command to get the userdata partition
> > size.
> 
> This is non-standard and doesn't scale to other partitions. There is
> already a standard var "partition-size:<part name>". There is also
> "partition-type:<part name>" which probably needs to be supported as
> well. It would probably be good to have generic code to retrieve
> fastboot variables from a u-boot environment variables. Something like
> this:
> 
>     fastboot: allow retrieving fastboot variables from env
> 
>     Signed-off-by: Rob Herring <robh@kernel.org>
> 
> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> index 310175a..31e1063 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -364,8 +364,15 @@ static void cb_getvar(struct usb_ep *ep, struct
> usb_request *req)
>                 else
>                         strcpy(response, "FAILValue not set");
>         } else {
> -               error("unknown variable: %s\n", cmd);
> -               strcpy(response, "FAILVariable not implemented");
> +               char envstr[32];
> +               snprintf(envstr, sizeof(envstr) - 1, "fastboot.%s", cmd);
> +               s = getenv(envstr);
> +               if (s) {
> +                       strncat(response, s, chars_left);
> +               } else {
> +                       error("unknown variable: %s\n", cmd);
> +                       strcpy(response, "FAILVariable not implemented");
> +               }
>         }
>         fastboot_tx_write_str(response);
>  }
> 

I need this feature to expose some uboot variable through 'fastboot
getvar', would you mind if I resend this patch for you?

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size
  2016-03-16 12:51   ` Boris Brezillon
@ 2016-03-17 12:12     ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2016-03-17 12:12 UTC (permalink / raw)
  To: u-boot

On Wed, Mar 16, 2016 at 7:51 AM, Boris Brezillon
<boris.brezillon@free-electrons.com> wrote:
> Hi Rob,
>
> On Fri, 20 Feb 2015 08:54:56 -0600
> Rob Herring <rob.herring@linaro.org> wrote:
>
>> On Wed, Feb 18, 2015 at 1:52 PM, Dileep Katta <dileep.katta@linaro.org> wrote:
>> > This patch adds functionality to getvar command to get the userdata partition
>> > size.
>>
>> This is non-standard and doesn't scale to other partitions. There is
>> already a standard var "partition-size:<part name>". There is also
>> "partition-type:<part name>" which probably needs to be supported as
>> well. It would probably be good to have generic code to retrieve
>> fastboot variables from a u-boot environment variables. Something like
>> this:
>>
>>     fastboot: allow retrieving fastboot variables from env
>>
>>     Signed-off-by: Rob Herring <robh@kernel.org>
>>
>> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
>> index 310175a..31e1063 100644
>> --- a/drivers/usb/gadget/f_fastboot.c
>> +++ b/drivers/usb/gadget/f_fastboot.c
>> @@ -364,8 +364,15 @@ static void cb_getvar(struct usb_ep *ep, struct
>> usb_request *req)
>>                 else
>>                         strcpy(response, "FAILValue not set");
>>         } else {
>> -               error("unknown variable: %s\n", cmd);
>> -               strcpy(response, "FAILVariable not implemented");
>> +               char envstr[32];
>> +               snprintf(envstr, sizeof(envstr) - 1, "fastboot.%s", cmd);
>> +               s = getenv(envstr);
>> +               if (s) {
>> +                       strncat(response, s, chars_left);
>> +               } else {
>> +                       error("unknown variable: %s\n", cmd);
>> +                       strcpy(response, "FAILVariable not implemented");
>> +               }
>>         }
>>         fastboot_tx_write_str(response);
>>  }
>>
>
> I need this feature to expose some uboot variable through 'fastboot
> getvar', would you mind if I resend this patch for you?

No, go ahead.

Rob

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

end of thread, other threads:[~2016-03-17 12:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 19:52 [U-Boot] [PATCH v1 1/1] fastboot: Update getvar command to get 'userdata' partition size Dileep Katta
2015-02-20 14:54 ` Rob Herring
2015-02-25 21:45   ` Dileep Katta
2015-02-26  0:38     ` Rob Herring
2016-03-16 12:51   ` Boris Brezillon
2016-03-17 12:12     ` Rob Herring

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.