]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - common/cmd_pxe.c
Merge branch 'master' of git://git.denx.de/u-boot-i2c
[karo-tx-uboot.git] / common / cmd_pxe.c
index 079d22658184c1917a9e80f9d7057884dd82c366..a2fb50ab9d2e93e16d729de5f9f6190737448f06 100644 (file)
@@ -1,19 +1,9 @@
 /*
  * Copyright 2010-2011 Calxeda, Inc.
  *
- * This program 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
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program.  If not, see <http://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier:    GPL-2.0+
  */
+
 #include <common.h>
 #include <command.h>
 #include <malloc.h>
 
 #define MAX_TFTP_PATH_LEN 127
 
+const char *pxe_default_paths[] = {
+#ifdef CONFIG_SYS_SOC
+       "default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC,
+#endif
+       "default-" CONFIG_SYS_ARCH,
+       "default",
+       NULL
+};
+
 /*
  * Like getenv, but prints an error if envvar isn't defined in the
  * environment.  It always returns what getenv does, so it can be used in
@@ -339,7 +338,7 @@ do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        char *pxefile_addr_str;
        unsigned long pxefile_addr_r;
-       int err;
+       int err, i = 0;
 
        do_getfile = do_get_tftp;
 
@@ -360,16 +359,23 @@ do_pxe_get(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
         * Keep trying paths until we successfully get a file we're looking
         * for.
         */
-       if (pxe_uuid_path((void *)pxefile_addr_r) > 0
-               || pxe_mac_path((void *)pxefile_addr_r) > 0
-               || pxe_ipaddr_paths((void *)pxefile_addr_r) > 0
-               || get_pxelinux_path("default", (void *)pxefile_addr_r) > 0) {
-
+       if (pxe_uuid_path((void *)pxefile_addr_r) > 0 ||
+           pxe_mac_path((void *)pxefile_addr_r) > 0 ||
+           pxe_ipaddr_paths((void *)pxefile_addr_r) > 0) {
                printf("Config file found\n");
 
                return 0;
        }
 
+       while (pxe_default_paths[i]) {
+               if (get_pxelinux_path(pxe_default_paths[i],
+                                     (void *)pxefile_addr_r) > 0) {
+                       printf("Config file found\n");
+                       return 0;
+               }
+               i++;
+       }
+
        printf("Config file not found\n");
 
        return 1;
@@ -436,6 +442,7 @@ struct pxe_label {
        char *append;
        char *initrd;
        char *fdt;
+       int ipappend;
        int attempted;
        int localboot;
        int localboot_val;
@@ -569,7 +576,11 @@ static int label_boot(struct pxe_label *label)
 {
        char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
        char initrd_str[22];
+       char mac_str[29] = "";
+       char ip_str[68] = "";
+       char *bootargs;
        int bootm_argc = 3;
+       int len = 0;
 
        label_print(label);
 
@@ -608,9 +619,39 @@ static int label_boot(struct pxe_label *label)
                return 1;
        }
 
-       if (label->append) {
-               setenv("bootargs", label->append);
-               printf("append: %s\n", label->append);
+       if (label->ipappend & 0x1) {
+               sprintf(ip_str, " ip=%s:%s:%s:%s",
+                       getenv("ipaddr"), getenv("serverip"),
+                       getenv("gatewayip"), getenv("netmask"));
+               len += strlen(ip_str);
+       }
+
+       if (label->ipappend & 0x2) {
+               int err;
+               strcpy(mac_str, " BOOTIF=");
+               err = format_mac_pxe(mac_str + 8, sizeof(mac_str) - 8);
+               if (err < 0)
+                       mac_str[0] = '\0';
+               len += strlen(mac_str);
+       }
+
+       if (label->append)
+               len += strlen(label->append);
+
+       if (len) {
+               bootargs = malloc(len + 1);
+               if (!bootargs)
+                       return 1;
+               bootargs[0] = '\0';
+               if (label->append)
+                       strcpy(bootargs, label->append);
+               strcat(bootargs, ip_str);
+               strcat(bootargs, mac_str);
+
+               setenv("bootargs", bootargs);
+               printf("append: %s\n", bootargs);
+
+               free(bootargs);
        }
 
        bootm_argv[1] = getenv("kernel_addr_r");
@@ -672,6 +713,8 @@ enum token_type {
        T_PROMPT,
        T_INCLUDE,
        T_FDT,
+       T_ONTIMEOUT,
+       T_IPAPPEND,
        T_INVALID
 };
 
@@ -700,6 +743,8 @@ static const struct token keywords[] = {
        {"initrd", T_INITRD},
        {"include", T_INCLUDE},
        {"fdt", T_FDT},
+       {"ontimeout", T_ONTIMEOUT,},
+       {"ipappend", T_IPAPPEND,},
        {NULL, T_INVALID}
 };
 
@@ -997,10 +1042,8 @@ static int parse_label_menu(char **c, struct pxe_menu *cfg,
 
        switch (t.type) {
        case T_DEFAULT:
-               if (cfg->default_label)
-                       free(cfg->default_label);
-
-               cfg->default_label = strdup(label->name);
+               if (!cfg->default_label)
+                       cfg->default_label = strdup(label->name);
 
                if (!cfg->default_label)
                        return -ENOMEM;
@@ -1093,6 +1136,10 @@ static int parse_label(char **c, struct pxe_menu *cfg)
                        err = parse_integer(c, &label->localboot_val);
                        break;
 
+               case T_IPAPPEND:
+                       err = parse_integer(c, &label->ipappend);
+                       break;
+
                case T_EOL:
                        break;
 
@@ -1159,6 +1206,7 @@ static int parse_pxefile_top(char *p, struct pxe_menu *cfg, int nest_level)
                        break;
 
                case T_DEFAULT:
+               case T_ONTIMEOUT:
                        err = parse_sliteral(&p, &label_name);
 
                        if (label_name) {
@@ -1280,7 +1328,7 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
                        return NULL;
                }
                if (cfg->default_label &&
-                       (strcmp(label->name, cfg->default_label) == 0))
+                   (strcmp(label->name, cfg->default_label) == 0))
                        default_num = label->num;
 
        }