Skip to contentSkip to conversation

fastboot: Add support to flash u-boot and MLO to QSPI

PATCH New Dileep Katta 5 participants 8 messages Feb 18, 2015 – Feb 27, 2015 USB

lore
Share & tools
lore
#0 lore raw

PATCH 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

---
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(+)
drivers/usb/gadget/f_fastboot.c +75 -0
index f7d84bf..a170eea 100644
@@ -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);
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 2/2 fastboot: Add support in fastboot oem command to set QSPI as boot device

Fastboot oem command is updated with SPI specific functionality.

---
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(+)
drivers/usb/gadget/f_fastboot.c +26 -0
index a170eea..04fa4c2 100644
@@ -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",
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH 2/2 fastboot: Add support in fastboot oem command to set QSPI as boot device

Quoted 22 lines · Dileep Katta

Fastboot oem command is updated with SPI specific functionality.

---
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(+)
drivers/usb/gadget/f_fastboot.c +3 -0
index a170eea..04fa4c2 100644
@@ -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"};

drivers/usb/gadget/f_fastboot.c static void cb_flash(struct usb_ep *ep, struct usb_request *req) · line 607

Quoted 10 lines
drivers/usb/gadget/f_fastboot.c +10 -0
+       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

Quoted 19 lines
drivers/usb/gadget/f_fastboot.c +13 -1
+               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

#3 lore raw

PATCH 1/2 fastboot: Add support to flash u-boot and MLO to QSPI

In reply to Dileep Katta
Quoted 1 line · Dileep Katta

This adds the functionality to flash u-boot and MLO images to QSPI using fastboot

[snip]

drivers/usb/gadget/f_fastboot.c static void cb_continue(struct usb_ep *ep, struct usb_request *req) · line 511

Quoted 10 lines
drivers/usb/gadget/f_fastboot.c +9 -0
 	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.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150219/d5f5fd4d/attachment.sig>
#4 lore raw

PATCH 1/2 fastboot: Add support to flash u-boot and MLO to QSPI

In reply to Dileep Katta
Quoted 37 lines · Dileep Katta

This adds the functionality to flash u-boot and MLO images to QSPI using fastboot

---
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(+)
drivers/usb/gadget/f_fastboot.c +13 -0
index f7d84bf..a170eea 100644
@@ -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) {

drivers/usb/gadget/f_fastboot.c static void cb_flash(struct usb_ep *ep, struct usb_request *req) · line 526

Quoted 9 lines
drivers/usb/gadget/f_fastboot.c +6 -0
@@ -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.

Quoted 19 lines
drivers/usb/gadget/f_fastboot.c +19 -0
+               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");

drivers/usb/gadget/f_fastboot.c static void cb_flash(struct usb_ep *ep, struct usb_request *req) · line 555

Quoted 10 lines
drivers/usb/gadget/f_fastboot.c +10 -0
+               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

Quoted 33 lines
drivers/usb/gadget/f_fastboot.c +27 -1
+               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

#5 lore raw

PATCH 1/2 fastboot: Add support to flash u-boot and MLO to QSPI

Quoted 40 lines · Rob Herring
Quoted 39 lines · Dileep Katta

This adds the functionality to flash u-boot and MLO images to QSPI using fastboot

---
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(+)
drivers/usb/gadget/f_fastboot.c +13 -0
index f7d84bf..a170eea 100644
@@ -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)
        }
 
Quoted 9 lines

drivers/usb/gadget/f_fastboot.c static void cb_flash(struct usb_ep *ep, struct usb_request *req) · line 526

Quoted 7 lines
drivers/usb/gadget/f_fastboot.c +6 -0
        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?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150221/b27dece1/attachment.sig>
#6 lore raw

PATCH 1/2 fastboot: Add support to flash u-boot and MLO to QSPI

Thanks Rob and Tom.

Quoted 59 lines · Tom Rini
Quoted 1 line · Rob Herring

On Wed, Feb 18, 2015 at 4:53 PM, Dileep Katta <[email protected]>

Quoted 1 line · wrote:
Quoted 1 line

This adds the functionality to flash u-boot and MLO images to QSPI

using fastboot

Quoted 4 lines
Quoted 4 lines

---
Note: This is on top of Rob Herring patches submitted to support oem

format command

Quoted 1 line
Quoted 1 line
 drivers/usb/gadget/f_fastboot.c | 75

+++++++++++++++++++++++++++++++++++++++++

Quoted 3 lines

Review

Quoted 3 lines
 1 file changed, 75 insertions(+)
(quoted diff) +0 -0

b/drivers/usb/gadget/f_fastboot.c

Quoted 4 lines

drivers/usb/gadget/f_fastboot.c static void cb_continue(struct usb_ep *ep,

Quoted 4 lines

index f7d84bf..a170eea 100644

drivers/usb/gadget/f_fastboot.c +0 -0
@@ -492,10 +492,23 @@ static void cb_continue(struct usb_ep *ep,

struct usb_request *req)

Quoted 16 lines
Quoted 6 lines
drivers/usb/gadget/f_fastboot.c +3 -0
 }
 
 #ifdef CONFIG_FASTBOOT_FLASH
+#ifdef CONFIG_SPL_SPI_SUPPORT
+int boot_from_spi = 0;
+#endif

drivers/usb/gadget/f_fastboot.c static void cb_continue(struct usb_ep *ep, struct usb_request *req)

Quoted 10 lines
drivers/usb/gadget/f_fastboot.c +6 -0
+
 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"};

Quoted 1 line

drivers/usb/gadget/f_fastboot.c static void cb_continue(struct usb_ep *ep, · line 508

Quoted 1 line
drivers/usb/gadget/f_fastboot.c +1 -0
+       char *sf_update_xloader[5] = {"sf", "update", NULL, "0",

"20000"};

Quoted 2 lines

drivers/usb/gadget/f_fastboot.c static void cb_continue(struct usb_ep *ep, · line 510

Quoted 2 lines
drivers/usb/gadget/f_fastboot.c +2 -0
+       char *sf_write_bl[5] = {"sf", "write", NULL, "80000", "80000"};
+       char *sf_update_bl[5] = {"sf", "update", NULL, "80000",

"80000"};

Quoted 5 lines

drivers/usb/gadget/f_fastboot.c static void cb_flash(struct usb_ep *ep, struct

Quoted 5 lines
drivers/usb/gadget/f_fastboot.c +1 -0
+#endif
 
        strsep(&cmd, ":");
        if (!cmd) {
@@ -505,6 +518,68 @@ static void cb_flash(struct usb_ep *ep, struct

usb_request *req)

Quoted 10 lines
Quoted 9 lines
drivers/usb/gadget/f_fastboot.c +6 -0
        }
 
        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) {
Quoted 5 lines
Quoted 1 line

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

Quoted 4 lines

--
Tom

#7 lore raw

PATCH 1/2 fastboot: Add support to flash u-boot and MLO to QSPI

In reply to Rob Herring

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).

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group