summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManel Caro <mcaro@iseebcn.com>2019-04-03 09:33:08 +0200
committerManel Caro <mcaro@iseebcn.com>2019-04-03 09:33:36 +0200
commitff86a6ad2e57798697d4211dec8b454c592da3de (patch)
treef92e6684399546c27c16fc1b9eb33b8b208327b7
parent042a7cb1e4163b6811f3859af308ca13c1ec9390 (diff)
downloadu-boot-imx-ff86a6ad2e57798697d4211dec8b454c592da3de.zip
u-boot-imx-ff86a6ad2e57798697d4211dec8b454c592da3de.tar.gz
u-boot-imx-ff86a6ad2e57798697d4211dec8b454c592da3de.tar.bz2
IGEP0046: Eeprom rework
-rw-r--r--board/isee/common/igep_common.h19
-rw-r--r--board/isee/common/igep_eeprom.h1
-rw-r--r--board/isee/igep0046/igep0046.c81
3 files changed, 69 insertions, 32 deletions
diff --git a/board/isee/common/igep_common.h b/board/isee/common/igep_common.h
index 17ec5dd..6a9829a 100644
--- a/board/isee/common/igep_common.h
+++ b/board/isee/common/igep_common.h
@@ -4,26 +4,19 @@
* Common resources for igep boards
*
* Author: Jose Miguel Sanchez Sanabria <jsanabria@iseebcn.com>
- *
+ * Author: Manel Caro <mcaro@iseebcn.com>
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __COMMON_HEADER__
#define __COMMON_HEADER__
-#define IGEP_MAGIC_ID 0x6D6A6DE4
-
struct __attribute__((packed)) igep_mf_setup {
- u32 magic_id; /* eeprom magic id */
- u32 crc32; /* eeprom crc32 */
- char board_uuid [36]; /* board identifier */
- char board_pid [16]; /* product identifier */
- char model [8]; /* board model */
- char variant [9]; /* board version */
- char manf_of[6]; /* manufacturer order of fabrication */
- char manf_timestamp[19]; /* manufacturer timestamp */
- uchar bmac0[17]; /* MAC 0 - default */
- uchar bmac1[17]; /* MAC 1 */
+ u32 magic_id; /* eeprom magic id */
+ u32 crc32; /* eeprom crc32 */
+ char board_uuid [37]; /* board identifier */
+ uchar bmac0[6]; /* MAC 0 - default */
+ uchar bmac1[6]; /* MAC 1 */
};
#endif
diff --git a/board/isee/common/igep_eeprom.h b/board/isee/common/igep_eeprom.h
index db56247..dfbf78c 100644
--- a/board/isee/common/igep_eeprom.h
+++ b/board/isee/common/igep_eeprom.h
@@ -14,4 +14,5 @@
int eeprom_write_setup (uint8_t s_addr, const char* data, u32 size);
int eeprom_read_setup (uint8_t s_addr, char* data, u32 size);
int check_eeprom (void);
+
#endif
diff --git a/board/isee/igep0046/igep0046.c b/board/isee/igep0046/igep0046.c
index 2843de6..cdb6174 100644
--- a/board/isee/igep0046/igep0046.c
+++ b/board/isee/igep0046/igep0046.c
@@ -4,6 +4,7 @@
* Source file for IGEP0046 board
*
* Author: Jose Miguel Sanchez Sanabria <jsanabria@iseebcn.com>
+ * Author: Manel Caro <mcaro@iseebcn.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
@@ -181,11 +182,19 @@ static iomux_v3_cfg_t const init_pads[] =
MX6_PAD_CSI0_DAT7__GPIO5_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL),
#endif
};
-#define STATION 0x01
-const uchar igep_mac0 [6] = { 0x02, 0xBA, 0xD0, 0xBA, 0xD0, STATION };
-uchar enetaddr[6];
+
+/* static unsigned int board_rev = 0; */
static int igep_eeprom_valid = 0;
-static struct igep_mf_setup igep0046_eeprom_config;
+
+#define IGEP_MAGIC_ID 0x78FC110E
+
+static struct igep_mf_setup igep0046_eeprom_config = {
+ .magic_id = IGEP_MAGIC_ID,
+ .crc32 = 0,
+ .board_uuid = "00000000-0000-0000-0000-000000000000",
+ .bmac0 = { 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ .bmac1 = { 0x0E, 0x00, 0x00, 0x00, 0x00, 0x01 },
+};
/* I2C MUX */
#ifdef CONFIG_SYS_I2C
@@ -379,24 +388,23 @@ int board_phy_config(struct phy_device *phydev)
static int get_mac_address (void)
{
- // MAC are 17 ASCII characters so we need to work it out a bit
- int i = 0;
- uchar ans[6];
+ uchar enetaddr[6];
- if(igep_eeprom_valid){
- for (i = 0; i < 6; i++){
- ans[i] = parse_char(igep0046_eeprom_config.bmac0[(i*3)]) * 0x10 + parse_char(igep0046_eeprom_config.bmac0[((i*3)+1)]);
- }
- memcpy(enetaddr, ans, 6);
- //memcpy(enetaddr, igep_mac0, 6);
- }else{
- memcpy(enetaddr, igep_mac0, 6);
+ /* Check if the enviroment have ethaddr defined */
+ if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
+ memcpy(enetaddr, igep0046_eeprom_config.bmac0, 6);
}
+
+ if (!is_valid_ethaddr(enetaddr)){
+ printf("MAC Address: Error\n");
+ return -1;
+ }
+
return eth_setenv_enetaddr("ethaddr", enetaddr);
}
int board_eth_init(bd_t *bis)
-{
+{
get_mac_address();
setup_iomux_enet();
#ifdef CONFIG_FEC_MXC
@@ -410,6 +418,35 @@ int checkboard(void)
return 0;
}
+static int load_eeprom (void)
+{
+ int result = -1;
+ igep_eeprom_valid = 0;
+ if(check_eeprom() != 0)
+ printf("eeprom: not found\n");
+ else{
+ struct igep_mf_setup eeprom_cfg;
+ /* Read configuration from eeprom */
+ if(!eeprom46_read_setup(0, (char*) &eeprom_cfg, sizeof(struct igep_mf_setup))){
+ /* if(!eeprom_read_setup(0, (char*) &igep00x0_eeprom_config, sizeof(struct igep_mf_setup))){ */
+ u32 crc_save_value = 0;
+ crc_save_value = eeprom_cfg.crc32;
+ eeprom_cfg.crc32=0;
+ u32 crc_value = crc32(0, (const unsigned char*) &eeprom_cfg, sizeof(struct igep_mf_setup));
+ /* Verify crc32 */
+ if((crc_save_value == crc_value) && (eeprom_cfg.magic_id == IGEP_MAGIC_ID)){
+ memcpy(&igep0046_eeprom_config, &eeprom_cfg, sizeof(struct igep_mf_setup));
+ igep_eeprom_valid = 1;
+ result = 0;
+ printf("eeprom: crc32 OK! Loading mac from eeprom\n");
+ }
+ else
+ printf("eeprom: crc32 Failed, using defaults\n");
+ }
+ }
+ return result;
+}
+
int board_early_init_f(void)
{
setup_iomux_uart();
@@ -421,12 +458,12 @@ int board_early_init_f(void)
gpio_direction_output(IMX_GPIO_NR(4, 19), 1);
gpio_direction_output(IMX_GPIO_NR(4, 20), 0);
gpio_direction_output(IMX_GPIO_NR(4, 17), 1);
+
return 0;
}
int board_init(void)
-{
-
+{
#ifdef CONFIG_BASE0040
reset_audio();
#endif
@@ -437,6 +474,10 @@ int board_init(void)
mdelay(1);
#endif
+ /* load eeprom configuration */
+ load_eeprom();
+
+
#ifdef CONFIG_BASE0040
reset_usb_hub();
#endif
@@ -481,11 +522,12 @@ static inline unsigned int pcb_version(void)
int board_late_init(void)
{
+#ifdef __notdef
u32 crc_value = 0;
u32 crc_save_value;
if(check_eeprom() != 0){
- printf("EEPROM: not found\n");
+ printf("EEPROM: not found\n");
}else{
/* Read configuration from eeprom */
if(eeprom46_read_setup(0, (char*) &igep0046_eeprom_config, sizeof(struct igep_mf_setup)))
@@ -518,6 +560,7 @@ int board_late_init(void)
igep_eeprom_valid = 1;
}
}
+#endif
checkboard();
switch (pcb_version()) {