public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 08/14] dfu: add DFU virtual backend
Date: Mon, 22 Jul 2019 10:20:22 +0200	[thread overview]
Message-ID: <20190722102022.1716084e@jawa> (raw)
In-Reply-To: <1563541046-6432-9-git-send-email-patrick.delaunay@st.com>

Hi Patrick,

> Add a virtual DFU backend to allow board specific read and write
> (for OTP update for example).

This looks like a great enhancement. Please add detailed documentation
entry of its intended usage.

> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
> 
>  drivers/dfu/Kconfig    |  7 +++++++
>  drivers/dfu/Makefile   |  1 +
>  drivers/dfu/dfu.c      |  5 ++++-
>  drivers/dfu/dfu_virt.c | 49
> +++++++++++++++++++++++++++++++++++++++++++++++++
> include/dfu.h          | 22 ++++++++++++++++++++++ 5 files changed,
> 83 insertions(+), 1 deletion(-) create mode 100644
> drivers/dfu/dfu_virt.c
> 
> diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
> index ee664a3..c0e6e5d 100644
> --- a/drivers/dfu/Kconfig
> +++ b/drivers/dfu/Kconfig
> @@ -52,5 +52,12 @@ config DFU_MTD
>  	help
>  	  This option enables using DFU to read and write to on any
> MTD device. 
> +config DFU_VIRT
> +	bool "VIRTUAL flash back end for DFU"
> +	help
> +	  This option enables using DFU to read and write to VIRTUAL
> device
> +	  used at board level to manage specific behavior
> +	  (OTP update for example).
> +
>  endif
>  endmenu
> diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile
> index ebb119f..0d7925c 100644
> --- a/drivers/dfu/Makefile
> +++ b/drivers/dfu/Makefile
> @@ -10,3 +10,4 @@ obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
>  obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
>  obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
>  obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
> +obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index ab7fdc0..a960b6e 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -473,6 +473,9 @@ static int dfu_fill_entity(struct dfu_entity
> *dfu, char *s, int alt, } else if (strcmp(interface, "sf") == 0) {
>  		if (dfu_fill_entity_sf(dfu, devstr, s))
>  			return -1;
> +	} else if (strcmp(interface, "virt") == 0) {
> +		if (dfu_fill_entity_virt(dfu, devstr, s))
> +			return -1;
>  	} else {
>  		printf("%s: Device %s not (yet) supported!\n",
>  		       __func__,  interface);
> @@ -568,7 +571,7 @@ int dfu_config_entities(char *env, char
> *interface, char *devstr) const char *dfu_get_dev_type(enum
> dfu_device_type t) {
>  	const char *const dev_t[] = {NULL, "eMMC", "OneNAND",
> "NAND", "RAM",
> -				     "SF", "MTD"};
> +				     "SF", "MTD", "VIRT"};
>  	return dev_t[t];
>  }
>  
> diff --git a/drivers/dfu/dfu_virt.c b/drivers/dfu/dfu_virt.c
> new file mode 100644
> index 0000000..ea8c71f
> --- /dev/null
> +++ b/drivers/dfu/dfu_virt.c
> @@ -0,0 +1,49 @@
> +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
> +/*
> + * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
> + */
> +#include <common.h>
> +#include <dfu.h>
> +#include <errno.h>
> +#include <malloc.h>
> +
> +int __weak dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset,
> +				 void *buf, long *len)
> +{
> +	debug("%s: off=0x%llx, len=0x%x\n", __func__, offset,
> (u32)*len); +
> +	return 0;
> +}
> +
> +int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64
> *size) +{
> +	*size = 0;
> +
> +	return 0;
> +}
> +
> +int __weak dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
> +				void *buf, long *len)
> +{
> +	debug("%s: off=0x%llx, len=0x%x\n", __func__, offset,
> (u32)*len);
> +	*len = 0;
> +
> +	return 0;
> +}
> +
> +int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char
> *s) +{
> +	debug("%s: devstr = %s\n", __func__, devstr);
> +
> +	dfu->dev_type = DFU_DEV_VIRT;
> +	dfu->layout = DFU_RAW_ADDR;
> +	dfu->data.virt.dev_num = simple_strtoul(devstr, NULL, 10);
> +
> +	dfu->write_medium = dfu_write_medium_virt;
> +	dfu->get_medium_size = dfu_get_medium_size_virt;
> +	dfu->read_medium = dfu_read_medium_virt;
> +
> +	dfu->inited = 0;
> +
> +	return 0;
> +}
> diff --git a/include/dfu.h b/include/dfu.h
> index a90732c..4de7d35 100644
> --- a/include/dfu.h
> +++ b/include/dfu.h
> @@ -23,6 +23,7 @@ enum dfu_device_type {
>  	DFU_DEV_RAM,
>  	DFU_DEV_SF,
>  	DFU_DEV_MTD,
> +	DFU_DEV_VIRT,
>  };
>  
>  enum dfu_layout {
> @@ -92,6 +93,10 @@ struct sf_internal_data {
>  	unsigned int ubi;
>  };
>  
> +struct virt_internal_data {
> +	int dev_num;
> +};
> +
>  #define DFU_NAME_SIZE			32
>  #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
>  #define CONFIG_SYS_DFU_DATA_BUF_SIZE
> (1024*1024*8)	/* 8 MiB */ @@ -120,6 +125,7 @@ struct
> dfu_entity { struct nand_internal_data nand;
>  		struct ram_internal_data ram;
>  		struct sf_internal_data sf;
> +		struct virt_internal_data virt;
>  	} data;
>  
>  	int (*get_medium_size)(struct dfu_entity *dfu, u64 *size);
> @@ -272,6 +278,22 @@ static inline int dfu_fill_entity_mtd(struct
> dfu_entity *dfu, char *devstr, }
>  #endif
>  
> +#ifdef CONFIG_DFU_VIRT
> +int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char
> *s); +int dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset,
> +			  void *buf, long *len);
> +int dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size);
> +int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
> +			 void *buf, long *len);
> +#else
> +static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char
> *devstr,
> +				       char *s)
> +{
> +	puts("VIRT support not available!\n");
> +	return -1;
> +}
> +#endif
> +
>  /**
>   * dfu_tftp_write - Write TFTP data to DFU medium
>   *




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: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190722/ca95f199/attachment.sig>

  reply	other threads:[~2019-07-22  8:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-19 12:57 [U-Boot] [RFC PATCH 00/14] dfu: update dfu stack and use them for stm32mp1 Patrick Delaunay
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 01/14] dfu: cosmetic: cleanup sf to avoid checkpatch error Patrick Delaunay
2019-07-22  7:51   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 02/14] dfu: sf: add partition support for nor backend Patrick Delaunay
2019-07-22  7:54   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 03/14] dfu: prepare the support of multiple interface Patrick Delaunay
2019-07-22  7:57   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 04/14] dfu: allow to manage DFU on several devices Patrick Delaunay
2019-07-22  8:04   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 05/14] dfu: allow read with 0 data for EOF indication Patrick Delaunay
2019-07-22  8:05   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 06/14] dfu: add backend for MTD device Patrick Delaunay
2019-07-22  8:11   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 07/14] dfu: add partition support for MTD backend Patrick Delaunay
2019-07-22  8:16   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 08/14] dfu: add DFU virtual backend Patrick Delaunay
2019-07-22  8:20   ` Lukasz Majewski [this message]
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 09/14] dfu: add callback for flush and initiated operation Patrick Delaunay
2019-07-22  8:22   ` Lukasz Majewski
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 10/14] stm32mp1: activate DFU support and command MTD Patrick Delaunay
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 11/14] stm32mp1: activate SET_DFU_ALT_INFO Patrick Delaunay
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 12/14] stp32mp1: configs: activate CONFIG_MTD_SPI_NAND Patrick Delaunay
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 13/14] stm32mp1: board: add spi nand support Patrick Delaunay
2019-07-19 12:57 ` [U-Boot] [RFC PATCH 14/14] stm32mp1: add support for virtual partition read Patrick Delaunay
2019-07-22  8:27 ` [U-Boot] [RFC PATCH 00/14] dfu: update dfu stack and use them for stm32mp1 Lukasz Majewski

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=20190722102022.1716084e@jawa \
    --to=lukma@denx.de \
    --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