]> git.sur5r.net Git - u-boot/commitdiff
dm: eth: Add support for ethprime env var
authorJoe Hershberger <joe.hershberger@ni.com>
Sun, 22 Mar 2015 22:09:17 +0000 (17:09 -0500)
committerSimon Glass <sjg@chromium.org>
Sat, 18 Apr 2015 17:11:13 +0000 (11:11 -0600)
The ethprime env var is used to indicate the starting device if none is
specified in ethact. Also support aliases specified in the ethprime var.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
net/eth.c
test/dm/eth.c

index a2e6f34535e08fa3b6841afe4216879dd47a8897..b6c2af3de6a9deacdf9b29b8432dcc9de95590e5 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -360,6 +360,18 @@ int eth_initialize(void)
                printf("No ethernet found.\n");
                bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
        } else {
+               char *ethprime = getenv("ethprime");
+               struct udevice *prime_dev = NULL;
+
+               if (ethprime)
+                       prime_dev = eth_get_dev_by_name(ethprime);
+               if (prime_dev) {
+                       eth_set_dev(prime_dev);
+                       eth_current_changed();
+               } else {
+                       eth_set_dev(NULL);
+               }
+
                bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
                do {
                        if (num_devices)
@@ -367,6 +379,9 @@ int eth_initialize(void)
 
                        printf("eth%d: %s", dev->seq, dev->name);
 
+                       if (ethprime && dev == prime_dev)
+                               printf(" [PRIME]");
+
                        eth_write_hwaddr(dev);
 
                        uclass_next_device(&dev);
@@ -915,8 +930,20 @@ void eth_set_current(void)
                act = getenv("ethact");
                env_changed_id = env_id;
        }
-       if (act != NULL)
+
+       if (act == NULL) {
+               char *ethprime = getenv("ethprime");
+               void *dev = NULL;
+
+               if (ethprime)
+                       dev = eth_get_dev_by_name(ethprime);
+               if (dev)
+                       eth_set_dev(dev);
+               else
+                       eth_set_dev(NULL);
+       } else {
                eth_set_dev(eth_get_dev_by_name(act));
+       }
 
        eth_current_changed();
 }
index 5688b71de07162ed6c48513750d0e93d3bf53ab2..96e3c46ea6991725360b3ca612152a28649278c4 100644 (file)
@@ -60,3 +60,23 @@ static int dm_test_eth_alias(struct dm_test_state *dms)
        return 0;
 }
 DM_TEST(dm_test_eth_alias, DM_TESTF_SCAN_FDT);
+
+static int dm_test_eth_prime(struct dm_test_state *dms)
+{
+       NetPingIP = string_to_ip("1.1.2.2");
+
+       /* Expected to be "eth@10003000" because of ethprime variable */
+       setenv("ethact", NULL);
+       setenv("ethprime", "eth5");
+       ut_assertok(NetLoop(PING));
+       ut_asserteq_str("eth@10003000", getenv("ethact"));
+
+       /* Expected to be "eth@10002000" because it is first */
+       setenv("ethact", NULL);
+       setenv("ethprime", NULL);
+       ut_assertok(NetLoop(PING));
+       ut_asserteq_str("eth@10002000", getenv("ethact"));
+
+       return 0;
+}
+DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);