Skip to contentSkip to conversation

board: stemmy: Read persistent radio addresses

PATCH In review Linus Walleij 2 participants 2 messages Nov 20 – Nov 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board: stemmy: Read persistent radio addresses

The device tree should contain the hardware addresses for Wifi and Bluetooth.

Samsung stores Wi-Fi and Bluetooth addresses in several locations depending on the device and firmware. The eMMC partition numbers also differ between devices.

Locate the EFS and DATAFS partitions by name, with a filesystem-content fallback for unlabeled partition tables. Search the Samsung Wi-Fi address files in priority order and support both Bluetooth EFS layouts.

Accept colon-separated and compact addresses, including Codina's
bt_macaddr: record, reject known firmware placeholders.

Pass valid addresses to the operating system through the device tree nodes from ft_board_setup().

Tested on some different phones such as Janice, Codina, Skomer, Golden...

---
 MAINTAINERS                     |   1 +
 board/ste/stemmy/Makefile       |   2 +-
 board/ste/stemmy/stemmy-radio.c | 325 ++++++++++++++++++++++++++++++++++++++++
 board/ste/stemmy/stemmy-radio.h |   8 +
 board/ste/stemmy/stemmy.c       |   4 +
 5 files changed, 339 insertions(+), 1 deletion(-)
MAINTAINERS +1 -0
index 6edf740a9ceb..ceb474751906 100644
@@ -772,6 +772,7 @@ R:	Linus Walleij <[email protected]>
 S:	Maintained
 F:	arch/arm/dts/ste-*
 F:	arch/arm/mach-u8500/
+F:	board/ste/stemmy/
 F:	drivers/gpio/nmk_gpio.c
 F:	drivers/pinctrl/pinctrl-nomadik.c
 F:	drivers/phy/phy-ab8500-usb.c
board/ste/stemmy/Makefile +1 -1
index 1245099bc918..f4e97c9d9972 100644
@@ -1,2 +1,2 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
-obj-y	:= stemmy.o
+obj-y	:= stemmy.o stemmy-radio.o
board/ste/stemmy/stemmy-radio.c new file +325 -0

325 lines not on this page · raw message

board/ste/stemmy/stemmy-radio.h new file +8 -0
new file mode 100644
index 000000000000..3c3ce03669b8
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __STEMMY_RADIO_H
+#define __STEMMY_RADIO_H
+
+void stemmy_radio_fixup(void *fdt);
+
+#endif
board/ste/stemmy/stemmy.c +4 -0
index 8526deeb29bc..97957e12d5b0 100644
@@ -12,6 +12,8 @@
 #include <asm/setup.h>
 #include <asm/system.h>
 
+#include "stemmy-radio.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /* Parse atags provided by Samsung bootloader to get available memory */
@@ -545,5 +547,7 @@ int ft_board_setup(void *fdt, struct bd_info *bd)
 		skomer_kyle_patch_display(fdt);
 	}
 
+	stemmy_radio_fixup(fdt);
+
 	return 0;
 }

---
base-commit: f2e99724255470a12119f696a0c579fd873cbef9
change-id: 20261110-ux500-efs-cb818375e8f6

Best regards,

Signature · 1 line
Linus Walleij <[email protected]>
#1 lore raw
Quoted 45 lines · Linus Walleij

The device tree should contain the hardware addresses for Wifi and Bluetooth.

Samsung stores Wi-Fi and Bluetooth addresses in several locations depending on the device and firmware. The eMMC partition numbers also differ between devices.

Locate the EFS and DATAFS partitions by name, with a filesystem-content fallback for unlabeled partition tables. Search the Samsung Wi-Fi address files in priority order and support both Bluetooth EFS layouts.

Accept colon-separated and compact addresses, including Codina's
bt_macaddr: record, reject known firmware placeholders.

Pass valid addresses to the operating system through the device tree nodes from ft_board_setup().

Tested on some different phones such as Janice, Codina, Skomer, Golden...

---
 MAINTAINERS                     |   1 +
 board/ste/stemmy/Makefile       |   2 +-
 board/ste/stemmy/stemmy-radio.c | 325 ++++++++++++++++++++++++++++++++++++++++
 board/ste/stemmy/stemmy-radio.h |   8 +
 board/ste/stemmy/stemmy.c       |   4 +
 5 files changed, 339 insertions(+), 1 deletion(-)

[...]

board/ste/stemmy/stemmy-radio.c new file +8 -0
new file mode 100644
index 000000000000..3394fb8ca75a
@@ -0,0 +1,325 @@
[...]
+static int stemmy_find_partition(struct blk_desc *desc, const char *name)
+{
+	struct disk_partition info;
+	int part;
+
+	if (!desc)
+		return -ENODEV;
+

board/ste/stemmy/stemmy-radio.c line 109

Quoted 10 lines
board/ste/stemmy/stemmy-radio.c new file +10 -0
+	part = part_get_info_by_name(desc, name, &info);
+	if (part >= 0)
+		return part;
+
+	for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
+		if (part_get_info(desc, part, &info))
+			continue;
+		if (!strcasecmp(name, (const char *)info.name))
+			return part;
+	}

