netboot: Move parameter loading into the netboot function.
This consolidates some code that had been duplicated in a few places, and also
eliminates the one case where uip header files needed to be included outside
of the network stack.
Change-Id: I96f7b76473479c3d2ed0c0ee165c2c1adc54629c
diff --git a/src/debug/netboot.c b/src/debug/netboot.c
index 517fc3d..6094dbf 100644
--- a/src/debug/netboot.c
+++ b/src/debug/netboot.c
@@ -22,7 +22,6 @@
#include "drivers/console/display.h"
#include "net/netboot/netboot.h"
#include "net/netboot/params.h"
-#include "net/ipv4/uip/uip.h"
/*
* These are the real implementations for developer-build features that override
@@ -31,15 +30,8 @@
void dc_dev_netboot(void)
{
- uip_ipaddr_t *tftp_ip;
- char *bootfile, *argsfile;
-
if (CONFIG_DRIVER_CONSOLE_DISPLAY)
display_console_attach();
- if (netboot_params_read(&tftp_ip, NULL, 0,
- &bootfile, &argsfile))
- printf("ERROR: Failed to read netboot parameters from flash\n");
-
- netboot(tftp_ip, bootfile, argsfile, NULL);
+ netboot(NULL, 0);
}
diff --git a/src/module/netboot.c b/src/module/netboot.c
index 764f682..a67ade8 100644
--- a/src/module/netboot.c
+++ b/src/module/netboot.c
@@ -35,7 +35,6 @@
#include "module/module.h"
#include "net/netboot/netboot.h"
#include "net/netboot/params.h"
-#include "net/ipv4/uip/uip.h"
#include "vboot/vbnv.h"
static void enable_graphics(void)
@@ -71,11 +70,5 @@
srand(timer_raw_value());
- uip_ipaddr_t *tftp_ip;
- char *bootfile, *argsfile;
- if (netboot_params_read(&tftp_ip, cmd_line, sizeof(cmd_line),
- &bootfile, &argsfile))
- printf("ERROR: Failed to read netboot parameters from flash\n");
-
- netboot(tftp_ip, bootfile, argsfile, cmd_line);
+ netboot(cmd_line, sizeof(cmd_line));
}
diff --git a/src/module/uefi/netboot.c b/src/module/uefi/netboot.c
index c8eb541..a897b6c 100644
--- a/src/module/uefi/netboot.c
+++ b/src/module/uefi/netboot.c
@@ -29,7 +29,6 @@
#include "module/uefi/fwdb.h"
#include "net/netboot/netboot.h"
#include "net/netboot/params.h"
-#include "net/ipv4/uip/uip.h"
void module_main(void)
{
@@ -44,12 +43,5 @@
halt();
}
- uip_ipaddr_t *tftp_ip;
- char *bootfile, *argsfile;
- if (netboot_params_read(&tftp_ip, cmd_line, sizeof(cmd_line),
- &bootfile, &argsfile)) {
- printf("Failed to read netboot parameters.\n");
- }
-
- netboot(tftp_ip, bootfile, argsfile, cmd_line);
+ netboot(cmd_line, sizeof(cmd_line));
}
diff --git a/src/net/netboot/netboot.c b/src/net/netboot/netboot.c
index 521d4f0..cd8243c 100644
--- a/src/net/netboot/netboot.c
+++ b/src/net/netboot/netboot.c
@@ -143,11 +143,19 @@
boot(payload, cmd_line, NULL, NULL);
}
-void netboot(uip_ipaddr_t *tftp_ip, char *bootfile, char *argsfile, char *args)
+void netboot(char *args, size_t args_size)
{
// Start up the network stack.
uip_init();
+ uip_ipaddr_t *tftp_ip;
+ char *bootfile;
+ char *argsfile;
+ if (netboot_params_read(&tftp_ip, args, args_size,
+ &bootfile, &argsfile)) {
+ printf("Failed to read netboot parameters from flash.\n");
+ }
+
NetDevice *dev = NULL;
while (1) {
dev = net_scan_for_link(dev);
diff --git a/src/net/netboot/netboot.h b/src/net/netboot/netboot.h
index cefe35c..b97912b 100644
--- a/src/net/netboot/netboot.h
+++ b/src/net/netboot/netboot.h
@@ -20,10 +20,12 @@
#ifndef __NETBOOT_NETBOOT_H__
#define __NETBOOT_NETBOOT_H__
+#include <stddef.h>
+
#include "net/ipv4/uip/uip.h"
// argsfile takes precedence before args. All parameters can be NULL.
-void netboot(uip_ipaddr_t *tftp_ip, char *bootfile, char *argsfile, char *args);
+void netboot(char *args, size_t args_size);
int netboot_entry(void);
#endif /* __NETBOOT_NETBOOT_H__ */