diff mbox series

[U-Boot,RFC,02/14] dfu: sf: add partition support for nor backend

Message ID 1563541046-6432-3-git-send-email-patrick.delaunay@st.com
State Superseded
Delegated to: Patrick Delaunay
Headers show
Series dfu: update dfu stack and use them for stm32mp1 | expand

Commit Message

Patrick DELAUNAY July 19, 2019, 12:57 p.m. UTC
Copy the partition support from NAND backend to SF,
support part and partubi option.
In case of ubi partition, erase the rest of the
partition as it is mandatory for UBI.

for example:

U-Boot> env set dfu_alt_info "spl part 0 1;\
u-boot part 0 2;u-boot-env part 0 3;UBI partubi 0 4"
U-Boot> dfu 0 sf 0:0:10000000:0

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 drivers/dfu/dfu_sf.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/dfu.h        |  2 ++
 2 files changed, 53 insertions(+)

Comments

Lukasz Majewski July 22, 2019, 7:54 a.m. UTC | #1
Hi Patrick,

> Copy the partition support from NAND backend to SF,
> support part and partubi option.
> In case of ubi partition, erase the rest of the
> partition as it is mandatory for UBI.
> 
> for example:
> 
> U-Boot> env set dfu_alt_info "spl part 0 1;\
> u-boot part 0 2;u-boot-env part 0 3;UBI partubi 0 4"
> U-Boot> dfu 0 sf 0:0:10000000:0
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
> 
>  drivers/dfu/dfu_sf.c | 51
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> include/dfu.h        |  2 ++ 2 files changed, 53 insertions(+)
> 
> diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
> index b78fcfd..d401b76 100644
> --- a/drivers/dfu/dfu_sf.c
> +++ b/drivers/dfu/dfu_sf.c
> @@ -10,6 +10,8 @@
>  #include <dfu.h>
>  #include <spi.h>
>  #include <spi_flash.h>
> +#include <jffs2/load_kernel.h>
> +#include <linux/mtd/mtd.h>
>  
>  static int dfu_get_medium_size_sf(struct dfu_entity *dfu, u64 *size)
>  {
> @@ -52,11 +54,33 @@ static int dfu_write_medium_sf(struct dfu_entity
> *dfu, 
>  static int dfu_flush_medium_sf(struct dfu_entity *dfu)
>  {
> +	u64 off, length;
> +
> +	if (!dfu->data.sf.ubi)
> +		return 0;
> +
> +	/* in case of ubi partition, erase rest of the partition */
> +	off = find_sector(dfu, dfu->data.sf.start, dfu->offset);
> +	/* last write ended with unaligned length jump to next */
> +	if (off != dfu->data.sf.start + dfu->offset)
> +		off += dfu->data.sf.dev->sector_size;
> +	length = dfu->data.sf.start + dfu->data.sf.size - off;
> +	if (length)
> +		return spi_flash_erase(dfu->data.sf.dev, off,
> length); +
>  	return 0;
>  }
>  
>  static unsigned int dfu_polltimeout_sf(struct dfu_entity *dfu)
>  {
> +	/*
> +	 * Currently, Poll Timeout != 0 is only needed on nand
							  ^^^^^ -
							  please update
							  the comment 

> +	 * ubi partition, as sectors which are not used need
> +	 * to be erased
> +	 */
> +	if (dfu->data.sf.ubi)
> +		return DFU_MANIFEST_POLL_TIMEOUT;
> +
>  	return DFU_DEFAULT_POLL_TIMEOUT;
>  }
>  
> @@ -133,6 +157,33 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu,
> char *devstr, char *s) dfu->data.sf.start = simple_strtoul(s, &s, 16);
>  		s++;
>  		dfu->data.sf.size = simple_strtoul(s, &s, 16);
> +	} else if ((!strcmp(st, "part")) || (!strcmp(st,
> "partubi"))) {
> +		char mtd_id[32];
> +		struct mtd_device *mtd_dev;
> +		u8 part_num;
> +		struct part_info *pi;
> +		int ret, dev, part;
> +
> +		dfu->layout = DFU_RAW_ADDR;
> +
> +		dev = simple_strtoul(s, &s, 10);
> +		s++;
> +		part = simple_strtoul(s, &s, 10);
> +
> +		sprintf(mtd_id, "%s%d,%d", "nor", dev, part - 1);
> +		printf("using id '%s'\n", mtd_id);
> +
> +		mtdparts_init();
> +
> +		ret = find_dev_and_part(mtd_id, &mtd_dev, &part_num,
> &pi);
> +		if (ret != 0) {
> +			printf("Could not locate '%s'\n", mtd_id);
> +			return -1;
> +		}
> +		dfu->data.sf.start = pi->offset;
> +		dfu->data.sf.size = pi->size;
> +		if (!strcmp(st, "partubi"))
> +			dfu->data.sf.ubi = 1;
>  	} else {
>  		printf("%s: Memory layout (%s) not supported!\n",
> __func__, st); spi_flash_free(dfu->data.sf.dev);
> diff --git a/include/dfu.h b/include/dfu.h
> index 145a157..bf51ab7 100644
> --- a/include/dfu.h
> +++ b/include/dfu.h
> @@ -77,6 +77,8 @@ struct sf_internal_data {
>  	/* RAW programming */
>  	u64 start;
>  	u64 size;
> +	/* for sf/ubi use */
> +	unsigned int ubi;
>  };
>  
>  #define DFU_NAME_SIZE			32




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@denx.de
diff mbox series

Patch

diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index b78fcfd..d401b76 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -10,6 +10,8 @@ 
 #include <dfu.h>
 #include <spi.h>
 #include <spi_flash.h>
+#include <jffs2/load_kernel.h>
+#include <linux/mtd/mtd.h>
 
 static int dfu_get_medium_size_sf(struct dfu_entity *dfu, u64 *size)
 {
@@ -52,11 +54,33 @@  static int dfu_write_medium_sf(struct dfu_entity *dfu,
 
 static int dfu_flush_medium_sf(struct dfu_entity *dfu)
 {
+	u64 off, length;
+
+	if (!dfu->data.sf.ubi)
+		return 0;
+
+	/* in case of ubi partition, erase rest of the partition */
+	off = find_sector(dfu, dfu->data.sf.start, dfu->offset);
+	/* last write ended with unaligned length jump to next */
+	if (off != dfu->data.sf.start + dfu->offset)
+		off += dfu->data.sf.dev->sector_size;
+	length = dfu->data.sf.start + dfu->data.sf.size - off;
+	if (length)
+		return spi_flash_erase(dfu->data.sf.dev, off, length);
+
 	return 0;
 }
 
 static unsigned int dfu_polltimeout_sf(struct dfu_entity *dfu)
 {
+	/*
+	 * Currently, Poll Timeout != 0 is only needed on nand
+	 * ubi partition, as sectors which are not used need
+	 * to be erased
+	 */
+	if (dfu->data.sf.ubi)
+		return DFU_MANIFEST_POLL_TIMEOUT;
+
 	return DFU_DEFAULT_POLL_TIMEOUT;
 }
 
@@ -133,6 +157,33 @@  int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s)
 		dfu->data.sf.start = simple_strtoul(s, &s, 16);
 		s++;
 		dfu->data.sf.size = simple_strtoul(s, &s, 16);
+	} else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) {
+		char mtd_id[32];
+		struct mtd_device *mtd_dev;
+		u8 part_num;
+		struct part_info *pi;
+		int ret, dev, part;
+
+		dfu->layout = DFU_RAW_ADDR;
+
+		dev = simple_strtoul(s, &s, 10);
+		s++;
+		part = simple_strtoul(s, &s, 10);
+
+		sprintf(mtd_id, "%s%d,%d", "nor", dev, part - 1);
+		printf("using id '%s'\n", mtd_id);
+
+		mtdparts_init();
+
+		ret = find_dev_and_part(mtd_id, &mtd_dev, &part_num, &pi);
+		if (ret != 0) {
+			printf("Could not locate '%s'\n", mtd_id);
+			return -1;
+		}
+		dfu->data.sf.start = pi->offset;
+		dfu->data.sf.size = pi->size;
+		if (!strcmp(st, "partubi"))
+			dfu->data.sf.ubi = 1;
 	} else {
 		printf("%s: Memory layout (%s) not supported!\n", __func__, st);
 		spi_flash_free(dfu->data.sf.dev);
diff --git a/include/dfu.h b/include/dfu.h
index 145a157..bf51ab7 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -77,6 +77,8 @@  struct sf_internal_data {
 	/* RAW programming */
 	u64 start;
 	u64 size;
+	/* for sf/ubi use */
+	unsigned int ubi;
 };
 
 #define DFU_NAME_SIZE			32