]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - net/bootp.c
Remove CONFIG_SYS_BOOTCOUNT_SINGLEWORD
[people/ms/u-boot.git] / net / bootp.c
index d7852dbb447a123b5e45af89e6483b5d5c3a9a53..efa959971c279fe4e74d04ec0007d0cb1ef52e34 100644 (file)
 
 #include <common.h>
 #include <command.h>
+#include <efi_loader.h>
 #include <net.h>
 #include <net/tftp.h>
 #include "bootp.h"
-#include "nfs.h"
-#ifdef CONFIG_STATUS_LED
+#ifdef CONFIG_LED_STATUS
 #include <status_led.h>
 #endif
 #ifdef CONFIG_BOOTP_RANDOM_DELAY
@@ -169,7 +169,7 @@ static void store_net_params(struct bootp_hdr *bp)
         * not contain a new value
         */
        if (*net_boot_file_name)
-               setenv("bootfile", net_boot_file_name);
+               env_set("bootfile", net_boot_file_name);
 #endif
        net_copy_ip(&net_ip, &bp->bp_yiaddr);
 }
@@ -358,8 +358,8 @@ static void bootp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
        /*
         *      Got a good BOOTP reply.  Copy the data into our variables.
         */
-#if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
-       status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
+#if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
+       status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_OFF);
 #endif
 
        store_net_params(bp);           /* Store net parameters from reply */
@@ -386,12 +386,19 @@ static void bootp_timeout_handler(void)
 
        if (time_taken >= time_taken_max) {
 #ifdef CONFIG_BOOTP_MAY_FAIL
-               puts("\nRetry time exceeded\n");
-               net_set_state(NETLOOP_FAIL);
-#else
-               puts("\nRetry time exceeded; starting again\n");
-               net_start_again();
+               char *ethrotate;
+
+               ethrotate = env_get("ethrotate");
+               if ((ethrotate && strcmp(ethrotate, "no") == 0) ||
+                   net_restart_wrap) {
+                       puts("\nRetry time exceeded\n");
+                       net_set_state(NETLOOP_FAIL);
+               } else
 #endif
+               {
+                       puts("\nRetry time exceeded; starting again\n");
+                       net_start_again();
+               }
        } else {
                bootp_timeout *= 2;
                if (bootp_timeout > 2000)
@@ -410,6 +417,26 @@ static void bootp_timeout_handler(void)
                e += vci_strlen;                                \
        } while (0)
 
+static u8 *add_vci(u8 *e)
+{
+       char *vci = NULL;
+       char *env_vci = env_get("bootp_vci");
+
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_NET_VCI_STRING)
+       vci = CONFIG_SPL_NET_VCI_STRING;
+#elif defined(CONFIG_BOOTP_VCI_STRING)
+       vci = CONFIG_BOOTP_VCI_STRING;
+#endif
+
+       if (env_vci)
+               vci = env_vci;
+
+       if (vci)
+               put_vci(e, vci);
+
+       return e;
+}
+
 /*
  *     Initialize BOOTP extension fields in the request.
  */
@@ -419,10 +446,10 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
 {
        u8 *start = e;
        u8 *cnt;
-#if defined(CONFIG_BOOTP_PXE)
+#ifdef CONFIG_LIB_UUID
        char *uuid;
-       u16 clientarch;
 #endif
+       int clientarch = -1;
 
 #if defined(CONFIG_BOOTP_VENDOREX)
        u8 *x;
@@ -467,7 +494,7 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
                *e++ = tmp & 0xff;
        }
 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
-       hostname = getenv("hostname");
+       hostname = env_get("hostname");
        if (hostname) {
                int hostnamelen = strlen(hostname);
 
@@ -478,12 +505,19 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
        }
 #endif
 
-#if defined(CONFIG_BOOTP_PXE)
+#ifdef CONFIG_BOOTP_PXE_CLIENTARCH
        clientarch = CONFIG_BOOTP_PXE_CLIENTARCH;
-       *e++ = 93;      /* Client System Architecture */
-       *e++ = 2;
-       *e++ = (clientarch >> 8) & 0xff;
-       *e++ = clientarch & 0xff;
+#endif
+
+       if (env_get("bootp_arch"))
+               clientarch = env_get_ulong("bootp_arch", 16, clientarch);
+
+       if (clientarch > 0) {
+               *e++ = 93;      /* Client System Architecture */
+               *e++ = 2;
+               *e++ = (clientarch >> 8) & 0xff;
+               *e++ = clientarch & 0xff;
+       }
 
        *e++ = 94;      /* Client Network Interface Identifier */
        *e++ = 3;
@@ -491,7 +525,8 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
        *e++ = 0;       /* major revision */
        *e++ = 0;       /* minor revision */
 
-       uuid = getenv("pxeuuid");
+#ifdef CONFIG_LIB_UUID
+       uuid = env_get("pxeuuid");
 
        if (uuid) {
                if (uuid_str_valid(uuid)) {
@@ -507,11 +542,7 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
        }
 #endif
 
-#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_NET_VCI_STRING)
-       put_vci(e, CONFIG_SPL_NET_VCI_STRING);
-#elif defined(CONFIG_BOOTP_VCI_STRING)
-       put_vci(e, CONFIG_BOOTP_VCI_STRING);
-#endif
+       e = add_vci(e);
 
 #if defined(CONFIG_BOOTP_VENDOREX)
        x = dhcp_vendorex_prep(e);
@@ -597,14 +628,7 @@ static int bootp_extended(u8 *e)
        *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
 #endif
 
-#if defined(CONFIG_BOOTP_VCI_STRING) || \
-       (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_NET_VCI_STRING))
-#ifdef CONFIG_SPL_BUILD
-       put_vci(e, CONFIG_SPL_NET_VCI_STRING);
-#else
-       put_vci(e, CONFIG_BOOTP_VCI_STRING);
-#endif
-#endif
+       add_vci(e);
 
 #if defined(CONFIG_BOOTP_SUBNETMASK)
        *e++ = 1;               /* Subnet mask request */
@@ -655,6 +679,15 @@ static int bootp_extended(u8 *e)
 
        *e++ = 255;             /* End of the list */
 
+       /*
+        * If nothing in list, remove it altogether. Some DHCP servers get
+        * upset by this minor faux pas and do not respond at all.
+        */
+       if (e == start + 3) {
+               printf("*** Warning: no DHCP options requested\n");
+               e -= 3;
+       }
+
        return e - start;
 }
 #endif
@@ -686,7 +719,7 @@ void bootp_request(void)
        dhcp_state = INIT;
 #endif
 
-       ep = getenv("bootpretryperiod");
+       ep = env_get("bootpretryperiod");
        if (ep != NULL)
                time_taken_max = simple_strtoul(ep, NULL, 10);
        else
@@ -1025,6 +1058,7 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                            strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
                        dhcp_packet_process_options(bp);
+                       efi_net_set_dhcp_ack(pkt, len);
 
                        debug("TRANSITIONING TO REQUESTING STATE\n");
                        dhcp_state = REQUESTING;