mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
net: Add a function to run dhcp
At present this must be done by executing the command. Also it involves fiddling with the environment to determine the correct autoload behaviour. Ideally it should be possible to run network operations without even having the command line present (CONFIG_CMDLINE). For now, add a function to handle DHCP, so it can be called from a bootdev more easily. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
This commit is contained in:
parent
843160fa7a
commit
c8c3fd24cc
2 changed files with 50 additions and 0 deletions
35
cmd/net.c
35
cmd/net.c
|
@ -4,6 +4,8 @@
|
||||||
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define LOG_CATEGORY UCLASS_ETH
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Boot support
|
* Boot support
|
||||||
*/
|
*/
|
||||||
|
@ -13,6 +15,7 @@
|
||||||
#include <dm.h>
|
#include <dm.h>
|
||||||
#include <env.h>
|
#include <env.h>
|
||||||
#include <image.h>
|
#include <image.h>
|
||||||
|
#include <log.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
#include <net6.h>
|
#include <net6.h>
|
||||||
#include <net/udp.h>
|
#include <net/udp.h>
|
||||||
|
@ -120,6 +123,38 @@ U_BOOT_CMD(
|
||||||
"boot image via network using DHCP/TFTP protocol",
|
"boot image via network using DHCP/TFTP protocol",
|
||||||
"[loadAddress] [[hostIPaddr:]bootfilename]"
|
"[loadAddress] [[hostIPaddr:]bootfilename]"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
int dhcp_run(ulong addr, const char *fname, bool autoload)
|
||||||
|
{
|
||||||
|
char *dhcp_argv[] = {"dhcp", NULL, (char *)fname, NULL};
|
||||||
|
struct cmd_tbl cmdtp = {}; /* dummy */
|
||||||
|
char file_addr[17];
|
||||||
|
int old_autoload;
|
||||||
|
int ret, result;
|
||||||
|
|
||||||
|
log_debug("addr=%lx, fname=%s, autoload=%d\n", addr, fname, autoload);
|
||||||
|
old_autoload = env_get_yesno("autoload");
|
||||||
|
ret = env_set("autoload", autoload ? "y" : "n");
|
||||||
|
if (ret)
|
||||||
|
return log_msg_ret("en1", -EINVAL);
|
||||||
|
|
||||||
|
if (autoload) {
|
||||||
|
sprintf(file_addr, "%lx", addr);
|
||||||
|
dhcp_argv[1] = file_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = do_dhcp(&cmdtp, 0, !autoload ? 1 : fname ? 3 : 2, dhcp_argv);
|
||||||
|
|
||||||
|
ret = env_set("autoload", old_autoload == -1 ? NULL :
|
||||||
|
old_autoload ? "y" : "n");
|
||||||
|
if (ret)
|
||||||
|
return log_msg_ret("en2", -EINVAL);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
return log_msg_ret("res", -ENOENT);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_CMD_NFS)
|
#if defined(CONFIG_CMD_NFS)
|
||||||
|
|
|
@ -65,6 +65,21 @@ struct in_addr {
|
||||||
*/
|
*/
|
||||||
int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dhcp_run() - Run DHCP on the current ethernet device
|
||||||
|
*
|
||||||
|
* This sets the autoload variable, then puts it back to similar to its original
|
||||||
|
* state (y, n or unset).
|
||||||
|
*
|
||||||
|
* @addr: Address to load the file into (0 if @autoload is false)
|
||||||
|
* @fname: Filename of file to load (NULL if @autoload is false or to use the
|
||||||
|
* default filename)
|
||||||
|
* @autoload: true to load the file, false to just get the network IP
|
||||||
|
* @return 0 if OK, -EINVAL if the environment failed, -ENOENT if ant file was
|
||||||
|
* not found
|
||||||
|
*/
|
||||||
|
int dhcp_run(ulong addr, const char *fname, bool autoload);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An incoming packet handler.
|
* An incoming packet handler.
|
||||||
* @param pkt pointer to the application packet
|
* @param pkt pointer to the application packet
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue