Merge git://git.denx.de/u-boot-x86
[oweals/u-boot.git] / net / net.c
index bff3e9c5b531cc76254b835b8bb5e938f0bc3a46..31cf306ae71e11cf0f5ad65e992a1380d84faeba 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -216,26 +216,6 @@ int __maybe_unused net_busy_flag;
 
 /**********************************************************************/
 
-static int on_bootfile(const char *name, const char *value, enum env_op op,
-       int flags)
-{
-       if (flags & H_PROGRAMMATIC)
-               return 0;
-
-       switch (op) {
-       case env_op_create:
-       case env_op_overwrite:
-               copy_filename(net_boot_file_name, value,
-                             sizeof(net_boot_file_name));
-               break;
-       default:
-               break;
-       }
-
-       return 0;
-}
-U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
-
 static int on_ipaddr(const char *name, const char *value, enum env_op op,
        int flags)
 {
@@ -332,6 +312,16 @@ void net_auto_load(void)
        const char *s = env_get("autoload");
 
        if (s != NULL && strcmp(s, "NFS") == 0) {
+               if (net_check_prereq(NFS)) {
+/* We aren't expecting to get a serverip, so just accept the assigned IP */
+#ifdef CONFIG_BOOTP_SERVERIP
+                       net_set_state(NETLOOP_SUCCESS);
+#else
+                       printf("Cannot autoload with NFS\n");
+                       net_set_state(NETLOOP_FAIL);
+#endif
+                       return;
+               }
                /*
                 * Use NFS to load the bootfile.
                 */
@@ -347,6 +337,16 @@ void net_auto_load(void)
                net_set_state(NETLOOP_SUCCESS);
                return;
        }
+       if (net_check_prereq(TFTPGET)) {
+/* We aren't expecting to get a serverip, so just accept the assigned IP */
+#ifdef CONFIG_BOOTP_SERVERIP
+               net_set_state(NETLOOP_SUCCESS);
+#else
+               printf("Cannot autoload with TFTPGET\n");
+               net_set_state(NETLOOP_FAIL);
+#endif
+               return;
+       }
        tftp_start(TFTPGET);
 }
 
@@ -1502,12 +1502,12 @@ void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, int sport,
 
 void copy_filename(char *dst, const char *src, int size)
 {
-       if (*src && (*src == '"')) {
+       if (src && *src && (*src == '"')) {
                ++src;
                --size;
        }
 
-       while ((--size > 0) && *src && (*src != '"'))
+       while ((--size > 0) && src && *src && (*src != '"'))
                *dst++ = *src++;
        *dst = '\0';
 }
@@ -1517,6 +1517,26 @@ int is_serverip_in_cmd(void)
        return !!strchr(net_boot_file_name, ':');
 }
 
+int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len)
+{
+       char *colon;
+
+       if (net_boot_file_name[0] == '\0')
+               return 0;
+
+       colon = strchr(net_boot_file_name, ':');
+       if (colon) {
+               if (ipaddr)
+                       *ipaddr = string_to_ip(net_boot_file_name);
+               strncpy(filename, colon + 1, max_len);
+       } else {
+               strncpy(filename, net_boot_file_name, max_len);
+       }
+       filename[max_len - 1] = '\0';
+
+       return 1;
+}
+
 #if    defined(CONFIG_CMD_NFS)         || \
        defined(CONFIG_CMD_SNTP)        || \
        defined(CONFIG_CMD_DNS)