changeset 898:6f9085944169

Improve download error handling. Also display more info during load.
author gthomas
date Thu, 03 Apr 2003 15:21:10 +0000
parents 07ad44cfd9a4
children 17dd6922881b
files packages/redboot/current/ChangeLog packages/redboot/current/include/net/http.h packages/redboot/current/src/load.c packages/redboot/current/src/net/http_client.c
diffstat 4 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/packages/redboot/current/ChangeLog
+++ b/packages/redboot/current/ChangeLog
@@ -1,3 +1,11 @@
+2003-04-03  Gary Thomas  <gary@mlbassoc.com>
+
+	* src/load.c: Better handling of default download mode.  Also
+	display information when I/O errors occor (was silent).
+
+	* src/net/http_client.c: 
+	* include/net/http.h: Improve parsing of HTTP responses for errors.
+
 2003-03-28  Gary Thomas  <gary@mlbassoc.com>  inspired by
 2003-03-28  Jani Monoses <jani@iv.ro>	
 
--- a/packages/redboot/current/include/net/http.h
+++ b/packages/redboot/current/include/net/http.h
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -65,6 +65,8 @@ extern char *http_error(int err);
 #define HTTP_BADHDR   1   // Invalid HTTP header (response)
 #define HTTP_OPEN     2   // Problems opening connection
 #define HTTP_IO       3   // Misc I/O problems
+#define HTTP_BADREQ   4   // Bad request
+#define HTTP_NOFILE   5   // No such file
 
 extern getc_io_funcs_t http_io;
 #endif // _HTTP_H_
--- a/packages/redboot/current/src/load.c
+++ b/packages/redboot/current/src/load.c
@@ -140,6 +140,9 @@ redboot_getc(void)
         getc_info.bufp = getc_info.buf;
         getc_info.len = (*getc_info.fun)(getc_info.bufp, BUF_SIZE, &getc_info.err);
         if ((getc_info.avail = getc_info.len) <= 0) {
+            if (getc_info.len < 0) {
+                diag_printf("I/O error: %s\n", (getc_info.io->error)(getc_info.err));
+            }
             if (getc_info.verbose) diag_printf("\n");
             return -1;
         }
@@ -590,7 +593,7 @@ do_load(int argc, char *argv[])
     char *filename = 0;
     struct option_info opts[7];
     connection_info_t info;
-    getc_io_funcs_t *io;
+    getc_io_funcs_t *io = NULL;
     struct load_io_entry *io_tab;
 #ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS
     bool spillover_ok = false;
@@ -653,7 +656,6 @@ do_load(int argc, char *argv[])
         return;
     }
     if (mode_str_set) {
-        io = (getc_io_funcs_t *)NULL;
         for (io_tab = __RedBoot_LOAD_TAB__; 
              io_tab != &__RedBoot_LOAD_TAB_END__;  io_tab++) {
             if (strncasecmp(&mode_str[0], io_tab->name, strlen(&mode_str[0])) == 0) {
@@ -679,20 +681,23 @@ do_load(int argc, char *argv[])
             return;
         }
     } else {
+        char *which;
         io_tab = (struct load_io_entry *)NULL;  // Default
 #ifdef CYGPKG_REDBOOT_NETWORKING
-#ifdef CYGSEM_REDBOOT_NET_TFTP_DOWNLOAD
+#ifdef CYGSEM_REDBOOT_NET_TFTP_DOWNLOAD        
+        which = "TFTP";
         io = &tftp_io;
-#elif CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD
+#else if defined(CYGSEM_REDBOOT_NET_HTTP_DOWNLOAD)
+        which = "HTTP";
         io = &http_io;
-#else
-        io = &xyzModem_io;
-        verbose = false;
+#endif
 #endif
-#else
-        io = &xyzModem_io;
-        verbose = false;
-#endif
+        if (!io) {
+            which = "Xmodem";
+            io = &xyzModem_io;
+            verbose = false;
+        }
+        diag_printf("Using default protocol (%s)\n", which);
     }
 #ifdef CYGSEM_REDBOOT_VALIDATE_USER_RAM_LOADS
     if (base_addr_set &&
--- a/packages/redboot/current/src/net/http_client.c
+++ b/packages/redboot/current/src/net/http_client.c
@@ -9,7 +9,7 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -173,7 +173,17 @@ http_stream_read(char *buf,
                             s->avail--;
                         }
                         if (strncmp(s->bufp, "OK", 2)) {
-                            *err = HTTP_BADHDR;
+                            switch (code) {
+                            case 400:
+                                *err = HTTP_BADREQ;
+                                break;
+                            case 404:
+                                *err = HTTP_NOFILE;
+                                break;
+                            default:
+                                *err = HTTP_BADHDR;
+                                break;
+                            }
                             return -1;
                         }
                         // Find \r\n\r\n - end of HTTP preamble
@@ -224,6 +234,10 @@ http_error(int err)
         return "";
     case HTTP_BADHDR:
         return "Unrecognized HTTP response";
+    case HTTP_BADREQ:
+        return "Bad HTTP request (check file name)";
+    case HTTP_NOFILE:
+        return "No such file";
     case HTTP_OPEN:
         return "Can't connect to host";
     case HTTP_IO: