]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_load.c
Merge branch 'master' of git://git.denx.de/u-boot-usb
[karo-tx-uboot.git] / common / cmd_load.c
index 749849711a007fcfc6817ddca3144e2e0c0dcfb2..1b75a7b5eccf15289e03d9f341efd5c193ba444e 100644 (file)
 #include <s_record.h>
 #include <net.h>
 #include <exports.h>
+#include <xyzModem.h>
 
+DECLARE_GLOBAL_DATA_PTR;
 
-#if (CONFIG_COMMANDS & CFG_CMD_LOADS)
+#if defined(CONFIG_CMD_LOADB)
+static ulong load_serial_ymodem (ulong offset);
+#endif
+
+#if defined(CONFIG_CMD_LOADS)
 static ulong load_serial (ulong offset);
 static int read_record (char *buf, ulong len);
-# if (CONFIG_COMMANDS & CFG_CMD_SAVES)
+# if defined(CONFIG_CMD_SAVES)
 static int save_serial (ulong offset, ulong size);
 static int write_record (char *buf);
-# endif /* CFG_CMD_SAVES */
+#endif
 
 static int do_echo = 1;
-#endif /* CFG_CMD_LOADS */
+#endif
 
 /* -------------------------------------------------------------------- */
 
-#if (CONFIG_COMMANDS & CFG_CMD_LOADS)
+#if defined(CONFIG_CMD_LOADS)
 int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        ulong offset = 0;
@@ -53,7 +59,6 @@ int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        char *env_echo;
        int rcode = 0;
 #ifdef CFG_LOADS_BAUD_CHANGE
-       DECLARE_GLOBAL_DATA_PTR;
        int load_baudrate, current_baudrate;
 
        load_baudrate = current_baudrate = gd->baudrate;
@@ -213,7 +218,6 @@ load_serial (ulong offset)
 static int
 read_record (char *buf, ulong len)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        char *p;
        char c;
 
@@ -249,14 +253,13 @@ read_record (char *buf, ulong len)
        return (p - buf);
 }
 
-#if (CONFIG_COMMANDS & CFG_CMD_SAVES)
+#if defined(CONFIG_CMD_SAVES)
 
 int do_save_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        ulong offset = 0;
        ulong size   = 0;
 #ifdef CFG_LOADS_BAUD_CHANGE
-       DECLARE_GLOBAL_DATA_PTR;
        int save_baudrate, current_baudrate;
 
        save_baudrate = current_baudrate = gd->baudrate;
@@ -396,13 +399,15 @@ write_record (char *buf)
        }
        return (0);
 }
-# endif /* CFG_CMD_SAVES */
-
-#endif /* CFG_CMD_LOADS */
+# endif
 
+#endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_LOADB)  /* loadb command (load binary) included */
 
+#if defined(CONFIG_CMD_LOADB)
+/*
+ * loadb command (load binary) included
+ */
 #define XON_CHAR        17
 #define XOFF_CHAR       19
 #define START_CHAR      0x01
@@ -433,8 +438,6 @@ char his_quote;      /* quote chars he'll use */
 
 int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        ulong offset = 0;
        ulong addr;
        int load_baudrate, current_baudrate;
@@ -475,21 +478,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);
@@ -508,8 +521,15 @@ int do_load_serial_bin (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                char *s;
 
                if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
-                       printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
-                       rcode = autoscript (load_addr);
+                       printf ("Running autoscript at addr 0x%08lX", load_addr);
+
+                       s = getenv ("autoscript_uname");
+                       if (s)
+                               printf (":%s ...\n", s);
+                       else
+                               puts (" ...\n");
+
+                       rcode = autoscript (load_addr, s);
                }
        }
 #endif
@@ -963,11 +983,73 @@ START:
        }
        return ((ulong) os_data_addr - (ulong) bin_start_address);
 }
-#endif /* CFG_CMD_LOADB */
+
+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
 
 /* -------------------------------------------------------------------- */
 
-#if (CONFIG_COMMANDS & CFG_CMD_LOADS)
+#if defined(CONFIG_CMD_LOADS)
 
 #ifdef CFG_LOADS_BAUD_CHANGE
 U_BOOT_CMD(
@@ -992,7 +1074,7 @@ U_BOOT_CMD(
  */
 
 
-#if (CONFIG_COMMANDS & CFG_CMD_SAVES)
+#if defined(CONFIG_CMD_SAVES)
 #ifdef CFG_LOADS_BAUD_CHANGE
 U_BOOT_CMD(
        saves, 4, 0,    do_save_serial,
@@ -1009,11 +1091,11 @@ U_BOOT_CMD(
        "    - save S-Record file over serial line with offset 'off' and size 'size'\n"
 );
 #endif /* CFG_LOADS_BAUD_CHANGE */
-#endif /* CFG_CMD_SAVES */
-#endif /* CFG_CMD_LOADS */
+#endif
+#endif
 
 
-#if (CONFIG_COMMANDS & CFG_CMD_LOADB)
+#if defined(CONFIG_CMD_LOADB)
 U_BOOT_CMD(
        loadb, 3, 0,    do_load_serial_bin,
        "loadb   - load binary file over serial line (kermit mode)\n",
@@ -1022,11 +1104,19 @@ U_BOOT_CMD(
        " with offset 'off' and baudrate 'baud'\n"
 );
 
-#endif /* CFG_CMD_LOADB */
+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
 
 /* -------------------------------------------------------------------- */
 
-#if (CONFIG_COMMANDS & CFG_CMD_HWFLOW)
+#if defined(CONFIG_CMD_HWFLOW)
 int do_hwflow (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        extern int hwflow_onoff(int);
@@ -1052,4 +1142,4 @@ U_BOOT_CMD(
        "[on|off]\n - change RTS/CTS hardware flow control over serial line\n"
 );
 
-#endif /* CFG_CMD_HWFLOW */
+#endif