summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/dfu/Kconfig21
-rw-r--r--drivers/dfu/Makefile2
-rw-r--r--drivers/dfu/dfu.c145
-rw-r--r--drivers/dfu/dfu_mmc.c13
-rw-r--r--drivers/dfu/dfu_mtd.c311
-rw-r--r--drivers/dfu/dfu_nand.c2
-rw-r--r--drivers/dfu/dfu_sf.c56
-rw-r--r--drivers/dfu/dfu_virt.c49
-rw-r--r--drivers/usb/dwc3/dwc3-generic.c4
-rw-r--r--drivers/usb/dwc3/gadget.c3
-rw-r--r--drivers/usb/gadget/f_thor.c7
-rw-r--r--drivers/usb/host/ehci-hcd.c51
12 files changed, 610 insertions, 54 deletions
diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
index 4692736c9d..9fe5bc0f58 100644
--- a/drivers/dfu/Kconfig
+++ b/drivers/dfu/Kconfig
@@ -46,5 +46,26 @@ config DFU_SF
This option enables using DFU to read and write to SPI flash based
storage.
+config DFU_SF_PART
+ bool "MTD partition support for SPI flash back end"
+ depends on DFU_SF && CMD_MTDPARTS
+ default y
+ help
+ This option enables the support of "part" and "partubi" target in
+ SPI flash DFU back end.
+
+config DFU_MTD
+ bool "MTD back end for DFU"
+ depends on MTD
+ help
+ This option enables using DFU to read and write to on any MTD device.
+
+config DFU_VIRT
+ bool "VIRTUAL flash back end for DFU"
+ help
+ This option enables using DFU to read and write to VIRTUAL device
+ used at board level to manage specific behavior
+ (OTP update for example).
+
endif
endmenu
diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile
index 4164f342ac..0d7925c083 100644
--- a/drivers/dfu/Makefile
+++ b/drivers/dfu/Makefile
@@ -5,7 +5,9 @@
obj-$(CONFIG_$(SPL_)DFU) += dfu.o
obj-$(CONFIG_$(SPL_)DFU_MMC) += dfu_mmc.o
+obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o
obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
+obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o
diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index d2b67b18cf..38aecd3a05 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -23,6 +23,22 @@ static int alt_num_cnt;
static struct hash_algo *dfu_hash_algo;
/*
+ * The purpose of the dfu_flush_callback() function is to
+ * provide callback for dfu user
+ */
+__weak void dfu_flush_callback(struct dfu_entity *dfu)
+{
+}
+
+/*
+ * The purpose of the dfu_initiated_callback() function is to
+ * provide callback for dfu user
+ */
+__weak void dfu_initiated_callback(struct dfu_entity *dfu)
+{
+}
+
+/*
* The purpose of the dfu_usb_get_reset() function is to
* provide information if after USB_DETACH request
* being sent the dfu-util performed reset of USB
@@ -53,6 +69,54 @@ static int dfu_find_alt_num(const char *s)
return ++i;
}
+/*
+ * treat dfu_alt_info with several interface information
+ * to allow DFU on several device with one command,
+ * the string format is
+ * interface devstring'='alternate list (';' separated)
+ * and each interface separated by '&'
+ */
+int dfu_config_interfaces(char *env)
+{
+ struct dfu_entity *dfu;
+ char *s, *i, *d, *a, *part;
+ int ret = -EINVAL;
+ int n = 1;
+
+ s = env;
+ for (; *s; s++) {
+ if (*s == ';')
+ n++;
+ if (*s == '&')
+ n++;
+ }
+ ret = dfu_alt_init(n, &dfu);
+ if (ret)
+ return ret;
+
+ s = env;
+ while (s) {
+ ret = -EINVAL;
+ i = strsep(&s, " ");
+ if (!i)
+ break;
+ d = strsep(&s, "=");
+ if (!d)
+ break;
+ a = strsep(&s, "&");
+ if (!a)
+ a = s;
+ do {
+ part = strsep(&a, ";");
+ ret = dfu_alt_add(dfu, i, d, part);
+ if (ret)
+ return ret;
+ } while (a);
+ }
+
+ return ret;
+}
+
int dfu_init_env_entities(char *interface, char *devstr)
{
const char *str_env;
@@ -69,7 +133,11 @@ int dfu_init_env_entities(char *interface, char *devstr)
}
env_bkp = strdup(str_env);
- ret = dfu_config_entities(env_bkp, interface, devstr);
+ if (!interface && !devstr)
+ ret = dfu_config_interfaces(env_bkp);
+ else
+ ret = dfu_config_entities(env_bkp, interface, devstr);
+
if (ret) {
pr_err("DFU entities configuration failed!\n");
pr_err("(partition table does not match dfu_alt_info?)\n");
@@ -83,6 +151,7 @@ done:
static unsigned char *dfu_buf;
static unsigned long dfu_buf_size;
+static enum dfu_device_type dfu_buf_device_type;
unsigned char *dfu_free_buf(void)
{
@@ -100,6 +169,10 @@ unsigned char *dfu_get_buf(struct dfu_entity *dfu)
{
char *s;
+ /* manage several entity with several contraint */
+ if (dfu_buf && dfu->dev_type != dfu_buf_device_type)
+ dfu_free_buf();
+
if (dfu_buf != NULL)
return dfu_buf;
@@ -118,6 +191,7 @@ unsigned char *dfu_get_buf(struct dfu_entity *dfu)
printf("%s: Could not memalign 0x%lx bytes\n",
__func__, dfu_buf_size);
+ dfu_buf_device_type = dfu->dev_type;
return dfu_buf;
}
@@ -205,6 +279,7 @@ int dfu_transaction_initiate(struct dfu_entity *dfu, bool read)
}
dfu->inited = 1;
+ dfu_initiated_callback(dfu);
return 0;
}
@@ -224,6 +299,8 @@ int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num)
printf("\nDFU complete %s: 0x%08x\n", dfu_hash_algo->name,
dfu->crc);
+ dfu_flush_callback(dfu);
+
dfu_transaction_cleanup(dfu);
return ret;
@@ -338,6 +415,8 @@ static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf, int size)
debug("%s: Read error!\n", __func__);
return ret;
}
+ if (dfu->b_left == 0)
+ break;
dfu->offset += dfu->b_left;
dfu->r_left -= dfu->b_left;
@@ -402,6 +481,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
if (strcmp(interface, "mmc") == 0) {
if (dfu_fill_entity_mmc(dfu, devstr, s))
return -1;
+ } else if (strcmp(interface, "mtd") == 0) {
+ if (dfu_fill_entity_mtd(dfu, devstr, s))
+ return -1;
} else if (strcmp(interface, "nand") == 0) {
if (dfu_fill_entity_nand(dfu, devstr, s))
return -1;
@@ -411,6 +493,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
} else if (strcmp(interface, "sf") == 0) {
if (dfu_fill_entity_sf(dfu, devstr, s))
return -1;
+ } else if (strcmp(interface, "virt") == 0) {
+ if (dfu_fill_entity_virt(dfu, devstr, s))
+ return -1;
} else {
printf("%s: Device %s not (yet) supported!\n",
__func__, interface);
@@ -439,13 +524,12 @@ void dfu_free_entities(void)
alt_num_cnt = 0;
}
-int dfu_config_entities(char *env, char *interface, char *devstr)
+int dfu_alt_init(int num, struct dfu_entity **dfu)
{
- struct dfu_entity *dfu;
- int i, ret;
char *s;
+ int ret;
- dfu_alt_num = dfu_find_alt_num(env);
+ dfu_alt_num = num;
debug("%s: dfu_alt_num=%d\n", __func__, dfu_alt_num);
dfu_hash_algo = NULL;
@@ -456,21 +540,49 @@ int dfu_config_entities(char *env, char *interface, char *devstr)
pr_err("Hash algorithm %s not supported\n", s);
}
- dfu = calloc(sizeof(*dfu), dfu_alt_num);
- if (!dfu)
+ *dfu = calloc(sizeof(struct dfu_entity), dfu_alt_num);
+ if (!*dfu)
+ return -1;
+
+ return 0;
+}
+
+int dfu_alt_add(struct dfu_entity *dfu, char *interface, char *devstr, char *s)
+{
+ struct dfu_entity *p_dfu;
+ int ret;
+
+ if (alt_num_cnt >= dfu_alt_num)
+ return -1;
+
+ p_dfu = &dfu[alt_num_cnt];
+ ret = dfu_fill_entity(p_dfu, s, alt_num_cnt, interface, devstr);
+ if (ret)
return -1;
- for (i = 0; i < dfu_alt_num; i++) {
+ list_add_tail(&p_dfu->list, &dfu_list);
+ alt_num_cnt++;
+
+ return 0;
+}
+
+int dfu_config_entities(char *env, char *interface, char *devstr)
+{
+ struct dfu_entity *dfu;
+ int i, ret;
+ char *s;
+
+ ret = dfu_alt_init(dfu_find_alt_num(env), &dfu);
+ if (ret)
+ return -1;
+
+ for (i = 0; i < dfu_alt_num; i++) {
s = strsep(&env, ";");
- ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface,
- devstr);
+ ret = dfu_alt_add(dfu, interface, devstr, s);
if (ret) {
/* We will free "dfu" in dfu_free_entities() */
return -1;
}
-
- list_add_tail(&dfu[i].list, &dfu_list);
- alt_num_cnt++;
}
return 0;
@@ -478,14 +590,15 @@ int dfu_config_entities(char *env, char *interface, char *devstr)
const char *dfu_get_dev_type(enum dfu_device_type t)
{
- const char *dev_t[] = {NULL, "eMMC", "OneNAND", "NAND", "RAM", "SF" };
+ const char *const dev_t[] = {NULL, "eMMC", "OneNAND", "NAND", "RAM",
+ "SF", "MTD", "VIRT"};
return dev_t[t];
}
const char *dfu_get_layout(enum dfu_layout l)
{
- const char *dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2",
- "EXT3", "EXT4", "RAM_ADDR" };
+ const char *const dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2",
+ "EXT3", "EXT4", "RAM_ADDR" };
return dfu_layout[l];
}
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index 403fd5351d..5b551f6ae1 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -352,6 +352,7 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
struct blk_desc *blk_dev = mmc_get_blk_desc(mmc);
int mmcdev = second_arg;
int mmcpart = third_arg;
+ int offset = 0;
if (part_get_info(blk_dev, mmcpart, &partinfo) != 0) {
pr_err("Couldn't find part #%d on mmc device #%d\n",
@@ -359,9 +360,17 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
return -ENODEV;
}
+ /*
+ * Check for an extra entry at dfu_alt_info env variable
+ * specifying the mmc HW defined partition number
+ */
+ if (s)
+ if (!strcmp(strsep(&s, " "), "offset"))
+ offset = simple_strtoul(s, NULL, 0);
+
dfu->layout = DFU_RAW_ADDR;
- dfu->data.mmc.lba_start = partinfo.start;
- dfu->data.mmc.lba_size = partinfo.size;
+ dfu->data.mmc.lba_start = partinfo.start + offset;
+ dfu->data.mmc.lba_size = partinfo.size-offset;
dfu->data.mmc.lba_blk_size = partinfo.blksz;
} else if (!strcmp(entity_type, "fat")) {
dfu->layout = DFU_FS_FAT;
diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c
new file mode 100644
index 0000000000..9528a7b4ee
--- /dev/null
+++ b/drivers/dfu/dfu_mtd.c
@@ -0,0 +1,311 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * dfu_mtd.c -- DFU for MTD device.
+ *
+ * Copyright (C) 2019,STMicroelectronics - All Rights Reserved
+ *
+ * Based on dfu_nand.c
+ */
+
+#include <common.h>
+#include <dfu.h>
+#include <mtd.h>
+#include <jffs2/load_kernel.h>
+
+static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size)
+{
+ return !do_div(size, mtd->erasesize);
+}
+
+static int mtd_block_op(enum dfu_op op, struct dfu_entity *dfu,
+ u64 offset, void *buf, long *len)
+{
+ u64 off, lim, remaining;
+ struct mtd_info *mtd = dfu->data.mtd.info;
+ struct mtd_oob_ops io_op = {};
+ int ret = 0;
+ bool has_pages = mtd->type == MTD_NANDFLASH ||
+ mtd->type == MTD_MLCNANDFLASH;
+
+ /* if buf == NULL return total size of the area */
+ if (!buf) {
+ *len = dfu->data.mtd.size;
+ return 0;
+ }
+
+ off = dfu->data.mtd.start + offset + dfu->bad_skip;
+ lim = dfu->data.mtd.start + dfu->data.mtd.size;
+
+ if (off >= lim) {
+ printf("Limit reached 0x%llx\n", lim);
+ *len = 0;
+ return op == DFU_OP_READ ? 0 : -EIO;
+ }
+ /* limit request with the available size */
+ if (off + *len >= lim)
+ *len = lim - off;
+
+ if (!mtd_is_aligned_with_block_size(mtd, off)) {
+ printf("Offset not aligned with a block (0x%x)\n",
+ mtd->erasesize);
+ return 0;
+ }
+
+ /* first erase */
+ if (op == DFU_OP_WRITE) {
+ struct erase_info erase_op = {};
+
+ remaining = round_up(*len, mtd->erasesize);
+ erase_op.mtd = mtd;
+ erase_op.addr = off;
+ erase_op.len = mtd->erasesize;
+ erase_op.scrub = 0;
+
+ while (remaining) {
+ if (erase_op.addr + remaining > lim) {
+ printf("Limit reached 0x%llx while erasing at offset 0x%llx\n",
+ lim, off);
+ return -EIO;
+ }
+
+ ret = mtd_erase(mtd, &erase_op);
+
+ if (ret) {
+ /* Abort if its not a bad block error */
+ if (ret != -EIO) {
+ printf("Failure while erasing at offset 0x%llx\n",
+ erase_op.fail_addr);
+ return 0;
+ }
+ printf("Skipping bad block at 0x%08llx\n",
+ erase_op.addr);
+ } else {
+ remaining -= mtd->erasesize;
+ }
+
+ /* Continue erase behind bad block */
+ erase_op.addr += mtd->erasesize;
+ }
+ }
+
+ io_op.mode = MTD_OPS_AUTO_OOB;
+ io_op.len = *len;
+ if (has_pages && io_op.len > mtd->writesize)
+ io_op.len = mtd->writesize;
+ io_op.ooblen = 0;
+ io_op.datbuf = buf;
+ io_op.oobbuf = NULL;
+
+ /* Loop over to do the actual read/write */
+ remaining = *len;
+ while (remaining) {
+ if (off + remaining > lim) {
+ printf("Limit reached 0x%llx while %s at offset 0x%llx\n",
+ lim, op == DFU_OP_READ ? "reading" : "writing",
+ off);
+ if (op == DFU_OP_READ) {
+ *len -= remaining;
+ return 0;
+ } else {
+ return -EIO;
+ }
+ }
+
+ /* Skip the block if it is bad */
+ if (mtd_is_aligned_with_block_size(mtd, off) &&
+ mtd_block_isbad(mtd, off)) {
+ off += mtd->erasesize;
+ dfu->bad_skip += mtd->erasesize;
+ continue;
+ }
+
+ if (op == DFU_OP_READ)
+ ret = mtd_read_oob(mtd, off, &io_op);
+ else
+ ret = mtd_write_oob(mtd, off, &io_op);
+
+ if (ret) {
+ printf("Failure while %s at offset 0x%llx\n",
+ op == DFU_OP_READ ? "reading" : "writing", off);
+ return -EIO;
+ }
+
+ off += io_op.retlen;
+ remaining -= io_op.retlen;
+ io_op.datbuf += io_op.retlen;
+ io_op.len = remaining;
+ if (has_pages && io_op.len > mtd->writesize)
+ io_op.len = mtd->writesize;
+ }
+
+ return ret;
+}
+
+static int dfu_get_medium_size_mtd(struct dfu_entity *dfu, u64 *size)
+{
+ *size = dfu->data.mtd.info->size;
+
+ return 0;
+}
+
+static int dfu_read_medium_mtd(struct dfu_entity *dfu, u64 offset, void *buf,
+ long *len)
+{
+ int ret = -1;
+
+ switch (dfu->layout) {
+ case DFU_RAW_ADDR:
+ ret = mtd_block_op(DFU_OP_READ, dfu, offset, buf, len);
+ break;
+ default:
+ printf("%s: Layout (%s) not (yet) supported!\n", __func__,
+ dfu_get_layout(dfu->layout));
+ }
+
+ return ret;
+}
+
+static int dfu_write_medium_mtd(struct dfu_entity *dfu,
+ u64 offset, void *buf, long *len)
+{
+ int ret = -1;
+
+ switch (dfu->layout) {
+ case DFU_RAW_ADDR:
+ ret = mtd_block_op(DFU_OP_WRITE, dfu, offset, buf, len);
+ break;
+ default:
+ printf("%s: Layout (%s) not (yet) supported!\n", __func__,
+ dfu_get_layout(dfu->layout));
+ }
+
+ return ret;
+}
+
+static int dfu_flush_medium_mtd(struct dfu_entity *dfu)
+{
+ struct mtd_info *mtd = dfu->data.mtd.info;
+ u64 remaining;
+ int ret;
+
+ /* in case of ubi partition, erase rest of the partition */
+ if (dfu->data.nand.ubi) {
+ struct erase_info erase_op = {};
+
+ erase_op.mtd = dfu->data.mtd.info;
+ erase_op.addr = round_up(dfu->data.mtd.start + dfu->offset +
+ dfu->bad_skip, mtd->erasesize);
+ erase_op.len = mtd->erasesize;
+ erase_op.scrub = 0;
+
+ remaining = dfu->data.mtd.start + dfu->data.mtd.size -
+ erase_op.addr;
+
+ while (remaining) {
+ ret = mtd_erase(mtd, &erase_op);
+
+ if (ret) {
+ /* Abort if its not a bad block error */
+ if (ret != -EIO)
+ break;
+ printf("Skipping bad block at 0x%08llx\n",
+ erase_op.addr);
+ }
+
+ /* Skip bad block and continue behind it */
+ erase_op.addr += mtd->erasesize;
+ remaining -= mtd->erasesize;
+ }
+ }
+ return 0;
+}
+
+static unsigned int dfu_polltimeout_mtd(struct dfu_entity *dfu)
+{
+ /*
+ * Currently, Poll Timeout != 0 is only needed on nand
+ * ubi partition, as sectors which are not used need
+ * to be erased
+ */
+ if (dfu->data.nand.ubi)
+ return DFU_MANIFEST_POLL_TIMEOUT;
+
+ return DFU_DEFAULT_POLL_TIMEOUT;
+}
+
+int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s)
+{
+ char *st;
+ struct mtd_info *mtd;
+ bool has_pages;
+ int ret, part;
+
+ mtd = get_mtd_device_nm(devstr);
+ if (IS_ERR_OR_NULL(mtd))
+ return -ENODEV;
+ put_mtd_device(mtd);
+
+ dfu->dev_type = DFU_DEV_MTD;
+ dfu->data.mtd.info = mtd;
+
+ has_pages = mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
+ dfu->max_buf_size = has_pages ? mtd->erasesize : 0;
+
+ st = strsep(&s, " ");
+ if (!strcmp(st, "raw")) {
+ dfu->layout = DFU_RAW_ADDR;
+ dfu->data.mtd.start = simple_strtoul(s, &s, 16);
+ s++;
+ dfu->data.mtd.size = simple_strtoul(s, &s, 16);
+ } else if ((!strcmp(st, "part")) || (!strcmp(st, "partubi"))) {
+ char mtd_id[32];
+ struct mtd_device *mtd_dev;
+ u8 part_num;
+ struct part_info *pi;
+
+ dfu->layout = DFU_RAW_ADDR;
+
+ part = simple_strtoul(s, &s, 10);
+
+ sprintf(mtd_id, "%s,%d", devstr, part - 1);
+ printf("using id '%s'\n", mtd_id);
+
+ mtdparts_init();
+
+ ret = find_dev_and_part(mtd_id, &mtd_dev, &part_num, &pi);
+ if (ret != 0) {
+ printf("Could not locate '%s'\n", mtd_id);
+ return -1;
+ }
+
+ dfu->data.mtd.start = pi->offset;
+ dfu->data.mtd.size = pi->size;
+ if (!strcmp(st, "partubi"))
+ dfu->data.mtd.ubi = 1;
+ } else {
+ printf("%s: Memory layout (%s) not supported!\n", __func__, st);
+ return -1;
+ }
+
+ if (!mtd_is_aligned_with_block_size(mtd, dfu->data.mtd.start)) {
+ printf("Offset not aligned with a block (0x%x)\n",
+ mtd->erasesize);
+ return -EINVAL;
+ }
+ if (!mtd_is_aligned_with_block_size(mtd, dfu->data.mtd.size)) {
+ printf("Size not aligned with a block (0x%x)\n",
+ mtd->erasesize);
+ return -EINVAL;
+ }
+
+ dfu->get_medium_size = dfu_get_medium_size_mtd;
+ dfu->read_medium = dfu_read_medium_mtd;
+ dfu->write_medium = dfu_write_medium_mtd;
+ dfu->flush_medium = dfu_flush_medium_mtd;
+ dfu->poll_timeout = dfu_polltimeout_mtd;
+
+ /* initial state */
+ dfu->inited = 0;
+
+ return 0;
+}
diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c
index 0bfdbf9428..b812a3dfb1 100644
--- a/drivers/dfu/dfu_nand.c
+++ b/drivers/dfu/dfu_nand.c
@@ -214,7 +214,7 @@ int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s)
part = simple_strtoul(s, &s, 10);
sprintf(mtd_id, "%s%d,%d", "nand", dev, part - 1);
- printf("using id '%s'\n", mtd_id);
+ debug("using id '%s'\n", mtd_id);
mtdparts_init();
diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index 066e7670d1..0fdbfae434 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -10,6 +10,8 @@
#include <dfu.h>
#include <spi.h>
#include <spi_flash.h>
+#include <jffs2/load_kernel.h>
+#include <linux/mtd/mtd.h>
static int dfu_get_medium_size_sf(struct dfu_entity *dfu, u64 *size)
{
@@ -19,7 +21,7 @@ static int dfu_get_medium_size_sf(struct dfu_entity *dfu, u64 *size)
}
static int dfu_read_medium_sf(struct dfu_entity *dfu, u64 offset, void *buf,
- long *len)
+ long *len)
{
return spi_flash_read(dfu->data.sf.dev, dfu->data.sf.start + offset,
*len, buf);
@@ -32,7 +34,7 @@ static u64 find_sector(struct dfu_entity *dfu, u64 start, u64 offset)
}
static int dfu_write_medium_sf(struct dfu_entity *dfu,
- u64 offset, void *buf, long *len)
+ u64 offset, void *buf, long *len)
{
int ret;
@@ -52,11 +54,33 @@ static int dfu_write_medium_sf(struct dfu_entity *dfu,
static int dfu_flush_medium_sf(struct dfu_entity *dfu)
{
+ u64 off, length;
+
+ if (!CONFIG_IS_ENABLED(DFU_SF_PART) || !dfu->data.sf.ubi)
+ return 0;
+
+ /* in case of ubi partition, erase rest of the partition */
+ off = find_sector(dfu, dfu->data.sf.start, dfu->offset);
+ /* last write ended with unaligned length jump to next */
+ if (off != dfu->data.sf.start + dfu->offset)
+ off += dfu->data.sf.dev->sector_size;
+ length = dfu->data.sf.start + dfu->data.sf.size - off;
+ if (length)
+ return spi_flash_erase(dfu->data.sf.dev, off, length);
+
return 0;
}
static unsigned int dfu_polltimeout_sf(struct dfu_entity *dfu)
{
+ /*
+ * Currently, Poll Timeout != 0 is only needed on nand
+ * ubi partition, as sectors which are not used need
+ * to be erased
+ */
+ if (CONFIG_IS_ENABLED(DFU_SF_PART) && dfu->data.sf.ubi)
+ return DFU_MANIFEST_POLL_TIMEOUT;
+
return DFU_DEFAULT_POLL_TIMEOUT;
}
@@ -133,6 +157,34 @@ int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s)
dfu->data.sf.start = simple_strtoul(s, &s, 16);
s++;
dfu->data.sf.size = simple_strtoul(s, &s, 16);
+ } else if (CONFIG_IS_ENABLED(DFU_SF_PART) &&
+ (!strcmp(st, "part") || !strcmp(st, "partubi"))) {
+ char mtd_id[32];
+ struct mtd_device *mtd_dev;
+ u8 part_num;
+ struct part_info *pi;
+ int ret, dev, part;
+
+ dfu->layout = DFU_RAW_ADDR;
+
+ dev = simple_strtoul(s, &s, 10);
+ s++;
+ part = simple_strtoul(s, &s, 10);
+
+ sprintf(mtd_id, "%s%d,%d", "nor", dev, part - 1);
+ printf("using id '%s'\n", mtd_id);
+
+ mtdparts_init();
+
+ ret = find_dev_and_part(mtd_id, &mtd_dev, &part_num, &pi);
+ if (ret != 0) {
+ printf("Could not locate '%s'\n", mtd_id);
+ return -1;
+ }
+ dfu->data.sf.start = pi->offset;
+ dfu->data.sf.size = pi->size;
+ if (!strcmp(st, "partubi"))
+ dfu->data.sf.ubi = 1;
} else {
printf("%s: Memory layout (%s) not supported!\n", __func__, st);
spi_flash_free(dfu->data.sf.dev);
diff --git a/drivers/dfu/dfu_virt.c b/drivers/dfu/dfu_virt.c
new file mode 100644
index 0000000000..ea8c71f100
--- /dev/null
+++ b/drivers/dfu/dfu_virt.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
+ */
+#include <common.h>
+#include <dfu.h>
+#include <errno.h>
+#include <malloc.h>
+
+int __weak dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset,
+ void *buf, long *len)
+{
+ debug("%s: off=0x%llx, len=0x%x\n", __func__, offset, (u32)*len);
+
+ return 0;
+}
+
+int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
+{
+ *size = 0;
+
+ return 0;
+}
+
+int __weak dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
+ void *buf, long *len)
+{
+ debug("%s: off=0x%llx, len=0x%x\n", __func__, offset, (u32)*len);
+ *len = 0;
+
+ return 0;
+}
+
+int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char *s)
+{
+ debug("%s: devstr = %s\n", __func__, devstr);
+
+ dfu->dev_type = DFU_DEV_VIRT;
+ dfu->layout = DFU_RAW_ADDR;
+ dfu->data.virt.dev_num = simple_strtoul(devstr, NULL, 10);
+
+ dfu->write_medium = dfu_write_medium_virt;
+ dfu->get_medium_size = dfu_get_medium_size_virt;
+ dfu->read_medium = dfu_read_medium_virt;
+
+ dfu->inited = 0;
+
+ return 0;
+}
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 023e95395b..24b320bbce 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -338,7 +338,7 @@ static int dwc3_glue_reset_init(struct udevice *dev,
int ret;
ret = reset_get_bulk(dev, &glue->resets);
- if (ret == -ENOTSUPP)
+ if (ret == -ENOTSUPP || ret == -ENOENT)
return 0;
else if (ret)
return ret;
@@ -358,7 +358,7 @@ static int dwc3_glue_clk_init(struct udevice *dev,
int ret;
ret = clk_get_bulk(dev, &glue->clks);
- if (ret == -ENOSYS)
+ if (ret == -ENOSYS || ret == -ENOENT)
return 0;
if (ret)
return ret;
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 085f7b8968..67d11b4c0d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -242,7 +242,8 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
list_del(&req->list);
req->trb = NULL;
- dwc3_flush_cache((uintptr_t)req->request.dma, req->request.length);
+ if (req->request.length)
+ dwc3_flush_cache((uintptr_t)req->request.dma, req->request.length);
if (req->request.status == -EINPROGRESS)
req->request.status = status;
diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c
index 8b3b19feaf..920fa5279c 100644
--- a/drivers/usb/gadget/f_thor.c
+++ b/drivers/usb/gadget/f_thor.c
@@ -941,6 +941,13 @@ static int thor_eps_setup(struct usb_function *f)
dev->out_req = req;
/* ACM control EP */
ep = dev->int_ep;
+ d = ep_desc(gadget, &hs_int_desc, &fs_int_desc);
+ debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress);
+
+ result = usb_ep_enable(ep, d);
+ if (result)
+ goto err;
+
ep->driver_data = cdev; /* claim */
return 0;
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 61a61abb21..85918e85be 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -307,7 +307,7 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
volatile struct qTD *vtd;
unsigned long ts;
uint32_t *tdp;
- uint32_t endpt, maxpacket, token, usbsts;
+ uint32_t endpt, maxpacket, token, usbsts, qhtoken;
uint32_t c, toggle;
uint32_t cmd;
int timeout;
@@ -551,22 +551,21 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
flush_dcache_range((unsigned long)qtd,
ALIGN_END_ADDR(struct qTD, qtd, qtd_count));
- /* Set async. queue head pointer. */
- ehci_writel(&ctrl->hcor->or_asynclistaddr, virt_to_phys(&ctrl->qh_list));
-
usbsts = ehci_readl(&ctrl->hcor->or_usbsts);
ehci_writel(&ctrl->hcor->or_usbsts, (usbsts & 0x3f));
/* Enable async. schedule. */
cmd = ehci_readl(&ctrl->hcor->or_usbcmd);
- cmd |= CMD_ASE;
- ehci_writel(&ctrl->hcor->or_usbcmd, cmd);
+ if (!(cmd & CMD_ASE)) {
+ cmd |= CMD_ASE;
+ ehci_writel(&ctrl->hcor->or_usbcmd, cmd);
- ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, STS_ASS,
- 100 * 1000);
- if (ret < 0) {
- printf("EHCI fail timeout STS_ASS set\n");
- goto fail;
+ ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, STS_ASS,
+ 100 * 1000);
+ if (ret < 0) {
+ printf("EHCI fail timeout STS_ASS set\n");
+ goto fail;
+ }
}
/* Wait for TDs to be processed. */
@@ -587,6 +586,11 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
break;
WATCHDOG_RESET();
} while (get_timer(ts) < timeout);
+ qhtoken = hc32_to_cpu(qh->qh_overlay.qt_token);
+
+ ctrl->qh_list.qh_link = cpu_to_hc32(virt_to_phys(&ctrl->qh_list) | QH_LINK_TYPE_QH);
+ flush_dcache_range((unsigned long)&ctrl->qh_list,
+ ALIGN_END_ADDR(struct QH, &ctrl->qh_list, 1));
/*
* Invalidate the memory area occupied by buffer
@@ -605,25 +609,12 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
if (QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE)
printf("EHCI timed out on TD - token=%#x\n", token);
- /* Disable async schedule. */
- cmd = ehci_readl(&ctrl->hcor->or_usbcmd);
- cmd &= ~CMD_ASE;
- ehci_writel(&ctrl->hcor->or_usbcmd, cmd);
-
- ret = handshake((uint32_t *)&ctrl->hcor->or_usbsts, STS_ASS, 0,
- 100 * 1000);
- if (ret < 0) {
- printf("EHCI fail timeout STS_ASS reset\n");
- goto fail;
- }
-
- token = hc32_to_cpu(qh->qh_overlay.qt_token);
- if (!(QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_ACTIVE)) {
- debug("TOKEN=%#x\n", token);
- switch (QT_TOKEN_GET_STATUS(token) &
+ if (!(QT_TOKEN_GET_STATUS(qhtoken) & QT_TOKEN_STATUS_ACTIVE)) {
+ debug("TOKEN=%#x\n", qhtoken);
+ switch (QT_TOKEN_GET_STATUS(qhtoken) &
~(QT_TOKEN_STATUS_SPLITXSTATE | QT_TOKEN_STATUS_PERR)) {
case 0:
- toggle = QT_TOKEN_GET_DT(token);
+ toggle = QT_TOKEN_GET_DT(qhtoken);
usb_settoggle(dev, usb_pipeendpoint(pipe),
usb_pipeout(pipe), toggle);
dev->status = 0;
@@ -641,11 +632,11 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
break;
default:
dev->status = USB_ST_CRC_ERR;
- if (QT_TOKEN_GET_STATUS(token) & QT_TOKEN_STATUS_HALTED)
+ if (QT_TOKEN_GET_STATUS(qhtoken) & QT_TOKEN_STATUS_HALTED)
dev->status |= USB_ST_STALLED;
break;
}
- dev->act_len = length - QT_TOKEN_GET_TOTALBYTES(token);
+ dev->act_len = length - QT_TOKEN_GET_TOTALBYTES(qhtoken);
} else {
dev->act_len = 0;
#ifndef CONFIG_USB_EHCI_FARADAY