Browse Source

u-boot: fsl_updater: Adding support for nand commands

    Two commands are supported:

    - nandinit: for initialize and configure nand device.
            qspiiint addr=<flash_offset_addr>

    - pipenand: Start the flashing of the image, flashing offset address
      is specified by passing the arg addr=.

        pipeqspi addr=<flash_offset_addr>

Signed-off-by: Pardeep Kumar Singla <b45784@freescale.com>
Pardeep Kumar Singla 11 years ago
parent
commit
fec7387619
1 changed files with 58 additions and 1 deletions
  1. 58 1
      drivers/usb/gadget/fsl_updater.c

+ 58 - 1
drivers/usb/gadget/fsl_updater.c

@@ -553,6 +553,42 @@ struct utp_user_data *utp_handle_command(char *cmd, u64 payload)
 		sprintf(argbuf, cmd + 8);
 		utp_run(argbuf);
 	}
+	else if (strncmp(cmd, "nandinit", 8) == 0) {
+		 pinfo.media_type = NAND;
+		 pinfo.index = 0;
+		 pinfo.blksz = 2048;
+		 sprintf(argbuf, cmd);
+		 cmd += 9;
+		 tmp = strsep(&cmd, " ");
+		 if (strncmp(tmp, "addr=", 5) == 0) {
+                        addr = simple_strtoul(tmp+5, NULL, 16);
+                        printf("addr: 0x%x\n", addr);
+			sprintf(argbuf, "nandinit 0x%x", addr);
+			printf(argbuf);
+			printf("%s\n", cmd);
+			utp_run(argbuf);
+                        }
+		else
+		{
+			printf(" Pass the proper address\n");
+		}
+
+	}
+	else if ( strncmp(cmd, "pipenand", 8) == 0 )
+	{
+		pinfo.media_type = NAND;
+		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
+		{
+			printf(" Please pass the proper address\n");
+		}
+	}
 
 	answer = utp_user_data_alloc(0, size);
 	if (flags & UTP_FLAG_STATUS)
@@ -560,10 +596,28 @@ struct utp_user_data *utp_handle_command(char *cmd, u64 payload)
 	return answer;
 }
 
+int utp_pipe_nand(u8 *data, size_t bufsize)
+{
+	pr_debug("got data chunk, size: %zx\n", bufsize);
+	unsigned int blkcnt, dest;
+	char argbuf[100];
+
+	blkcnt = (bufsize / pinfo.blksz) + (((bufsize % pinfo.blksz) != 0) ? 1 : 0);
+	dest = pinfo.addr + pinfo.blksz * pinfo.index;
+	pr_debug("blkcnt: %x, index: %lx, bufsize: %zx\n", blkcnt, pinfo.index, bufsize);
+
+	sprintf(argbuf, "nandwrite %x 0x%lx %x",dest, data, bufsize);
+	pr_debug("%s\n", argbuf);
+	utp_run(argbuf);
+	pr_debug("after write to nand flash\n");
+	pinfo.index += blkcnt;
+
+}
+
 int utp_pipe_sd(u8 *data, size_t bufsize)
 {
 	pr_debug("got data chunk, size: %zx\n", bufsize);
-	unsigned int blkcnt;
+	unsigned int blkcnt, dest;
 	char argbuf[100];
 
 	blkcnt = (bufsize / pinfo.blksz) + (((bufsize % pinfo.blksz) != 0) ? 1 : 0);
@@ -609,6 +663,9 @@ struct utp_user_data *utp_interpret_message(struct utp_user_data *uud2r)
 			return answer;
 	} else if (msg->flags & UTP_FLAG_DATA) {
 		switch(pinfo.media_type) {
+		case NAND:
+			utp_pipe_nand(msg->data, msg->bufsize);
+			break;
 		case SD:
 			utp_pipe_sd(msg->data, msg->bufsize);
 		break;