diff mbox

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

Message ID 1424300035-19634-1-git-send-email-dileep.katta@linaro.org
State New
Headers show

Commit Message

Dileep Katta Feb. 18, 2015, 10:53 p.m. UTC
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(+)

Comments

Dileep Katta Feb. 27, 2015, 1:04 p.m. UTC | #1
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
>
diff mbox

Patch

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