Add the 'eth' command for operations on ethernet devices.
This first version only contains a command to show a device
properties, currently only name, index and MAC address.

Signed-off-by: Alban Bedel <alban.be...@avionic-design.de>
---
v1: * Patch didn't exists
v2: * Patch didn't exists
v3: * Replace the dedicated 'eth_eeprom' command with a subcommand
      to the 'eth' command
---
 common/cmd_net.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/common/cmd_net.c b/common/cmd_net.c
index 09489d4..9cc0bdf 100644
--- a/common/cmd_net.c
+++ b/common/cmd_net.c
@@ -445,3 +445,51 @@ U_BOOT_CMD(
 );
 
 #endif  /* CONFIG_CMD_LINK_LOCAL */
+
+static int do_eth_show(struct eth_device *dev,
+                       int argc, char * const argv[])
+{
+       printf("Name : %s\n", dev->name);
+       printf("Index: %d\n", dev->index);
+       printf("MAC  : %pM\n", dev->enetaddr);
+       return 0;
+}
+
+static int do_eth(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct eth_device *dev;
+       char *endp = NULL;
+       int index;
+
+       if (argc < 3)
+               return CMD_RET_USAGE;
+
+       /* Get the ethernet device, by ID or by name */
+       index = (int) simple_strtoul(argv[1], &endp, 16);
+       if (endp > argv[1])
+               dev = eth_get_dev_by_index(index);
+       else
+               dev = eth_get_dev_by_name(argv[2]);
+
+       if (!dev) {
+               printf("Ethernet device not found\n");
+               return CMD_RET_FAILURE;
+       }
+
+       if (!strcmp(argv[2], "show"))
+               return do_eth_show(dev, argc - 2, argv + 2);
+
+       printf("Unknown eth sub command: %s\n", argv[2]);
+
+       return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+       eth,    7,      0,      do_eth,
+       "extended ops for ethernet devices",
+       "<dev> <command> [<args>...]\n"
+       "    - run command on a device, device may be a name or id.\n"
+       "\n"
+       "eth <dev> show\n"
+       "    - show basic information about the ethernet device\n"
+);
-- 
2.1.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to