mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-23 13:56:20 +00:00
dfu: defer parsing of device string to IO backend
Devices are not all identified by a single integer. To support this, defer the parsing of the device string to the IO backed, so that it can apply the appropriate rules. SPI devices are specified as controller:chip_select. SPI/SF support will be added soon. MMC devices can also be specified as controller[.hwpart][:partition] in many commands, although we don't support that syntax in DFU. Signed-off-by: Stephen Warren <swarren@nvidia.com>
This commit is contained in:
parent
3ee9593fce
commit
dd64827eb6
6 changed files with 38 additions and 32 deletions
|
@ -24,8 +24,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
|
|
||||||
int ret, i = 0;
|
int ret, i = 0;
|
||||||
|
|
||||||
ret = dfu_init_env_entities(interface, simple_strtoul(devstring,
|
ret = dfu_init_env_entities(interface, devstring);
|
||||||
NULL, 10));
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ static int dfu_find_alt_num(const char *s)
|
||||||
return ++i;
|
return ++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dfu_init_env_entities(char *interface, int dev)
|
int dfu_init_env_entities(char *interface, char *devstr)
|
||||||
{
|
{
|
||||||
const char *str_env;
|
const char *str_env;
|
||||||
char *env_bkp;
|
char *env_bkp;
|
||||||
|
@ -57,7 +57,7 @@ int dfu_init_env_entities(char *interface, int dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
env_bkp = strdup(str_env);
|
env_bkp = strdup(str_env);
|
||||||
ret = dfu_config_entities(env_bkp, interface, dev);
|
ret = dfu_config_entities(env_bkp, interface, devstr);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error("DFU entities configuration failed!\n");
|
error("DFU entities configuration failed!\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -389,26 +389,25 @@ int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
|
static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
|
||||||
char *interface, int num)
|
char *interface, char *devstr)
|
||||||
{
|
{
|
||||||
char *st;
|
char *st;
|
||||||
|
|
||||||
debug("%s: %s interface: %s num: %d\n", __func__, s, interface, num);
|
debug("%s: %s interface: %s dev: %s\n", __func__, s, interface, devstr);
|
||||||
st = strsep(&s, " ");
|
st = strsep(&s, " ");
|
||||||
strcpy(dfu->name, st);
|
strcpy(dfu->name, st);
|
||||||
|
|
||||||
dfu->dev_num = num;
|
|
||||||
dfu->alt = alt;
|
dfu->alt = alt;
|
||||||
|
|
||||||
/* Specific for mmc device */
|
/* Specific for mmc device */
|
||||||
if (strcmp(interface, "mmc") == 0) {
|
if (strcmp(interface, "mmc") == 0) {
|
||||||
if (dfu_fill_entity_mmc(dfu, s))
|
if (dfu_fill_entity_mmc(dfu, devstr, s))
|
||||||
return -1;
|
return -1;
|
||||||
} else if (strcmp(interface, "nand") == 0) {
|
} else if (strcmp(interface, "nand") == 0) {
|
||||||
if (dfu_fill_entity_nand(dfu, s))
|
if (dfu_fill_entity_nand(dfu, devstr, s))
|
||||||
return -1;
|
return -1;
|
||||||
} else if (strcmp(interface, "ram") == 0) {
|
} else if (strcmp(interface, "ram") == 0) {
|
||||||
if (dfu_fill_entity_ram(dfu, s))
|
if (dfu_fill_entity_ram(dfu, devstr, s))
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
printf("%s: Device %s not (yet) supported!\n",
|
printf("%s: Device %s not (yet) supported!\n",
|
||||||
|
@ -434,7 +433,7 @@ void dfu_free_entities(void)
|
||||||
alt_num_cnt = 0;
|
alt_num_cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dfu_config_entities(char *env, char *interface, int num)
|
int dfu_config_entities(char *env, char *interface, char *devstr)
|
||||||
{
|
{
|
||||||
struct dfu_entity *dfu;
|
struct dfu_entity *dfu;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
@ -457,7 +456,8 @@ int dfu_config_entities(char *env, char *interface, int num)
|
||||||
for (i = 0; i < dfu_alt_num; i++) {
|
for (i = 0; i < dfu_alt_num; i++) {
|
||||||
|
|
||||||
s = strsep(&env, ";");
|
s = strsep(&env, ";");
|
||||||
ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface, num);
|
ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface,
|
||||||
|
devstr);
|
||||||
if (ret)
|
if (ret)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ static int mmc_access_part(struct dfu_entity *dfu, struct mmc *mmc, int part)
|
||||||
if (part == mmc->part_num)
|
if (part == mmc->part_num)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = mmc_switch_part(dfu->dev_num, part);
|
ret = mmc_switch_part(dfu->data.mmc.dev_num, part);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error("Cannot switch to partition %d\n", part);
|
error("Cannot switch to partition %d\n", part);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -40,7 +40,7 @@ static int mmc_access_part(struct dfu_entity *dfu, struct mmc *mmc, int part)
|
||||||
static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
|
static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
|
||||||
u64 offset, void *buf, long *len)
|
u64 offset, void *buf, long *len)
|
||||||
{
|
{
|
||||||
struct mmc *mmc = find_mmc_device(dfu->dev_num);
|
struct mmc *mmc = find_mmc_device(dfu->data.mmc.dev_num);
|
||||||
u32 blk_start, blk_count, n = 0;
|
u32 blk_start, blk_count, n = 0;
|
||||||
int ret, part_num_bkp = 0;
|
int ret, part_num_bkp = 0;
|
||||||
|
|
||||||
|
@ -67,15 +67,15 @@ static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("%s: %s dev: %d start: %d cnt: %d buf: 0x%p\n", __func__,
|
debug("%s: %s dev: %d start: %d cnt: %d buf: 0x%p\n", __func__,
|
||||||
op == DFU_OP_READ ? "MMC READ" : "MMC WRITE", dfu->dev_num,
|
op == DFU_OP_READ ? "MMC READ" : "MMC WRITE",
|
||||||
blk_start, blk_count, buf);
|
dfu->data.mmc.dev_num, blk_start, blk_count, buf);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case DFU_OP_READ:
|
case DFU_OP_READ:
|
||||||
n = mmc->block_dev.block_read(dfu->dev_num, blk_start,
|
n = mmc->block_dev.block_read(dfu->data.mmc.dev_num, blk_start,
|
||||||
blk_count, buf);
|
blk_count, buf);
|
||||||
break;
|
break;
|
||||||
case DFU_OP_WRITE:
|
case DFU_OP_WRITE:
|
||||||
n = mmc->block_dev.block_write(dfu->dev_num, blk_start,
|
n = mmc->block_dev.block_write(dfu->data.mmc.dev_num, blk_start,
|
||||||
blk_count, buf);
|
blk_count, buf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -270,7 +270,7 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf,
|
||||||
* 4th (optional):
|
* 4th (optional):
|
||||||
* mmcpart <num> (access to HW eMMC partitions)
|
* mmcpart <num> (access to HW eMMC partitions)
|
||||||
*/
|
*/
|
||||||
int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
|
int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
|
||||||
{
|
{
|
||||||
const char *entity_type;
|
const char *entity_type;
|
||||||
size_t second_arg;
|
size_t second_arg;
|
||||||
|
@ -281,6 +281,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
|
||||||
const char *argv[3];
|
const char *argv[3];
|
||||||
const char **parg = argv;
|
const char **parg = argv;
|
||||||
|
|
||||||
|
dfu->data.mmc.dev_num = simple_strtoul(devstr, NULL, 10);
|
||||||
|
|
||||||
for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) {
|
for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) {
|
||||||
*parg = strsep(&s, " ");
|
*parg = strsep(&s, " ");
|
||||||
if (*parg == NULL) {
|
if (*parg == NULL) {
|
||||||
|
@ -297,9 +299,10 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
|
||||||
second_arg = simple_strtoul(argv[1], NULL, 0);
|
second_arg = simple_strtoul(argv[1], NULL, 0);
|
||||||
third_arg = simple_strtoul(argv[2], NULL, 0);
|
third_arg = simple_strtoul(argv[2], NULL, 0);
|
||||||
|
|
||||||
mmc = find_mmc_device(dfu->dev_num);
|
mmc = find_mmc_device(dfu->data.mmc.dev_num);
|
||||||
if (mmc == NULL) {
|
if (mmc == NULL) {
|
||||||
error("Couldn't find MMC device no. %d.\n", dfu->dev_num);
|
error("Couldn't find MMC device no. %d.\n",
|
||||||
|
dfu->data.mmc.dev_num);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,7 @@ unsigned int dfu_polltimeout_nand(struct dfu_entity *dfu)
|
||||||
return DFU_DEFAULT_POLL_TIMEOUT;
|
return DFU_DEFAULT_POLL_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
|
int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s)
|
||||||
{
|
{
|
||||||
char *st;
|
char *st;
|
||||||
int ret, dev, part;
|
int ret, dev, part;
|
||||||
|
|
|
@ -52,7 +52,7 @@ static int dfu_read_medium_ram(struct dfu_entity *dfu, u64 offset,
|
||||||
return dfu_transfer_medium_ram(DFU_OP_READ, dfu, offset, buf, len);
|
return dfu_transfer_medium_ram(DFU_OP_READ, dfu, offset, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s)
|
int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s)
|
||||||
{
|
{
|
||||||
char *st;
|
char *st;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ enum dfu_op {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mmc_internal_data {
|
struct mmc_internal_data {
|
||||||
|
int dev_num;
|
||||||
|
|
||||||
/* RAW programming */
|
/* RAW programming */
|
||||||
unsigned int lba_start;
|
unsigned int lba_start;
|
||||||
unsigned int lba_size;
|
unsigned int lba_size;
|
||||||
|
@ -87,7 +89,6 @@ struct dfu_entity {
|
||||||
char name[DFU_NAME_SIZE];
|
char name[DFU_NAME_SIZE];
|
||||||
int alt;
|
int alt;
|
||||||
void *dev_private;
|
void *dev_private;
|
||||||
int dev_num;
|
|
||||||
enum dfu_device_type dev_type;
|
enum dfu_device_type dev_type;
|
||||||
enum dfu_layout layout;
|
enum dfu_layout layout;
|
||||||
|
|
||||||
|
@ -125,7 +126,7 @@ struct dfu_entity {
|
||||||
unsigned int inited:1;
|
unsigned int inited:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
int dfu_config_entities(char *s, char *interface, int num);
|
int dfu_config_entities(char *s, char *interface, char *devstr);
|
||||||
void dfu_free_entities(void);
|
void dfu_free_entities(void);
|
||||||
void dfu_show_entities(void);
|
void dfu_show_entities(void);
|
||||||
int dfu_get_alt_number(void);
|
int dfu_get_alt_number(void);
|
||||||
|
@ -136,7 +137,7 @@ char *dfu_extract_token(char** e, int *n);
|
||||||
void dfu_trigger_reset(void);
|
void dfu_trigger_reset(void);
|
||||||
int dfu_get_alt(char *name);
|
int dfu_get_alt(char *name);
|
||||||
bool dfu_reset(void);
|
bool dfu_reset(void);
|
||||||
int dfu_init_env_entities(char *interface, int dev);
|
int dfu_init_env_entities(char *interface, char *devstr);
|
||||||
unsigned char *dfu_get_buf(void);
|
unsigned char *dfu_get_buf(void);
|
||||||
unsigned char *dfu_free_buf(void);
|
unsigned char *dfu_free_buf(void);
|
||||||
unsigned long dfu_get_buf_size(void);
|
unsigned long dfu_get_buf_size(void);
|
||||||
|
@ -146,9 +147,10 @@ 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);
|
int dfu_flush(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
|
||||||
/* Device specific */
|
/* Device specific */
|
||||||
#ifdef CONFIG_DFU_MMC
|
#ifdef CONFIG_DFU_MMC
|
||||||
extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
|
extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s);
|
||||||
#else
|
#else
|
||||||
static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
|
static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr,
|
||||||
|
char *s)
|
||||||
{
|
{
|
||||||
puts("MMC support not available!\n");
|
puts("MMC support not available!\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -156,9 +158,10 @@ static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_DFU_NAND
|
#ifdef CONFIG_DFU_NAND
|
||||||
extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
|
extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s);
|
||||||
#else
|
#else
|
||||||
static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
|
static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr,
|
||||||
|
char *s)
|
||||||
{
|
{
|
||||||
puts("NAND support not available!\n");
|
puts("NAND support not available!\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -166,9 +169,10 @@ static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_DFU_RAM
|
#ifdef CONFIG_DFU_RAM
|
||||||
extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s);
|
extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s);
|
||||||
#else
|
#else
|
||||||
static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s)
|
static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr,
|
||||||
|
char *s)
|
||||||
{
|
{
|
||||||
puts("RAM support not available!\n");
|
puts("RAM support not available!\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue