All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 06/10] dfu: mmc: buffer file reads too
Date: Tue, 08 Sep 2015 14:57:39 +0200	[thread overview]
Message-ID: <20150908145739.6ceef155@amdc2363> (raw)
In-Reply-To: <1441425831-3441-6-git-send-email-swarren@wwwdotorg.org>

Hi Stephen,

> From: Stephen Warren <swarren@nvidia.com>
> 
> When writing to files in a filesystem on MMC, dfu_mmc.c buffers up the
> entire file content until the end of the transaction, at which point
> the file is written in one go. This allows writing files larger than
> the USB transfer size (CONFIG_SYS_DFU_DATA_BUF_SIZE); the maximum
> written file size is CONFIG_SYS_DFU_MAX_FILE_SIZE (the size of the
> temporary buffer).
> 
> The current file reading code does not do any buffering, and so limits
> the maximum read file size to the USB transfer size. Enhance the code
> to do the same kind of buffering as the write path, so the same file
> size limits apply.
> 
> Remove the size checking code from dfu_read() since all read paths now
> support larger files than the USB transfer buffer.
> 
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  drivers/dfu/dfu.c     | 11 -----------
>  drivers/dfu/dfu_mmc.c | 27 ++++++++++++++++++++++++++-
>  2 files changed, 26 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index d85d3f507a7b..d1e465aa7695 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -338,17 +338,6 @@ int dfu_read(struct dfu_entity *dfu, void *buf,
> int size, int blk_seq_num) dfu->r_left = dfu->get_medium_size(dfu);
>  		if (dfu->r_left < 0)
>  			return dfu->r_left;
> -		switch (dfu->layout) {
> -		case DFU_RAW_ADDR:
> -		case DFU_RAM_ADDR:
> -			break;
> -		default:
> -			if (dfu->r_left > dfu_buf_size) {
> -				printf("%s: File too big for
> buffer\n",
> -				       __func__);
> -				return -EOVERFLOW;
> -			}
> -		}
>  
>  		debug("%s: %s %ld [B]\n", __func__, dfu->name,
> dfu->r_left); 
> diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
> index 2a780f7b5d31..5a9fb4a6e247 100644
> --- a/drivers/dfu/dfu_mmc.c
> +++ b/drivers/dfu/dfu_mmc.c
> @@ -18,6 +18,7 @@
>  
>  static unsigned char *dfu_file_buf;
>  static long dfu_file_buf_len;
> +static long dfu_file_buf_filled;
>  
>  static int mmc_access_part(struct dfu_entity *dfu, struct mmc *mmc,
> int part) {
> @@ -230,9 +231,12 @@ long dfu_get_medium_size_mmc(struct dfu_entity
> *dfu) return dfu->data.mmc.lba_size * dfu->data.mmc.lba_blk_size;
>  	case DFU_FS_FAT:
>  	case DFU_FS_EXT4:
> +		dfu_file_buf_filled = -1;
>  		ret = mmc_file_op(DFU_OP_SIZE, dfu, NULL, &len);
>  		if (ret < 0)
>  			return ret;
> +		if (len > CONFIG_SYS_DFU_MAX_FILE_SIZE)
> +			return -1;
>  		return len;
>  	default:
>  		printf("%s: Layout (%s) not (yet) supported!\n",
> __func__, @@ -241,6 +245,27 @@ long dfu_get_medium_size_mmc(struct
> dfu_entity *dfu) }
>  }
>  
> +static int mmc_file_unbuffer(struct dfu_entity *dfu, u64 offset,
> void *buf,
> +			     long *len)
> +{
> +	int ret;
> +	long file_len;
> +
> +	if (dfu_file_buf_filled == -1) {
> +		ret = mmc_file_op(DFU_OP_READ, dfu, dfu_file_buf,
> &file_len);
> +		if (ret < 0)
> +			return ret;
> +		dfu_file_buf_filled = file_len;
> +	}
> +	if (offset + *len > dfu_file_buf_filled)
> +		return -EINVAL;
> +
> +	/* Add to the current buffer. */
> +	memcpy(buf, dfu_file_buf + offset, *len);
> +
> +	return 0;
> +}
> +
>  int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void
> *buf, long *len)
>  {
> @@ -252,7 +277,7 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu,
> u64 offset, void *buf, break;
>  	case DFU_FS_FAT:
>  	case DFU_FS_EXT4:
> -		ret = mmc_file_op(DFU_OP_READ, dfu, buf, len);
> +		ret = mmc_file_unbuffer(dfu, offset, buf, len);
>  		break;
>  	default:
>  		printf("%s: Layout (%s) not (yet) supported!\n",
> __func__,

Acked-by: Lukasz Majewski <l.majewski@samsung.com>

Tested-by: Lukasz Majewski <l.majewski@samsung.com>
Test HW: Odroid XU3 - Exynos5433
[DFU Tests]

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

  reply	other threads:[~2015-09-08 12:57 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-05  4:03 [U-Boot] [PATCH 01/10] usb: gadget: don't leak configs when unbinding Stephen Warren
2015-09-05  4:03 ` [U-Boot] [PATCH 02/10] ext4: avoid calling ext4fs_mount() twice, which leaks Stephen Warren
2015-09-08 13:22   ` Lukasz Majewski
2015-09-12 12:51   ` [U-Boot] [U-Boot, " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 03/10] ext4: free allocations by parse_path() Stephen Warren
2015-09-08 13:10   ` Lukasz Majewski
2015-09-12 12:51   ` [U-Boot] [U-Boot,03/10] " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 04/10] ext4: fix leak in check_filename() Stephen Warren
2015-09-08 13:05   ` Lukasz Majewski
2015-09-12 12:51   ` [U-Boot] [U-Boot,04/10] " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 05/10] dfu: don't keep freeing/reallocating Stephen Warren
2015-09-08 12:32   ` Lukasz Majewski
2015-09-12 12:51   ` [U-Boot] [U-Boot,05/10] " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 06/10] dfu: mmc: buffer file reads too Stephen Warren
2015-09-08 12:57   ` Lukasz Majewski [this message]
2015-09-12 12:51   ` [U-Boot] [U-Boot,06/10] " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 07/10] ARM: tegra: fix malloc region sizing Stephen Warren
2015-09-08 16:53   ` Tom Warren
2015-09-08 21:45     ` Stephen Warren
2015-09-08 21:52       ` Stephen Warren
2015-09-08 21:56         ` Tom Rini
2015-09-08 21:56           ` Stephen Warren
2015-09-09  6:51         ` Lukasz Majewski
2015-09-09 16:08           ` Tom Warren
2015-09-12 12:51   ` [U-Boot] [U-Boot,07/10] " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 08/10] ARM: tegra: tweak DFU buffer sizes Stephen Warren
2015-09-12 12:51   ` [U-Boot] [U-Boot,08/10] " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 09/10] ARM: tegra: enable filesystem writing Stephen Warren
2015-09-12 12:51   ` [U-Boot] [U-Boot,09/10] " Tom Rini
2015-09-05  4:03 ` [U-Boot] [PATCH 10/10] ARM: tegra: enable DFU for RAM Stephen Warren
2015-09-12 12:51   ` [U-Boot] [U-Boot,10/10] " Tom Rini
2015-09-08 12:00 ` [U-Boot] [PATCH 01/10] usb: gadget: don't leak configs when unbinding Lukasz Majewski
2015-09-08 21:50   ` Stephen Warren
2015-09-12 12:51 ` [U-Boot] [U-Boot, " 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=20150908145739.6ceef155@amdc2363 \
    --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 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.