net.c 1.74 KB
Newer Older
Tomeu Vizoso's avatar
Tomeu Vizoso committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright (C) 2017 Google Inc.
 * Copyright (C) 2017, 2018 Collabora Limited
 *
 * Author: Tomeu Vizoso <tomeu.vizoso@collabora.com>
 * Author: Guillaume Tucker <guillaume.tucker@collabora.com>
 *
 * 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 that 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.
 */

/*
 * Boot support
 */
#include "common.h"

#include "netboot/netboot.h"
#include "net/uiplib.h"

#define MAX_ARGS_LEN 4096

29
30
static const char DHCP[] = "dhcp";

Tomeu Vizoso's avatar
Tomeu Vizoso committed
31
32
33
34
35
36
int do_tftpboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	char *address;
	char *bootfile;
	char *argsfile;
	uip_ipaddr_t tftp_ip;
37
	uip_ipaddr_t *tftp_ip_arg;
Tomeu Vizoso's avatar
Tomeu Vizoso committed
38
39
40
41
42

	if (argc != 4)
		return CMD_RET_USAGE;

	address = argv[1];
43
	bootfile = (!strcmp(argv[2], DHCP)) ? NULL : argv[2];
Tomeu Vizoso's avatar
Tomeu Vizoso committed
44
45
	argsfile = argv[3];

46
47
48
	if (!strcmp(address, DHCP)) {
		tftp_ip_arg = NULL;
	} else if (!uiplib_ipaddrconv(address, &tftp_ip)) {
Tomeu Vizoso's avatar
Tomeu Vizoso committed
49
50
		printf("Invalid IPv4 address: %s\n", address);
		return CMD_RET_USAGE;
51
52
	} else {
		tftp_ip_arg = &tftp_ip;
Tomeu Vizoso's avatar
Tomeu Vizoso committed
53
54
	}

55
	netboot(tftp_ip_arg, bootfile, argsfile, NULL);
Tomeu Vizoso's avatar
Tomeu Vizoso committed
56
57
58
59
60
61
62
63
64

	/* netboot() only returns if it failed */

	return CMD_RET_FAILURE;
}

U_BOOT_CMD(
	tftpboot,	4,	1,
	"boot image via network using TFTP protocol",
65
66
67
68
	"[host IP addr] [boot file] [args file]\n"
	"\n"
	"The IP address and boot file can take the \"dhcp\" special value\n"
	"to send DHCP requests rather than using static values."
Tomeu Vizoso's avatar
Tomeu Vizoso committed
69
);