From cb986ba0fe4692a9d21a193c4ca9db460df77364 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:00 +0200 Subject: dfu: sf: add partition support for nor backend 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. The added code is under compilation flag CONFIG_DFU_SF_PART activated by default. 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 --- include/dfu.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') 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 -- cgit v1.1 From 9ada683055a11860b83d5c2cc13713ca2b173c33 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:01 +0200 Subject: dfu: prepare the support of multiple interface Split the function dfu_config_entities with 2 new functions - dfu_alt_init - dfu_alt_add Signed-off-by: Patrick Delaunay --- include/dfu.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/dfu.h b/include/dfu.h index bf51ab7..7d60ffc 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -143,6 +143,8 @@ struct dfu_entity { #ifdef CONFIG_SET_DFU_ALT_INFO void set_dfu_alt_info(char *interface, char *devstr); #endif +int dfu_alt_init(int num, struct dfu_entity **dfu); +int dfu_alt_add(struct dfu_entity *dfu, char *interface, char *devstr, char *s); int dfu_config_entities(char *s, char *interface, char *devstr); void dfu_free_entities(void); void dfu_show_entities(void); -- cgit v1.1 From 6015af28ee6d44d6c7b21f3844c90df9239f66f4 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:04 +0200 Subject: dfu: add backend for MTD device Add DFU backend for MTD device: allow to read and write on all MTD device (NAND, SPI-NOR, SPI-NAND,...) For example : > set dfu_alt_info "nand_raw raw 0x0 0x100000" > dfu 0 mtd nand0 This MTD backend provides the same level than dfu nand backend for NAND and dfu sf backend for SPI-NOR; So it can replace booth of them but it also add support of spi-nand. > set dfu_alt_info "nand_raw raw 0x0 0x100000" > dfu 0 mtd spi-nand0 The backend code is based on the "mtd" command introduced by commit 5db66b3aee6f ("cmd: mtd: add 'mtd' command") Signed-off-by: Patrick Delaunay --- include/dfu.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include') diff --git a/include/dfu.h b/include/dfu.h index 7d60ffc..924952f 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -22,6 +22,7 @@ enum dfu_device_type { DFU_DEV_NAND, DFU_DEV_RAM, DFU_DEV_SF, + DFU_DEV_MTD, }; enum dfu_layout { @@ -55,6 +56,14 @@ struct mmc_internal_data { unsigned int part; }; +struct mtd_internal_data { + struct mtd_info *info; + + /* RAW programming */ + u64 start; + u64 size; +}; + struct nand_internal_data { /* RAW programming */ u64 start; @@ -105,6 +114,7 @@ struct dfu_entity { union { struct mmc_internal_data mmc; + struct mtd_internal_data mtd; struct nand_internal_data nand; struct ram_internal_data ram; struct sf_internal_data sf; @@ -249,6 +259,17 @@ static inline int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, } #endif +#if CONFIG_IS_ENABLED(DFU_MTD) +int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s); +#else +static inline int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, + char *s) +{ + puts("MTD support not available!\n"); + return -1; +} +#endif + /** * dfu_tftp_write - Write TFTP data to DFU medium * -- cgit v1.1 From d5640f700d0413059b39cdd621c9401ef90d08fa Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:05 +0200 Subject: dfu: add partition support for MTD backend Add the support of MTD partition for the MTD backend. The expected dfu_alt_info for one alternate on the mtd device : part partubi "partubi" also erase up to the end of the partition after write operation. For example: dfu_alt_info = "spl part 1;u-boot part 2; UBI partubi 3" U-Boot> dfu 0 mtd nand0 Acked-by: Lukasz Majewski Signed-off-by: Patrick Delaunay --- include/dfu.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/dfu.h b/include/dfu.h index 924952f..a90732c 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -62,6 +62,8 @@ struct mtd_internal_data { /* RAW programming */ u64 start; u64 size; + /* for ubi partition */ + unsigned int ubi; }; struct nand_internal_data { -- cgit v1.1 From ec44cace4b8d23556924550fe76bf2744eb91144 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:06 +0200 Subject: dfu: add DFU virtual backend Add a virtual DFU backend to allow board specific read and write (for OTP update for example). Acked-by: Lukasz Majewski Signed-off-by: Patrick Delaunay --- include/dfu.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include') 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 * -- cgit v1.1 From 067c13c70bfb99d25979b989870ed39eab34659a Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 14 Oct 2019 09:28:07 +0200 Subject: dfu: add callback for flush and initiated operation Add weak callback to allow board specific behavior - flush - initiated This patch prepare usage of DFU back end for communication with STM32CubeProgrammer on stm32mp1 platform with stm32prog command. Signed-off-by: Patrick Delaunay --- include/dfu.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include') diff --git a/include/dfu.h b/include/dfu.h index 4de7d35..5649663 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -183,6 +183,28 @@ int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num); int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num); int dfu_flush(struct dfu_entity *de, void *buf, int size, int blk_seq_num); +/** + * dfu_initiated_callback - weak callback called on DFU transaction start + * + * It is a callback function called by DFU stack when a DFU transaction is + * initiated. This function allows to manage some board specific behavior on + * DFU targets. + * + * @param dfu - pointer to the dfu_entity, which should be initialized + * + */ +void dfu_initiated_callback(struct dfu_entity *dfu); +/** + * dfu_flush_callback - weak callback called at the end of the DFU write + * + * It is a callback function called by DFU stack after DFU manifestation. + * This function allows to manage some board specific behavior on DFU targets + * + * @param dfu - pointer to the dfu_entity, which should be flushed + * + */ +void dfu_flush_callback(struct dfu_entity *dfu); + /* * dfu_defer_flush - pointer to store dfu_entity for deferred flashing. * It should be NULL when not used. -- cgit v1.1