From e7da9fdc996e433a9c9168a1baad0906f21c22d8 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Thu, 1 Sep 2016 23:21:53 +0200 Subject: [PATCH] Add support for reading/storing MAC address in env variable Use ethaddr variable for MAC address. If variable is not set, try to get MAC from defined FLASH offset or if it's not there, use fake/static one. Also, set ethaddr with MAC address from FLASH. If ethaddr variable is set (ex. user saved it in writable env or defined during build), set MAC address based on its value. --- u-boot/board/ar7240/common/common.c | 41 +++++++++++++---------------- u-boot/lib_mips/board.c | 19 ++++++++++++- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/u-boot/board/ar7240/common/common.c b/u-boot/board/ar7240/common/common.c index 3eae060..d4f2c54 100644 --- a/u-boot/board/ar7240/common/common.c +++ b/u-boot/board/ar7240/common/common.c @@ -20,11 +20,11 @@ #define CONFIG_BOARD_CUSTOM_STRING "Unknown/OEM" #endif -#define ALIGN_SIZE "8" +#define ALIGN_SIZE "8" DECLARE_GLOBAL_DATA_PTR; -static u32 mac_is_not_valid = 1; +static u32 mac_is_not_valid = 0; /* * Put QCA SOC name, version and revision in buffer @@ -127,9 +127,9 @@ void print_board_info(void) /* tCL-tRCD-tRP-tRAS latency */ printf("CL%d-%d-%d-%d\n", qca_dram_cas_lat(), - qca_dram_trcd_lat(), - qca_dram_trp_lat(), - qca_dram_tras_lat()); + qca_dram_trcd_lat(), + qca_dram_trp_lat(), + qca_dram_tras_lat()); /* SPI NOR FLASH sizes and types */ printf("%" ALIGN_SIZE "s ", "FLASH:"); @@ -159,34 +159,30 @@ void print_board_info(void) #if (SOC_TYPE & QCA_AR934X_SOC) |\ (SOC_TYPE & QCA_QCA955X_SOC) if (!qca_pcie0_in_ep_mode()) { - if (qca_pcie_dev_info(0, &vid, &did)) { + if (qca_pcie_dev_info(0, &vid, &did)) printf("%04X:%04X", vid, did); - } else { + else puts("no device"); - } } else { puts("EP mode"); } #elif (SOC_TYPE & QCA_QCA953X_SOC) - if (qca_pcie_dev_info(0, &vid, &did)) { + if (qca_pcie_dev_info(0, &vid, &did)) printf("%04X:%04X", vid, did); - } else { + else puts("no device"); - } #endif #if (SOC_TYPE & QCA_QCA956X_SOC) - if (qca_pcie_dev_info(1, &vid, &did)) { + if (qca_pcie_dev_info(1, &vid, &did)) printf("%04X:%04X", vid, did); - } else { + else puts("no device"); - } #elif (SOC_TYPE & QCA_QCA955X_SOC) - if (qca_pcie_dev_info(1, &vid, &did)) { + if (qca_pcie_dev_info(1, &vid, &did)) printf(", %04X:%04X", vid, did); - } else { + else puts(", no device"); - } #endif puts("\n"); @@ -197,11 +193,10 @@ void print_board_info(void) bd->bi_enetaddr[0],bd->bi_enetaddr[1], bd->bi_enetaddr[2], bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]); - if (mac_is_not_valid) { + if (mac_is_not_valid) puts(" (fixed)\n"); - } else { + else puts("\n"); - } /* System clocks */ printf("%" ALIGN_SIZE "s CPU/RAM/AHB/SPI/REF\n", "CLOCKS:"); @@ -238,13 +233,13 @@ void macaddr_init(u8 *mac_addr) * U/L bit == 0 -> Burned-In-Address (BIA) MAC address */ if (CHECK_BIT((buffer[0] & 0xFF), 0) != 0 || - CHECK_BIT((buffer[0] & 0xFF), 1) != 0) { + CHECK_BIT((buffer[0] & 0xFF), 1) != 0) { memcpy(buffer, fixed_mac, 6); - } else { - mac_is_not_valid = 0; + mac_is_not_valid = 1; } #else memcpy(buffer, fixed_mac, 6); + mac_is_not_valid = 1; #endif memcpy(mac_addr, buffer, 6); diff --git a/u-boot/lib_mips/board.c b/u-boot/lib_mips/board.c index 0af5981..7723c23 100644 --- a/u-boot/lib_mips/board.c +++ b/u-boot/lib_mips/board.c @@ -310,8 +310,10 @@ void board_init_r(gd_t *id, ulong dest_addr) #ifndef CFG_ENV_IS_NOWHERE extern char *env_name_spec; #endif + char buf[20]; bd_t *bd; char *s; + int i; gd = id; @@ -406,7 +408,22 @@ void board_init_r(gd_t *id, ulong dest_addr) #endif /* Init MAC address in board data info */ - macaddr_init(bd->bi_enetaddr); + if ((s = getenv("ethaddr")) != NULL && strlen(s) == 17) { + /* Use the one from env */ + for (i = 0; i < 6; i++) + bd->bi_enetaddr[i] = + simple_strtoul((char *)(s + (i * 3)), NULL, 16); + } else { + /* Use the one provided by board func */ + macaddr_init(bd->bi_enetaddr); + + /* And revrite it to env variable */ + for (i = 0; i < 6; i++) + sprintf((char *)(buf + (i * 3)), "%02X%c", + bd->bi_enetaddr[i], i < 5 ? ':' : '\0'); + + setenv("ethaddr", buf); + } /* Print some information about board */ print_board_info(); -- 2.25.1