From 9cd3e1573856c1c9b2cbf2487cc964d6b6c7e6b8 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Fri, 7 Mar 2025 15:54:58 +0000
Subject: [PATCH] overlays: Add the wifimac overlay

The wifimac overlay allows the MAC address for the onboard WiFi
interface to be overridden. This is equivalent to the Pi 5 wifiaddr
dtparam.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 arch/arm/boot/dts/overlays/Makefile           |  1 +
 arch/arm/boot/dts/overlays/README             |  9 ++++++++
 arch/arm/boot/dts/overlays/overlay_map.dts    |  4 ++++
 .../arm/boot/dts/overlays/wifimac-overlay.dts | 21 +++++++++++++++++++
 4 files changed, 35 insertions(+)
 create mode 100644 arch/arm/boot/dts/overlays/wifimac-overlay.dts

--- a/arch/arm/boot/dts/overlays/Makefile
+++ b/arch/arm/boot/dts/overlays/Makefile
@@ -348,6 +348,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
 	watterott-display.dtbo \
 	waveshare-can-fd-hat-mode-a.dtbo \
 	waveshare-can-fd-hat-mode-b.dtbo \
+	wifimac.dtbo \
 	wittypi.dtbo \
 	wm8960-soundcard.dtbo \
 	ws2812-pio.dtbo
--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -5668,6 +5668,15 @@ Load:   dtoverlay=waveshare-can-fd-hat-m
 Params: <None>
 
 
+Name:   wifimac
+Info:   Override the MAC address for the onboard WiFi. Not Pi 5.
+Load:   dtoverlay=wifimac,<param>=<val>
+Params: wifiaddr                Set an alternative WiFi MAC address.
+                                The value should be a 6-byte hexadecimal value,
+                                with or without colon separators, written in the
+                                natural (big-endian) order.
+
+
 Name:   wittypi
 Info:   Configures the wittypi RTC module.
 Load:   dtoverlay=wittypi,<param>=<val>
--- a/arch/arm/boot/dts/overlays/overlay_map.dts
+++ b/arch/arm/boot/dts/overlays/overlay_map.dts
@@ -520,4 +520,8 @@
 		bcm2712;
 	};
 
+	wifimac {
+		bcm2835;
+		bcm2711;
+	};
 };
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/wifimac-overlay.dts
@@ -0,0 +1,21 @@
+/dts-v1/;
+/plugin/;
+
+/{
+	compatible = "brcm,bcm2835";
+
+	fragment@0 {
+		target = <&brcmf>;
+		wifi0: __overlay__ {
+			local-mac-address = [ 00 00 00 00 00 00 ];
+		};
+	};
+
+	__overrides__ {
+		wifiaddr = <&wifi0>, "local-mac-address[";
+	};
+
+	__exports__ {
+		wifi0;
+	};
+};
