All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] cmd: net: add a 'net list' command to list network devs
@ 2021-06-11 19:52 Tim Harvey
  2021-06-12 18:26 ` Ramon Fried
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Harvey @ 2021-06-11 19:52 UTC (permalink / raw)
  To: u-boot, Joe Hershberger, Ramon Fried; +Cc: Tim Harvey

In a system with multiple network controllers it can be difficult
to know the names of the various devices available. This is especially
true for USB ether devices as they do not display device names upon
detection.

This is being added as a net sub-system in case other commands may
want to be added or moved here.

Example:
U-Boot > net
net - NET sub-system

Usage:
net list - list available devices

U-Boot > net list
eth0 : ethernet@2188000 00:d0:12:98:f5:47 active
eth1 : e1000#0 00:d0:12:98:f5:48
eth2 : asix_eth 8c:ae:4c:f5:84:9d
eth3 : asix_eth 8c:ae:4c:f9:41:e3

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

---
v2: added Reviewed-by tags
---
 cmd/net.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/cmd/net.c b/cmd/net.c
index beb2877dfd..e51bc443f7 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -10,6 +10,7 @@
 #include <common.h>
 #include <bootstage.h>
 #include <command.h>
+#include <dm.h>
 #include <env.h>
 #include <image.h>
 #include <net.h>
@@ -480,3 +481,46 @@ U_BOOT_CMD(
 );
 
 #endif  /* CONFIG_CMD_LINK_LOCAL */
+
+static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	const struct udevice *current = eth_get_dev();
+	unsigned char env_enetaddr[ARP_HLEN];
+	const struct udevice *dev;
+	struct uclass *uc;
+
+	uclass_id_foreach_dev(UCLASS_ETH, dev, uc) {
+		eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr);
+		printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr,
+		       current == dev ? "active" : "");
+	}
+	return CMD_RET_SUCCESS;
+}
+
+static struct cmd_tbl cmd_net[] = {
+	U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""),
+};
+
+static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	struct cmd_tbl *cp;
+
+	cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net));
+
+	/* Drop the net command */
+	argc--;
+	argv++;
+
+	if (!cp || argc > cp->maxargs)
+		return CMD_RET_USAGE;
+	if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
+		return CMD_RET_SUCCESS;
+
+	return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+	net, 2, 1, do_net,
+	"NET sub-system",
+	"list - list available devices\n"
+);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] cmd: net: add a 'net list' command to list network devs
  2021-06-11 19:52 [PATCH v2] cmd: net: add a 'net list' command to list network devs Tim Harvey
@ 2021-06-12 18:26 ` Ramon Fried
  2021-06-12 19:01   ` Ramon Fried
  0 siblings, 1 reply; 5+ messages in thread
From: Ramon Fried @ 2021-06-12 18:26 UTC (permalink / raw)
  To: Tim Harvey, u-boot, Joe Hershberger

On Fri Jun 11, 2021 at 10:52 PM IDT, Tim Harvey wrote:
> In a system with multiple network controllers it can be difficult
> to know the names of the various devices available. This is especially
> true for USB ether devices as they do not display device names upon
> detection.
>
> This is being added as a net sub-system in case other commands may
> want to be added or moved here.
>
> Example:
> U-Boot > net
> net - NET sub-system
>
> Usage:
> net list - list available devices
>
> U-Boot > net list
> eth0 : ethernet@2188000 00:d0:12:98:f5:47 active
> eth1 : e1000#0 00:d0:12:98:f5:48
> eth2 : asix_eth 8c:ae:4c:f5:84:9d
> eth3 : asix_eth 8c:ae:4c:f9:41:e3
>
> Signed-off-by: Tim Harvey <tharvey@gateworks.com>
> Reviewed-by: Stefan Roese <sr@denx.de>
> Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
>
> ---
> v2: added Reviewed-by tags
> ---
> cmd/net.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
>
> diff --git a/cmd/net.c b/cmd/net.c
> index beb2877dfd..e51bc443f7 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -10,6 +10,7 @@
> #include <common.h>
> #include <bootstage.h>
> #include <command.h>
> +#include <dm.h>
> #include <env.h>
> #include <image.h>
> #include <net.h>
> @@ -480,3 +481,46 @@ U_BOOT_CMD(
> );
>  
> #endif /* CONFIG_CMD_LINK_LOCAL */
> +
> +static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char
> *const argv[])
> +{
> + const struct udevice *current = eth_get_dev();
> + unsigned char env_enetaddr[ARP_HLEN];
> + const struct udevice *dev;
> + struct uclass *uc;
> +
> + uclass_id_foreach_dev(UCLASS_ETH, dev, uc) {
> + eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr);
> + printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr,
> + current == dev ? "active" : "");
> + }
> + return CMD_RET_SUCCESS;
> +}
> +
> +static struct cmd_tbl cmd_net[] = {
> + U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""),
> +};
> +
> +static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char
> *const argv[])
> +{
> + struct cmd_tbl *cp;
> +
> + cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net));
> +
> + /* Drop the net command */
> + argc--;
> + argv++;
> +
> + if (!cp || argc > cp->maxargs)
> + return CMD_RET_USAGE;
> + if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp))
> + return CMD_RET_SUCCESS;
> +
> + return cp->cmd(cmdtp, flag, argc, argv);
> +}
> +
> +U_BOOT_CMD(
> + net, 2, 1, do_net,
> + "NET sub-system",
> + "list - list available devices\n"
> +);
> --
> 2.17.1

Applied to u-boot-net/master, thanks!

Best regards,
Ramon Fried

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] cmd: net: add a 'net list' command to list network devs
  2021-06-12 18:26 ` Ramon Fried
