* [U-Boot] [PATCH v1 1/3] snapdragon: added msm_board_serial() func
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 ` 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-03 13:25 ` [U-Boot] [PATCH v1 3/3] db410: alter WLAN/BT MAC address fixup Ramon Fried
2 siblings, 1 reply; 8+ messages in thread
From: Ramon Fried @ 2018-08-03 13:25 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
---
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
diff --git a/arch/arm/mach-snapdragon/Makefile b/arch/arm/mach-snapdragon/Makefile
index f375d07d03..2d94083600 100644
--- a/arch/arm/mach-snapdragon/Makefile
+++ b/arch/arm/mach-snapdragon/Makefile
@@ -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
diff --git a/arch/arm/mach-snapdragon/include/mach/misc.h b/arch/arm/mach-snapdragon/include/mach/misc.h
new file mode 100644
index 0000000000..5af6ae8da4
--- /dev/null
+++ b/arch/arm/mach-snapdragon/include/mach/misc.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Snapdragon DRAM
+ * Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
+ */
+
+#ifndef MISC_H
+#define MISC_H
+
+u32 msm_board_serial(void);
+
+#endif
diff --git a/arch/arm/mach-snapdragon/misc.c b/arch/arm/mach-snapdragon/misc.c
new file mode 100644
index 0000000000..678bd69f83
--- /dev/null
+++ b/arch/arm/mach-snapdragon/misc.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Miscellaneous Snapdragon functionality
+ *
+ * (C) Copyright 2018 Ramon Fried <ramon.fried@gmail.com>
+ *
+ */
+
+#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);
+}
--
2.18.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [U-Boot] [PATCH v1 2/3] snapdragon: added MAC generation functions
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-03 13:25 ` Ramon Fried
2018-08-13 23:57 ` [U-Boot] [U-Boot, v1, " Tom Rini
2018-08-03 13:25 ` [U-Boot] [PATCH v1 3/3] db410: alter WLAN/BT MAC address fixup Ramon Fried
2 siblings, 1 reply; 8+ messages in thread
From: Ramon Fried @ 2018-08-03 13:25 UTC (permalink / raw)
To: u-boot
Add support for generation of unique MAC address
that is derived from board serial.
Algorithm for generation of MAC taken from LK.
Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
---
arch/arm/mach-snapdragon/include/mach/misc.h | 1 +
arch/arm/mach-snapdragon/misc.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/arch/arm/mach-snapdragon/include/mach/misc.h b/arch/arm/mach-snapdragon/include/mach/misc.h
index 5af6ae8da4..c60e3e4724 100644
--- a/arch/arm/mach-snapdragon/include/mach/misc.h
+++ b/arch/arm/mach-snapdragon/include/mach/misc.h
@@ -8,5 +8,6 @@
#define MISC_H
u32 msm_board_serial(void);
+void msm_generate_mac_addr(u8 *mac);
#endif
diff --git a/arch/arm/mach-snapdragon/misc.c b/arch/arm/mach-snapdragon/misc.c
index 678bd69f83..f6c87866c0 100644
--- a/arch/arm/mach-snapdragon/misc.c
+++ b/arch/arm/mach-snapdragon/misc.c
@@ -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;
+ }
+}
--
2.18.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [U-Boot] [PATCH v1 3/3] db410: alter WLAN/BT MAC address fixup
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-03 13:25 ` [U-Boot] [PATCH v1 2/3] snapdragon: added MAC generation functions Ramon Fried
@ 2018-08-03 13:25 ` Ramon Fried
2018-08-13 23:57 ` [U-Boot] [U-Boot, v1, " Tom Rini
2018-08-13 23:57 ` Tom Rini
2 siblings, 2 replies; 8+ messages in thread
From: Ramon Fried @ 2018-08-03 13:25 UTC (permalink / raw)
To: u-boot
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
^ permalink raw reply related [flat|nested] 8+ messages in thread