2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2012-08-06 12:41:07 +00:00
|
|
|
/*
|
|
|
|
* dfu.h - DFU flashable area description
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Samsung Electronics
|
|
|
|
* authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
|
|
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DFU_ENTITY_H_
|
|
|
|
#define __DFU_ENTITY_H_
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <mmc.h>
|
2014-06-11 22:03:36 +00:00
|
|
|
#include <spi_flash.h>
|
2013-09-17 13:58:23 +00:00
|
|
|
#include <linux/usb/composite.h>
|
2012-08-06 12:41:07 +00:00
|
|
|
|
|
|
|
enum dfu_device_type {
|
|
|
|
DFU_DEV_MMC = 1,
|
|
|
|
DFU_DEV_ONENAND,
|
|
|
|
DFU_DEV_NAND,
|
2013-09-17 19:45:24 +00:00
|
|
|
DFU_DEV_RAM,
|
2014-06-11 22:03:36 +00:00
|
|
|
DFU_DEV_SF,
|
2019-10-14 07:28:04 +00:00
|
|
|
DFU_DEV_MTD,
|
2019-10-14 07:28:06 +00:00
|
|
|
DFU_DEV_VIRT,
|
2012-08-06 12:41:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum dfu_layout {
|
|
|
|
DFU_RAW_ADDR = 1,
|
|
|
|
DFU_FS_FAT,
|
|
|
|
DFU_FS_EXT2,
|
|
|
|
DFU_FS_EXT3,
|
|
|
|
DFU_FS_EXT4,
|
2013-09-17 19:45:24 +00:00
|
|
|
DFU_RAM_ADDR,
|
2020-12-22 10:32:21 +00:00
|
|
|
DFU_SKIP,
|
2020-12-22 10:32:22 +00:00
|
|
|
DFU_SCRIPT,
|
2012-08-06 12:41:07 +00:00
|
|
|
};
|
|
|
|
|
2013-09-17 19:44:50 +00:00
|
|
|
enum dfu_op {
|
|
|
|
DFU_OP_READ = 1,
|
|
|
|
DFU_OP_WRITE,
|
2014-06-11 18:47:27 +00:00
|
|
|
DFU_OP_SIZE,
|
2013-09-17 19:44:50 +00:00
|
|
|
};
|
|
|
|
|
2012-08-06 12:41:07 +00:00
|
|
|
struct mmc_internal_data {
|
2014-06-11 22:03:33 +00:00
|
|
|
int dev_num;
|
|
|
|
|
2012-08-06 12:41:07 +00:00
|
|
|
/* RAW programming */
|
|
|
|
unsigned int lba_start;
|
|
|
|
unsigned int lba_size;
|
|
|
|
unsigned int lba_blk_size;
|
|
|
|
|
2014-05-09 14:58:15 +00:00
|
|
|
/* eMMC HW partition access */
|
|
|
|
int hw_partition;
|
|
|
|
|
2012-08-06 12:41:07 +00:00
|
|
|
/* FAT/EXT */
|
|
|
|
unsigned int dev;
|
|
|
|
unsigned int part;
|
|
|
|
};
|
|
|
|
|
2019-10-14 07:28:04 +00:00
|
|
|
struct mtd_internal_data {
|
|
|
|
struct mtd_info *info;
|
|
|
|
|
|
|
|
/* RAW programming */
|
|
|
|
u64 start;
|
|
|
|
u64 size;
|
2019-10-14 07:28:05 +00:00
|
|
|
/* for ubi partition */
|
|
|
|
unsigned int ubi;
|
2019-10-14 07:28:04 +00:00
|
|
|
};
|
|
|
|
|
2013-03-14 05:32:52 +00:00
|
|
|
struct nand_internal_data {
|
|
|
|
/* RAW programming */
|
|
|
|
u64 start;
|
|
|
|
u64 size;
|
|
|
|
|
|
|
|
unsigned int dev;
|
|
|
|
unsigned int part;
|
2013-07-25 04:43:11 +00:00
|
|
|
/* for nand/ubi use */
|
|
|
|
unsigned int ubi;
|
2013-03-14 05:32:52 +00:00
|
|
|
};
|
|
|
|
|
2013-09-17 19:45:24 +00:00
|
|
|
struct ram_internal_data {
|
2020-07-22 15:46:02 +00:00
|
|
|
unsigned long start;
|
2013-09-17 19:45:24 +00:00
|
|
|
unsigned int size;
|
|
|
|
};
|
|
|
|
|
2014-06-11 22:03:36 +00:00
|
|
|
struct sf_internal_data {
|
|
|
|
struct spi_flash *dev;
|
|
|
|
|
|
|
|
/* RAW programming */
|
|
|
|
u64 start;
|
|
|
|
u64 size;
|
2019-10-14 07:28:00 +00:00
|
|
|
/* for sf/ubi use */
|
|
|
|
unsigned int ubi;
|
2014-06-11 22:03:36 +00:00
|
|
|
};
|
|
|
|
|
2019-10-14 07:28:06 +00:00
|
|
|
struct virt_internal_data {
|
|
|
|
int dev_num;
|
|
|
|
};
|
|
|
|
|
2013-03-14 05:32:49 +00:00
|
|
|
#define DFU_NAME_SIZE 32
|
2013-12-09 15:20:14 +00:00
|
|
|
#ifndef DFU_DEFAULT_POLL_TIMEOUT
|
|
|
|
#define DFU_DEFAULT_POLL_TIMEOUT 0
|
|
|
|
#endif
|
2014-03-18 07:09:56 +00:00
|
|
|
#ifndef DFU_MANIFEST_POLL_TIMEOUT
|
|
|
|
#define DFU_MANIFEST_POLL_TIMEOUT DFU_DEFAULT_POLL_TIMEOUT
|
|
|
|
#endif
|
2012-08-06 12:41:07 +00:00
|
|
|
|
|
|
|
struct dfu_entity {
|
|
|
|
char name[DFU_NAME_SIZE];
|
|
|
|
int alt;
|
|
|
|
void *dev_private;
|
|
|
|
enum dfu_device_type dev_type;
|
|
|
|
enum dfu_layout layout;
|
2014-06-11 22:03:34 +00:00
|
|
|
unsigned long max_buf_size;
|
2012-08-06 12:41:07 +00:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct mmc_internal_data mmc;
|
2019-10-14 07:28:04 +00:00
|
|
|
struct mtd_internal_data mtd;
|
2013-03-14 05:32:52 +00:00
|
|
|
struct nand_internal_data nand;
|
2013-09-17 19:45:24 +00:00
|
|
|
struct ram_internal_data ram;
|
2014-06-11 22:03:36 +00:00
|
|
|
struct sf_internal_data sf;
|
2019-10-14 07:28:06 +00:00
|
|
|
struct virt_internal_data virt;
|
2012-08-06 12:41:07 +00:00
|
|
|
} data;
|
|
|
|
|
2017-07-19 14:39:23 +00:00
|
|
|
int (*get_medium_size)(struct dfu_entity *dfu, u64 *size);
|
2014-06-11 18:47:27 +00:00
|
|
|
|
2013-03-14 05:32:48 +00:00
|
|
|
int (*read_medium)(struct dfu_entity *dfu,
|
|
|
|
u64 offset, void *buf, long *len);
|
|
|
|
|
|
|
|
int (*write_medium)(struct dfu_entity *dfu,
|
|
|
|
u64 offset, void *buf, long *len);
|
|
|
|
|
|
|
|
int (*flush_medium)(struct dfu_entity *dfu);
|
2014-04-11 05:59:47 +00:00
|
|
|
unsigned int (*poll_timeout)(struct dfu_entity *dfu);
|
2012-08-06 12:41:07 +00:00
|
|
|
|
2014-06-11 22:03:35 +00:00
|
|
|
void (*free_entity)(struct dfu_entity *dfu);
|
|
|
|
|
2012-08-06 12:41:07 +00:00
|
|
|
struct list_head list;
|
2013-03-14 05:32:48 +00:00
|
|
|
|
|
|
|
/* on the fly state */
|
|
|
|
u32 crc;
|
|
|
|
u64 offset;
|
|
|
|
int i_blk_seq_num;
|
|
|
|
u8 *i_buf;
|
|
|
|
u8 *i_buf_start;
|
|
|
|
u8 *i_buf_end;
|
2017-07-19 14:39:23 +00:00
|
|
|
u64 r_left;
|
2013-03-14 05:32:48 +00:00
|
|
|
long b_left;
|
|
|
|
|
2013-03-14 05:32:52 +00:00
|
|
|
u32 bad_skip; /* for nand use */
|
|
|
|
|
2013-03-14 05:32:48 +00:00
|
|
|
unsigned int inited:1;
|
2012-08-06 12:41:07 +00:00
|
|
|
};
|
|
|
|
|
2020-10-29 04:47:44 +00:00
|
|
|
struct list_head;
|
|
|
|
extern struct list_head dfu_list;
|
|
|
|
|
2015-02-17 11:24:11 +00:00
|
|
|
#ifdef CONFIG_SET_DFU_ALT_INFO
|
2020-05-23 12:24:40 +00:00
|
|
|
/**
|
|
|
|
* set_dfu_alt_info() - set dfu_alt_info environment variable
|
|
|
|
*
|
|
|
|
* If CONFIG_SET_DFU_ALT_INFO=y, this board specific function is called to set
|
|
|
|
* environment variable dfu_alt_info.
|
|
|
|
*
|
|
|
|
* @interface: dfu interface, e.g. "mmc" or "nand"
|
|
|
|
* @devstr: device number as string
|
|
|
|
*/
|
2015-02-17 11:24:11 +00:00
|
|
|
void set_dfu_alt_info(char *interface, char *devstr);
|
|
|
|
#endif
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_alt_init() - initialize buffer for dfu entities
|
|
|
|
*
|
|
|
|
* @num: number of entities
|
|
|
|
* @dfu: on return allocated buffer
|
|
|
|
* Return: 0 on success
|
|
|
|
*/
|
2019-10-14 07:28:01 +00:00
|
|
|
int dfu_alt_init(int num, struct dfu_entity **dfu);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_alt_add() - add alternate to dfu entity buffer
|
|
|
|
*
|
|
|
|
* @dfu: dfu entity
|
|
|
|
* @interface: dfu interface, e.g. "mmc" or "nand"
|
|
|
|
* @devstr: device number as string
|
|
|
|
* @s: string description of alternate
|
|
|
|
* Return: 0 on success
|
|
|
|
*/
|
2019-10-14 07:28:01 +00:00
|
|
|
int dfu_alt_add(struct dfu_entity *dfu, char *interface, char *devstr, char *s);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_config_entities() - initialize dfu entitities from envirionment
|
|
|
|
*
|
|
|
|
* Initialize the list of dfu entities from environment variable dfu_alt_info.
|
|
|
|
* The list must be freed by calling dfu_free_entities(). This function bypasses
|
|
|
|
* set_dfu_alt_info(). So typically you should use dfu_init_env_entities()
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* See function :c:func:`dfu_free_entities`
|
|
|
|
* See function :c:func:`dfu_init_env_entities`
|
|
|
|
*
|
|
|
|
* @s: string with alternates
|
|
|
|
* @interface: interface, e.g. "mmc" or "nand"
|
|
|
|
* @devstr: device number as string
|
|
|
|
* Return: 0 on success, a negative error code otherwise
|
|
|
|
*/
|
2014-06-11 22:03:33 +00:00
|
|
|
int dfu_config_entities(char *s, char *interface, char *devstr);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_free_entities() - free the list of dfu entities
|
|
|
|
*
|
|
|
|
* Free the internal list of dfu entities.
|
|
|
|
*
|
|
|
|
* See function :c:func:`dfu_init_env_entities`
|
|
|
|
*/
|
2012-08-06 12:41:07 +00:00
|
|
|
void dfu_free_entities(void);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_show_entities() - print DFU alt settings list
|
|
|
|
*/
|
2012-08-06 12:41:07 +00:00
|
|
|
void dfu_show_entities(void);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_get_alt_number() - get number of alternates
|
|
|
|
*
|
|
|
|
* Return: number of alternates in the dfu entities list
|
|
|
|
*/
|
2012-08-06 12:41:07 +00:00
|
|
|
int dfu_get_alt_number(void);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_get_dev_type() - get string representation for dfu device type
|
|
|
|
*
|
|
|
|
* @type: device type
|
|
|
|
* Return: string representation for device type
|
|
|
|
*/
|
|
|
|
const char *dfu_get_dev_type(enum dfu_device_type type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_get_layout() - get string describing layout
|
|
|
|
*
|
|
|
|
* Internally layouts are represented by enum dfu_device_type values. This
|
|
|
|
* function translates an enum value to a human readable string, e.g. DFU_FS_FAT
|
|
|
|
* is translated to "FAT".
|
|
|
|
*
|
|
|
|
* @layout: layout
|
|
|
|
* Result: string representation for the layout
|
|
|
|
*/
|
|
|
|
const char *dfu_get_layout(enum dfu_layout layout);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_get_entity() - get dfu entity for an alternate id
|
|
|
|
*
|
|
|
|
* @alt: alternate id
|
|
|
|
* Return: dfu entity
|
|
|
|
*/
|
2012-08-06 12:41:07 +00:00
|
|
|
struct dfu_entity *dfu_get_entity(int alt);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
2012-08-06 12:41:07 +00:00
|
|
|
char *dfu_extract_token(char** e, int *n);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_get_alt() - get alternate id for filename
|
|
|
|
*
|
|
|
|
* Environment variable dfu_alt_info defines the write destinations (alternates)
|
|
|
|
* for different filenames. This function get the index of the alternate for
|
|
|
|
* a filename. If an absolute filename is provided (starting with '/'), the
|
|
|
|
* directory path is ignored.
|
|
|
|
*
|
|
|
|
* @name: filename
|
|
|
|
* Return: id of the alternate or negative error number (-ENODEV)
|
|
|
|
*/
|
2013-10-08 12:30:38 +00:00
|
|
|
int dfu_get_alt(char *name);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_init_env_entities() - initialize dfu entitities from envirionment
|
|
|
|
*
|
|
|
|
* Initialize the list of dfu entities from environment variable dfu_alt_info.
|
|
|
|
* The list must be freed by calling dfu_free_entities().
|
|
|
|
* @interface and @devstr are used to select the relevant set of alternates
|
|
|
|
* from environment variable dfu_alt_info.
|
|
|
|
*
|
|
|
|
* If environment variable dfu_alt_info specifies the interface and the device,
|
|
|
|
* use NULL for @interface and @devstr.
|
|
|
|
*
|
|
|
|
* See function :c:func:`dfu_free_entities`
|
|
|
|
*
|
|
|
|
* @interface: interface, e.g. "mmc" or "nand"
|
|
|
|
* @devstr: device number as string
|
|
|
|
* Return: 0 on success, a negative error code otherwise
|
|
|
|
*/
|
2014-06-11 22:03:33 +00:00
|
|
|
int dfu_init_env_entities(char *interface, char *devstr);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
2014-06-11 22:03:34 +00:00
|
|
|
unsigned char *dfu_get_buf(struct dfu_entity *dfu);
|
2013-10-08 12:30:39 +00:00
|
|
|
unsigned char *dfu_free_buf(void);
|
2013-12-09 15:20:13 +00:00
|
|
|
unsigned long dfu_get_buf_size(void);
|
2014-08-25 09:07:28 +00:00
|
|
|
bool dfu_usb_get_reset(void);
|
2012-08-06 12:41:07 +00:00
|
|
|
|
2019-11-27 16:12:15 +00:00
|
|
|
#ifdef CONFIG_DFU_TIMEOUT
|
|
|
|
unsigned long dfu_get_timeout(void);
|
|
|
|
void dfu_set_timeout(unsigned long);
|
|
|
|
#endif
|
|
|
|
|
2020-05-23 12:24:40 +00:00
|
|
|
/**
|
|
|
|
* dfu_read() - read from dfu entity
|
|
|
|
*
|
|
|
|
* The block sequence number @blk_seq_num is a 16 bit counter that must be
|
|
|
|
* incremented with each call for the same dfu entity @de.
|
|
|
|
*
|
|
|
|
* @de: dfu entity
|
|
|
|
* @buf: buffer
|
|
|
|
* @size: size of buffer
|
|
|
|
* @blk_seq_num: block sequence number
|
|
|
|
* Return: 0 for success, -1 for error
|
|
|
|
*/
|
2012-08-06 12:41:07 +00:00
|
|
|
int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_write() - write to dfu entity
|
|
|
|
*
|
|
|
|
* Write the contents of a buffer @buf to the dfu entity @de. After writing
|
|
|
|
* the last block call dfu_flush(). If a file is already loaded completely
|
|
|
|
* into memory it is preferable to use dfu_write_from_mem_addr() which takes
|
|
|
|
* care of blockwise transfer and flushing.
|
|
|
|
*
|
|
|
|
* The block sequence number @blk_seq_num is a 16 bit counter that must be
|
|
|
|
* incremented with each call for the same dfu entity @de.
|
|
|
|
*
|
|
|
|
* See function :c:func:`dfu_flush`
|
|
|
|
* See function :c:func:`dfu_write_from_mem_addr`
|
|
|
|
*
|
|
|
|
* @de: dfu entity
|
|
|
|
* @buf: buffer
|
|
|
|
* @size: size of buffer
|
|
|
|
* @blk_seq_num: block sequence number
|
|
|
|
* Return: 0 for success, -1 for error
|
|
|
|
*/
|
2012-08-06 12:41:07 +00:00
|
|
|
int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_flush() - flush to dfu entity
|
|
|
|
*
|
|
|
|
* This function has to be called after writing the last block to the dfu
|
|
|
|
* entity @de.
|
|
|
|
*
|
|
|
|
* The block sequence number @blk_seq_num is a 16 bit counter that must be
|
|
|
|
* incremented with each call for the same dfu entity @de.
|
|
|
|
*
|
|
|
|
* See function :c:func:`dfu_write`
|
|
|
|
*
|
|
|
|
* @de: dfu entity
|
|
|
|
* @buf: ignored
|
|
|
|
* @size: ignored
|
|
|
|
* @blk_seq_num: block sequence number of last write - ignored
|
|
|
|
* Return: 0 for success, -1 for error
|
|
|
|
*/
|
2014-03-18 07:09:55 +00:00
|
|
|
int dfu_flush(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
|
2015-08-23 22:21:46 +00:00
|
|
|
|
2019-10-14 07:28:07 +00:00
|
|
|
/**
|
2020-05-23 10:01:08 +00:00
|
|
|
* dfu_initiated_callback() - weak callback called on DFU transaction start
|
2019-10-14 07:28:07 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2020-05-23 10:01:08 +00:00
|
|
|
* @dfu: pointer to the dfu_entity, which should be initialized
|
2019-10-14 07:28:07 +00:00
|
|
|
*/
|
|
|
|
void dfu_initiated_callback(struct dfu_entity *dfu);
|
2020-05-23 12:24:40 +00:00
|
|
|
|
2019-10-14 07:28:07 +00:00
|
|
|
/**
|
2020-05-23 10:01:08 +00:00
|
|
|
* dfu_flush_callback() - weak callback called at the end of the DFU write
|
2019-10-14 07:28:07 +00:00
|
|
|
*
|
|
|
|
* It is a callback function called by DFU stack after DFU manifestation.
|
|
|
|
* This function allows to manage some board specific behavior on DFU targets
|
|
|
|
*
|
2020-05-23 10:01:08 +00:00
|
|
|
* @dfu: pointer to the dfu_entity, which should be flushed
|
2019-10-14 07:28:07 +00:00
|
|
|
*/
|
|
|
|
void dfu_flush_callback(struct dfu_entity *dfu);
|
|
|
|
|
2021-05-18 13:12:12 +00:00
|
|
|
/**
|
|
|
|
* dfu_error_callback() - weak callback called at the DFU write error
|
|
|
|
*
|
|
|
|
* It is a callback function called by DFU stack after DFU write error.
|
|
|
|
* This function allows to manage some board specific behavior on DFU targets
|
|
|
|
*
|
|
|
|
* @dfu: pointer to the dfu_entity which cause the error
|
|
|
|
* @msg: the message of the error
|
|
|
|
*/
|
|
|
|
void dfu_error_callback(struct dfu_entity *dfu, const char *msg);
|
|
|
|
|
2020-03-18 08:24:47 +00:00
|
|
|
int dfu_transaction_initiate(struct dfu_entity *dfu, bool read);
|
|
|
|
void dfu_transaction_cleanup(struct dfu_entity *dfu);
|
|
|
|
|
2016-01-28 15:14:49 +00:00
|
|
|
/*
|
|
|
|
* dfu_defer_flush - pointer to store dfu_entity for deferred flashing.
|
|
|
|
* It should be NULL when not used.
|
|
|
|
*/
|
|
|
|
extern struct dfu_entity *dfu_defer_flush;
|
2020-05-23 12:24:40 +00:00
|
|
|
|
2016-01-28 15:14:49 +00:00
|
|
|
/**
|
2020-05-23 10:01:08 +00:00
|
|
|
* dfu_get_defer_flush() - get current value of dfu_defer_flush pointer
|
2016-01-28 15:14:49 +00:00
|
|
|
*
|
2020-05-23 10:01:08 +00:00
|
|
|
* Return: value of the dfu_defer_flush pointer
|
2016-01-28 15:14:49 +00:00
|
|
|
*/
|
|
|
|
static inline struct dfu_entity *dfu_get_defer_flush(void)
|
|
|
|
{
|
|
|
|
return dfu_defer_flush;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-23 10:01:08 +00:00
|
|
|
* dfu_set_defer_flush() - set the dfu_defer_flush pointer
|
2016-01-28 15:14:49 +00:00
|
|
|
*
|
2020-05-23 10:01:08 +00:00
|
|
|
* @dfu: pointer to the dfu_entity, which should be written
|
2016-01-28 15:14:49 +00:00
|
|
|
*/
|
|
|
|
static inline void dfu_set_defer_flush(struct dfu_entity *dfu)
|
|
|
|
{
|
|
|
|
dfu_defer_flush = dfu;
|
|
|
|
}
|
|
|
|
|
2015-08-23 22:21:46 +00:00
|
|
|
/**
|
2020-05-23 10:01:08 +00:00
|
|
|
* dfu_write_from_mem_addr() - write data from memory to DFU managed medium
|
2015-08-23 22:21:46 +00:00
|
|
|
*
|
|
|
|
* This function adds support for writing data starting from fixed memory
|
|
|
|
* address (like $loadaddr) to dfu managed medium (e.g. NAND, MMC, file system)
|
|
|
|
*
|
2020-05-23 10:01:08 +00:00
|
|
|
* @dfu: dfu entity to which we want to store data
|
|
|
|
* @buf: fixed memory address from where data starts
|
|
|
|
* @size: number of bytes to write
|
2015-08-23 22:21:46 +00:00
|
|
|
*
|
2020-05-23 10:01:08 +00:00
|
|
|
* Return: 0 on success, other value on failure
|
2015-08-23 22:21:46 +00:00
|
|
|
*/
|
|
|
|
int dfu_write_from_mem_addr(struct dfu_entity *dfu, void *buf, int size);
|
|
|
|
|
2012-08-06 12:41:07 +00:00
|
|
|
/* Device specific */
|
2019-01-17 19:43:03 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DFU_MMC)
|
2014-06-11 22:03:33 +00:00
|
|
|
extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s);
|
2012-08-06 12:41:07 +00:00
|
|
|
#else
|
2014-06-11 22:03:33 +00:00
|
|
|
static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr,
|
|
|
|
char *s)
|
2012-08-06 12:41:07 +00:00
|
|
|
{
|
|
|
|
puts("MMC support not available!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-14 05:32:52 +00:00
|
|
|
|
2019-01-17 19:43:03 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DFU_NAND)
|
2014-06-11 22:03:33 +00:00
|
|
|
extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s);
|
2013-03-14 05:32:52 +00:00
|
|
|
#else
|
2014-06-11 22:03:33 +00:00
|
|
|
static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr,
|
|
|
|
char *s)
|
2013-03-14 05:32:52 +00:00
|
|
|
{
|
|
|
|
puts("NAND support not available!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-01-17 19:43:03 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DFU_RAM)
|
2014-06-11 22:03:33 +00:00
|
|
|
extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s);
|
2013-09-17 19:45:24 +00:00
|
|
|
#else
|
2014-06-11 22:03:33 +00:00
|
|
|
static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr,
|
|
|
|
char *s)
|
2013-09-17 19:45:24 +00:00
|
|
|
{
|
|
|
|
puts("RAM support not available!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-01-17 19:43:03 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DFU_SF)
|
2014-06-11 22:03:36 +00:00
|
|
|
extern int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s);
|
|
|
|
#else
|
|
|
|
static inline int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr,
|
|
|
|
char *s)
|
|
|
|
{
|
|
|
|
puts("SF support not available!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-10-14 07:28:04 +00:00
|
|
|
#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
|
|
|
|
|
2019-10-14 07:28:06 +00:00
|
|
|
#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
|
|
|
|
|
2020-12-22 10:32:22 +00:00
|
|
|
extern bool dfu_reinit_needed;
|
|
|
|
|
2020-10-29 04:47:52 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DFU_WRITE_ALT)
|
2015-08-23 22:21:45 +00:00
|
|
|
/**
|
2020-10-29 04:47:41 +00:00
|
|
|
* dfu_write_by_name() - write data to DFU medium
|
|
|
|
* @dfu_entity_name: Name of DFU entity to write
|
|
|
|
* @addr: Address of data buffer to write
|
|
|
|
* @len: Number of bytes
|
|
|
|
* @interface: Destination DFU medium (e.g. "mmc")
|
|
|
|
* @devstring: Instance number of destination DFU medium (e.g. "1")
|
2015-08-23 22:21:45 +00:00
|
|
|
*
|
2020-10-29 04:47:41 +00:00
|
|
|
* This function is storing data received on DFU supported medium which
|
|
|
|
* is specified by @dfu_entity_name.
|
2015-08-23 22:21:45 +00:00
|
|
|
*
|
2020-10-29 04:47:41 +00:00
|
|
|
* Return: 0 - on success, error code - otherwise
|
2015-08-23 22:21:45 +00:00
|
|
|
*/
|
2020-10-29 04:47:42 +00:00
|
|
|
int dfu_write_by_name(char *dfu_entity_name, void *addr,
|
2020-10-29 04:47:41 +00:00
|
|
|
unsigned int len, char *interface, char *devstring);
|
2020-10-29 04:47:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dfu_write_by_alt() - write data to DFU medium
|
|
|
|
* @dfu_alt_num: DFU alt setting number
|
|
|
|
* @addr: Address of data buffer to write
|
|
|
|
* @len: Number of bytes
|
|
|
|
* @interface: Destination DFU medium (e.g. "mmc")
|
|
|
|
* @devstring: Instance number of destination DFU medium (e.g. "1")
|
|
|
|
*
|
|
|
|
* This function is storing data received on DFU supported medium which
|
|
|
|
* is specified by @dfu_alt_name.
|
|
|
|
*
|
|
|
|
* Return: 0 - on success, error code - otherwise
|
|
|
|
*/
|
|
|
|
int dfu_write_by_alt(int dfu_alt_num, void *addr, unsigned int len,
|
|
|
|
char *interface, char *devstring);
|
2015-08-23 22:21:45 +00:00
|
|
|
#else
|
2020-10-29 04:47:42 +00:00
|
|
|
static inline int dfu_write_by_name(char *dfu_entity_name, void *addr,
|
2020-10-29 04:47:41 +00:00
|
|
|
unsigned int len, char *interface,
|
|
|
|
char *devstring)
|
2015-08-23 22:21:45 +00:00
|
|
|
{
|
2020-10-29 04:47:41 +00:00
|
|
|
puts("write support for DFU not available!\n");
|
2015-08-23 22:21:45 +00:00
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2020-10-29 04:47:52 +00:00
|
|
|
|
|
|
|
static inline int dfu_write_by_alt(int dfu_alt_num, void *addr,
|
|
|
|
unsigned int len, char *interface,
|
|
|
|
char *devstring)
|
|
|
|
{
|
|
|
|
puts("write support for DFU not available!\n");
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2015-08-23 22:21:45 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-17 13:58:23 +00:00
|
|
|
int dfu_add(struct usb_configuration *c);
|
2012-08-06 12:41:07 +00:00
|
|
|
#endif /* __DFU_ENTITY_H_ */
|