I guess this is basically part_get_info_by_name_case_insensitive() as fallback to the real part_get_info_by_name() above? Do we actually have partitions with differing case on some of the phones?

Quoted 8 lines
board/ste/stemmy/stemmy-radio.c new file +7 -0
+
+	return -ENOENT;
+}
+
[...]
+static int stemmy_read_radio_addr(struct blk_desc *desc, int part,
+				  const char *path, u8 *addr)
+{

board/ste/stemmy/stemmy-radio.c line 177

Quoted 10 lines
board/ste/stemmy/stemmy-radio.c new file +10 -0
+	char buf[RADIO_ADDR_BUF_SIZE + 1];
+	loff_t len;
+	int ret;
+
+	ret = fs_set_blk_dev_with_part(desc, part);
+	if (ret)
+		return ret;
+
+	if (fs_get_type() != FS_TYPE_EXT) {
+		fs_close();

Do we need the same fs_close() call in any of the other error paths (or maybe even the success path)?

Quoted 23 lines
board/ste/stemmy/stemmy-radio.c new file +23 -0
+		return -EINVAL;
+	}
+
+	ret = fs_read(path, (ulong)buf, 0, RADIO_ADDR_BUF_SIZE, &len);
+	if (ret)
+		return ret;
+	if (!len || len > RADIO_ADDR_BUF_SIZE)
+		return -EINVAL;
+
+	buf[len] = '\0';
+
+	return stemmy_parse_radio_addr(buf, len, addr);
+}
+
+static int stemmy_try_radio_source(struct stemmy_radio_storage *storage,
+				   const struct stemmy_radio_source *source,
+				   u8 *addr)
+{
+	struct disk_partition info;
+	int part, ret;
+
+	if (!storage->desc)
+		return -ENODEV;

board/ste/stemmy/stemmy-radio.c line 210

Quoted 10 lines
board/ste/stemmy/stemmy-radio.c new file +10 -0
+
+	part = storage->part[source->partition];
+	if (part >= 0)
+		return stemmy_read_radio_addr(storage->desc, part, source->path,
+					      addr);
+
+	/* Fall back to locating an unlabeled partition by its contents. */
+	for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
+		if (part_get_info(storage->desc, part, &info))
+			continue;

Oh wow, do we have unlabeled partitions on one of the phones even? :o

Quoted 17 lines
board/ste/stemmy/stemmy-radio.c new file +16 -0
+
+		ret = stemmy_read_radio_addr(storage->desc, part, source->path,
+					     addr);
+		if (!ret) {
+			storage->part[source->partition] = part;
+			return 0;
+		}
+	}
+
+	return -ENOENT;
+}
+
[...]
+static void stemmy_fixup_radio_addr(void *fdt,
+				    struct stemmy_radio_storage *storage,
+				    const struct stemmy_radio_source *sources,
+				    size_t count, const char *compatible,

board/ste/stemmy/stemmy-radio.c line 284

Quoted 10 lines
board/ste/stemmy/stemmy-radio.c new file +10 -0
+				    bool bluetooth)
+{
+	const char *property = bluetooth ? "local-bd-address" : "local-mac-address";
+	const char *name = bluetooth ? "Bluetooth BD" : "WiFi MAC";
+	u8 addr[ETH_ALEN];
+	int node, ret, i;
+
+	ret = stemmy_find_radio_addr(storage, sources, count, bluetooth, addr);
+	if (ret) {
+		printf("Persistent %s missing\n", name);

log_warning()?

board/ste/stemmy/stemmy-radio.c line 288

Quoted 4 lines
board/ste/stemmy/stemmy-radio.c new file +4 -0
+		return;
+	}
+
+	printf("Persistent %s: %pM\n", name, addr);

log_info()?

Quoted 8 lines
board/ste/stemmy/stemmy-radio.c new file +8 -0
+
+	node = fdt_node_offset_by_compatible(fdt, -1, compatible);
+	if (node < 0)
+		return;
+
+	/* local-bd-address uses Bluetooth (least significant byte first) order. */
+	if (bluetooth) {
+		for (i = 0; i < ETH_ALEN / 2; i++)

board/ste/stemmy/stemmy-radio.c line 306

Quoted 10 lines
board/ste/stemmy/stemmy-radio.c new file +10 -0
+			swap(addr[i], addr[ETH_ALEN - i - 1]);
+	}
+
+	ret = fdt_setprop(fdt, node, property, addr, sizeof(addr));
+	if (!ret)
+		return;
+
+	log_warning("Cannot set %s: %s\n", property, fdt_strerror(ret));
+}
+

Thanks,
Stephan