[U-Boot] [PATCH 1/2] board: advantech: dms-ba16: GBE MAC addr support in kernel bootargs

Ken Lin yungching0725 at gmail.com
Fri Aug 24 22:15:57 UTC 2018


Add configurable support for loading the GBE MAC from the Q7 SPI-NOR
and add it to the kernel bootargs.

Signed-off-by: Ken Lin <yungching0725 at gmail.com>
---
 board/advantech/dms-ba16/Kconfig     |  3 +++
 board/advantech/dms-ba16/dms-ba16.c  | 19 +++++++++++++++++++
 include/configs/advantech_dms-ba16.h | 13 +++++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/board/advantech/dms-ba16/Kconfig b/board/advantech/dms-ba16/Kconfig
index 040eb866b5..f5d9f61f13 100644
--- a/board/advantech/dms-ba16/Kconfig
+++ b/board/advantech/dms-ba16/Kconfig
@@ -28,4 +28,7 @@ config SYS_SOC
 config SYS_CONFIG_NAME
 	default "advantech_dms-ba16"
 
+config QSPI_MACADDR
+	string "0xD0000"
+
 endif
diff --git a/board/advantech/dms-ba16/dms-ba16.c b/board/advantech/dms-ba16/dms-ba16.c
index 09620435d3..bfc4e2319e 100644
--- a/board/advantech/dms-ba16/dms-ba16.c
+++ b/board/advantech/dms-ba16/dms-ba16.c
@@ -26,6 +26,8 @@
 #include <i2c.h>
 #include <input.h>
 #include <pwm.h>
+#include <spi.h>
+#include <spi_flash.h>
 DECLARE_GLOBAL_DATA_PTR;
 
 #define NC_PAD_CTRL (PAD_CTL_PUS_100K_UP |	\
@@ -584,6 +586,21 @@ void pmic_init(void)
 
 }
 
+int load_mac_addrs(void)
+{
+    struct spi_flash *flash;
+    char mac_addrs[31] = CONFIG_QSPI_MACADDR;
+
+    flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
+	CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
+
+    if (strcmp(mac_addrs, "") && !spi_flash_read(flash, simple_strtoul(mac_addrs, NULL, 16), sizeof(mac_addrs), mac_addrs)) {
+	env_set("fec_addr", mac_addrs);
+    }
+
+    return 0;
+}
+
 int board_late_init(void)
 {
 #ifdef CONFIG_CMD_BMODE
@@ -609,6 +626,8 @@ int board_late_init(void)
 	pwm_enable(0);
 #endif
 
+    load_mac_addrs();
+
 #ifdef CONFIG_SATA
 	setup_ba16_sata();
 #endif
diff --git a/include/configs/advantech_dms-ba16.h b/include/configs/advantech_dms-ba16.h
index 0c9de6125d..bffd9b50a9 100644
--- a/include/configs/advantech_dms-ba16.h
+++ b/include/configs/advantech_dms-ba16.h
@@ -15,8 +15,11 @@
 
 #define CONFIG_MXC_UART_BASE	UART4_BASE
 #define CONSOLE_DEV	"ttymxc3"
+#if defined(CONFIG_QSPI_MACADDR)
+#define CONFIG_EXTRA_BOOTARGS	"panic=10 ${macaddrs}"
+#else
 #define CONFIG_EXTRA_BOOTARGS	"panic=10"
-
+#endif
 #define CONFIG_BOOT_DIR	""
 #define CONFIG_LOADCMD "fatload"
 #define CONFIG_RFSPART "2"
@@ -111,6 +114,12 @@
 			"sf write $loadaddr 0x400 $filesize; " \
 			"echo 'U-Boot upgraded. Please reset'; " \
 		"fi\0" \
+    "safe_macaddrs=" \
+	"if test -n ${fec_addr}; then " \
+		"setenv macaddrs fec.macaddr=${fec_addr}; " \
+	"else " \
+		"setenv macaddrs; " \
+	"fi;\0" \
 	"setargs=setenv bootargs console=${console},${baudrate} " \
 		"root=/dev/${rootdev} rw rootwait " CONFIG_EXTRA_BOOTARGS "\0" \
 	"loadbootscript=" \
@@ -129,7 +138,7 @@
 			"fi; " \
 		"fi;\0" \
 	"doboot=echo Booting from ${dev}:${devnum}:${partnum} ...; " \
-		"run setargs; " \
+		"run safe_macaddrs; run setargs; " \
 		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
 			"if run loadfdt; then " \
 				"bootm ${loadaddr} - ${fdt_addr}; " \
-- 
2.17.1



More information about the U-Boot mailing list