cmd: net: add a 'net list' command to list network devs
PATCH 1/1 cmd: net: add a 'net list' command to list network devs
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 at 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
--- cmd/net.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
cmd/net.c +44 -0
@@ -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" +);
Signature · 1 line
2.17.1
PATCH 1/1 cmd: net: add a 'net list' command to list network devs
Quoted 15 lines · 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-systemUsage:
net list - list available devices
Quoted 7 lines
U-Boot > net list
eth0 : ethernet at 2188000 00:d0:12:98:f5:47 active eth1 : e1000#0 00:d0:12:98:f5:48
eth2 :asix_eth8c:ae:4c:f5:84:9d
eth3 :asix_eth8c:ae:4c:f9:41:e3Signed-off-by Tim Harvey <[email protected]>
I like it:
Thanks,
Stefan
Quoted 54 lines
--- cmd/net.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)cmd/net.c +34
-0@@ -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))
cmd/net.c U_BOOT_CMD( · line 526
Quoted 10 lines
cmd/net.c +10
-0+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" +);
Viele Gr??e,
Stefan
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
PATCH 1/1 cmd: net: add a 'net list' command to list network devs
In reply to Tim HarveyQuoted 87 lines · 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-systemUsage:
net list - list available devicesU-Boot > net list
eth0 : ethernet at 2188000 00:d0:12:98:f5:47 active eth1 : e1000#0 00:d0:12:98:f5:48
eth2 :asix_eth8c:ae:4c:f5:84:9d
eth3 :asix_eth8c:ae:4c:f9:41:e3Signed-off-by Tim Harvey <[email protected]>--- cmd/net.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)cmd/net.c +44
-1@@ -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" +); --
Quoted 2 lines
2.17.1
Excellent ! Thanks.