net: Add new wol command - Wake on LAN
Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or
time out if no WoL packed is received.
If the WoL packet contains a password, it is saved in the environment
variable 'wolpassword' using the etherwake format (dot or colon
separated decimals).
Intended use case: a networked device should boot an alternate image.
It's attached to a network on a client site, modifying the DHCP server
configuration or setup of a tftp server is not allowed.
After power on the device waits a few seconds for a WoL packet. If a
packet is received, the device boots the alternate image. Otherwise
it boots the default image.
This method is a simple way to interact with a system via network even
if only the MAC address is known. Tools to send WoL packets are
available on all common platforms.
Some Ethernet drivers seem to pad the incoming packet. The additional
padding bytes might be recognized as Wake-on-LAN password bytes.
By default enabled in pengwyn_defconfig.
Signed-off-by: Lothar Felten <lothar.felten@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 45c8335..bbf9fc9 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1239,6 +1239,11 @@
help
Boot image via network using PXE protocol
+config CMD_WOL
+ bool "wol"
+ help
+ Wait for wake-on-lan Magic Packet
+
endif
menu "Misc commands"
diff --git a/cmd/Makefile b/cmd/Makefile
index 13cf7bf..323f1fd 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -100,6 +100,7 @@
endif
obj-y += pcmcia.o
obj-$(CONFIG_CMD_PXE) += pxe.o
+obj-$(CONFIG_CMD_WOL) += wol.o
obj-$(CONFIG_CMD_QFW) += qfw.o
obj-$(CONFIG_CMD_READ) += read.o
obj-$(CONFIG_CMD_REGINFO) += reginfo.o
diff --git a/cmd/wol.c b/cmd/wol.c
new file mode 100644
index 0000000..8a756f3
--- /dev/null
+++ b/cmd/wol.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018
+ * Lothar Felte, lothar.felten@gmail.com
+ */
+
+/*
+ * Wake-on-LAN support
+ */
+#include <common.h>
+#include <command.h>
+#include <net.h>
+
+#if defined(CONFIG_CMD_WOL)
+void wol_set_timeout(ulong);
+
+int do_wol(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ /* Validate arguments */
+ if (argc < 2)
+ return CMD_RET_USAGE;
+ wol_set_timeout(simple_strtol(argv[1], NULL, 10) * 1000);
+ if (net_loop(WOL) < 0)
+ return CMD_RET_FAILURE;
+ return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+ wol, 2, 1, do_wol,
+ "wait for an incoming wake-on-lan packet",
+ "Timeout"
+);
+#endif