[U-Boot] [PATCH v1 1/2] fastboot: Add support to flash u-boot and MLO to QSPI

This adds the functionality to flash u-boot and MLO images to QSPI using fastboot
Signed-off-by: Dileep Katta dileep.katta@linaro.org --- Note: This is on top of Rob Herring patches submitted to support oem format command drivers/usb/gadget/f_fastboot.c | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index f7d84bf..a170eea 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -492,10 +492,23 @@ static void cb_continue(struct usb_ep *ep, struct usb_request *req) }
#ifdef CONFIG_FASTBOOT_FLASH +#ifdef CONFIG_SPL_SPI_SUPPORT +int boot_from_spi = 0; +#endif + static void cb_flash(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; char response[RESPONSE_LEN]; +#ifdef CONFIG_SPL_SPI_SUPPORT + char source[32]; + int status = 0; + char *sf_probe[3] = {"sf", "probe", "0"}; + char *sf_write_xloader[5] = {"sf", "write", NULL, "0", "20000"}; + char *sf_update_xloader[5] = {"sf", "update", NULL, "0", "20000"}; + char *sf_write_bl[5] = {"sf", "write", NULL, "80000", "80000"}; + char *sf_update_bl[5] = {"sf", "update", NULL, "80000", "80000"}; +#endif
strsep(&cmd, ":"); if (!cmd) { @@ -505,6 +518,68 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req) }
strcpy(response, "FAILno flash device defined"); +#ifdef CONFIG_SPL_SPI_SUPPORT + /* + * Check if this is for xloader or bootloader. + * Also, check if we have to flash to SPI + */ + if (strcmp(cmd, "xloader") == 0 && boot_from_spi) { + printf("Flashing %s to SPI\n", cmd); + status = do_spi_flash(NULL, 0, 3, sf_probe); + if (status) { + fastboot_tx_write_str("FAILcould not probe SPI"); + return; + } + sf_write_xloader[2] = source; + sf_update_xloader[2] = source; + sprintf(source, "0x%x", + (unsigned int)CONFIG_USB_FASTBOOT_BUF_ADDR); + + printf("Updating X-LOADER to SPI\n"); + status = do_spi_flash(NULL, 0, 5, sf_update_xloader); + if (status) { + fastboot_tx_write_str("FAILupdate xloader failed"); + return; + } + + printf("Writing X-LOADER to SPI\n"); + status = do_spi_flash(NULL, 0, 5, sf_write_xloader); + if (status) { + fastboot_tx_write_str("FAILwrite xloader failed"); + return; + } + printf("Writing xloader DONE\n"); + fastboot_tx_write_str("OKAY"); + return; + } + if (strcmp(cmd, "bootloader") == 0 && boot_from_spi) { + printf("Flashing %s to SPI\n", cmd); + status = do_spi_flash(NULL, 0, 3, sf_probe); + if (status) { + fastboot_tx_write_str("FAILcould not probe SPI"); + return; + } + sf_write_bl[2] = source; + sf_update_bl[2] = source; + sprintf(source, "0x%x", + (unsigned int)CONFIG_USB_FASTBOOT_BUF_ADDR); + printf("Updating bootloader to SPI\n"); + status = do_spi_flash(NULL, 0, 5, sf_update_bl); + if (status) { + fastboot_tx_write_str("FAILupdate bootloader failed"); + return; + } + printf("Writing bootloader to SPI\n"); + status = do_spi_flash(NULL, 0, 5, sf_write_bl); + if (status) { + fastboot_tx_write_str("FAILwrite bootloader failed"); + return; + } + printf("Writing bootloader DONE\n"); + fastboot_tx_write_str("OKAY"); + return; + } +#endif #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV fb_mmc_flash_write(cmd, (void *)CONFIG_USB_FASTBOOT_BUF_ADDR, download_bytes, response);

