Adding support functions to run dfu commands with support for eMMC/MMC/SD memory device.
Signed-off-by: Ravi Babu <ravib...@ti.com> --- drivers/dfu/dfu.c | 28 ++++++++++++++++++++++++++++ drivers/dfu/dfu_mmc.c | 28 ++++++++++++++++++++++++++++ include/dfu.h | 8 ++++++++ 3 files changed, 64 insertions(+) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 20dfcbb..1d4690b 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -16,6 +16,7 @@ #include <hash.h> #include <linux/list.h> #include <linux/compiler.h> +#include <environment.h> static LIST_HEAD(dfu_list); static int dfu_alt_num; @@ -596,3 +597,30 @@ int dfu_write_from_mem_addr(struct dfu_entity *dfu, void *buf, int size) return ret; } + +int dfu_run_cmd(char *dfu_alt_info, char *dfu_cmd_str) +{ + char *str_env; + int ret; + + /* set default environment */ + set_default_env(0); + str_env = getenv(dfu_alt_info); + if (!str_env) { + error("\"dfu_alt_info\" env variable not defined!\n"); + return -EINVAL; + } + + ret = setenv("dfu_alt_info", str_env); + if (ret) { + error("unable to set env variable \"dfu_alt_info\"!\n"); + return -EINVAL; + } + + /* invoke dfu command */ + ret = run_command(dfu_cmd_str, 0); + if (ret) + error("dfu: error = %d\n", ret); + + return ret; +} diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index faece88..28517e8 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -15,6 +15,7 @@ #include <ext4fs.h> #include <fat.h> #include <mmc.h> +#include <environment.h> static unsigned char *dfu_file_buf; static long dfu_file_buf_len; @@ -401,3 +402,30 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) return 0; } + +int dfu_run_mmc(int usb_index, int mmc_dev, char *dfu_alt_info) +{ + char cmd_buf[DFU_CMD_BUF_SIZE]; + struct mmc *mmcdev; + struct mmc **mmc = &mmcdev; + int device = mmc_dev; + int ret; + + /* initialize the mmc module */ + mmc_initialize(0); + + *mmc = find_mmc_device(device); + if (!*mmc) { + error("failed to find mmc device %d\n", device); + return -ENODEV; + } + + ret = mmc_init(*mmc); + if (ret) { + error("spl: mmc init failed with error: %d\n", ret); + return ret; + } + + sprintf(cmd_buf, "dfu %d mmc %d", usb_index, device); + return dfu_run_cmd(dfu_alt_info, cmd_buf); +} diff --git a/include/dfu.h b/include/dfu.h index f39d3f1..0bc75bc 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -274,4 +274,12 @@ static inline int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, #endif int dfu_add(struct usb_configuration *c); +/* dfu_run_umc - run dfu command with chosen mmc device interface + * @param usb_index - usb controller number + * @param mmc_dev - mmc device nubmer + * + * @return 0 on success, otherwise error code + */ +int dfu_run_mmc(int usb_index, int mmc_dev, char *dfu_alt_info); +int dfu_run_cmd(char *dfu_alt_info, char *dfu_cmd_str); #endif /* __DFU_ENTITY_H_ */ -- 1.7.9.5 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot