summaryrefslogtreecommitdiff
path: root/common/cmd_load.c
diff options
context:
space:
mode:
authorWolfgang Denk <wd@pollux.denx.de>2006-04-01 15:52:46 +0200
committerWolfgang Denk <wd@pollux.denx.de>2006-04-01 15:52:46 +0200
commit534ff676a9c2ffd460e096754894e78551e4ed1e (patch)
tree54c8832a9b2954ed5692c39543935c76ff9481e4 /common/cmd_load.c
parentd87080b721e4f8dca977af7571c5338ae7bb8db7 (diff)
parent9e7b5ce61b2641e726a38505ffc077642bff44fa (diff)
downloadu-boot-imx-534ff676a9c2ffd460e096754894e78551e4ed1e.zip
u-boot-imx-534ff676a9c2ffd460e096754894e78551e4ed1e.tar.gz
u-boot-imx-534ff676a9c2ffd460e096754894e78551e4ed1e.tar.bz2
* Add support for ymodem protocol download
Patch by Stefano Babic, 29 Mar 2006 * Memory Map Update for Delta board: U-Boot is at 0x80000000-0x84000000 Merge with /home/mk/8-benq/u-boot
Diffstat (limited to 'common/cmd_load.c')
-rw-r--r--common/cmd_load.c104
1 files changed, 92 insertions, 12 deletions
diff --git a/common/cmd_load.c b/common/cmd_load.c
index b18709a..31fef81 100644
--- a/common/cmd_load.c
+++ b/common/cmd_load.c
@@ -29,11 +29,13 @@
#include <s_record.h>
#include <net.h>
#include <exports.h>
+#include <xyzModem.h>
DECLARE_GLOBAL_DATA_PTR;
#if (CONFIG_COMMANDS & CFG_CMD_LOADS)
static ulong load_serial (ulong offset);
+static ulong load_serial_ymodem (ulong offset);
static int read_record (char *buf, ulong len);
# if (CONFIG_COMMANDS & CFG_CMD_SAVES)
static int save_serial (ulong offset, ulong size);
@@ -471,21 +473,31 @@ int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
}
}
- printf ("## Ready for binary (kermit) download "
- "to 0x%08lX at %d bps...\n",
- offset,
- load_baudrate);
- addr = load_serial_bin (offset);
+ if (strcmp(argv[0],"loady")==0) {
+ printf ("## Ready for binary (ymodem) download "
+ "to 0x%08lX at %d bps...\n",
+ offset,
+ load_baudrate);
+
+ addr = load_serial_ymodem (offset);
- if (addr == ~0) {
- load_addr = 0;
- printf ("## Binary (kermit) download aborted\n");
- rcode = 1;
} else {
- printf ("## Start Addr = 0x%08lX\n", addr);
- load_addr = addr;
- }
+ printf ("## Ready for binary (kermit) download "
+ "to 0x%08lX at %d bps...\n",
+ offset,
+ load_baudrate);
+ addr = load_serial_bin (offset);
+
+ if (addr == ~0) {
+ load_addr = 0;
+ printf ("## Binary (kermit) download aborted\n");
+ rcode = 1;
+ } else {
+ printf ("## Start Addr = 0x%08lX\n", addr);
+ load_addr = addr;
+ }
+ }
if (load_baudrate != current_baudrate) {
printf ("## Switch baudrate to %d bps and press ESC ...\n",
current_baudrate);
@@ -959,6 +971,66 @@ START:
}
return ((ulong) os_data_addr - (ulong) bin_start_address);
}
+
+static int getcxmodem(void) {
+ if (tstc())
+ return (getc());
+ return -1;
+}
+static ulong load_serial_ymodem (ulong offset)
+{
+ int size;
+ char buf[32];
+ int err;
+ int res;
+ connection_info_t info;
+ char ymodemBuf[1024];
+ ulong store_addr = ~0;
+ ulong addr = 0;
+
+ size=0;
+ info.mode=xyzModem_ymodem;
+ res=xyzModem_stream_open(&info, &err);
+ if (!res) {
+
+ while ((res=xyzModem_stream_read(ymodemBuf, 1024, &err)) > 0 ){
+ store_addr = addr + offset;
+ size+=res;
+ addr+=res;
+#ifndef CFG_NO_FLASH
+ if (addr2info(store_addr)) {
+ int rc;
+
+ rc = flash_write((char *)ymodemBuf,store_addr,res);
+ if (rc != 0) {
+ flash_perror (rc);
+ return (~0);
+ }
+ } else
+#endif
+ {
+ memcpy ((char *)(store_addr), ymodemBuf, res);
+ }
+
+ }
+ }
+ else {
+ printf ("%s\n",xyzModem_error(err));
+ }
+
+ xyzModem_stream_close(&err);
+ xyzModem_stream_terminate(false,&getcxmodem);
+
+
+ flush_cache (offset, size);
+
+ printf("## Total Size = 0x%08x = %d Bytes\n", size, size);
+ sprintf(buf, "%X", size);
+ setenv("filesize", buf);
+
+ return offset;
+}
+
#endif /* CFG_CMD_LOADB */
/* -------------------------------------------------------------------- */
@@ -1018,6 +1090,14 @@ U_BOOT_CMD(
" with offset 'off' and baudrate 'baud'\n"
);
+U_BOOT_CMD(
+ loady, 3, 0, do_load_serial_bin,
+ "loady - load binary file over serial line (ymodem mode)\n",
+ "[ off ] [ baud ]\n"
+ " - load binary file over serial line"
+ " with offset 'off' and baudrate 'baud'\n"
+);
+
#endif /* CFG_CMD_LOADB */
/* -------------------------------------------------------------------- */