[LEDE-DEV] [PATCH 2/3] ar71xx: add mac partition to the MR12/MR16

Chris Blake chrisrblake93 at gmail.com
Wed Oct 19 10:53:08 PDT 2016


On the stock Meraki Firmare for the MR12/MR16, a chunk of SPI space
after u-boot-env is used to store the boards Mac address. Sadly as this
was removed on any device already on OpenWRT/LEDE, moving forward a new,
64k partition named "mac" will be used to store the mac address for the
device (which is the minimum size). This allows users to properly set
the correct MAC, without editing the ART partition (which holds the same
MAC for all devices).

The reason the space is taken from kernel instead of rootfs is currently
kernels are only 1.3MB, so that way we can leave the current rootfs
space alone for users who fully utilize the available storage space.

Once this partition is added to a device, you can set your MAC doing the
following:

mtd erase mac
echo -n -e '\x00\x18\x0a\x33\x44\x55' > /dev/mtd5
sync && reboot

Where 00:18:0a:33:44:55 is your MAC address.

This was tested, and confirmed working on both the MR12 and MR16.

Signed-off-by: Chris Blake <chrisrblake93 at gmail.com>
---
 .../linux/ar71xx/files/arch/mips/ath79/mach-mr12.c | 14 +++++++-------
 .../linux/ar71xx/files/arch/mips/ath79/mach-mr16.c | 22 +++++++++++-----------
 target/linux/ar71xx/image/generic.mk               |  4 ++--
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-mr12.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-mr12.c
index 12c9a1c..dc880c5 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-mr12.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-mr12.c
@@ -42,8 +42,7 @@

 #define MR12_WAN_PHYMASK    BIT(4)

-#define MR12_WMAC0_MAC_OFFSET           0x120c
-#define MR12_CALDATA0_OFFSET            0x1000
+#define MR12_CALDATA0_OFFSET            0x21000

 static struct gpio_led MR12_leds_gpio[] __initdata = {
 	{
@@ -90,8 +89,9 @@ static struct gpio_keys_button MR12_gpio_keys[] __initdata = {

 static void __init MR12_setup(void)
 {
-	u8 *mac = (u8 *) KSEG1ADDR(0xbfff0000);
-
+	u8 *mac = (u8 *) KSEG1ADDR(0xbffd0000);
+	u8 WLAN0_MAC[ETH_ALEN];
+
 	ath79_register_mdio(0,0x0);

 	ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
@@ -107,9 +107,9 @@ static void __init MR12_setup(void)
 					ARRAY_SIZE(MR12_gpio_keys),
 					MR12_gpio_keys);

-	ap91_pci_init(mac + MR12_CALDATA0_OFFSET,
-				mac + MR12_WMAC0_MAC_OFFSET);
+	ath79_init_mac(WLAN0_MAC, mac, 1);
+	ap91_pci_init(mac + MR12_CALDATA0_OFFSET, WLAN0_MAC);

 }

-MIPS_MACHINE(ATH79_MACH_MR12, "MR12", "Meraki MR12", MR12_setup);
\ No newline at end of file
+MIPS_MACHINE(ATH79_MACH_MR12, "MR12", "Meraki MR12", MR12_setup);
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-mr16.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-mr16.c
index 9f08e3d..2897ee5 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-mr16.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-mr16.c
@@ -42,10 +42,8 @@

 #define MR16_WAN_PHYMASK    BIT(0)

-#define MR16_WMAC0_MAC_OFFSET		0x120c
-#define MR16_WMAC1_MAC_OFFSET		0x520c
-#define MR16_CALDATA0_OFFSET		0x1000
-#define MR16_CALDATA1_OFFSET		0x5000
+#define MR16_CALDATA0_OFFSET		0x21000
+#define MR16_CALDATA1_OFFSET		0x25000

 static struct gpio_led MR16_leds_gpio[] __initdata = {
 	{
@@ -92,8 +90,10 @@ static struct gpio_keys_button MR16_gpio_keys[] __initdata = {

 static void __init MR16_setup(void)
 {
-	u8 *mac = (u8 *) KSEG1ADDR(0xbfff0000);
-
+	u8 *mac = (u8 *) KSEG1ADDR(0xbffd0000);
+	u8 WLAN0_MAC[ETH_ALEN];
+	u8 WLAN1_MAC[ETH_ALEN];
+
 	ath79_register_mdio(0,0x0);

 	ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
@@ -109,10 +109,10 @@ static void __init MR16_setup(void)
 					ARRAY_SIZE(MR16_gpio_keys),
 					MR16_gpio_keys);

-	ap94_pci_init(mac + MR16_CALDATA0_OFFSET,
-		    mac + MR16_WMAC0_MAC_OFFSET,
-		    mac + MR16_CALDATA1_OFFSET,
-		    mac + MR16_WMAC1_MAC_OFFSET);
+	ath79_init_mac(WLAN0_MAC, mac, 1);
+	ath79_init_mac(WLAN1_MAC, mac, 2);
+	ap94_pci_init(mac + MR16_CALDATA0_OFFSET, WLAN0_MAC,
+		    mac + MR16_CALDATA1_OFFSET, WLAN1_MAC);
 }

-MIPS_MACHINE(ATH79_MACH_MR16, "MR16", "Meraki MR16", MR16_setup);
\ No newline at end of file
+MIPS_MACHINE(ATH79_MACH_MR16, "MR16", "Meraki MR16", MR16_setup);
diff --git a/target/linux/ar71xx/image/generic.mk b/target/linux/ar71xx/image/generic.mk
index 04fed88..ee910af 100644
--- a/target/linux/ar71xx/image/generic.mk
+++ b/target/linux/ar71xx/image/generic.mk
@@ -102,7 +102,7 @@ define Device/mr12
   DEVICE_PACKAGES := kmod-spi-gpio
   BOARDNAME = MR12
   IMAGE_SIZE = 15744k
-  MTDPARTS = spi0.0:256k(u-boot)ro,256k(u-boot-env)ro,13440k(rootfs),2304k(kernel),128k(art)ro,15744k at 0x80000(firmware)
+  MTDPARTS = spi0.0:256k(u-boot)ro,256k(u-boot-env)ro,13440k(rootfs),2240k(kernel),64k(mac),128k(art)ro,15680k at 0x80000(firmware)
   IMAGE/kernel.bin = append-kernel
   IMAGE/rootfs.bin = append-rootfs | pad-rootfs
   IMAGE/sysupgrade.bin = append-rootfs | pad-rootfs | pad-to 13440k | append-kernel | check-size $$$$(IMAGE_SIZE)
@@ -115,7 +115,7 @@ define Device/mr16
   DEVICE_PACKAGES := kmod-spi-gpio
   BOARDNAME = MR16
   IMAGE_SIZE = 15744k
-  MTDPARTS = spi0.0:256k(u-boot)ro,256k(u-boot-env)ro,13440k(rootfs),2304k(kernel),128k(art)ro,15744k at 0x80000(firmware)
+  MTDPARTS = spi0.0:256k(u-boot)ro,256k(u-boot-env)ro,13440k(rootfs),2240k(kernel),64k(mac),128k(art)ro,15680k at 0x80000(firmware)
   IMAGE/kernel.bin = append-kernel
   IMAGE/rootfs.bin = append-rootfs | pad-rootfs
   IMAGE/sysupgrade.bin = append-rootfs | pad-rootfs | pad-to 13440k | append-kernel | check-size $$$$(IMAGE_SIZE)
--
2.7.4



More information about the Lede-dev mailing list