@ 2021-06-12 19:01   ` Ramon Fried
  2021-06-14 15:36     ` Tim Harvey
  0 siblings, 1 reply; 5+ messages in thread
From: Ramon Fried @ 2021-06-12 19:01 UTC (permalink / raw)
  To: Tim Harvey, U-Boot Mailing List, Joe Hershberger

Hi Tim.
The patch fails build in several boards (Malta variants):

+cmd/net.c: In function 'do_net_list':
42+cmd/net.c:487:34: error: initialization of 'const struct udevice *'
from incompatible pointer type 'struct eth_device *'
[-Werror=incompatible-pointer-types]
43+ 487 | const struct udevice *current = eth_get_dev();
44+ | ^~~~~~~~~~~


Thanks,
Ramon.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] cmd: net: add a 'net list' command to list network devs
  2021-06-12 19:01   ` Ramon Fried
@ 2021-06-14 15:36     ` Tim Harvey
  2021-06-14 17:04       ` Ramon Fried
  0 siblings, 1 reply; 5+ messages in thread
From: Tim Harvey @ 2021-06-14 15:36 UTC (permalink / raw)
  To: Ramon Fried
  Cc: U-Boot Mailing List, Joe Hershberger, Stefan Roese, Marek Vasut

On Sat, Jun 12, 2021 at 12:02 PM Ramon Fried <rfried.dev@gmail.com> wrote:
>
> Hi Tim.
> The patch fails build in several boards (Malta variants):
>
> +cmd/net.c: In function 'do_net_list':
> 42+cmd/net.c:487:34: error: initialization of 'const struct udevice *'
> from incompatible pointer type 'struct eth_device *'
> [-Werror=incompatible-pointer-types]
> 43+ 487 | const struct udevice *current = eth_get_dev();
> 44+ | ^~~~~~~~~~~
>

Ramon,

Looks like my patch only works for DM_ETH. If I were to implement this
for legacy eth it would probably be a mess as the device list is a
static struct in net/eth_legacy.c. I'm not sure how to tell how many
boards are out there that are not yet converted to DM_ETH and am not
sure when legacy eth goes away. How about if I just add #ifdef
CONFIG_DM_ETH around the whole thing and it isn't supported for legacy
eth?

Best Regards,

Tim

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] cmd: net: add a 'net list' command to list network devs
  2021-06-14 15:36     ` Tim Harvey
@ 2021-06-14 17:04       ` Ramon Fried
  0 siblings, 0 replies; 5+ messages in thread
From: Ramon Fried @ 2021-06-14 17:04 UTC (permalink / raw)
  To: Tim Harvey
  Cc: U-Boot Mailing List, Joe Hershberger, Stefan Roese, Marek Vasut

On Mon, Jun 14, 2021 at 6:36 PM Tim Harvey <tharvey@gateworks.com> wrote:
>
> On Sat, Jun 12, 2021 at 12:02 PM Ramon Fried <rfried.dev@gmail.com> wrote:
> >
> > Hi Tim.
> > The patch fails build in several boards (Malta variants):
> >
> > +cmd/net.c: In function 'do_net_list':
> > 42+cmd/net.c:487:34: error: initialization of 'const struct udevice *'
> > from incompatible pointer type 'struct eth_device *'
> > [-Werror=incompatible-pointer-types]
> > 43+ 487 | const struct udevice *current = eth_get_dev();
> > 44+ | ^~~~~~~~~~~
> >
>
> Ramon,
>
> Looks like my patch only works for DM_ETH. If I were to implement this
> for legacy eth it would probably be a mess as the device list is a
> static struct in net/eth_legacy.c. I'm not sure how to tell how many
> boards are out there that are not yet converted to DM_ETH and am not
> sure when legacy eth goes away. How about if I just add #ifdef
> CONFIG_DM_ETH around the whole thing and it isn't supported for legacy
> eth?
>
> Best Regards,
>
> Tim
Sounds good to me.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-14 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11 19:52 [PATCH v2] cmd: net: add a 'net list' command to list network devs Tim Harvey
2021-06-12 18:26 ` Ramon Fried
2021-06-12 19:01   ` Ramon Fried
2021-06-14 15:36     ` Tim Harvey
2021-06-14 17:04       ` Ramon Fried

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.