Skip to contentSkip to conversation

board: apalis_t30/tk1/colibri_t20/t30: integrate mac address via dt

PATCH In review Marcel Ziswiler 3 participants 3 messages May 21, 2022 – May 31, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board: apalis_t30/tk1/colibri_t20/t30: integrate mac address via dt

From: Marcel Ziswiler <[email protected]>

Use device tree to set MAC address of the Ethernet chip.

---

 board/toradex/apalis-tk1/apalis-tk1.c   | 19 +++++++++++++++++++
 board/toradex/apalis_t30/apalis_t30.c   | 20 ++++++++++++++++++++
 board/toradex/colibri_t20/colibri_t20.c | 19 +++++++++++++++++++
 board/toradex/colibri_t30/colibri_t30.c | 20 ++++++++++++++++++++
 4 files changed, 78 insertions(+)
board/toradex/apalis-tk1/apalis-tk1.c +19 -0
index ccf665b2118..86b10400ffa 100644
@@ -14,6 +14,7 @@
 #include <asm/arch/gpio.h>
 #include <asm/arch/pinmux.h>
 #include <env_internal.h>
+#include <fdt_support.h>
 #include <pci_tegra.h>
 #include <linux/delay.h>
 #include <power/as3722.h>
@@ -99,6 +100,24 @@ int checkboard(void)
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
+	u8 enetaddr[6];
+
+	/* MAC addr */
+	if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+		int err = fdt_find_and_setprop(blob,
+					       "/pcie@1003000/pci@2,0/ethernet@0,0",
+					       "local-mac-address", enetaddr, 6, 0);
+
+		/* Older device trees might have used a different node name */
+		if (err < 0)
+			err = fdt_find_and_setprop(blob,
+						   "/pcie@1003000/pci@2,0/pcie@0",
+						   "local-mac-address", enetaddr, 6, 0);
+
+		if (err >= 0)
+			puts("   MAC address updated...\n");
+	}
+
 	return ft_common_board_setup(blob, bd);
 }
 #endif
board/toradex/apalis_t30/apalis_t30.c +20 -0
index 0396eea56b5..ef71270d9f2 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <log.h>
 #include <asm/arch/gp_padctrl.h>
@@ -16,6 +17,7 @@
 #include <asm/io.h>
 #include <dm.h>
 #include <i2c.h>
+#include <fdt_support.h>
 #include <pci_tegra.h>
 #include <linux/delay.h>
 #include "../common/tdx-common.h"
@@ -54,6 +56,24 @@ int checkboard(void)
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
+	u8 enetaddr[6];
+
+	/* MAC addr */
+	if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+		int err = fdt_find_and_setprop(blob,
+					       "/pcie@3000/pci@3,0/ethernet@0,0",
+					       "local-mac-address", enetaddr, 6, 0);
+
+		/* Older device trees might have used a different node name */
+		if (err < 0)
+			err = fdt_find_and_setprop(blob,
+						   "/pcie@3000/pci@3,0/pcie@0",
+						   "local-mac-address", enetaddr, 6, 0);
+
+		if (err >= 0)
+			puts("   MAC address updated...\n");
+	}
+
 	return ft_common_board_setup(blob, bd);
 }
 #endif
board/toradex/colibri_t20/colibri_t20.c +19 -0
index 73ef4d2db32..c58d2021cd3 100644
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <log.h>
 #include <asm/arch/clock.h>
@@ -81,6 +82,24 @@ int checkboard(void)
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
+	u8 enetaddr[6];
+
+	/* MAC addr */
+	if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+		int err = fdt_find_and_setprop(blob,
+					       "/usb@7d004000/ethernet@1",
+					       "local-mac-address", enetaddr, 6, 0);
+
+		/* Older device trees might have used a different node name */
+		if (err < 0)
+			err = fdt_find_and_setprop(blob,
+						   "/usb@7d004000/asix@1",
+						   "local-mac-address", enetaddr, 6, 0);
+
+		if (err >= 0)
+			puts("   MAC address updated...\n");
+	}
+
 	return ft_common_board_setup(blob, bd);
 }
 #endif
board/toradex/colibri_t30/colibri_t30.c +20 -0
index 20cbb75a365..b6b004669c2 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <asm/arch/gp_padctrl.h>
 #include <asm/arch/pinmux.h>
@@ -12,6 +13,7 @@
 #include <asm/arch-tegra/tegra.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <fdt_support.h>
 #include <i2c.h>
 #include <linux/delay.h>
 #include "pinmux-config-colibri_t30.h"
@@ -36,6 +38,24 @@ int checkboard(void)
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
+	u8 enetaddr[6];
+
+	/* MAC addr */
+	if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+		int err = fdt_find_and_setprop(blob,
+					       "/usb@7d004000/ethernet@1",
+					       "local-mac-address", enetaddr, 6, 0);
+
+		/* Older device trees might have used a different node name */
+		if (err < 0)
+			err = fdt_find_and_setprop(blob,
+						   "/usb@7d004000/asix@1",
+						   "local-mac-address", enetaddr, 6, 0);
+
+		if (err >= 0)
+			puts("   MAC address updated...\n");
+	}
+
 	return ft_common_board_setup(blob, bd);
 }
 #endif
Signature · 1 line
2.34.1
#1 lore raw

Hi Tom (Warren that is)

Quoted 3 lines · Marcel Ziswiler

From: Marcel Ziswiler <[email protected]>

Use device tree to set MAC address of the Ethernet chip.

Don't want to rush anything but this one would fix booting regular mainline upstream Linux kernel on those good oldé Tegra boards. Thanks!

Cheers

Marcel

Quoted 174 lines

---

 board/toradex/apalis-tk1/apalis-tk1.c   | 19 +++++++++++++++++++ board/toradex/apalis_t30/apalis_t30.c   | 20 ++++++++++++++++++++ board/toradex/colibri_t20/colibri_t20.c | 19 +++++++++++++++++++ board/toradex/colibri_t30/colibri_t30.c | 20 ++++++++++++++++++++

 4 files changed, 78 insertions(+)
board/toradex/apalis-tk1/apalis-tk1.c +19 -0
index ccf665b2118..86b10400ffa 100644
@@ -14,6 +14,7 @@
  #include <asm/arch/gpio.h>
  #include <asm/arch/pinmux.h>
  #include <env_internal.h>
+#include <fdt_support.h>
  #include <pci_tegra.h>
  #include <linux/delay.h>
  #include <power/as3722.h>
@@ -99,6 +100,24 @@ int checkboard(void)
  #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  int ft_board_setup(void *blob, struct bd_info *bd)
  {
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/pcie@1003000/pci@2,0/ethernet@0,0",
+                                              "local-mac-address", enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/pcie@1003000/pci@2,0/pcie@0",
+                                                  "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
         return ft_common_board_setup(blob, bd);
  }
  #endif
board/toradex/apalis_t30/apalis_t30.c +0 -0
index 0396eea56b5..ef71270d9f2 100644
@@ -5,6 +5,7 @@
   */


 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <log.h>
 #include <asm/arch/gp_padctrl.h>

board/toradex/apalis_t30/apalis_t30.c +19 -0
@@ -16,6 +17,7 @@
  #include <asm/io.h>
  #include <dm.h>
  #include <i2c.h>
+#include <fdt_support.h>
  #include <pci_tegra.h>
  #include <linux/delay.h>
  #include "../common/tdx-common.h"
@@ -54,6 +56,24 @@ int checkboard(void)
  #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  int ft_board_setup(void *blob, struct bd_info *bd)
  {
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/pcie@3000/pci@3,0/ethernet@0,0",
+                                              "local-mac-address", enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/pcie@3000/pci@3,0/pcie@0",
+                                                  "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
         return ft_common_board_setup(blob, bd);
  }
  #endif
board/toradex/colibri_t20/colibri_t20.c +0 -0
index 73ef4d2db32..c58d2021cd3 100644
@@ -4,6 +4,7 @@
   */


 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <log.h>
 #include <asm/arch/clock.h>

board/toradex/colibri_t20/colibri_t20.c +18 -0
@@ -81,6 +82,24 @@ int checkboard(void)
  #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  int ft_board_setup(void *blob, struct bd_info *bd)
  {
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/usb@7d004000/ethernet@1",
+                                              "local-mac-address", enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/usb@7d004000/asix@1",
+                                                  "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
         return ft_common_board_setup(blob, bd);
  }
  #endif
board/toradex/colibri_t30/colibri_t30.c +0 -0
index 20cbb75a365..b6b004669c2 100644
@@ -5,6 +5,7 @@
   */


 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <asm/arch/gp_padctrl.h>
 #include <asm/arch/pinmux.h>

board/toradex/colibri_t30/colibri_t30.c +19 -0
@@ -12,6 +13,7 @@
  #include <asm/arch-tegra/tegra.h>
  #include <asm/gpio.h>
  #include <asm/io.h>
+#include <fdt_support.h>
  #include <i2c.h>
  #include <linux/delay.h>
  #include "pinmux-config-colibri_t30.h"
@@ -36,6 +38,24 @@ int checkboard(void)
  #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  int ft_board_setup(void *blob, struct bd_info *bd)
  {
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/usb@7d004000/ethernet@1",
+                                              "local-mac-address", enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/usb@7d004000/asix@1",
+                                                  "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
         return ft_common_board_setup(blob, bd);
  }
  #endif
#2 lore raw

Thanks, Marcel. Been OOTO, I'll take a look and get a PR up this week.

-----Original Message-----
From: Marcel Ziswiler <[email protected]>
Sent: Wednesday, May 25, 2022 1:20 AM
To: [email protected]
Cc: Tom Warren <[email protected]>
Subject: Re: [PATCH v1] board: apalis_t30/tk1/colibri_t20/t30: integrate mac address via dt

External email: Use caution opening links or attachments

Hi Tom (Warren that is)

Quoted 3 lines · Marcel Ziswiler

