public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] DFU: fix for raw data write
Date: Mon, 12 Aug 2013 16:37:52 +0200	[thread overview]
Message-ID: <20130812163752.2e99607b@amdc308.digital.local> (raw)
In-Reply-To: <1375786266-11822-2-git-send-email-m.zalega@samsung.com>

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@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> Cc: Minkyu Kang <mk7.kang@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

  reply	other threads:[~2013-08-12 14:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-06 10:51 [U-Boot] [PATCH] DFU: fix for raw data write Mateusz Zalega
2013-08-06 10:51 ` Mateusz Zalega
2013-08-12 14:37   ` Lukasz Majewski [this message]
2013-08-21 11:00 ` [U-Boot] [PATCH v2] dfu:mmc: raw data write fix Mateusz Zalega
2013-08-21 11:04   ` Mateusz Zalega
2013-09-05 13:47   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130812163752.2e99607b@amdc308.digital.local \
    --to=l.majewski@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox