]> www.infradead.org Git - users/rw/armboot.git/commitdiff
- Changed the various serial_putc()'s to output <CR>-<LF> on
authorrobertkaiser <robertkaiser>
Wed, 2 Oct 2002 16:16:10 +0000 (16:16 +0000)
committerrobertkaiser <robertkaiser>
Wed, 2 Oct 2002 16:16:10 +0000 (16:16 +0000)
  '\n' (rather than <LF>-<CR>.
- Added new "saves" command to dump memory contents to serial
  line in S-record form.

CHANGELOG
common/cmd_boot.c
common/command.c
cpu/arm920t/serial.c
cpu/epxa/serial.c
cpu/sa1100/serial.c
cpu/xscale/serial.c
include/cmd_boot.h

index 110d29b33547c2b2e68b25531840ae35f9c0218b..4fa76704c549c192985f573f2a86535730940482 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,13 @@
 Recent Modifications
 ======================================================================
 
+* Patch by Robert Kaiser <rob@sysgo.de>:
+
+  - Changed the various serial_putc()'s to output <CR>-<LF> on 
+    '\n' (rather than <LF>-<CR>.
+  - Added new "saves" command to dump memory contents to serial
+    line in S-record form.
+
 * Patch by Robert Kaiser <rob@sysgo.de>:
 
   - one more network code cleanup. Code is now mostly in sync
index 96126ffc9b33a2169070368379693606dadc96af..9a519cae54490c527c51bcd47fb159523384ff67 100644 (file)
@@ -38,7 +38,9 @@
 
 #if (CONFIG_COMMANDS & CFG_CMD_LOADS)
 static ulong load_serial (ulong offset);
+static int save_serial (ulong offset, ulong size);
 static int read_record (char *buf, ulong len);
+static int write_record (char *buf);
 
 static int do_echo = 1;
 #endif
@@ -156,7 +158,7 @@ int do_load_serial (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]
                printf ("## Switch baudrate to %d bps and press ENTER ...\n",
                        loads_baudrate);
                udelay(50000);
-               serial_setbrg (bd->bi_intfreq, loads_baudrate);
+               serial_setbrg (bd, loads_baudrate);
                udelay(50000);
                for (;;) {
                        if (getc() == '\r')
@@ -192,7 +194,7 @@ int do_load_serial (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]
                printf ("## Switch baudrate to %d bps and press ESC ...\n",
                        (int)bd->bi_baudrate);
                udelay (50000);
-               serial_setbrg (bd->bi_intfreq, bd->bi_baudrate);
+               serial_setbrg (bd, bd->bi_baudrate);
                udelay (50000);
                for (;;) {
                        if (getc() == 0x1B) /* ESC */
@@ -335,6 +337,159 @@ read_record (char *buf, ulong len)
        *p = '\0';
        return (p - buf);
 }
+
+
+
+int do_save_serial (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
+{
+       ulong offset = 0;
+       ulong size   = 0;
+       char *env_echo;
+#ifdef CFG_LOADS_BAUD_CHANGE
+       int saves_baudrate = bd->bi_baudrate;
+#endif
+
+       if (argc >= 2) {
+               offset = simple_strtoul(argv[1], NULL, 16);
+       }
+#ifdef CFG_LOADS_BAUD_CHANGE
+       if (argc >= 3) {
+               size = simple_strtoul(argv[2], NULL, 16);
+       }
+       if (argc == 4) {
+               saves_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
+
+               /* default to current baudrate */
+               if (saves_baudrate == 0)
+                       saves_baudrate = bd->bi_baudrate;
+       }
+#else  /* ! CFG_LOADS_BAUD_CHANGE */
+       if (argc == 3) {
+               size = simple_strtoul(argv[2], NULL, 16);
+       }
+#endif /* CFG_LOADS_BAUD_CHANGE */
+
+#ifdef CFG_LOADS_BAUD_CHANGE
+       if (saves_baudrate != bd->bi_baudrate) {
+               printf ("## Switch baudrate to %d bps and press ENTER ...\n",
+                       saves_baudrate);
+               udelay(50000);
+               serial_setbrg (bd, saves_baudrate);
+               udelay(50000);
+               for (;;) {
+                       if (getc() == '\r')
+                               break;
+               }
+       }
+#endif /* CFG_LOADS_BAUD_CHANGE */
+       printf ("## Ready for S-Record upload, press ENTER to proceed ...\n");
+       for (;;) {
+               if (getc() == '\r')
+                       break;
+       }
+       if(save_serial (offset, size)) {
+               printf ("## S-Record upload aborted\n");
+       } else {
+               printf ("## S-Record upload complete\n");
+       }
+#ifdef CFG_LOADS_BAUD_CHANGE
+       if (saves_baudrate != bd->bi_baudrate) {
+               printf ("## Switch baudrate to %d bps and press ESC ...\n",
+                       (int)bd->bi_baudrate);
+               udelay (50000);
+               serial_setbrg (bd, bd->bi_baudrate);
+               udelay (50000);
+               for (;;) {
+                       if (getc() == 0x1B) /* ESC */
+                               break;
+               }
+       }
+#endif
+       return 0;
+}
+
+#define SREC3_START                            "S0030000FC\n"
+#define SREC3_FORMAT                   "S3%02X%08X%s%02X\n"
+#define SREC3_END                              "S70500000000FA\n"
+#define SREC_BYTES_PER_RECORD  16
+
+static int save_serial (ulong address, ulong count)
+{
+       int i, c, reclen, checksum, length;
+       char *hex = "0123456789ABCDEF";
+       char    record[2*SREC_BYTES_PER_RECORD+16];     /* buffer for one S-Record      */
+       char    data[2*SREC_BYTES_PER_RECORD+1];        /* buffer for hex data  */
+
+       reclen = 0;
+       checksum  = 0;
+
+       if(write_record(SREC3_START))                   /* write the header */
+               return (-1);
+       do {
+               if(count) {                                             /* collect hex data in the buffer  */
+                       c = *(volatile uchar*)(address + reclen);       /* get one byte    */
+                       checksum += c;                                                  /* accumulate checksum */
+                       data[2*reclen]   = hex[(c>>4)&0x0f];
+                       data[2*reclen+1] = hex[c & 0x0f];
+                       data[2*reclen+2] = '\0';
+                       ++reclen;
+                       --count;
+               }
+               if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
+                       /* enough data collected for one record: dump it */
+                       if(reclen) {    /* build & write a data record: */
+                               /* address + data + checksum */
+                               length = 4 + reclen + 1;
+
+                               /* accumulate length bytes into checksum */
+                               for(i = 0; i < 2; i++)
+                                       checksum += (length >> (8*i)) & 0xff;
+
+                               /* accumulate address bytes into checksum: */
+                               for(i = 0; i < 4; i++)
+                                       checksum += (address >> (8*i)) & 0xff;
+
+                               /* make proper checksum byte: */
+                               checksum = ~checksum & 0xff;
+
+                               /* output one record: */
+                               sprintf(record, SREC3_FORMAT, length, address, data, checksum);
+                               if(write_record(record))
+                                       return (-1);
+                       }
+                       address  += reclen;  /* increment address */
+                       checksum  = 0;
+                       reclen    = 0;
+               }
+       }
+       while(count);
+       if(write_record(SREC3_END))     /* write the final record */
+               return (-1);
+       return(0);
+}
+
+static int
+write_record (char *buf)
+{
+       char *p;
+       char c;
+
+       while((c = *buf++))
+               serial_putc(c);
+
+    // Check for the console hangup (if any different from serial)
+
+       if (ctrlc())
+       {
+           return (-1);
+       }
+       return (0);
+}
+
+
+
+
+
 #endif /* CFG_CMD_LOADS */
 
 
index 61e58899ca9870bff138555955fa15ff4f47bbe5..5f0686871992b872dfdc4cf331370eb7deefb6a5 100644 (file)
@@ -189,6 +189,7 @@ cmd_tbl_t cmd_tbl[] = {
        CMD_TBL_DHCP
        CMD_TBL_BOOTD
        CMD_TBL_LOADS
+       CMD_TBL_SAVES
        CMD_TBL_LOADB
        CMD_TBL_AUTOSCRIPT
        CMD_TBL_MD
index fcff3a311aac4cc7c9aef9e65f8968e52ba09453..5bd44aa0c8b536031ff23b3d3355971859bbce39 100644 (file)
@@ -130,6 +130,10 @@ int serial_getc(void)
  */
 void serial_putc(const char c)
 {
+    /* If \n, also do \r */
+    if(c == '\n')
+      serial_putc('\r');
+
 #ifdef CONFIG_SERIAL1
     /* wait for room in the tx FIFO on SERIAL1 */
     while(!(rUTRSTAT0 & 0x2))
@@ -143,10 +147,6 @@ void serial_putc(const char c)
 
     rUTXH1= c;
 #endif
-
-    /* If \n, also do \r */
-    if(c == '\n')
-      serial_putc('\r');
 }              
 
 /*
index e9f861b6adbeef2295bad437b1708d8c42fbeda7..e076db157270cafc94ec222064c5a109f8b96b04 100644 (file)
@@ -75,14 +75,14 @@ void serial_init(bd_t *bd)
  */
 void serial_putc(const char c)
 {
+       /* If \n, also do \r */
+       if(c == '\n')
+               serial_putc('\r');
+
        /* Wait for space in the fifo */
         while(((*UART_TSR(EXC_UART00_BASE) & UART_TSR_TX_LEVEL_MSK)==15));
 
        *UART_TD(EXC_UART00_BASE)=c;
-
-       /* If \n, also do \r */
-       if(c == '\n')
-               serial_putc('\r');
 }
 
 /*
index 88277437c1b49d5fd6504ce895b4c2b6a8c99eb1..5d1b33cc36a86f8d733e660e0c1df4902f97814c 100644 (file)
@@ -89,6 +89,10 @@ void serial_init(bd_t *bd)
  */
 void serial_putc(const char c)
 {
+    /* If \n, also do \r */
+    if(c == '\n')
+      serial_putc('\r');
+
 #ifdef CONFIG_SERIAL1
     /* wait for room in the tx FIFO on SERIAL1 */
     while((Ser1UTSR0 & UTSR0_TFS) == 0) ;
@@ -100,10 +104,6 @@ void serial_putc(const char c)
 
     Ser3UTDR = c;
 #endif
-
-    /* If \n, also do \r */
-    if(c == '\n')
-      serial_putc('\r');
 }
 
 /*
index 11ea81d1bebb694c45b7c6a979ebfd62bb042a40..e355fa79e0b1bf0d84b996227632a9da39e7d339 100644 (file)
@@ -84,6 +84,10 @@ void serial_init(bd_t *bd)
  */
 void serial_putc(const char c)
 {
+    /* If \n, also do \r */
+    if(c == '\n')
+      serial_putc('\r');
+
 #ifdef CONFIG_FFUART
     /* wait for room in the tx FIFO on FFUART */
     while((FFLSR & LSR_TEMT) == 0) ;
@@ -91,10 +95,6 @@ void serial_putc(const char c)
     FFTHR = c;
 #elif CONFIG_STUART
 #endif
-
-    /* If \n, also do \r */
-    if(c == '\n')
-      serial_putc('\r');
 }
 
 /*
index a4d2db0cf410d1060b58da8cf72f6e3e7215e0fd..f3f31301c75472fcb7a2d593a49cb550b1ba0a45 100644 (file)
@@ -72,6 +72,25 @@ int do_go (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]);
 
 int do_load_serial (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]);
 
+#ifdef CFG_LOADS_BAUD_CHANGE
+#define        CMD_TBL_SAVES   MK_CMD_TBL_ENTRY(                                       \
+       "saves",        5,      4,      0,      do_save_serial,                 \
+       "saves   - save S-Record file over serial line\n",                      \
+       "[ off ] [size] [ baud ]\n"                                                     \
+       "    - save S-Record file over serial line"                             \
+       " with offset 'off', size 'size' and baudrate 'baud'\n"                         \
+),
+#else  /* ! CFG_LOADS_BAUD_CHANGE */
+#define        CMD_TBL_SAVES   MK_CMD_TBL_ENTRY(                                       \
+       "saves",        5,      3,      0,      do_save_serial,                 \
+       "saves   - save S-Record file over serial line\n",                      \
+       "[ off ] [size]\n"                                                              \
+       "    - save S-Record file over serial line with offset 'off' and size 'size'\n"         \
+),
+#endif /* CFG_LOADS_BAUD_CHANGE */
+
+int do_save_serial (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]);
+
 #else  /* ! CFG_CMD_LOADS */
 #define CMD_TBL_LOADS
 #endif /* CFG_CMD_LOADS */