On Thu, 13 Jun 2019 00:14:10 +0300
Sam Protsenko <semen.protse...@linaro.org> wrote:

> Extract fastboot_*_get_part_info() usage for MMC and NAND into
> getvar_get_part_info() function, as it will be needed further in other
> functions. This way we can avoid code duplication and mess with
> preprocessor directives across all points of usage.
> 
> Signed-off-by: Sam Protsenko <semen.protse...@linaro.org>
> ---
>  drivers/fastboot/fb_getvar.c | 52
> +++++++++++++++++++++++++----------- 1 file changed, 36
> insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/fastboot/fb_getvar.c
> b/drivers/fastboot/fb_getvar.c index 4268628f5e..b23880089e 100644
> --- a/drivers/fastboot/fb_getvar.c
> +++ b/drivers/fastboot/fb_getvar.c
> @@ -81,6 +81,41 @@ static const struct {
>       }
>  };
>  
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
> +/**
> + * Universal function to get partition number and size.
> + *
> + * @param[in] part_name Info for which partition name to look for
> + * @param[in,out] response Pointer to fastboot response buffer
> + * @param[out] size If not NULL, will contain partition size (in
> blocks)
> + * @return Partition number or negative value on error
> + */
> +static int getvar_get_part_info(const char *part_name, char
> *response,
> +                             size_t *size)
> +{
> +     int r;
> +# if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> +     struct blk_desc *dev_desc;
> +     disk_partition_t part_info;
> +
> +     r = fastboot_mmc_get_part_info(part_name, &dev_desc,
> &part_info,
> +                                    response);
> +     if (r >= 0 && size)
> +             *size = part_info.size;
> +# elif CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
> +     struct part_info *part_info;
> +
> +     r = fastboot_nand_get_part_info(part_name, &part_info,
> response);
> +     if (r >= 0 && size)
> +             *size = part_info->size;
> +# else
> +     r = -ENODEV;
> +# endif
> +
> +     return r;
> +}
> +#endif
> +
>  static void getvar_version(char *var_parameter, char *response)
>  {
>       fastboot_okay(FASTBOOT_VERSION, response);
> @@ -176,22 +211,7 @@ static void getvar_partition_size(char
> *part_name, char *response) int r;
>       size_t size;
>  
> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> -     struct blk_desc *dev_desc;
> -     disk_partition_t part_info;
> -
> -     r = fastboot_mmc_get_part_info(part_name, &dev_desc,
> &part_info,
> -                                    response);
> -     if (r >= 0)
> -             size = part_info.size;
> -#endif
> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
> -     struct part_info *part_info;
> -
> -     r = fastboot_nand_get_part_info(part_name, &part_info,
> response);
> -     if (r >= 0)
> -             size = part_info->size;
> -#endif
> +     r = getvar_get_part_info(part_name, response, &size);
>       if (r >= 0)
>               fastboot_response("OKAY", response, "0x%016zx",
> size); }

Reviewed-by: Lukasz Majewski <lu...@denx.de>


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de

Attachment: pgpTy5m49TBif.pgp
Description: OpenPGP digital signature

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

Reply via email to