Browse Source

u-boot: fsl_updater: Adding support for quadspi commands

Two commands are supported:

- qspiinit: for initialize and configure qspi0 or qspi1 (dev)
       and set the flash device top addresses.

        qspiiint dev=X <fa1=A1> <fa2=A2> <fb1=B1> <fb2=B2>

- pipeqspi: Start the flashin of the image, flashing address can
  be specified by passing the arg addr=, otherwise it will start
  flashing at the begining of the QSPI device address.

	pipeqspi addr=<flash_addr>

Signed-off-by: Juan Gutierrez <b44802@freescale.com>
Juan Gutierrez 11 years ago
parent
commit
b76ec5b75e
1 changed files with 54 additions and 0 deletions
  1. 54 0
      drivers/usb/gadget/fsl_updater.c

+ 54 - 0
drivers/usb/gadget/fsl_updater.c

@@ -14,6 +14,7 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 #include <common.h>
+#include <asm/arch/vf610_qspi.h>
 
 #define pr_debug printf
 #define pr_info printf
@@ -38,6 +39,7 @@ struct utp_pipe_info {
 	int media_id;
 	unsigned long int index;
 	size_t blksz;
+	unsigned long int addr;
 } pinfo = {
 	.media_type = NOMEDIA,
 	.media_id = 0,
@@ -490,6 +492,7 @@ struct utp_user_data *utp_handle_command(char *cmd, u64 payload)
 	struct utp_user_data	*answer;
 	unsigned long int	dev;
 	unsigned long int	skip;
+	unsigned long int	addr;
 	char			argbuf[20];
 	char			*tmp;
 
@@ -520,6 +523,31 @@ struct utp_user_data *utp_handle_command(char *cmd, u64 payload)
 		skip = simple_strtoul(tmp+5, NULL, 10);
 		pinfo.index += skip;
 		utp_run(argbuf);
+	} else if (strncmp(cmd, "pipeqspi", 8) == 0) {
+		pinfo.media_type = QSPI;
+		cmd += 9;
+		tmp = strsep(&cmd, " ");
+		if (strncmp(tmp, "addr=", 5) == 0) {
+			addr = simple_strtoul(tmp+5, NULL, 16);
+			printf("addr: 0x%x\n", addr);
+			pinfo.addr = addr;
+		} else {
+			pinfo.addr = (pinfo.media_id ? QSPI1_FLASH_BASE_ADDR
+						     : QSPI0_FLASH_BASE_ADDR);
+		}
+	} else if (strncmp(cmd, "qspiinit", 8) == 0) {
+		pinfo.media_type = QSPI;
+		pinfo.index = 0;
+		pinfo.blksz = 0x200;
+		sprintf(argbuf, cmd);
+		cmd += 7;
+		tmp = strsep(&cmd, " ");
+		printf(tmp);
+                dev = simple_strtoul(tmp+4, NULL, 10);
+                printf("dev: %lu\n", dev);
+		pinfo.media_id = dev;
+		printf("%s\n", cmd);
+		utp_run(argbuf);
 	}
 
 	answer = utp_user_data_alloc(0, size);
@@ -545,6 +573,27 @@ int utp_pipe_sd(u8 *data, size_t bufsize)
 	return 0;
 }
 
+int utp_pipe_qspi(u8 *data, size_t bufsize)
+{
+	pr_debug("got data chunk, size: %zx\n", bufsize);
+	unsigned int blkcnt, dest, len;
+	char argbuf[100];
+
+	blkcnt = (bufsize / pinfo.blksz) + (((bufsize % pinfo.blksz) != 0) ? 1 : 0);
+	dest = pinfo.addr + pinfo.blksz * pinfo.index;
+	len = bufsize;
+
+	pr_debug("dest: %x, data: %lx, len: %zx\n", dest, data, len);
+
+	sprintf(argbuf, "qspiwrite %x %lx %x",dest, data, len);
+	pr_debug("%s\n", argbuf);
+	utp_run(argbuf);
+	pr_debug("after write to qspi\n");
+	pinfo.index += blkcnt;
+
+	return 0;
+}
+
 struct utp_user_data *utp_interpret_message(struct utp_user_data *uud2r)
 {
 	struct utp_user_data *answer;
@@ -558,6 +607,11 @@ struct utp_user_data *utp_interpret_message(struct utp_user_data *uud2r)
 		switch(pinfo.media_type) {
 		case SD:
 			utp_pipe_sd(msg->data, msg->bufsize);
+		break;
+		case QSPI:
+			utp_pipe_qspi(msg->data, msg->bufsize);
+		default:
+		break;
 		}
 	}
 	return NULL;