mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-16 09:54:35 +00:00
dfu: mmc: raw data write fix
When user attempted to perform a raw write using DFU (vide dfu_fill_entity_mmc) with MMC interface not initialized before, get_mmc_blk_size() reported invalid (zero) block size - it wasn't possible to write ie. a new u-boot image. This commit fixes that by initializing MMC device before use in dfu_fill_entity_mmc(). While fixing initialization sequence, I had to change about half of dfu_fill_entity_mmc's body, so I refactored it on the way to make it, IMHO, considerably more comprehensible. Being left as dead code, get_mmc_blk_size() was removed. Tested on Samsung Goni. Signed-off-by: Mateusz Zalega <m.zalega@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Lukasz Majewski <l.majewski@samsung.com> Acked-by: Tom Rini <trini@ti.com> Cc: Minkyu Kang <mk7.kang@samsung.com>
This commit is contained in:
parent
75504e9592
commit
711b931f90
2 changed files with 68 additions and 48 deletions
|
@ -184,66 +184,91 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param s Parameter string containing space-separated arguments:
|
||||||
|
* 1st:
|
||||||
|
* raw (raw read/write)
|
||||||
|
* fat (files)
|
||||||
|
* ext4 (^)
|
||||||
|
* part (partition image)
|
||||||
|
* 2nd and 3rd:
|
||||||
|
* lba_start and lba_size, for raw write
|
||||||
|
* mmc_dev and mmc_part, for filesystems and part
|
||||||
|
*/
|
||||||
int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
|
int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
|
||||||
{
|
{
|
||||||
int dev, part;
|
const char *entity_type;
|
||||||
|
size_t second_arg;
|
||||||
|
size_t third_arg;
|
||||||
|
|
||||||
struct mmc *mmc;
|
struct mmc *mmc;
|
||||||
block_dev_desc_t *blk_dev;
|
|
||||||
disk_partition_t partinfo;
|
|
||||||
char *st;
|
|
||||||
|
|
||||||
dfu->dev_type = DFU_DEV_MMC;
|
const char *argv[3];
|
||||||
st = strsep(&s, " ");
|
const char **parg = argv;
|
||||||
if (!strcmp(st, "mmc")) {
|
|
||||||
dfu->layout = DFU_RAW_ADDR;
|
|
||||||
dfu->data.mmc.lba_start = simple_strtoul(s, &s, 16);
|
|
||||||
dfu->data.mmc.lba_size = simple_strtoul(++s, &s, 16);
|
|
||||||
dfu->data.mmc.lba_blk_size = get_mmc_blk_size(dfu->dev_num);
|
|
||||||
} else if (!strcmp(st, "fat")) {
|
|
||||||
dfu->layout = DFU_FS_FAT;
|
|
||||||
} else if (!strcmp(st, "ext4")) {
|
|
||||||
dfu->layout = DFU_FS_EXT4;
|
|
||||||
} else if (!strcmp(st, "part")) {
|
|
||||||
|
|
||||||
dfu->layout = DFU_RAW_ADDR;
|
for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) {
|
||||||
|
*parg = strsep(&s, " ");
|
||||||
dev = simple_strtoul(s, &s, 10);
|
if (*parg == NULL) {
|
||||||
s++;
|
error("Invalid number of arguments.\n");
|
||||||
part = simple_strtoul(s, &s, 10);
|
|
||||||
|
|
||||||
mmc = find_mmc_device(dev);
|
|
||||||
if (mmc == NULL || mmc_init(mmc)) {
|
|
||||||
printf("%s: could not find mmc device #%d!\n",
|
|
||||||
__func__, dev);
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
blk_dev = &mmc->block_dev;
|
entity_type = argv[0];
|
||||||
if (get_partition_info(blk_dev, part, &partinfo) != 0) {
|
second_arg = simple_strtoul(argv[1], NULL, 16);
|
||||||
printf("%s: could not find partition #%d on mmc device #%d!\n",
|
third_arg = simple_strtoul(argv[2], NULL, 16);
|
||||||
__func__, part, dev);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
dfu->data.mmc.lba_start = partinfo.start;
|
mmc = find_mmc_device(dfu->dev_num);
|
||||||
dfu->data.mmc.lba_size = partinfo.size;
|
if (mmc == NULL) {
|
||||||
dfu->data.mmc.lba_blk_size = partinfo.blksz;
|
error("Couldn't find MMC device no. %d.\n", dfu->dev_num);
|
||||||
|
|
||||||
} else {
|
|
||||||
printf("%s: Memory layout (%s) not supported!\n", __func__, st);
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dfu->layout == DFU_FS_EXT4 || dfu->layout == DFU_FS_FAT) {
|
if (mmc_init(mmc)) {
|
||||||
dfu->data.mmc.dev = simple_strtoul(s, &s, 10);
|
error("Couldn't init MMC device.\n");
|
||||||
dfu->data.mmc.part = simple_strtoul(++s, &s, 10);
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcmp(entity_type, "raw")) {
|
||||||
|
dfu->layout = DFU_RAW_ADDR;
|
||||||
|
dfu->data.mmc.lba_start = second_arg;
|
||||||
|
dfu->data.mmc.lba_size = third_arg;
|
||||||
|
dfu->data.mmc.lba_blk_size = mmc->read_bl_len;
|
||||||
|
} else if (!strcmp(entity_type, "part")) {
|
||||||
|
disk_partition_t partinfo;
|
||||||
|
block_dev_desc_t *blk_dev = &mmc->block_dev;
|
||||||
|
int mmcdev = second_arg;
|
||||||
|
int mmcpart = third_arg;
|
||||||
|
|
||||||
|
if (get_partition_info(blk_dev, mmcpart, &partinfo) != 0) {
|
||||||
|
error("Couldn't find part #%d on mmc device #%d\n",
|
||||||
|
mmcpart, mmcdev);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
dfu->layout = DFU_RAW_ADDR;
|
||||||
|
dfu->data.mmc.lba_start = partinfo.start;
|
||||||
|
dfu->data.mmc.lba_size = partinfo.size;
|
||||||
|
dfu->data.mmc.lba_blk_size = partinfo.blksz;
|
||||||
|
} else if (!strcmp(entity_type, "fat")) {
|
||||||
|
dfu->layout = DFU_FS_FAT;
|
||||||
|
} else if (!strcmp(entity_type, "ext4")) {
|
||||||
|
dfu->layout = DFU_FS_EXT4;
|
||||||
|
} else {
|
||||||
|
error("Memory layout (%s) not supported!\n", entity_type);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if it's NOT a raw write */
|
||||||
|
if (strcmp(entity_type, "raw")) {
|
||||||
|
dfu->data.mmc.dev = second_arg;
|
||||||
|
dfu->data.mmc.part = third_arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
dfu->dev_type = DFU_DEV_MMC;
|
||||||
dfu->read_medium = dfu_read_medium_mmc;
|
dfu->read_medium = dfu_read_medium_mmc;
|
||||||
dfu->write_medium = dfu_write_medium_mmc;
|
dfu->write_medium = dfu_write_medium_mmc;
|
||||||
dfu->flush_medium = dfu_flush_medium_mmc;
|
dfu->flush_medium = dfu_flush_medium_mmc;
|
||||||
|
|
||||||
/* initial state */
|
|
||||||
dfu->inited = 0;
|
dfu->inited = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -64,11 +64,6 @@ struct ram_internal_data {
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline unsigned int get_mmc_blk_size(int dev)
|
|
||||||
{
|
|
||||||
return find_mmc_device(dev)->read_bl_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DFU_NAME_SIZE 32
|
#define DFU_NAME_SIZE 32
|
||||||
#define DFU_CMD_BUF_SIZE 128
|
#define DFU_CMD_BUF_SIZE 128
|
||||||
#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
|
#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
|
||||||
|
|
Loading…
Add table
Reference in a new issue