checkpatch.pl: Warn if the flattree API is used
[oweals/u-boot.git] / cmd / net.c
index 67888d4e184add6a53531ff17ff758cfad41869b..25390b0474f4c9032cea1c678a1053e9d195a3f5 100644 (file)
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -1,21 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
  * Boot support
  */
 #include <common.h>
+#include <bootstage.h>
 #include <command.h>
+#include <env.h>
+#include <image.h>
 #include <net.h>
 
-static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []);
+static int netboot_common(enum proto_t, struct cmd_tbl *, int, char * const []);
 
 #ifdef CONFIG_CMD_BOOTP
-static int do_bootp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_bootp(struct cmd_tbl *cmdtp, int flag, int argc,
+                   char *const argv[])
 {
        return netboot_common(BOOTP, cmdtp, argc, argv);
 }
@@ -28,7 +31,7 @@ U_BOOT_CMD(
 #endif
 
 #ifdef CONFIG_CMD_TFTPBOOT
-int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
        int ret;
 
@@ -46,7 +49,8 @@ U_BOOT_CMD(
 #endif
 
 #ifdef CONFIG_CMD_TFTPPUT
-static int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_tftpput(struct cmd_tbl *cmdtp, int flag, int argc,
+                     char *const argv[])
 {
        return netboot_common(TFTPPUT, cmdtp, argc, argv);
 }
@@ -59,7 +63,8 @@ U_BOOT_CMD(
 #endif
 
 #ifdef CONFIG_CMD_TFTPSRV
-static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+static int do_tftpsrv(struct cmd_tbl *cmdtp, int flag, int argc,
+                     char *const argv[])
 {
        return netboot_common(TFTPSRV, cmdtp, argc, argv);
 }
@@ -76,7 +81,7 @@ U_BOOT_CMD(
 
 
 #ifdef CONFIG_CMD_RARP
-int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_rarpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
        return netboot_common(RARP, cmdtp, argc, argv);
 }
@@ -89,7 +94,8 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_DHCP)
-static int do_dhcp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc,
+                  char *const argv[])
 {
        return netboot_common(DHCP, cmdtp, argc, argv);
 }
@@ -102,7 +108,8 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_NFS)
-static int do_nfs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_nfs(struct cmd_tbl *cmdtp, int flag, int argc,
+                 char *const argv[])
 {
        return netboot_common(NFS, cmdtp, argc, argv);
 }
@@ -175,8 +182,8 @@ static void netboot_update_env(void)
 #endif
 }
 
-static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
-               char * const argv[])
+static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
+                         char *const argv[])
 {
        char *s;
        char *end;
@@ -184,13 +191,18 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
        int   size;
        ulong addr;
 
-       /* pre-set load_addr */
+       net_boot_file_name_explicit = false;
+
+       /* pre-set image_load_addr */
        s = env_get("loadaddr");
        if (s != NULL)
-               load_addr = simple_strtoul(s, NULL, 16);
+               image_load_addr = simple_strtoul(s, NULL, 16);
 
        switch (argc) {
        case 1:
+               /* refresh bootfile name from env */
+               copy_filename(net_boot_file_name, env_get("bootfile"),
+                             sizeof(net_boot_file_name));
                break;
 
        case 2: /*
@@ -200,15 +212,21 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
                 * mis-interpreted as a valid number.
                 */
                addr = simple_strtoul(argv[1], &end, 16);
-               if (end == (argv[1] + strlen(argv[1])))
-                       load_addr = addr;
-               else
+               if (end == (argv[1] + strlen(argv[1]))) {
+                       image_load_addr = addr;
+                       /* refresh bootfile name from env */
+                       copy_filename(net_boot_file_name, env_get("bootfile"),
+                                     sizeof(net_boot_file_name));
+               } else {
+                       net_boot_file_name_explicit = true;
                        copy_filename(net_boot_file_name, argv[1],
                                      sizeof(net_boot_file_name));
+               }
                break;
 
        case 3:
-               load_addr = simple_strtoul(argv[1], NULL, 16);
+               image_load_addr = simple_strtoul(argv[1], NULL, 16);
+               net_boot_file_name_explicit = true;
                copy_filename(net_boot_file_name, argv[2],
                              sizeof(net_boot_file_name));
 
@@ -216,11 +234,12 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
 
 #ifdef CONFIG_CMD_TFTPPUT
        case 4:
-               if (strict_strtoul(argv[1], 16, &save_addr) < 0 ||
-                   strict_strtoul(argv[2], 16, &save_size) < 0) {
+               if (strict_strtoul(argv[1], 16, &image_save_addr) < 0 ||
+                   strict_strtoul(argv[2], 16, &image_save_size) < 0) {
                        printf("Invalid address/size\n");
                        return CMD_RET_USAGE;
                }
+               net_boot_file_name_explicit = true;
                copy_filename(net_boot_file_name, argv[3],
                              sizeof(net_boot_file_name));
                break;
@@ -259,7 +278,8 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
 }
 
 #if defined(CONFIG_CMD_PING)
-static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_ping(struct cmd_tbl *cmdtp, int flag, int argc,
+                  char *const argv[])
 {
        if (argc < 2)
                return CMD_RET_USAGE;
@@ -307,7 +327,7 @@ static void cdp_update_env(void)
        }
 }
 
-int do_cdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_cdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
        int r;
 
@@ -330,7 +350,7 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_SNTP)
-int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
        char *toff;
 
@@ -371,7 +391,7 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_DNS)
-int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
        if (argc == 1)
                return CMD_RET_USAGE;
@@ -417,8 +437,8 @@ U_BOOT_CMD(
 #endif /* CONFIG_CMD_DNS */
 
 #if defined(CONFIG_CMD_LINK_LOCAL)
-static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char * const argv[])
+static int do_link_local(struct cmd_tbl *cmdtp, int flag, int argc,
+                        char *const argv[])
 {
        char tmp[22];