[U-Boot] [PATCH] DFU: fix for raw data write
Lukasz Majewski
l.majewski at samsung.com
Mon Aug 12 16:37:52 CEST 2013
Hi Mateusz,
> When user attempted to perform a raw write using DFU (vide
> dfu_fill_entity_mmc) with MMC interface not initialized before,
> get_mmc_blk_size() reported invalid (zero) block size - it wasn't
> possible to write ie. a new u-boot image.
>
> This commit fixes that by initializing device in get_mmc_blk_size()
> when needed.
>
> Tested on Samsung Goni.
>
> Signed-off-by: Mateusz Zalega <m.zalega at samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
> Cc: Lukasz Majewski <l.majewski at samsung.com>
> Cc: Minkyu Kang <mk7.kang at samsung.com>
> ---
> drivers/dfu/dfu.c | 22 ++++++++++++++++++++++
> drivers/dfu/dfu_mmc.c | 3 +++
> include/dfu.h | 7 ++-----
> 3 files changed, 27 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index d73d510..6979112 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
The mmc (or any other medium) related code shall NOT be added to
generic dfu.c file.
> @@ -414,3 +414,25 @@ struct dfu_entity *dfu_get_entity(int alt)
>
> return NULL;
> }
> +
> +int get_mmc_blk_size(int dev)
> +{
> + struct mmc *mmc = find_mmc_device(dev);
> +
> + if (mmc == NULL) {
> + error("Couldn't find MMC device no. %d.\n", dev);
> + return -ENODEV;
> + }
> + if (!mmc->has_init) {
> + if (!mmc_init(mmc)) {
> + if (!mmc->read_bl_len) {
> + error("invalid block length\n");
> + return -ENODEV;
> + }
> + } else {
> + error("Couldn't init MMC device.\n");
> + return -ENODEV;
> + }
> + }
> + return mmc->read_bl_len;
> +}
The above code fits better at dfu_mmc.c file. My proposition would be
to clean up the dfu_fill_entity_mmc() function and add the above code
there.
> diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
> index 0871a77..c776e26 100644
> --- a/drivers/dfu/dfu_mmc.c
> +++ b/drivers/dfu/dfu_mmc.c
> @@ -235,5 +235,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu,
> char *s) /* initial state */
> dfu->inited = 0;
>
> + /* better safe than sorry */
> + assert(dfu->data.mmc.lba_blk_size > 0);
> +
> return 0;
> }
> diff --git a/include/dfu.h b/include/dfu.h
> index 1d4006d..67ca711 100644
> --- a/include/dfu.h
> +++ b/include/dfu.h
> @@ -40,6 +40,8 @@ struct mmc_internal_data {
> unsigned int part;
> };
>
> +int get_mmc_blk_size(int dev);
> +
> struct nand_internal_data {
> /* RAW programming */
> u64 start;
> @@ -49,11 +51,6 @@ struct nand_internal_data {
> unsigned int part;
> };
>
> -static inline unsigned int get_mmc_blk_size(int dev)
> -{
> - return find_mmc_device(dev)->read_bl_len;
> -}
> -
> #define DFU_NAME_SIZE 32
> #define DFU_CMD_BUF_SIZE 128
> #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
--
Best regards,
Lukasz Majewski
Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
More information about the U-Boot
mailing list