Skip to contentSkip to conversation

Let U-Boot generate MAC address for db410

PATCH New Ramon Fried 2 participants 8 messages Aug 3, 2018 – Aug 13, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Let U-Boot generate MAC address for db410

This patchset gives U-boot ownership on generating WLAN/BT mac addresses for WCNSS chip on Dragonboard410. Previously, this was done by LK and U-boot only read the results from the patched DTB LK fixed-up.

This is is part of my ongoing effort to get rid of LK once and for all for Snapdragon ARCH.

Ramon Fried (3):
snapdragon: added msm_board_serial() func
snapdragon: added MAC generation functions
db410: alter WLAN/BT MAC address fixup

 arch/arm/mach-snapdragon/Makefile             |  1 +
 arch/arm/mach-snapdragon/include/mach/misc.h  | 13 +++++
 arch/arm/mach-snapdragon/misc.c               | 53 ++++++++++++++++++
 .../dragonboard410c/dragonboard410c.c         | 54 +++++++++----------
 4 files changed, 94 insertions(+), 27 deletions(-)
 create mode 100644 arch/arm/mach-snapdragon/include/mach/misc.h
 create mode 100644 arch/arm/mach-snapdragon/misc.c
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/3 snapdragon: added msm_board_serial() func

This commit adds a function to get the board serial number.
In snapdragon it's actually the eMMC serial number.

Function added in a new file misc.c that will include further snapdragon miscellaneous functions.

---

 arch/arm/mach-snapdragon/Makefile            |  1 +
 arch/arm/mach-snapdragon/include/mach/misc.h | 12 +++++++
 arch/arm/mach-snapdragon/misc.c              | 37 ++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 arch/arm/mach-snapdragon/include/mach/misc.h
 create mode 100644 arch/arm/mach-snapdragon/misc.c
arch/arm/mach-snapdragon/Makefile +1 -0
index f375d07d03..2d94083600 100644
@@ -8,5 +8,6 @@ obj-$(CONFIG_TARGET_DRAGONBOARD410C) += clock-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += sysmap-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += pinctrl-apq8016.o
 obj-$(CONFIG_TARGET_DRAGONBOARD410C) += pinctrl-snapdragon.o
+obj-y += misc.o
 obj-y += clock-snapdragon.o
 obj-y += dram.o
arch/arm/mach-snapdragon/include/mach/misc.h new file +12 -0
new file mode 100644
index 0000000000..5af6ae8da4
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Snapdragon DRAM
+ * Copyright (C) 2018 Ramon Fried <[email protected]>
+ */
+
+#ifndef MISC_H
+#define MISC_H
+
+u32 msm_board_serial(void);
+
+#endif
arch/arm/mach-snapdragon/misc.c new file +37 -0
new file mode 100644
index 0000000000..678bd69f83
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Miscellaneous Snapdragon functionality
+ *
+ * (C) Copyright 2018 Ramon Fried <[email protected]>
+ *
+ */
+
+#include <common.h>
+#include <mmc.h>
+#include <asm/arch/misc.h>
+
+/* UNSTUFF_BITS macro taken from Linux Kernel: drivers/mmc/core/sd.c */
+#define UNSTUFF_BITS(resp, start, size) \
+	({ \
+		const int __size = size; \
+		const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1;	\
+		const int __off = 3 - ((start) / 32); \
+		const int __shft = (start) & 31; \
+		u32 __res; \
+					\
+		__res = resp[__off] >> __shft; \
+		if (__size + __shft > 32) \
+			__res |= resp[__off - 1] << ((32 - __shft) % 32); \
+		__res & __mask;	\
+	})
+
+u32 msm_board_serial(void)
+{
+	struct mmc *mmc_dev;
+
+	mmc_dev = find_mmc_device(0);
+	if (!mmc_dev)
+		return 0;
+
+	return UNSTUFF_BITS(mmc_dev->cid, 16, 32);
+}
Signature · 1 line
2.18.0
#2 lore raw

PATCH 1/3 snapdragon: added msm_board_serial() func

Quoted 8 lines · Ramon Fried

This commit adds a function to get the board serial number.
In snapdragon it's actually the eMMC serial number.

Function added in a new file misc.c that will include further snapdragon miscellaneous functions.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180813/a76b9fb6/attachment.sig>
#3 lore raw

PATCH 2/3 snapdragon: added MAC generation functions

In reply to Ramon Fried

Add support for generation of unique MAC address
that is derived from board serial.
Algorithm for generation of MAC taken from LK.

---

 arch/arm/mach-snapdragon/include/mach/misc.h |  1 +
 arch/arm/mach-snapdragon/misc.c              | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
arch/arm/mach-snapdragon/include/mach/misc.h +1 -0
index 5af6ae8da4..c60e3e4724 100644
@@ -8,5 +8,6 @@
 #define MISC_H
 
 u32 msm_board_serial(void);
+void msm_generate_mac_addr(u8 *mac);
 
 #endif
arch/arm/mach-snapdragon/misc.c +16 -0
index 678bd69f83..f6c87866c0 100644
@@ -35,3 +35,19 @@ u32 msm_board_serial(void)
 
 	return UNSTUFF_BITS(mmc_dev->cid, 16, 32);
 }
+
+void msm_generate_mac_addr(u8 *mac)
+{
+	int i;
+	char sn[9];
+
+	snprintf(sn, 8, "%08x", msm_board_serial());
+
+	/* fill in the mac with serialno, use locally adminstrated pool */
+	mac[0] = 0x02;
+	mac[1] = 00;
+	for (i = 3; i >= 0; i--) {
+		mac[i + 2] = simple_strtoul(&sn[2 * i], NULL, 16);
+		sn[2 * i] = 0;
+	}
+}
Signature · 1 line
2.18.0
#4 lore raw

PATCH 2/3 snapdragon: added MAC generation functions

Quoted 5 lines · Ramon Fried

Add support for generation of unique MAC address
that is derived from board serial.
Algorithm for generation of MAC taken from LK.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180813/41858913/attachment.sig>
#5 lore raw

PATCH 3/3 db410: alter WLAN/BT MAC address fixup

In reply to Ramon Fried

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".

---

 .../dragonboard410c/dragonboard410c.c         | 54 +++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)
board/qualcomm/dragonboard410c/dragonboard410c.c +27 -27
index 4f0b999e50..53e231e55a 100644
@@ -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;
 }
 
Signature · 1 line
2.18.0
#6 lore raw

PATCH 3/3 db410: alter WLAN/BT MAC address fixup

Quoted 7 lines · Ramon Fried

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".

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180813/5987a0b5/attachment.sig>
#7 lore raw

PATCH 3/3 db410: alter WLAN/BT MAC address fixup

In reply to Ramon Fried
Quoted 7 lines · Ramon Fried

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".

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180813/4b0b271c/attachment.sig>