diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2015-01-09 17:38:27 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-01-09 17:38:27 +0100 |
commit | b396f385967a00e801559593f18e30a8617dcf69 (patch) | |
tree | 92c8e2f5c3cfcb20503b68ef0f8d0bc5181f9244 | |
parent | 39c6c3480a9cb88e722af1142c7b31a00e9ec546 (diff) | |
parent | f648eb9e65bbdbb460ea3eaf548b3ba3f3373307 (diff) | |
download | barebox-b396f385967a00e801559593f18e30a8617dcf69.tar.gz barebox-b396f385967a00e801559593f18e30a8617dcf69.tar.xz |
Merge branch 'for-next/netconsole'
-rw-r--r-- | Documentation/user/networking.rst | 6 | ||||
-rw-r--r-- | common/console.c | 7 | ||||
-rw-r--r-- | include/console.h | 1 | ||||
-rw-r--r-- | net/netconsole.c | 55 |
4 files changed, 45 insertions, 24 deletions
diff --git a/Documentation/user/networking.rst b/Documentation/user/networking.rst index 6802138af9..6eeb93dd88 100644 --- a/Documentation/user/networking.rst +++ b/Documentation/user/networking.rst @@ -61,15 +61,15 @@ Network console barebox has a UDP-based network console. If enabled in the config, you will see something like this during startup:: - registered netconsole as cs1 + registered netconsole as netconsole By default the network console is disabled during runtime to prevent security risks. It can be enabled using: .. code-block:: sh - cs1.ip=192.168.23.2 - cs1.active=ioe + netconsole.ip=192.168.23.2 + netconsole.active=ioe This will send UDP packets to 192.168.23.2 on port 6666. On 192.168.23.2 the scripts/netconsole script can be used to control barebox: diff --git a/common/console.c b/common/console.c index e5f4267cbd..c092621aa1 100644 --- a/common/console.c +++ b/common/console.c @@ -64,6 +64,7 @@ static int console_std_set(struct device_d *dev, struct param_d *param, struct console_device *cdev = to_console_dev(dev); char active[4]; unsigned int flag = 0, i = 0; + int ret; if (val) { if (strchr(val, 'i') && cdev->getc) { @@ -90,6 +91,12 @@ static int console_std_set(struct device_d *dev, struct param_d *param, cdev->setbrg(cdev, cdev->baudrate); } + if (cdev->set_active) { + ret = cdev->set_active(cdev, flag); + if (ret) + return ret; + } + active[i] = 0; cdev->f_active = flag; diff --git a/include/console.h b/include/console.h index 97a406d9c9..beafb4d778 100644 --- a/include/console.h +++ b/include/console.h @@ -44,6 +44,7 @@ struct console_device { int (*setbrg)(struct console_device *cdev, int baudrate); void (*flush)(struct console_device *cdev); int (*set_mode)(struct console_device *cdev, enum console_mode mode); + int (*set_active)(struct console_device *cdev, unsigned active); char *devname; diff --git a/net/netconsole.c b/net/netconsole.c index c817107296..99b998408c 100644 --- a/net/netconsole.c +++ b/net/netconsole.c @@ -52,24 +52,6 @@ static void nc_handler(void *ctx, char *pkt, unsigned len) kfifo_put(priv->fifo, packet, net_eth_to_udplen(pkt)); } -static int nc_init(void) -{ - struct nc_priv *priv = g_priv; - - if (priv->con) - net_unregister(priv->con); - - priv->con = net_udp_new(priv->ip, priv->port, nc_handler, NULL); - if (IS_ERR(priv->con)) { - int ret = PTR_ERR(priv->con); - priv->con = NULL; - return ret; - } - - net_udp_bind(priv->con, priv->port); - return 0; -} - static int nc_getc(struct console_device *cdev) { struct nc_priv *priv = container_of(cdev, @@ -123,9 +105,39 @@ static void nc_putc(struct console_device *cdev, char c) priv->busy = 0; } -static int nc_port_set(struct param_d *p, void *_priv) +static int nc_set_active(struct console_device *cdev, unsigned flags) { - nc_init(); + struct nc_priv *priv = container_of(cdev, + struct nc_priv, cdev); + + if (priv->con) { + net_unregister(priv->con); + priv->con = NULL; + } + + if (!flags) + return 0; + + if (!priv->port) { + pr_err("port not set\n"); + return -EINVAL; + } + + if (!priv->ip) { + pr_err("ip not set\n"); + return -EINVAL; + } + + priv->con = net_udp_new(priv->ip, priv->port, nc_handler, NULL); + if (IS_ERR(priv->con)) { + int ret = PTR_ERR(priv->con); + priv->con = NULL; + return ret; + } + + net_udp_bind(priv->con, priv->port); + + pr_info("netconsole initialized with %s:%d\n", ip_to_string(priv->ip), priv->port); return 0; } @@ -142,6 +154,7 @@ static int netconsole_init(void) cdev->putc = nc_putc; cdev->getc = nc_getc; cdev->devname = "netconsole"; + cdev->set_active = nc_set_active; g_priv = priv; @@ -157,7 +170,7 @@ static int netconsole_init(void) priv->port = 6666; dev_add_param_ip(&cdev->class_dev, "ip", NULL, NULL, &priv->ip, NULL); - dev_add_param_int(&cdev->class_dev, "port", nc_port_set, NULL, &priv->port, "%u", NULL); + dev_add_param_int(&cdev->class_dev, "port", NULL, NULL, &priv->port, "%u", NULL); pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id); |