From 581272f8c59a71e8f64a15b6b33bb0d1fc5ac6ba Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 15 Sep 2016 12:48:28 +0200 Subject: [PATCH 01/12] vsprintf: Add support for printing ipv4 addresses with %pI4 Can be used conveniently in places that currently use ip_to_string(). Signed-off-by: Sascha Hauer --- lib/vsprintf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index f3885a820..fa9fb7580 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -190,6 +190,27 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int #endif } +static noinline_for_stack +char *ip4_addr_string(char *buf, char *end, const u8 *addr, int field_width, + int precision, int flags, const char *fmt) +{ + char ip4_addr[sizeof("255.255.255.255")]; + char *pos; + int i; + + pos = ip4_addr; + + for (i = 0; i < 4; i++) { + pos = number(pos, pos + 3, addr[i], 10, 0, 0, LEFT); + if (i < 3) + *pos++ = '.'; + } + + *pos = 0; + + return string(buf, end, ip4_addr, field_width, precision, flags); +} + static noinline_for_stack char *uuid_string(char *buf, char *end, const u8 *addr, int field_width, int precision, int flags, const char *fmt) @@ -267,6 +288,8 @@ char *address_val(char *buf, char *end, const void *addr, * * Right now we handle: * + * - 'I' [4] for IPv4 addresses printed in the usual way + * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) * - 'S' For symbolic direct pointers * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" @@ -297,6 +320,12 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field break; case 'a': return address_val(buf, end, ptr, field_width, precision, flags, fmt); + case 'I': + switch (fmt[1]) { + case '4': + return ip4_addr_string(buf, end, ptr, field_width, precision, flags, fmt); + } + break; } flags |= SMALL; if (field_width == -1) { From d60230bded854fe5a357c77038cf6089defcfd24 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 15 Sep 2016 12:51:27 +0200 Subject: [PATCH 02/12] convert users to %pI4 Convert users of ip_to_string() and print_IPaddr() to %pI4 and remove the now unused functions. Signed-off-by: Sascha Hauer --- arch/arm/mach-omap/xload.c | 9 ++++++--- commands/tftp.c | 4 +++- common/blspec.c | 2 +- fs/nfs.c | 4 +--- include/net.h | 6 ------ lib/parameter.c | 2 +- net/dhcp.c | 6 +++--- net/dns.c | 6 ++---- net/lib.c | 19 ------------------- net/net.c | 4 ++-- net/netconsole.c | 2 +- 11 files changed, 20 insertions(+), 44 deletions(-) diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c index 14a631ebf..822389c38 100644 --- a/arch/arm/mach-omap/xload.c +++ b/arch/arm/mach-omap/xload.c @@ -231,8 +231,10 @@ static void *am33xx_net_boot(void) int err; int len; struct dhcp_req_param dhcp_param; - const char *bootfile, *ip; + const char *bootfile; + IPaddr_t ip; char *file; + char ip4_str[sizeof("255.255.255.255")]; am33xx_register_ethaddr(0, 0); @@ -258,8 +260,9 @@ static void *am33xx_net_boot(void) if (err) return NULL; - ip = ip_to_string(net_get_serverip()); - err = mount(ip, "tftp", TFTP_MOUNT, NULL); + ip = net_get_serverip(); + sprintf(ip4_str, "%pI4", &ip); + err = mount(ip4_str, "tftp", TFTP_MOUNT, NULL); if (err < 0) { printf("Unable to mount.\n"); return NULL; diff --git a/commands/tftp.c b/commands/tftp.c index 6a3121ad5..08366b476 100644 --- a/commands/tftp.c +++ b/commands/tftp.c @@ -36,6 +36,7 @@ static int do_tftpb(int argc, char *argv[]) int tftp_push = 0; int ret; IPaddr_t ip; + char ip4_str[sizeof("255.255.255.255")]; while ((opt = getopt(argc, argv, "p")) > 0) { switch(opt) { @@ -73,7 +74,8 @@ static int do_tftpb(int argc, char *argv[]) goto err_free; ip = net_get_serverip(); - ret = mount(ip_to_string(ip), "tftp", TFTP_MOUNT_PATH, NULL); + sprintf(ip4_str, "%pI4", &ip); + ret = mount(ip4_str, "tftp", TFTP_MOUNT_PATH, NULL); if (ret) goto err_rmdir; diff --git a/common/blspec.c b/common/blspec.c index f02f5e9ce..b45bd291e 100644 --- a/common/blspec.c +++ b/common/blspec.c @@ -306,7 +306,7 @@ static char *parse_nfs_url(const char *url) if (ip == 0) goto out; - hostpath = basprintf("%s:%s", ip_to_string(ip), path); + hostpath = basprintf("%pI4:%s", &ip, path); prevpath = nfs_find_mountpath(hostpath); diff --git a/fs/nfs.c b/fs/nfs.c index 1e874d541..a0a9dfcf7 100644 --- a/fs/nfs.c +++ b/fs/nfs.c @@ -1314,10 +1314,8 @@ static char *rootnfsopts; static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev) { char *str, *tmp; - const char *ip; - ip = ip_to_string(npriv->server); - str = basprintf("root=/dev/nfs nfsroot=%s:%s%s%s", ip, npriv->path, + str = basprintf("root=/dev/nfs nfsroot=%pI4:%s%s%s", &npriv->server, npriv->path, rootnfsopts[0] ? "," : "", rootnfsopts); /* forward specific mount options on demand */ diff --git a/include/net.h b/include/net.h index 8f857c8f8..fd1c412ed 100644 --- a/include/net.h +++ b/include/net.h @@ -257,9 +257,6 @@ static inline int net_eth_to_udplen(char *pkt) int net_checksum_ok(unsigned char *, int); /* Return true if cksum OK */ uint16_t net_checksum(unsigned char *, int); /* Calculate the checksum */ -/* Print an IP address on the console */ -void print_IPaddr (IPaddr_t); - /* * The following functions are a bit ugly, but necessary to deal with * alignment restrictions on ARM. @@ -308,9 +305,6 @@ static inline void net_copy_uint32(uint32_t *to, uint32_t *from) memcpy(to, from, sizeof(uint32_t)); } -/* Convert an IP address to a string */ -char *ip_to_string (IPaddr_t x); - /* Convert a string to ip address */ int string_to_ip(const char *s, IPaddr_t *ip); diff --git a/lib/parameter.c b/lib/parameter.c index 656a6037c..a754fb8a9 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -642,7 +642,7 @@ static const char *param_ip_get(struct device_d *dev, struct param_d *p) } free(p->value); - p->value = xstrdup(ip_to_string(*pi->ip)); + p->value = xasprintf("%pI4", pi->ip); return p->value; } diff --git a/net/dhcp.c b/net/dhcp.c index 792ece491..c5386fe94 100644 --- a/net/dhcp.c +++ b/net/dhcp.c @@ -613,13 +613,13 @@ static void dhcp_handler(void *ctx, char *packet, unsigned int len) debug ("%s: State REQUESTING\n", __func__); if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK ) { + IPaddr_t ip; if (net_read_uint32((uint32_t *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) dhcp_options_process((u8 *)&bp->bp_vend[4], bp); bootp_copy_net_params(bp); /* Store net params from reply */ dhcp_state = BOUND; - puts ("DHCP client bound to address "); - print_IPaddr(net_get_ip()); - putchar('\n'); + ip = net_get_ip(); + printf("DHCP client bound to address %pI4\n", &ip); return; } break; diff --git a/net/dns.c b/net/dns.c index 2acdb935e..700c6b025 100644 --- a/net/dns.c +++ b/net/dns.c @@ -221,7 +221,7 @@ IPaddr_t resolv(const char *host) if (string_to_ip(ns, &ip)) return 0; - debug("resolving host %s via nameserver %s\n", host, ip_to_string(ip)); + debug("resolving host %s via nameserver %pI4\n", host, &ip); dns_con = net_udp_new(ip, DNS_PORT, dns_handler, NULL); if (IS_ERR(dns_con)) @@ -258,9 +258,7 @@ static int do_host(int argc, char *argv[]) if (!ip) printf("unknown host %s\n", argv[1]); else { - printf("%s is at ", argv[1]); - print_IPaddr(ip); - printf("\n"); + printf("%s is at %pI4\n", argv[1], &ip); } return 0; diff --git a/net/lib.c b/net/lib.c index f1c60c9a7..d4343bced 100644 --- a/net/lib.c +++ b/net/lib.c @@ -57,25 +57,6 @@ void ethaddr_to_string(const u8 enetaddr[6], char *str) enetaddr[4], enetaddr[5]); } -void print_IPaddr(IPaddr_t x) -{ - puts(ip_to_string(x)); -} - -char *ip_to_string(IPaddr_t x) -{ - static char s[sizeof("xxx.xxx.xxx.xxx")]; - - x = ntohl(x); - sprintf(s, "%d.%d.%d.%d", - (int) ((x >> 24) & 0xff), - (int) ((x >> 16) & 0xff), - (int) ((x >> 8) & 0xff), (int) ((x >> 0) & 0xff) - ); - - return s; -} - int string_to_ip(const char *s, IPaddr_t *ip) { IPaddr_t addr = 0; diff --git a/net/net.c b/net/net.c index df1d677ba..3c0e71560 100644 --- a/net/net.c +++ b/net/net.c @@ -78,9 +78,9 @@ IPaddr_t getenv_ip(const char *name) int setenv_ip(const char *name, IPaddr_t ip) { - const char *str; + char str[sizeof("255.255.255.255")]; - str = ip_to_string(ip); + sprintf(str, "%pI4", &ip); setenv(name, str); diff --git a/net/netconsole.c b/net/netconsole.c index 0ee6a7655..ce3c41879 100644 --- a/net/netconsole.c +++ b/net/netconsole.c @@ -137,7 +137,7 @@ static int nc_set_active(struct console_device *cdev, unsigned flags) net_udp_bind(priv->con, priv->port); - pr_info("netconsole initialized with %s:%d\n", ip_to_string(priv->ip), priv->port); + pr_info("netconsole initialized with %pI4:%d\n", &priv->ip, priv->port); return 0; } From 841d83ff0a30dfdb58ae94f497097b52aecacf67 Mon Sep 17 00:00:00 2001 From: Enrico Jorns Date: Mon, 19 Sep 2016 18:03:48 +0200 Subject: [PATCH 03/12] net: add linux.bootarg parameter from ifup call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This sets a `ip=dhcp` or `ip=::::::` bootarg for the network device upon execution of 'ifup'. This is the only point where we can distinguish between a static ip and a dhcp-based network setup and thus set a valid bootarg options as it will be required for nfs boot, for example. Signed-off-by: Enrico Jorns Acked-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- include/net.h | 1 + net/eth.c | 2 ++ net/ifup.c | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/include/net.h b/include/net.h index fd1c412ed..632b6d541 100644 --- a/include/net.h +++ b/include/net.h @@ -62,6 +62,7 @@ struct eth_device { IPaddr_t netmask; IPaddr_t gateway; char ethaddr[6]; + char *bootarg; }; #define dev_to_edev(d) container_of(d, struct eth_device, dev) diff --git a/net/eth.c b/net/eth.c index 6f8e78d8d..dac2400b8 100644 --- a/net/eth.c +++ b/net/eth.c @@ -384,6 +384,8 @@ int eth_register(struct eth_device *edev) dev_add_param_ip(dev, "netmask", NULL, NULL, &edev->netmask, edev); dev_add_param_mac(dev, "ethaddr", eth_param_set_ethaddr, NULL, edev->ethaddr, edev); + edev->bootarg = xstrdup(""); + dev_add_param_string(dev, "linux.bootargs", NULL, NULL, &edev->bootarg, NULL); if (edev->init) edev->init(edev); diff --git a/net/ifup.c b/net/ifup.c index 30ac3f586..5113d1383 100644 --- a/net/ifup.c +++ b/net/ifup.c @@ -106,12 +106,21 @@ int ifup(const char *name, unsigned flags) ret = eth_set_param(dev, "serverip"); if (ret) goto out; + dev_set_param(dev, "linux.bootargs", "ip=dhcp"); } else if (!strcmp(ip, "static")) { + char *bootarg; for (i = 0; i < ARRAY_SIZE(vars); i++) { ret = eth_set_param(dev, vars[i]); if (ret) goto out; } + bootarg = basprintf("ip=%pI4:%pI4:%pI4:%pI4:::", + &edev->ipaddr, + &edev->serverip, + &edev->gateway, + &edev->netmask); + dev_set_param(dev, "linux.bootargs", bootarg); + free(bootarg); } else { pr_err("unknown ip type: %s\n", ip); ret = -EINVAL; From b6ca0241b0ba2f166f12b9d58c608fb777ec3bd5 Mon Sep 17 00:00:00 2001 From: Enrico Jorns Date: Mon, 19 Sep 2016 18:03:49 +0200 Subject: [PATCH 04/12] fs: nfs: pick up network interface bootargs parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds the linux.bootarg device parameter from the network device of the current nfs connection and adds it to the nfs bootargs line. This allows booting from nfs without manually setting a ip=dhcp or ip= option. Signed-off-by: Enrico Jorns Acked-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- fs/nfs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/nfs.c b/fs/nfs.c index a0a9dfcf7..97f01cfb3 100644 --- a/fs/nfs.c +++ b/fs/nfs.c @@ -1314,6 +1314,7 @@ static char *rootnfsopts; static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev) { char *str, *tmp; + const char *bootargs; str = basprintf("root=/dev/nfs nfsroot=%pI4:%s%s%s", &npriv->server, npriv->path, rootnfsopts[0] ? "," : "", rootnfsopts); @@ -1331,6 +1332,13 @@ static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev) str = tmp; } + bootargs = dev_get_param(&npriv->con->edev->dev, "linux.bootargs"); + if (bootargs) { + tmp = basprintf("%s %s", str, bootargs); + free(str); + str = tmp; + } + fsdev_set_linux_rootarg(fsdev, str); free(str); From 8b07b925ac4c40d1f8d81db71ad1be3af6769263 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Thu, 22 Sep 2016 21:16:34 +0200 Subject: [PATCH 05/12] environment: "wrong magic" gives the impression of an error From 15e7ff689cfda27eab10aacda5c26a1ba47979ec Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Thu, 22 Sep 2016 06:54:42 +0200 Subject: [PATCH 1/1] environment: "wrong magic" give the impression of an error Introduce a more soft wording when the magic of the superblock does not match. Include a hint to the typical reason "(envfs never written?)" This prevents a "what is wrong?" moment when looking at the boot log. Signed-off-by: Sam Ravnborg Signed-off-by: Sascha Hauer --- common/environment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/environment.c b/common/environment.c index db127d71a..c9cef6322 100644 --- a/common/environment.c +++ b/common/environment.c @@ -382,7 +382,7 @@ EXPORT_SYMBOL(envfs_save); static int envfs_check_super(struct envfs_super *super, size_t *size) { if (ENVFS_32(super->magic) != ENVFS_MAGIC) { - printf("envfs: wrong magic\n"); + printf("envfs: no envfs (magic mismatch) - envfs newer written?\n"); return -EIO; } From c43d8ac0d8b86d2ef28b83e97ba6392564d89795 Mon Sep 17 00:00:00 2001 From: Robert Schwebel Date: Thu, 22 Sep 2016 19:14:22 +0200 Subject: [PATCH 06/12] Documentation: clarify that patches should target the master branch. I asked Sascha if he still prefers patches against 'next', and it turned out that this is not true any more and patches should be sent against master. Signed-off-by: Robert Schwebel Signed-off-by: Sascha Hauer --- Documentation/user/barebox.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/user/barebox.rst b/Documentation/user/barebox.rst index 32cec3d97..1203c10cd 100644 --- a/Documentation/user/barebox.rst +++ b/Documentation/user/barebox.rst @@ -28,9 +28,11 @@ can be checked out as follows: Checking connectivity... done. Checking out files: 100% (5651/5651), done. -After this, make sure to check out the appropriate branch. If you want to -develop for barebox, it's best to check out the ``next`` branch rather than -the ``master`` branch: +By default, the master branch is checked out. If you want to develop for +barebox, this is the right branch to send patches against. + +If you want to see which patches are already selected for the next release, +you can look at the ``next`` branch: .. code-block:: sh From eb2b96d68a3b216b3f935383979a8c67a257bebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Mon, 26 Sep 2016 11:11:36 +0200 Subject: [PATCH 07/12] firmware: altera-serial: Make the driver match the dt binding documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- drivers/firmware/altera_serial.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/altera_serial.c b/drivers/firmware/altera_serial.c index 4527d27c5..382e84500 100644 --- a/drivers/firmware/altera_serial.c +++ b/drivers/firmware/altera_serial.c @@ -35,9 +35,9 @@ * * fpga@0 { * compatible = "altr,fpga-passive-serial"; - * nstat-gpio = <&gpio4 18 0>; - * confd-gpio = <&gpio4 19 0>; - * nconfig-gpio = <&gpio4 20 0>; + * nstat-gpios = <&gpio4 18 0>; + * confd-gpios = <&gpio4 19 0>; + * nconfig-gpios = <&gpio4 20 0>; * spi-max-frequency = <10000000>; * reg = <0>; * }; @@ -220,7 +220,7 @@ static int altera_spi_of(struct device_d *dev, struct fpga_spi *this) const char *name; int ret; - name = "nstat-gpio"; + name = "nstat-gpios"; if (!of_get_property(n, name, NULL)) { dev_info(dev, "nstat-gpio is not specified, assuming it is not connected\n"); this->nstat_gpio = -1; @@ -232,14 +232,14 @@ static int altera_spi_of(struct device_d *dev, struct fpga_spi *this) } } - name = "confd-gpio"; + name = "confd-gpios"; this->confd_gpio = of_get_named_gpio(n, name, 0); if (this->confd_gpio < 0) { ret = this->confd_gpio; goto out; } - name = "nconfig-gpio"; + name = "nconfig-gpios"; this->nconfig_gpio = of_get_named_gpio(n, name, 0); if (this->nconfig_gpio < 0) { ret = this->nconfig_gpio; @@ -330,7 +330,7 @@ out: static struct of_device_id altera_spi_id_table[] = { { - .compatible = "altr,passive-serial", + .compatible = "altr,fpga-passive-serial", }, }; From a1e19c94d13d1b1eb4c8bc4f4dfce0dd3500bdfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Mon, 26 Sep 2016 11:11:37 +0200 Subject: [PATCH 08/12] firmware: altera-serial: simplify handling of optional gpio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Uwe Kleine-König Signed-off-by: Sascha Hauer --- drivers/firmware/altera_serial.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/altera_serial.c b/drivers/firmware/altera_serial.c index 382e84500..b119778d7 100644 --- a/drivers/firmware/altera_serial.c +++ b/drivers/firmware/altera_serial.c @@ -221,15 +221,13 @@ static int altera_spi_of(struct device_d *dev, struct fpga_spi *this) int ret; name = "nstat-gpios"; - if (!of_get_property(n, name, NULL)) { + this->nstat_gpio = of_get_named_gpio(n, name, 0); + if (this->nstat_gpio == -ENOENT) { dev_info(dev, "nstat-gpio is not specified, assuming it is not connected\n"); this->nstat_gpio = -1; - } else { - this->nstat_gpio = of_get_named_gpio(n, name, 0); - if (this->nstat_gpio < 0) { - ret = this->nstat_gpio; - goto out; - } + } else if (this->nstat_gpio < 0) { + ret = this->nstat_gpio; + goto out; } name = "confd-gpios"; From 322890fa62ff98e3d96465d7a202306a0e4f2687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulrich=20=C3=96lmann?= Date: Tue, 27 Sep 2016 09:33:12 +0200 Subject: [PATCH 09/12] blspec: fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/blspec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/blspec.c b/common/blspec.c index b45bd291e..98e2b01c1 100644 --- a/common/blspec.c +++ b/common/blspec.c @@ -348,7 +348,7 @@ out: * entry_is_of_compatible - check if a bootspec entry is compatible with * the current machine. * - * returns true is the entry is compatible, false otherwise + * returns true if the entry is compatible, false otherwise */ static bool entry_is_of_compatible(struct blspec_entry *entry) { From 098635daba0163e8e6ce48bf3c4169c7c9806008 Mon Sep 17 00:00:00 2001 From: Antony Pavlov Date: Mon, 3 Oct 2016 14:56:57 +0300 Subject: [PATCH 10/12] sandbox: Makefile: drop unused SUBARCH stuff Signed-off-by: Antony Pavlov Signed-off-by: Sascha Hauer --- arch/sandbox/Makefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile index a539a901f..8155a790e 100644 --- a/arch/sandbox/Makefile +++ b/arch/sandbox/Makefile @@ -31,11 +31,6 @@ else CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs)) endif -SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ - -e s/arm.*/arm/ -e s/sa110/arm/ \ - -e s/s390x/s390/ -e s/parisc64/parisc/ \ - -e s/ppc.*/powerpc/ -e s/mips.*/mips/ ) - archprepare: maketools PHONY += maketools From f5d77d80f569b0c2f8e7aec39f61ebc66d20b4ba Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 7 Oct 2016 08:56:59 +0200 Subject: [PATCH 11/12] Allow device parameters for devices with dots in name Devices can have a dot in the name, so we can't expect to find the full device name before the first dot. Currently parameters of devices with a dot in the name are inaccessible from the shell. Fix this by iterating over the possible device name / parameter name combinations to find a existing combination. Signed-off-by: Sascha Hauer --- common/env.c | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/common/env.c b/common/env.c index 6f736d5ad..df8a4dff6 100644 --- a/common/env.c +++ b/common/env.c @@ -135,25 +135,45 @@ static const char *getenv_raw(struct list_head *l, const char *name) return NULL; } -const char *getenv (const char *name) +static const char *dev_getenv(const char *name) +{ + const char *pos, *val, *dot, *varname; + char *devname; + struct device_d *dev; + + pos = name; + + while (1) { + dot = strchr(pos, '.'); + if (!dot) + break; + + devname = xstrndup(name, dot - name); + varname = dot + 1; + + dev = get_device_by_name(devname); + + free(devname); + + if (dev) { + val = dev_get_param(dev, varname); + if (val) + return val; + } + + pos = dot + 1; + } + + return NULL; +} + +const char *getenv(const char *name) { struct env_context *c; const char *val; - if (strchr(name, '.')) { - const char *ret = NULL; - char *devstr = strdup(name); - char *par = strchr(devstr, '.'); - struct device_d *dev; - *par = 0; - dev = get_device_by_name(devstr); - if (dev) { - par++; - ret = dev_get_param(dev, par); - } - free(devstr); - return ret; - } + if (strchr(name, '.')) + return dev_getenv(name); c = context; From e4a45c096136deaf56a200054c46f474250cc89c Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 7 Oct 2016 09:06:37 +0200 Subject: [PATCH 12/12] completion: Fix completion for devices with a dot in the name Devices can have a dot in the name, so do not expect the full device name before the first dot. Signed-off-by: Sascha Hauer --- common/complete.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/complete.c b/common/complete.c index aee21ea18..2dab7d1dd 100644 --- a/common/complete.c +++ b/common/complete.c @@ -279,7 +279,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) struct env_context *c; char *instr_param; int len; - char end = '='; + char end = '=', *pos, *dot; char *begin = ""; if (!instr) @@ -290,7 +290,6 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) end = ' '; } - instr_param = strchr(instr, '.'); len = strlen(instr); c = get_current_context(); @@ -312,20 +311,21 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval) c = c->parent; } - if (instr_param) { + pos = instr; + while ((dot = strchr(pos, '.'))) { char *devname; - len = (instr_param - instr); - - devname = xstrndup(instr, len); + devname = xstrndup(instr, dot - instr); instr_param++; dev = get_device_by_name(devname); free(devname); + if (dev) - device_param_complete(dev, sl, instr_param, eval); - return 0; + device_param_complete(dev, sl, dot + 1, eval); + + pos = dot + 1; } len = strlen(instr);