[ipxe-devel] ifwait command

Gerardo Richarte gera at satellogic.com
Fri Apr 1 22:13:25 UTC 2016


Hi, I've added a new command, ifwait.

I needed the command to do netboot with static ip addresses. Bringing
up the interfaces take pretty long in my board, and instead of adding
a static delay I borrowed some code from other commands (dhcp) and
hacked this command which is no more than a single line of code but
pretty useful.

This is the script where I use it:
$ cat http_boot.ipxe
#!ipxe

ifwait net1 ||

echo Trying to boot from net1
set net1/ip 10.0.0.2 ||
ifopen net1 ||
chain -t 2000 http://10.0.0.1/ipxe.s ||
ifclose net1 ||

echo Trying to boot from net0
set net0/ip 10.0.0.2 ||
ifopen net0 ||
chain -t 2000 http://10.0.0.1/ipxe.s ||
ifclose net0 ||

#prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE command
line... && shell ||

exit

(the exit at the end is, I believe, redundant)

and here's the diff for the command, I hope you find it useful and
incorporate it in mainline code so I don't have to patch every time
;-):

@@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/netdevice.h>
 #include <ipxe/command.h>
 #include <ipxe/parseopt.h>
+#include <ipxe/timer.h>
 #include <usr/ifmgmt.h>
 #include <hci/ifmgmt_cmd.h>

@@ -244,6 +245,32 @@ int ifconf_exec ( int argc, char **argv ) {
  return ifcommon_exec ( argc, argv, &ifconf_cmd );
 }

+/**
+ * "ifwait" payload
+ *
+ * @v netdev Network device
+ * @v opts Command options
+ * @ret rc Return status code
+ */
+#define LINK_WAIT_TIMEOUT_s ( 15 * TICKS_PER_SEC )
+
+static int ifwait_payload ( struct net_device *netdev,
+    struct ifconf_options *opts __unused) {
+
+ /* Wait for link to be up */
+ return iflinkwait ( netdev, LINK_WAIT_TIMEOUT_s );
+}
+
+/** "ifconf" command descriptor */
+static struct ifcommon_command_descriptor ifwait_cmd =
+ IFCOMMON_COMMAND_DESC ( struct ifconf_options, ifconf_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ ifwait_payload, 1 );
+
+int ifwait_exec ( int argc, char **argv ) {
+ return ifcommon_exec ( argc, argv, &ifwait_cmd );
+}
+
 /** Interface management commands */
 struct command ifmgmt_commands[] __command = {
  {
@@ -262,4 +289,8 @@ struct command ifmgmt_commands[] __command = {
  .name = "ifconf",
  .exec = ifconf_exec,
  },
+ {
+ .name = "ifwait",
+ .exec = ifwait_exec,
+ }
 };



More information about the ipxe-devel mailing list