Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
Hi Fabio, > On Tue, Sep 22, 2015 at 12:23 AM, Stephen Warren > wrote: > > > Oh good:-) Nice to hear, that the bug is fixed. > > > > I was going to give you my dfu_alt_info, but it's at work right > > now, so I was waiting until tomorrow. I did try to repro this, but > > I was having a lot of trouble with both the two boards I have that > > have SPI, so wasn't able to test yet. > > > > One thing I did notice: dfu_sf.c's parsing code doesn't work with > > multiple entries in dfu_alt_info (e.g. for different partitions) > > since the parsing of the device parameter (to the dfu command; not > > part of dfu_info) modifies that parameter so it can't be parsed the > > second time around. Since you're set up to test this, perhaps you > > could fix it too? I assume all it'd need is to add a > > strdup()/free() to the start/end of the alt info parsing function? > > Yes, I noticed a problem here on parsing dfu_alt_info. In my case I > need to flash the u-boot binary at offset 0x400 of the SPI NOR, but I > was not able to find the correct syntax for this. I have tried: > > dfu_alt_info=u-boot raw 0x400 For some dfu_alt_info example, please refer to ./include/configs/trats[2].h files. > > ,but I am not familiar with the dfu_alt_info syntax, so maybe this > needs some adjustment. > > For the eMMC I am able to flash it at offset 0x400 using the > dfu_alt_info from warp.h: > "dfu_alt_info=boot raw 0x2 0x400 mmcpart 1\0" \ ---> I am not sure > what the 0x2 means. As fair as I remember - 0x2 is the starting LBA number for eMMC. 0x400 is the number of consecutive LBAs to write to the medium. > > At least the SPI NOR is getting flashed now (at offset 0x0 instead of > 0x400) with the fix I have made. Will submit the fix soon. > > About the incorrect offset, it is a different issue and I will > investigate more tomorrow. Since I don't have any target with SPI Flash, I can only guess or provide analogy to eMMC. In the eMMC case it is also possible to flash "raw" eMMC with passing starting LBA and number of LBAs for write. In ./include/configs/trats.h : dfu_alt_info="params.bin raw 0x38 0x8" > > Thanks -- Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
On Tue, Sep 22, 2015 at 12:23 AM, Stephen Warren wrote: > Oh good:-) > > I was going to give you my dfu_alt_info, but it's at work right now, so > I was waiting until tomorrow. I did try to repro this, but I was having > a lot of trouble with both the two boards I have that have SPI, so > wasn't able to test yet. > > One thing I did notice: dfu_sf.c's parsing code doesn't work with > multiple entries in dfu_alt_info (e.g. for different partitions) since > the parsing of the device parameter (to the dfu command; not part of > dfu_info) modifies that parameter so it can't be parsed the second time > around. Since you're set up to test this, perhaps you could fix it too? > I assume all it'd need is to add a strdup()/free() to the start/end of > the alt info parsing function? Yes, I noticed a problem here on parsing dfu_alt_info. In my case I need to flash the u-boot binary at offset 0x400 of the SPI NOR, but I was not able to find the correct syntax for this. I have tried: dfu_alt_info=u-boot raw 0x400 ,but I am not familiar with the dfu_alt_info syntax, so maybe this needs some adjustment. For the eMMC I am able to flash it at offset 0x400 using the dfu_alt_info from warp.h: "dfu_alt_info=boot raw 0x2 0x400 mmcpart 1\0" \ ---> I am not sure what the 0x2 means. At least the SPI NOR is getting flashed now (at offset 0x0 instead of 0x400) with the fix I have made. Will submit the fix soon. About the incorrect offset, it is a different issue and I will investigate more tomorrow. Thanks ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
On 09/21/2015 08:55 PM, Fabio Estevam wrote: > On Mon, Sep 21, 2015 at 10:50 PM, Fabio Estevam wrote: >> Stephen, >> >> On Mon, Sep 21, 2015 at 2:37 PM, Fabio Estevam wrote: >>> On Mon, Sep 21, 2015 at 2:31 PM, Stephen Warren >>> wrote: >>> I haven't tested SF support recently (only MMC). However, it should still work:-) Are you using ci_udc? If so, make sure you have this very recent patch: > commit b337b3b2a53f112a217f4bd31307b02f830bb787 > Author: Stephen Warren > Date: Fri Sep 11 17:10:02 2015 -0600 > > usb: ci_udc: fix emissions of ZLPs >>> >>> Yes, I am using ci_udc and this patch is applied. >> >> Do you recall what you used as 'dfu_alt_info' variable when flashing >> SPI via DFU? > > Nevermind. I fixed the issue and will submit the patch shortly. Oh good:-) I was going to give you my dfu_alt_info, but it's at work right now, so I was waiting until tomorrow. I did try to repro this, but I was having a lot of trouble with both the two boards I have that have SPI, so wasn't able to test yet. One thing I did notice: dfu_sf.c's parsing code doesn't work with multiple entries in dfu_alt_info (e.g. for different partitions) since the parsing of the device parameter (to the dfu command; not part of dfu_info) modifies that parameter so it can't be parsed the second time around. Since you're set up to test this, perhaps you could fix it too? I assume all it'd need is to add a strdup()/free() to the start/end of the alt info parsing function? ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
On Mon, Sep 21, 2015 at 10:50 PM, Fabio Estevam wrote: > Stephen, > > On Mon, Sep 21, 2015 at 2:37 PM, Fabio Estevam wrote: >> On Mon, Sep 21, 2015 at 2:31 PM, Stephen Warren >> wrote: >> >>> I haven't tested SF support recently (only MMC). However, it should still >>> work:-) Are you using ci_udc? If so, make sure you have this very recent >>> patch: >>> commit b337b3b2a53f112a217f4bd31307b02f830bb787 Author: Stephen Warren Date: Fri Sep 11 17:10:02 2015 -0600 usb: ci_udc: fix emissions of ZLPs >> >> Yes, I am using ci_udc and this patch is applied. > > Do you recall what you used as 'dfu_alt_info' variable when flashing > SPI via DFU? Nevermind. I fixed the issue and will submit the patch shortly. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
Stephen, On Mon, Sep 21, 2015 at 2:37 PM, Fabio Estevam wrote: > On Mon, Sep 21, 2015 at 2:31 PM, Stephen Warren wrote: > >> I haven't tested SF support recently (only MMC). However, it should still >> work:-) Are you using ci_udc? If so, make sure you have this very recent >> patch: >> >>> commit b337b3b2a53f112a217f4bd31307b02f830bb787 >>> Author: Stephen Warren >>> Date: Fri Sep 11 17:10:02 2015 -0600 >>> >>> usb: ci_udc: fix emissions of ZLPs > > Yes, I am using ci_udc and this patch is applied. Do you recall what you used as 'dfu_alt_info' variable when flashing SPI via DFU? Thanks ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
On Mon, Sep 21, 2015 at 2:31 PM, Stephen Warren wrote: > I haven't tested SF support recently (only MMC). However, it should still > work:-) Are you using ci_udc? If so, make sure you have this very recent > patch: > >> commit b337b3b2a53f112a217f4bd31307b02f830bb787 >> Author: Stephen Warren >> Date: Fri Sep 11 17:10:02 2015 -0600 >> >> usb: ci_udc: fix emissions of ZLPs Yes, I am using ci_udc and this patch is applied. I am able to flash SD/eMMC via DFU but SPI does not work here. Thanks ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
On 09/21/2015 11:13 AM, Fabio Estevam wrote: Hi Stephen, On Wed, Jun 11, 2014 at 7:03 PM, Stephen Warren wrote: From: Stephen Warren This allows SPI Flash to be programmed using DFU. Signed-off-by: Stephen Warren Is this still working in mainline U-boot? I haven't tested SF support recently (only MMC). However, it should still work:-) Are you using ci_udc? If so, make sure you have this very recent patch: commit b337b3b2a53f112a217f4bd31307b02f830bb787 Author: Stephen Warren Date: Fri Sep 11 17:10:02 2015 -0600 usb: ci_udc: fix emissions of ZLPs Commit 6a132416359e "ci_udc: Update the ci_udc driver to support bulk transfers" caused the value of "len" to change without updating subsquent users of that variable in ci_ep_submit_next_request(). This caused the code that detects when to emit ZLPs (Zero Length Packets) never to trigger, which in turn caused host timeouts when a ZLP was required, which in turn broke tests/dfu/, even despite the assertion in that commit's description that "These changes are tested for both the DFU and lthor." Fix this by modifying the added dtd iteration code not to modify "len", but rather to keep state in a separate variable. Rename the variables while we're at it so they describe their purpose better. Fixes: 6a132416359e ("ci_udc: Update the ci_udc driver to support bulk transfers") Cc: Siva Durga Prasad Paladugu Signed-off-by: Stephen Warren ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
Hi Stephen, On Wed, Jun 11, 2014 at 7:03 PM, Stephen Warren wrote: > From: Stephen Warren > > This allows SPI Flash to be programmed using DFU. > > Signed-off-by: Stephen Warren Is this still working in mainline U-boot? I am getting the following error on the PC host side: sudo dfu-util -D u-boot.imx -a u-boot dfu-util 0.8 Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc. Copyright 2010-2014 Tormod Volden and Stefan Schmidt This program is Free Software and has ABSOLUTELY NO WARRANTY Please report bugs to dfu-u...@lists.gnumonks.org dfu-util: Invalid DFU suffix signature dfu-util: A valid DFU suffix will be required in a future dfu-util release!!! Opening DFU capable USB device... ID 0525:a4a5 Run-time device DFU version 0110 Claiming USB DFU Interface... Setting Alternate Setting #0 ... Determining device status: state = dfuIDLE, status = 0 dfuIDLE, continuing DFU mode device DFU version 0110 Device returned transfer size 4096 Copying data from PC to DFU device Download[=] 100% 478208 bytes Download done. state(7) = dfuMANIFEST, status(0) = No error condition is present state(10) = dfuERROR, status(14) = Something went wrong, but the device does not know what it was Done! On the target side: => dfu 0 sf 0:0:2500:0 SF: Detected M25P32 with page size 256 Bytes, erase size 64 KiB, total 4 MiB Any ideas? Thanks, Fabio Estevam ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 4/4] dfu: add SF backend
Hi Stephen, > From: Stephen Warren > > This allows SPI Flash to be programmed using DFU. > > Signed-off-by: Stephen Warren Applied to u-boot-dfu Thanks for the patch. -- Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 4/4] dfu: add SF backend
From: Stephen Warren This allows SPI Flash to be programmed using DFU. Signed-off-by: Stephen Warren --- drivers/dfu/Makefile | 1 + drivers/dfu/dfu.c| 3 ++ drivers/dfu/dfu_sf.c | 139 +++ include/dfu.h| 22 4 files changed, 165 insertions(+) create mode 100644 drivers/dfu/dfu_sf.c diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile index def628dcdcc4..5cc535efdd47 100644 --- a/drivers/dfu/Makefile +++ b/drivers/dfu/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_DFU_FUNCTION) += dfu.o obj-$(CONFIG_DFU_MMC) += dfu_mmc.o obj-$(CONFIG_DFU_NAND) += dfu_nand.o obj-$(CONFIG_DFU_RAM) += dfu_ram.o +obj-$(CONFIG_DFU_SF) += dfu_sf.o diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 897dfab77be6..6cd3fbb58ae4 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -413,6 +413,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, } else if (strcmp(interface, "ram") == 0) { if (dfu_fill_entity_ram(dfu, devstr, s)) return -1; + } else if (strcmp(interface, "sf") == 0) { + if (dfu_fill_entity_sf(dfu, devstr, s)) + return -1; } else { printf("%s: Device %s not (yet) supported!\n", __func__, interface); diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c new file mode 100644 index ..91f6df220b1d --- /dev/null +++ b/drivers/dfu/dfu_sf.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + +static long dfu_get_medium_size_sf(struct dfu_entity *dfu) +{ + return dfu->data.sf.size; +} + +static int dfu_read_medium_sf(struct dfu_entity *dfu, u64 offset, void *buf, + long *len) +{ + return spi_flash_read(dfu->data.sf.dev, offset, *len, buf); +} + +static int dfu_write_medium_sf(struct dfu_entity *dfu, + u64 offset, void *buf, long *len) +{ + int ret; + + ret = spi_flash_erase(dfu->data.sf.dev, offset, *len); + if (ret) + return ret; + + ret = spi_flash_write(dfu->data.sf.dev, offset, *len, buf); + if (ret) + return ret; + + return 0; +} + +static int dfu_flush_medium_sf(struct dfu_entity *dfu) +{ + return 0; +} + +static unsigned int dfu_polltimeout_sf(struct dfu_entity *dfu) +{ + return DFU_DEFAULT_POLL_TIMEOUT; +} + +static void dfu_free_entity_sf(struct dfu_entity *dfu) +{ + spi_flash_free(dfu->data.sf.dev); +} + +static struct spi_flash *parse_dev(char *devstr) +{ + unsigned int bus; + unsigned int cs; + unsigned int speed = CONFIG_SF_DEFAULT_SPEED; + unsigned int mode = CONFIG_SF_DEFAULT_MODE; + char *s, *endp; + struct spi_flash *dev; + + s = strsep(&devstr, ":"); + if (!s || !*s || (bus = simple_strtoul(s, &endp, 0), *endp)) { + printf("Invalid SPI bus %s\n", s); + return NULL; + } + + s = strsep(&devstr, ":"); + if (!s || !*s || (cs = simple_strtoul(s, &endp, 0), *endp)) { + printf("Invalid SPI chip-select %s\n", s); + return NULL; + } + + s = strsep(&devstr, ":"); + if (s && *s) { + speed = simple_strtoul(s, &endp, 0); + if (*endp || !speed) { + printf("Invalid SPI speed %s\n", s); + return NULL; + } + } + + s = strsep(&devstr, ":"); + if (s && *s) { + mode = simple_strtoul(s, &endp, 0); + if (*endp || mode > 3) { + printf("Invalid SPI mode %s\n", s); + return NULL; + } + } + + dev = spi_flash_probe(bus, cs, speed, mode); + if (!dev) { + printf("Failed to create SPI flash at %d:%d:%d:%d\n", + bus, cs, speed, mode); + return NULL; + } + + return dev; +} + +int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) +{ + char *st; + + dfu->data.sf.dev = parse_dev(devstr); + if (!dfu->data.sf.dev) + return -ENODEV; + + dfu->dev_type = DFU_DEV_SF; + dfu->max_buf_size = dfu->data.sf.dev->sector_size; + + st = strsep(&s, " "); + if (!strcmp(st, "raw")) { + dfu->layout = DFU_RAW_ADDR; + dfu->data.sf.start = simple_strtoul(s, &s, 16); + s++; + dfu->data.sf.size = simple_strtoul(s, &s, 16); + } else { + printf("%s: Memory layout (%s) not supported!\n", __func__, st); + spi_flash_free(dfu->data.sf.dev); + return -1; + } + + dfu->get_medium_size = dfu_get_medium_size_sf; + dfu->read_medium = dfu_read_medium_sf; +