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

Signed-off-by: Dileep Katta <dileep.ka...@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

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to