Fastboot oem command is updated with SPI specific functionality.
Signed-off-by: Dileep Katta dileep.katta@linaro.org --- Note: This is on top of Rob Herring patches submitted to support oem format command Ref: https://patchwork.ozlabs.org/patch/433056/ https://patchwork.ozlabs.org/patch/433057/ drivers/usb/gadget/f_fastboot.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index a170eea..04fa4c2 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -591,7 +591,33 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req) static void cb_oem(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; + #ifdef CONFIG_FASTBOOT_FLASH +#ifdef CONFIG_SPL_SPI_SUPPORT + char *sf_erase[4] = {"sf", "erase", "0", "20000"}; + int status; + char *sf_probe[3] = {"sf", "probe", "0"}; + if (strncmp(req->buf + 4, "spi", 3) == 0) { + boot_from_spi = 1; + status = do_spi_flash(NULL, 0, 3, sf_probe); + if (status) { + fastboot_tx_write_str("FAILcould not probe SPI"); + return; + } + status = do_spi_flash(NULL, 0, 4, sf_erase); + if (status) { + fastboot_tx_write_str("FAILcould not erase SPI"); + return; + } + fastboot_tx_write_str("OKAY"); + return; + } else if (strncmp(req->buf + 4, "mmc", 3) == 0) { + boot_from_spi = 0; + fastboot_tx_write_str("OKAY"); + return; + } +#endif + if (strncmp("format", cmd + 4, 6) == 0) { char cmdbuf[32]; sprintf(cmdbuf, "gpt write mmc %x $partitions",

