[U-Boot] [RFC PATCH 3/5] spl: dfu: adding dfu support functions for SPL-DFU

B, Ravi ravibabu at ti.com
Mon May 30 14:49:20 CEST 2016


Hi Lukasz


> On 30-May-2016, at 5:34 PM, Lukasz Majewski <l.majewski at samsung.com> wrote:
> 
> Hi Ravi,
> 
>> Adding support functions to run dfu commands
>> with support for eMMC/MMC/SD memory device.
>> 
>> Signed-off-by: Ravi Babu <ravibabu at 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_ */
> 
> I would like to avoid mixing SPL and non SPL code as much as possible:
> 
> I can propose two options here:
> 1. In the ./drivers/dfu/ create dfu_spl.c file and put the needed
> functionality there.
> 
> 2. Or better, move all dfu related code to ./common/spl/spl_dfu.c 
> 
> 
Ok. That make sense. 

Regards
Ravi
> -- 
> Best regards,
> 
> Lukasz Majewski
> 
> Samsung R&D Institute Poland (SRPOL) | Linux Platform Group


More information about the U-Boot mailing list