From: Marcel Ziswiler <[email protected]>

Use device tree to set MAC address of the Ethernet chip.

Don't want to rush anything but this one would fix booting regular mainline upstream Linux kernel on those good oldé Tegra boards. Thanks!

Cheers

Marcel

Quoted 174 lines

---

 board/toradex/apalis-tk1/apalis-tk1.c   | 19 +++++++++++++++++++
 board/toradex/apalis_t30/apalis_t30.c   | 20 ++++++++++++++++++++
 board/toradex/colibri_t20/colibri_t20.c | 19 +++++++++++++++++++  
board/toradex/colibri_t30/colibri_t30.c | 20 ++++++++++++++++++++
 4 files changed, 78 insertions(+)
board/toradex/apalis-tk1/apalis-tk1.c +1 -0
index ccf665b2118..86b10400ffa 100644
@@ -14,6 +14,7 @@
 #include <asm/arch/gpio.h>
 #include <asm/arch/pinmux.h>
 #include <env_internal.h>
+#include <fdt_support.h>
 #include <pci_tegra.h>
 #include <linux/delay.h>
 #include <power/as3722.h>
@@ -99,6 +100,24 @@ int checkboard(void)  #if 

defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) int ft_board_setup(void *blob, struct bd_info *bd) {

board/toradex/apalis-tk1/apalis-tk1.c +20 -0
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/pcie@1003000/pci@2,0/ethernet@0,0",
+                                              "local-mac-address", 
+ enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/pcie@1003000/pci@2,0/pcie@0",
+                                                  
+ "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
        return ft_common_board_setup(blob, bd);  }  #endif diff --git 

a/board/toradex/apalis_t30/apalis_t30.c
b/board/toradex/apalis_t30/apalis_t30.c
index 0396eea56b5..ef71270d9f2 100644

board/toradex/apalis_t30/apalis_t30.c +22 -0
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <log.h>
 #include <asm/arch/gp_padctrl.h>
@@ -16,6 +17,7 @@
 #include <asm/io.h>
 #include <dm.h>
 #include <i2c.h>
+#include <fdt_support.h>
 #include <pci_tegra.h>
 #include <linux/delay.h>
 #include "../common/tdx-common.h"
@@ -54,6 +56,24 @@ int checkboard(void)  #if defined(CONFIG_OF_LIBFDT) 
 && defined(CONFIG_OF_BOARD_SETUP)  int ft_board_setup(void *blob, 
 struct bd_info *bd)  {
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/pcie@3000/pci@3,0/ethernet@0,0",
+                                              "local-mac-address", 
+ enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/pcie@3000/pci@3,0/pcie@0",
+                                                  
+ "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
        return ft_common_board_setup(blob, bd);  }  #endif diff --git 

a/board/toradex/colibri_t20/colibri_t20.c
b/board/toradex/colibri_t20/colibri_t20.c
index 73ef4d2db32..c58d2021cd3 100644

board/toradex/colibri_t20/colibri_t20.c +21 -0
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <log.h>
 #include <asm/arch/clock.h>
@@ -81,6 +82,24 @@ int checkboard(void)  #if defined(CONFIG_OF_LIBFDT) 
 && defined(CONFIG_OF_BOARD_SETUP)  int ft_board_setup(void *blob, 
 struct bd_info *bd)  {
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/usb@7d004000/ethernet@1",
+                                              "local-mac-address", 
+ enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/usb@7d004000/asix@1",
+                                                  
+ "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
        return ft_common_board_setup(blob, bd);  }  #endif diff --git 

a/board/toradex/colibri_t30/colibri_t30.c
b/board/toradex/colibri_t30/colibri_t30.c
index 20cbb75a365..b6b004669c2 100644

board/toradex/colibri_t30/colibri_t30.c +22 -0
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <env.h>
 #include <init.h>
 #include <asm/arch/gp_padctrl.h>
 #include <asm/arch/pinmux.h>
@@ -12,6 +13,7 @@
 #include <asm/arch-tegra/tegra.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <fdt_support.h>
 #include <i2c.h>
 #include <linux/delay.h>
 #include "pinmux-config-colibri_t30.h"
@@ -36,6 +38,24 @@ int checkboard(void)  #if defined(CONFIG_OF_LIBFDT) 
 && defined(CONFIG_OF_BOARD_SETUP)  int ft_board_setup(void *blob, 
 struct bd_info *bd)  {
+       u8 enetaddr[6];
+
+       /* MAC addr */
+       if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
+               int err = fdt_find_and_setprop(blob,
+                                              "/usb@7d004000/ethernet@1",
+                                              "local-mac-address", 
+ enetaddr, 6, 0);
+
+               /* Older device trees might have used a different node name */
+               if (err < 0)
+                       err = fdt_find_and_setprop(blob,
+                                                  "/usb@7d004000/asix@1",
+                                                  
+ "local-mac-address", enetaddr, 6, 0);
+
+               if (err >= 0)
+                       puts("   MAC address updated...\n");
+       }
+
        return ft_common_board_setup(blob, bd);  }  #endif