[PATCH 20/39] net: Return the size from parse_args()
Simon Glass
sjg at chromium.org
Tue Nov 19 14:18:25 CET 2024
Rather than setting global variables, return the size, if provided. For
tftput, use the addr argument to store the save address, to avoid adding
yet another parameter.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
cmd/net.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/cmd/net.c b/cmd/net.c
index 920d9918ff6..8bb8604faf6 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -321,12 +321,14 @@ static int parse_addr_size(char * const argv[], ulong *addrp, ulong *sizep)
* parsed
* @argv: command line arguments, with argv[0] being the command
* @fnamep: set to the filename, if provided, else NULL
- * @addrp: returns the load address, if any is provided, else it is left
+ * @addrp: returns the load/save address, if any is provided, else it is
+ * left unchanged
+ * @sizep: returns the save size, if any is provided, else it is left
* unchanged
* Return: 0 on success
*/
static int parse_args(enum proto_t proto, int argc, char *const argv[],
- const char **fnamep, ulong *addrp)
+ const char **fnamep, ulong *addrp, ulong *sizep)
{
ulong addr;
char *end;
@@ -356,8 +358,7 @@ static int parse_args(enum proto_t proto, int argc, char *const argv[],
case 3:
if (IS_ENABLED(CONFIG_CMD_TFTPPUT) && proto == TFTPPUT) {
- if (parse_addr_size(argv, &image_save_addr,
- &image_save_size))
+ if (parse_addr_size(argv, addrp, sizep))
return 1;
} else {
*addrp = hextoul(argv[1], NULL);
@@ -367,7 +368,7 @@ static int parse_args(enum proto_t proto, int argc, char *const argv[],
#ifdef CONFIG_CMD_TFTPPUT
case 4:
- if (parse_addr_size(argv, &image_save_addr, &image_save_size))
+ if (parse_addr_size(argv, addrp, sizep))
return 1;
*fnamep = argv[3];
break;
@@ -383,6 +384,7 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
char *const argv[])
{
const char *fname;
+ ulong addr;
char *s;
int rcode = 0;
int size;
@@ -390,10 +392,10 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
net_boot_file_name_explicit = false;
*net_boot_file_name = '\0';
- /* pre-set image_load_addr */
+ /* pre-set addr */
s = env_get("loadaddr");
if (s != NULL)
- image_load_addr = hextoul(s, NULL);
+ addr = hextoul(s, NULL);
if (IS_ENABLED(CONFIG_IPV6)) {
use_ip6 = false;
@@ -406,10 +408,14 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
}
}
- if (parse_args(proto, argc, argv, &fname, &image_load_addr)) {
+ if (parse_args(proto, argc, argv, &fname, &addr, &image_save_size)) {
bootstage_error(BOOTSTAGE_ID_NET_START);
return CMD_RET_USAGE;
}
+ if (IS_ENABLED(CONFIG_CMD_TFTPPUT) && proto == TFTPPUT)
+ image_save_addr = addr;
+ else
+ image_load_addr = addr;
if (fname) {
net_boot_file_name_explicit = true;
--
2.34.1
More information about the U-Boot
mailing list