summaryrefslogtreecommitdiffstats
path: root/src/hci
diff options
context:
space:
mode:
authorSimon Rettberg2021-03-08 15:55:33 +0100
committerSimon Rettberg2021-03-08 15:55:33 +0100
commit6707d9218c8e6e760e53068d5f41ceb31fac6ea0 (patch)
tree88e8fc84ede2a0ed2c1cec3a6109beb9fb53abf5 /src/hci
parentMerge branch 'master' into openslx (diff)
parent[linux] Do not assume that stat() works on sysfs files (diff)
downloadipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.tar.gz
ipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.tar.xz
ipxe-6707d9218c8e6e760e53068d5f41ceb31fac6ea0.zip
Merge branch 'master' into openslx
Diffstat (limited to 'src/hci')
-rw-r--r--src/hci/commands/ifmgmt_cmd.c56
-rw-r--r--src/hci/commands/image_mem_cmd.c96
-rw-r--r--src/hci/linux_args.c20
3 files changed, 155 insertions, 17 deletions
diff --git a/src/hci/commands/ifmgmt_cmd.c b/src/hci/commands/ifmgmt_cmd.c
index 2e976d3fb..591cb3da8 100644
--- a/src/hci/commands/ifmgmt_cmd.c
+++ b/src/hci/commands/ifmgmt_cmd.c
@@ -250,6 +250,58 @@ int ifconf_exec ( int argc, char **argv ) {
return ifcommon_exec ( argc, argv, &ifconf_cmd );
}
+/** "iflinkwait" option list */
+struct iflinkwait_options {
+ /** Link timeout */
+ unsigned long timeout;
+};
+
+/** "iflinkwait" option list */
+static struct option_descriptor iflinkwait_opts[] = {
+ OPTION_DESC ( "timeout", 't', required_argument,
+ struct iflinkwait_options, timeout, parse_timeout ),
+};
+
+/**
+ * "iflinkwait" payload
+ *
+ * @v netdev Network device
+ * @v opts Command options
+ * @ret rc Return status code
+ */
+static int iflinkwait_payload ( struct net_device *netdev,
+ struct iflinkwait_options *opts ) {
+ int rc;
+
+ /* Wait for link-up */
+ if ( ( rc = iflinkwait ( netdev, opts->timeout, 1 ) ) != 0 ) {
+
+ /* Close device on failure, to avoid memory exhaustion */
+ netdev_close ( netdev );
+
+ return rc;
+ }
+
+ return 0;
+}
+
+/** "iflinkwait" command descriptor */
+static struct ifcommon_command_descriptor iflinkwait_cmd =
+ IFCOMMON_COMMAND_DESC ( struct iflinkwait_options, iflinkwait_opts,
+ 0, MAX_ARGUMENTS, "[<interface>...]",
+ iflinkwait_payload, 1 );
+
+/**
+ * The "iflinkwait" command
+ *
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Return status code
+ */
+static int iflinkwait_exec ( int argc, char **argv ) {
+ return ifcommon_exec ( argc, argv, &iflinkwait_cmd );
+}
+
/** Interface management commands */
struct command ifmgmt_commands[] __command = {
{
@@ -268,4 +320,8 @@ struct command ifmgmt_commands[] __command = {
.name = "ifconf",
.exec = ifconf_exec,
},
+ {
+ .name = "iflinkwait",
+ .exec = iflinkwait_exec,
+ },
};
diff --git a/src/hci/commands/image_mem_cmd.c b/src/hci/commands/image_mem_cmd.c
new file mode 100644
index 000000000..c8bfab1ad
--- /dev/null
+++ b/src/hci/commands/image_mem_cmd.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2021 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * 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 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <getopt.h>
+#include <ipxe/command.h>
+#include <ipxe/parseopt.h>
+#include <usr/imgmgmt.h>
+
+/** @file
+ *
+ * Read memory command
+ *
+ */
+
+/** "imgmem" options */
+struct imgmem_options {
+ /** Image name */
+ char *name;
+};
+
+/** "imgmem" option list */
+static struct option_descriptor imgmem_opts[] = {
+ OPTION_DESC ( "name", 'n', required_argument,
+ struct imgmem_options, name, parse_string ),
+};
+
+/** "imgmem" command descriptor */
+static struct command_descriptor imgmem_cmd =
+ COMMAND_DESC ( struct imgmem_options, imgmem_opts, 2, 2,
+ "<address> <length>" );
+
+/**
+ * The "imgmem" command
+ *
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Return status code
+ */
+static int imgmem_exec ( int argc, char **argv ) {
+ struct imgmem_options opts;
+ unsigned int data;
+ unsigned int len;
+ int rc;
+
+ /* Parse options */
+ if ( ( rc = parse_options ( argc, argv, &imgmem_cmd, &opts ) ) != 0 )
+ return rc;
+
+ /* Use start address as name if none specified */
+ if ( ! opts.name )
+ opts.name = argv[optind];
+
+ /* Parse address */
+ if ( ( rc = parse_integer ( argv[optind++], &data ) ) != 0 )
+ return rc;
+
+ /* Parse length */
+ if ( ( rc = parse_integer ( argv[optind++], &len ) ) != 0 )
+ return rc;
+
+ /* Create image */
+ if ( ( rc = imgmem ( opts.name, phys_to_user ( data ), len ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/** Read memory command */
+struct command imgmem_commands[] __command = {
+ {
+ .name = "imgmem",
+ .exec = imgmem_exec,
+ },
+};
diff --git a/src/hci/linux_args.c b/src/hci/linux_args.c
index 5f903e3b6..12020bd0b 100644
--- a/src/hci/linux_args.c
+++ b/src/hci/linux_args.c
@@ -18,7 +18,6 @@
FILE_LICENCE(GPL2_OR_LATER);
-#include <hci/linux_args.h>
#include <getopt.h>
#include <string.h>
#include <stdio.h>
@@ -27,21 +26,8 @@ FILE_LICENCE(GPL2_OR_LATER);
#include <ipxe/malloc.h>
#include <ipxe/init.h>
-/** Saved argc */
-static int saved_argc = 0;
-/** Saved argv */
-static char ** saved_argv;
-
-/**
- * Save argc and argv for later access.
- *
- * To be called by linuxprefix
- */
-__asmcall void save_args(int argc, char **argv)
-{
- saved_argc = argc;
- saved_argv = argv;
-}
+int linux_argc;
+char **linux_argv;
/** Supported command-line options */
static struct option options[] = {
@@ -138,7 +124,7 @@ void linux_args_parse()
while (1) {
int option_index = 0;
- c = getopt_long(saved_argc, saved_argv, "", options, &option_index);
+ c = getopt_long(linux_argc, linux_argv, "", options, &option_index);
if (c == -1)
break;