On Wed, Feb 18, 2015 at 4:53 PM, Dileep Katta dileep.katta@linaro.org wrote:
Fastboot oem command is updated with SPI specific functionality.
Signed-off-by: Dileep Katta dileep.katta@linaro.org
Note: This is on top of Rob Herring patches submitted to support oem format command Ref: https://patchwork.ozlabs.org/patch/433056/ https://patchwork.ozlabs.org/patch/433057/ drivers/usb/gadget/f_fastboot.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index a170eea..04fa4c2 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -591,7 +591,33 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req) static void cb_oem(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf;
#ifdef CONFIG_FASTBOOT_FLASH +#ifdef CONFIG_SPL_SPI_SUPPORT
char *sf_erase[4] = {"sf", "erase", "0", "20000"};
int status;
char *sf_probe[3] = {"sf", "probe", "0"};
if (strncmp(req->buf + 4, "spi", 3) == 0) {
boot_from_spi = 1;
status = do_spi_flash(NULL, 0, 3, sf_probe);
if (status) {
fastboot_tx_write_str("FAILcould not probe SPI");
return;
}
status = do_spi_flash(NULL, 0, 4, sf_erase);
This doesn't enable SPI boot, but just erases the SPI. We already have erase and format commands. I suppose you have 2 xloader/bootloader partitions on SPI and MMC and want to select which one to flash? But you have no way to select which device to actually boot from.
This could all be supported without this by enforcing that the SPI have unique partition names.
Rob
if (status) {
fastboot_tx_write_str("FAILcould not erase SPI");
return;
}
fastboot_tx_write_str("OKAY");
return;
} else if (strncmp(req->buf + 4, "mmc", 3) == 0) {
boot_from_spi = 0;
fastboot_tx_write_str("OKAY");
return;
}
+#endif
if (strncmp("format", cmd + 4, 6) == 0) { char cmdbuf[32]; sprintf(cmdbuf, "gpt write mmc %x $partitions",
-- 1.8.3.2

On Thu, Feb 19, 2015 at 04:23:54AM +0530, Dileep Katta wrote:
This adds the functionality to flash u-boot and MLO images to QSPI using fastboot
[snip]
char response[RESPONSE_LEN]; +#ifdef CONFIG_SPL_SPI_SUPPORT
- char source[32];
- int status = 0;
- char *sf_probe[3] = {"sf", "probe", "0"};
- char *sf_write_xloader[5] = {"sf", "write", NULL, "0", "20000"};
- char *sf_update_xloader[5] = {"sf", "update", NULL, "0", "20000"};
- char *sf_write_bl[5] = {"sf", "write", NULL, "80000", "80000"};
- char *sf_update_bl[5] = {"sf", "update", NULL, "80000", "80000"};
+#endif
Here's what I don't like. 0 -> 0x20000 isn't horrible as it's the location for the first and second "MLO" locations, on a 64KiB sector QSPI flash, or just the first one on a 128KiB sector QSPI. But then we hard-code U-Boot to 0x80000 which isn't right. For example dra7xx_evm sets this to 0x40000 and we should just use CONFIG_SYS_SPI_U_BOOT_OFFS since that has to be set in the resulting binary to the right location.

On Wed, Feb 18, 2015 at 4:53 PM, Dileep Katta dileep.katta@linaro.org wrote:
This adds the functionality to flash u-boot and MLO images to QSPI using fastboot
Signed-off-by: Dileep Katta dileep.katta@linaro.org
Note: This is on top of Rob Herring patches submitted to support oem format command drivers/usb/gadget/f_fastboot.c | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index f7d84bf..a170eea 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -492,10 +492,23 @@ static void cb_continue(struct usb_ep *ep, struct usb_request *req) }
#ifdef CONFIG_FASTBOOT_FLASH +#ifdef CONFIG_SPL_SPI_SUPPORT +int boot_from_spi = 0; +#endif
static void cb_flash(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; char response[RESPONSE_LEN]; +#ifdef CONFIG_SPL_SPI_SUPPORT
char source[32];
int status = 0;
char *sf_probe[3] = {"sf", "probe", "0"};
char *sf_write_xloader[5] = {"sf", "write", NULL, "0", "20000"};
char *sf_update_xloader[5] = {"sf", "update", NULL, "0", "20000"};
char *sf_write_bl[5] = {"sf", "write", NULL, "80000", "80000"};
char *sf_update_bl[5] = {"sf", "update", NULL, "80000", "80000"};
+#endif
strsep(&cmd, ":"); if (!cmd) {
@@ -505,6 +518,68 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req) }
strcpy(response, "FAILno flash device defined");
+#ifdef CONFIG_SPL_SPI_SUPPORT
/*
* Check if this is for xloader or bootloader.
* Also, check if we have to flash to SPI
*/
if (strcmp(cmd, "xloader") == 0 && boot_from_spi) {
xloader is pretty specific to TI, so it belongs in TI specific code.
printf("Flashing %s to SPI\n", cmd);
status = do_spi_flash(NULL, 0, 3, sf_probe);
if (status) {
fastboot_tx_write_str("FAILcould not probe SPI");
return;
}
sf_write_xloader[2] = source;
sf_update_xloader[2] = source;
sprintf(source, "0x%x",
(unsigned int)CONFIG_USB_FASTBOOT_BUF_ADDR);
printf("Updating X-LOADER to SPI\n");
status = do_spi_flash(NULL, 0, 5, sf_update_xloader);
if (status) {
fastboot_tx_write_str("FAILupdate xloader failed");
return;
}
printf("Writing X-LOADER to SPI\n");
status = do_spi_flash(NULL, 0, 5, sf_write_xloader);
if (status) {
fastboot_tx_write_str("FAILwrite xloader failed");
return;
}
printf("Writing xloader DONE\n");
fastboot_tx_write_str("OKAY");
return;
}
if (strcmp(cmd, "bootloader") == 0 && boot_from_spi) {
This if is almost completely duplicated from above.
To address both issues, I would create a weak function to retrieve all the spi programming parameters as well as whether to use spi or not.
Rob
printf("Flashing %s to SPI\n", cmd);
status = do_spi_flash(NULL, 0, 3, sf_probe);
if (status) {
fastboot_tx_write_str("FAILcould not probe SPI");
return;
}
sf_write_bl[2] = source;
sf_update_bl[2] = source;
sprintf(source, "0x%x",
(unsigned int)CONFIG_USB_FASTBOOT_BUF_ADDR);
printf("Updating bootloader to SPI\n");
status = do_spi_flash(NULL, 0, 5, sf_update_bl);
if (status) {
fastboot_tx_write_str("FAILupdate bootloader failed");
return;
}
printf("Writing bootloader to SPI\n");
status = do_spi_flash(NULL, 0, 5, sf_write_bl);
if (status) {
fastboot_tx_write_str("FAILwrite bootloader failed");
return;
}
printf("Writing bootloader DONE\n");
fastboot_tx_write_str("OKAY");
return;
}
+#endif #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV fb_mmc_flash_write(cmd, (void *)CONFIG_USB_FASTBOOT_BUF_ADDR, download_bytes, response); -- 1.8.3.2

On Thu, Feb 19, 2015 at 02:04:01PM -0600, Rob Herring wrote:
On Wed, Feb 18, 2015 at 4:53 PM, Dileep Katta dileep.katta@linaro.org wrote:
This adds the functionality to flash u-boot and MLO images to QSPI using fastboot
Signed-off-by: Dileep Katta dileep.katta@linaro.org
Note: This is on top of Rob Herring patches submitted to support oem format command drivers/usb/gadget/f_fastboot.c | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index f7d84bf..a170eea 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -492,10 +492,23 @@ static void cb_continue(struct usb_ep *ep, struct usb_request *req) }
#ifdef CONFIG_FASTBOOT_FLASH +#ifdef CONFIG_SPL_SPI_SUPPORT +int boot_from_spi = 0; +#endif
static void cb_flash(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; char response[RESPONSE_LEN]; +#ifdef CONFIG_SPL_SPI_SUPPORT
char source[32];
int status = 0;
char *sf_probe[3] = {"sf", "probe", "0"};
char *sf_write_xloader[5] = {"sf", "write", NULL, "0", "20000"};
char *sf_update_xloader[5] = {"sf", "update", NULL, "0", "20000"};
char *sf_write_bl[5] = {"sf", "write", NULL, "80000", "80000"};
char *sf_update_bl[5] = {"sf", "update", NULL, "80000", "80000"};
+#endif
strsep(&cmd, ":"); if (!cmd) {
@@ -505,6 +518,68 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req) }
strcpy(response, "FAILno flash device defined");
+#ifdef CONFIG_SPL_SPI_SUPPORT
/*
* Check if this is for xloader or bootloader.
* Also, check if we have to flash to SPI
*/
if (strcmp(cmd, "xloader") == 0 && boot_from_spi) {
xloader is pretty specific to TI, so it belongs in TI specific code.
And it's not even "xloader", it's SPL. So are there external tools relying on this that can't be updated?

Thanks Rob and Tom.
On 22 February 2015 at 08:29, Tom Rini trini@ti.com wrote:
On Thu, Feb 19, 2015 at 02:04:01PM -0600, Rob Herring wrote:
On Wed, Feb 18, 2015 at 4:53 PM, Dileep Katta dileep.katta@linaro.org
wrote:
This adds the functionality to flash u-boot and MLO images to QSPI
using fastboot
Signed-off-by: Dileep Katta dileep.katta@linaro.org
Note: This is on top of Rob Herring patches submitted to support oem
format command
drivers/usb/gadget/f_fastboot.c | 75
+++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/drivers/usb/gadget/f_fastboot.c
b/drivers/usb/gadget/f_fastboot.c
index f7d84bf..a170eea 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -492,10 +492,23 @@ static void cb_continue(struct usb_ep *ep,
struct usb_request *req)
}
#ifdef CONFIG_FASTBOOT_FLASH +#ifdef CONFIG_SPL_SPI_SUPPORT +int boot_from_spi = 0; +#endif
static void cb_flash(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; char response[RESPONSE_LEN]; +#ifdef CONFIG_SPL_SPI_SUPPORT
char source[32];
int status = 0;
char *sf_probe[3] = {"sf", "probe", "0"};
char *sf_write_xloader[5] = {"sf", "write", NULL, "0",
"20000"};
char *sf_update_xloader[5] = {"sf", "update", NULL, "0",
"20000"};
char *sf_write_bl[5] = {"sf", "write", NULL, "80000", "80000"};
char *sf_update_bl[5] = {"sf", "update", NULL, "80000",
"80000"};
+#endif
strsep(&cmd, ":"); if (!cmd) {
@@ -505,6 +518,68 @@ static void cb_flash(struct usb_ep *ep, struct
usb_request *req)
} strcpy(response, "FAILno flash device defined");
+#ifdef CONFIG_SPL_SPI_SUPPORT
/*
* Check if this is for xloader or bootloader.
* Also, check if we have to flash to SPI
*/
if (strcmp(cmd, "xloader") == 0 && boot_from_spi) {
xloader is pretty specific to TI, so it belongs in TI specific code.
And it's not even "xloader", it's SPL. So are there external tools relying on this that can't be updated?
There are no such tools. Will change the name.
Will send a patch incorporating the suggestions from Rob and Tom.
Regards, Dileep
-- Tom

Dear All,
First of all I would like to apologize for delay with reviewing/PRs fastboot related patches.
I've collected fastboot related patches and push them to u-boot-dfu repo (master branch):
http://git.denx.de/?p=u-boot/u-boot-dfu.git;a=summary
Please look into this repository and let me know if I've forgotten to take some of those patches.
As fair as I've discovered from reading ML, following patches are still under development/discussion:
"fastboot: Update getvar command to get 'userdata' partition size" https://patchwork.ozlabs.org/patch/442024/
"fastboot: Add support to flash u-boot and MLO to QSPI" https://patchwork.ozlabs.org/patch/441296/
"fastboot: Add support in fastboot oem command to set QSPI as boot device" https://patchwork.ozlabs.org/patch/441298/
Are there any other patches which are under review?
I've built tested (for ti) -dfu branch with buildman and it doesn't bring any new regressions (despite of am335x_evm_usbspl build error - which happens also without those patches).
participants (5)
-
Dileep Katta
-
Lukasz Majewski
-
Rob Herring
-
Rob Herring
-
Tom Rini