From 127e10842b2474ac20e40572a4102dd4d5ed80f1 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Tue, 3 Nov 2009 12:22:10 +0530 Subject: usb: write command for RAW partition. This patch implements write support to usb device with raw partition. It will be useful for filesystem write support to usb device from u-boot in future. Tested with writing kernel image to raw usb disk & booting with usb read command into ram. [Note: run usb part to get info about start sector & number of sectors on a partition for usb write operation.] Signed-off-by: Mahavir Jain --- common/cmd_usb.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'common/cmd_usb.c') diff --git a/common/cmd_usb.c b/common/cmd_usb.c index 1e297d53da..9de515c323 100644 --- a/common/cmd_usb.c +++ b/common/cmd_usb.c @@ -642,6 +642,28 @@ int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } } + if (strcmp(argv[1], "write") == 0) { + if (usb_stor_curr_dev < 0) { + printf("no current device selected\n"); + return 1; + } + if (argc == 5) { + unsigned long addr = simple_strtoul(argv[2], NULL, 16); + unsigned long blk = simple_strtoul(argv[3], NULL, 16); + unsigned long cnt = simple_strtoul(argv[4], NULL, 16); + unsigned long n; + printf("\nUSB write: device %d block # %ld, count %ld" + " ... ", usb_stor_curr_dev, blk, cnt); + stor_dev = usb_stor_get_dev(usb_stor_curr_dev); + n = stor_dev->block_write(usb_stor_curr_dev, blk, cnt, + (ulong *)addr); + printf("%ld blocks write: %s\n", n, + (n == cnt) ? "OK" : "ERROR"); + if (n == cnt) + return 0; + return 1; + } + } if (strncmp(argv[1], "dev", 3) == 0) { if (argc == 3) { int dev = (int)simple_strtoul(argv[2], NULL, 10); @@ -687,6 +709,8 @@ U_BOOT_CMD( " devices\n" "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" " to memory address `addr'" + "usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'\n" + " from memory address `addr'" ); -- cgit v1.2.1