From patchwork Tue Oct 27 16:10:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 536718 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 4D45A1412FD for ; Wed, 28 Oct 2015 03:08:13 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=UCSYDRkL; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 01ECD4A03A; Tue, 27 Oct 2015 17:08:10 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ku99PE_tz0qN; Tue, 27 Oct 2015 17:08:09 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1DD504B615; Tue, 27 Oct 2015 17:08:09 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A09594B615 for ; Tue, 27 Oct 2015 17:08:06 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y8O2IRXx65VB for ; Tue, 27 Oct 2015 17:08:06 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by theia.denx.de (Postfix) with ESMTPS id 1EE274A03A for ; Tue, 27 Oct 2015 17:08:03 +0100 (CET) Received: by pabla5 with SMTP id la5so33549618pab.0 for ; Tue, 27 Oct 2015 09:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=6X3q5VHP7PGJN+GfHtVu4r8aviyVjk08KAJ+MS5WCN4=; b=UCSYDRkL8akGhUNlcPbiXbsUjVXneXgDELUTAtK6cNPou70xntS3VOfwASBs/0ce4s le3GlsXPpqUGshEWVBwUv8c+2TNQZxD5E1yMvRKg2SlHjHTJ8R2QbjJstKCRL4AXDK94 eA9o7myyqeRvJQlxIAnag0SeWeErw8DWH2vij8GFg/HbFZTNJTDGkoU8CnpX2/etqiCt KuFDxVb9vkK3GF43aiW2Rgb2vU++YzIZMPx69J1a+5uzp+gddSgHRCB916km/l+G8q9u lFx+obdf32uDoBe8yXbLQqWxGx+IIqyDWT92VmV0IxtqIg7oNIKGwPMukj1veFJn8UZY Ws7w== X-Received: by 10.68.57.235 with SMTP id l11mr29392339pbq.26.1445962081649; Tue, 27 Oct 2015 09:08:01 -0700 (PDT) Received: from ala-d2121-lx1.wrs.com (unknown-157-139.windriver.com. [147.11.157.139]) by smtp.gmail.com with ESMTPSA id v13sm40463248pbs.51.2015.10.27.09.08.01 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Oct 2015 09:08:01 -0700 (PDT) From: Bin Meng To: Simon Glass , U-Boot Mailing List , Tom Rini Date: Tue, 27 Oct 2015 09:10:39 -0700 Message-Id: <1445962239-14213-1-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.9.5 Subject: [U-Boot] [PATCH] fdt: Rewrite the logic in fdt_fixup_ethernet() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently in fdt_fixup_ethernet() the MAC address fix up is handled in a loop of which the exit condition is to test the "eth%daddr" env is not NULL. However this creates unnecessary constrains that those "eth%daddr" env variables must be sequential even if "ethernet%d" does not start from 0 in the "/aliases" node. For example, with "/aliases" node below: aliases { ethernet3 = &enet3; ethernet4 = &enet4; }; "ethaddr", "eth1addr", "eth2addr" must exist in order to fix up ethernet3's MAC address successfully. Now we change the loop logic to iterate the properties in the "/aliases" node. For each property, test if it is in a format of "ethernet%d", then get its MAC address from corresponding "eth%daddr" env and fix it up in the dtb. Signed-off-by: Bin Meng Acked-by: Joe Hershberger Reviewed-by: Tom Rini --- common/fdt_support.c | 53 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/common/fdt_support.c b/common/fdt_support.c index f86365e..5cdf185 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -476,10 +476,11 @@ int fdt_fixup_memory(void *blob, u64 start, u64 size) void fdt_fixup_ethernet(void *fdt) { int node, i, j; - char enet[16], *tmp, *end; + char *tmp, *end; char mac[16]; const char *path; unsigned char mac_addr[6]; + int offset; node = fdt_path_offset(fdt, "/aliases"); if (node < 0) @@ -496,27 +497,39 @@ void fdt_fixup_ethernet(void *fdt) strcpy(mac, "ethaddr"); } - i = 0; - while ((tmp = getenv(mac)) != NULL) { - sprintf(enet, "ethernet%d", i); - path = fdt_getprop(fdt, node, enet, NULL); - if (!path) { - debug("No alias for %s\n", enet); - sprintf(mac, "eth%daddr", ++i); - continue; - } + for (offset = fdt_first_property_offset(fdt, node); + offset > 0; + offset = fdt_next_property_offset(fdt, offset)) { + const char *name; + int len = strlen("ethernet"); + + path = fdt_getprop_by_offset(fdt, offset, &name, NULL); + if (!strncmp(name, "ethernet", len)) { + i = trailing_strtol(name); + if (i != -1) { + if (i == 0) + strcpy(mac, "ethaddr"); + else + sprintf(mac, "eth%daddr", i); + } else { + continue; + } + tmp = getenv(mac); + if (!tmp) + continue; + + for (j = 0; j < 6; j++) { + mac_addr[j] = tmp ? + simple_strtoul(tmp, &end, 16) : 0; + if (tmp) + tmp = (*end) ? end + 1 : end; + } - for (j = 0; j < 6; j++) { - mac_addr[j] = tmp ? simple_strtoul(tmp, &end, 16) : 0; - if (tmp) - tmp = (*end) ? end+1 : end; + do_fixup_by_path(fdt, path, "mac-address", + &mac_addr, 6, 0); + do_fixup_by_path(fdt, path, "local-mac-address", + &mac_addr, 6, 1); } - - do_fixup_by_path(fdt, path, "mac-address", &mac_addr, 6, 0); - do_fixup_by_path(fdt, path, "local-mac-address", - &mac_addr, 6, 1); - - sprintf(mac, "eth%daddr", ++i); } }