public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ramon Fried <ramon.fried@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 3/3] db410: alter WLAN/BT MAC address fixup
Date: Fri,  3 Aug 2018 16:25:37 +0300	[thread overview]
Message-ID: <20180803132537.1747-4-ramon.fried@gmail.com> (raw)
In-Reply-To: <20180803132537.1747-1-ramon.fried@gmail.com>

Change the way MAC address fixup is done:
1. Stop using LK handed device-tree and calculate
   the MAC address our own.
2. Allow overriding the generated MACS with environment variables:
   "wlanaddr" and  "btaddr".

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
---

 .../dragonboard410c/dragonboard410c.c         | 54 +++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/board/qualcomm/dragonboard410c/dragonboard410c.c b/board/qualcomm/dragonboard410c/dragonboard410c.c
index 4f0b999e50..53e231e55a 100644
--- a/board/qualcomm/dragonboard410c/dragonboard410c.c
+++ b/board/qualcomm/dragonboard410c/dragonboard410c.c
@@ -10,7 +10,9 @@
 #include <usb.h>
 #include <asm/gpio.h>
 #include <fdt_support.h>
+#include <environment.h>
 #include <asm/arch/dram.h>
+#include <asm/arch/misc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -149,40 +151,38 @@ int board_init(void)
 	return 0;
 }
 
+/* Fixup of DTB for Linux Kernel
+ * 1. Fixup installed DRAM.
+ * 2. Fixup WLAN/BT Mac address:
+ *	First, check if MAC addresses for WLAN/BT exists as environemnt
+ *	variables wlanaddr,btaddr. if not, generate a unique address.
+ */
+
 int ft_board_setup(void *blob, bd_t *bd)
 {
-	int offset, len, i;
-	const char *mac;
-	struct {
-		const char *compatible;
-		const char *property;
-	} fix[] = {
-		[0] = {
-			/* update the kernel's dtb with wlan mac */
-			.compatible = "qcom,wcnss-wlan",
-			.property = "local-mac-address",
-		},
-		[1] = {
-			/* update the kernel's dtb with bt mac */
-			.compatible = "qcom,wcnss-bt",
-			.property = "local-bd-address",
-		},
+	u8 mac[ARP_HLEN];
+
+	msm_fixup_memory(blob);
+
+	if (!eth_env_get_enetaddr("wlanaddr", mac)) {
+		msm_generate_mac_addr(mac);
 	};
 
-	for (i = 0; i < sizeof(fix) / sizeof(fix[0]); i++) {
-		offset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
-						       fix[i].compatible);
-		if (offset < 0)
-			continue;
+	do_fixup_by_compat(blob, "qcom,wcnss-wlan",
+			   "local-mac-address", mac, ARP_HLEN, 1);
 
-		mac = fdt_getprop(gd->fdt_blob, offset, fix[i].property, &len);
-		if (mac)
-			do_fixup_by_compat(blob, fix[i].compatible,
-					   fix[i].property, mac, ARP_HLEN, 1);
-	}
 
-	msm_fixup_memory(blob);
+	if (!eth_env_get_enetaddr("btaddr", mac)) {
+		msm_generate_mac_addr(mac);
+
+/* The BD address is same as WLAN MAC address but with
+ * least significant bit flipped.
+ */
+		mac[0] ^= 0x01;
+	};
 
+	do_fixup_by_compat(blob, "qcom,wcnss-bt",
+			   "local-bd-address", mac, ARP_HLEN, 1);
 	return 0;
 }
 
-- 
2.18.0

  parent reply	other threads:[~2018-08-03 13:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-03 13:25 [U-Boot] [PATCH v1 0/3] Let U-Boot generate MAC address for db410 Ramon Fried
2018-08-03 13:25 ` [U-Boot] [PATCH v1 1/3] snapdragon: added msm_board_serial() func Ramon Fried
2018-08-13 23:57   ` [U-Boot] [U-Boot, v1, " Tom Rini
2018-08-03 13:25 ` [U-Boot] [PATCH v1 2/3] snapdragon: added MAC generation functions Ramon Fried
2018-08-13 23:57   ` [U-Boot] [U-Boot, v1, " Tom Rini
2018-08-03 13:25 ` Ramon Fried [this message]
2018-08-13 23:57   ` [U-Boot] [U-Boot, v1, 3/3] db410: alter WLAN/BT MAC address fixup Tom Rini
2018-08-13 23:57   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180803132537.1747-4-ramon.fried@gmail.com \
    --to=ramon.fried@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox