News:

Attention: For security reasons,please choose a user name *different* from your login name.
Also make sure to choose a secure password and change it regularly.

Main Menu

TE0720 Reading the MAC Address without using u-boot

Started by dave74321, December 19, 2016, 04:51:55 PM

Previous topic - Next topic

dave74321

The design I wish to run on the TE0720 uses FreeRTOS, with the FSBL generated by Xilinx SDK.  There is no u-boot.
It sets up the Ethernet PHY fine and connects to a web browser fine.

What I still need to sort out is to read out the MAC address from the EEPROM.

How can I communicate with the EEPROM that stores the MAC address (without using the demo u-boot stuff but just by bare metal or RTOS) and where in the EEPROM is the MAC address stored?

Thanks

Oleksandr Kiyenko

Hello,

MAC address read function is implemented in FSBL and then pass to U-Boot via environment. You can found MAC read source code in FSBL file fsbl_hooks.c.

Best regards
Oleksandr Kiyenko

Antti Lukats

Quote from: dave74321 on December 19, 2016, 04:51:55 PM
The design I wish to run on the TE0720 uses FreeRTOS, with the FSBL generated by Xilinx SDK.  There is no u-boot.
It sets up the Ethernet PHY fine and connects to a web browser fine.

What I still need to sort out is to read out the MAC address from the EEPROM.

How can I communicate with the EEPROM that stores the MAC address (without using the demo u-boot stuff but just by bare metal or RTOS) and where in the EEPROM is the MAC address stored?

Thanks

FSBL reads the MAC addresses and WRITES it to the PS ETH Hardware registers also, the u-boot problem comes from the uboot bug that uboot does not honor the MAC address in the IP registers. Linux as example does, if uboot or other second stage bootloader does not override then linux would fetch from IP core registers.

in your bare metal code you can either:

use the MAC address as prefilled by FSBL from the IP core mac address registers, or use the shared memory method as we do to pass the MAC to the uboot.







dave74321

This seems to work fine for me:


In the Xilinx SDK generated FSBL source file fsbl_hooks.c add to function FsblHookBeforeHandoff:

   #include "xparameters.h"
   #include "xemacps.h"
   u16 rval16;
   XEmacPs Emac;
   XEmacPs_Config *Mac_Config;
   unsigned char mac_addr[6];
   int i = 0;
   Mac_Config = XEmacPs_LookupConfig(XPAR_PS7_ETHERNET_0_DEVICE_ID); if(Mac_Config == NULL) { return XST_FAILURE; }
   Status = XEmacPs_CfgInitialize(&Emac, Mac_Config, Mac_Config->BaseAddress); if(Status != XST_SUCCESS){ return XST_FAILURE; }

   fsbl_printf(DEBUG_INFO,"Read out MAC Address bytes from CPLD\r\n");
   Status = XEmacPs_PhyRead(&Emac, 0x1A,  9, &rval16); if(Status != XST_SUCCESS){ return XST_FAILURE; }
   mac_addr[0] = (unsigned char)(rval16 >> 8 );
   mac_addr[1] = (unsigned char)(rval16 & 0xFF);
   Status = XEmacPs_PhyRead(&Emac, 0x1A,  10, &rval16); if(Status != XST_SUCCESS){   return XST_FAILURE; }
   mac_addr[2] = (unsigned char)(rval16 >> 8 );
   mac_addr[3] = (unsigned char)(rval16 & 0xFF);
   Status = XEmacPs_PhyRead(&Emac, 0x1A,  11, &rval16); if(Status != XST_SUCCESS){   return XST_FAILURE; }
   mac_addr[4] = (unsigned char)(rval16 >> 8 );
   mac_addr[5] = (unsigned char)(rval16 & 0xFF);

   fsbl_printf(DEBUG_INFO,"create pointer to OCM to store MAC Address\r\n");
   char *p_env = (char*) 0xFFFFFC04;

   fsbl_printf(DEBUG_INFO,"Store MAC Address to OCM\r\n");
   for(i = 0; i < 6; i++)
   {
      xil_printf("%02x ", mac_addr);
      *p_env = mac_addr;
      p_env++;
   }


Then in the application , e.g. source file main.c, add to function main

   unsigned char mac_addr[6] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };//Temporary MAC Address if using Zedboard

   //The MAC address is stored in the EEPROM on the Trenz module.
   //This is accessed by the CPLD during FSBL.
   //Then during FSBL the MAC Address is retrieved from the CPLD and saved to OCM.
   //Create pointer to the OCM memory where the MAC was stored by FSBL FsblHookBeforeHandoff
   char *p_env = (char*) 0xFFFFFC04;

   xil_printf("MAC Address is: ");
   int i;
   for(i = 0; i < 6; i++)
   {
      mac_addr = *p_env;
      xil_printf("%02x ", mac_addr);
      p_env++;
   }
   //mac_addr is now available for use in this function

Stonebull

Hello!
I know that this post is already fairly old but it is exactly what I was looking for.

I'm using the TE0720 and the Zynq CPU without a Linux OS, instead I use FreeRTOS. I need to retrieve the MAC address and to write it to the FreeRTOS TCP/IP stack on start-up.

I tried the approach expained in the last thread but somehow the OCM address where I store the MAC during the FSBL is always completely cleared when I reach to the application.

I already posted this problem with detailed description in the Xilinx Forum but did not get a helpful response.
Feel free to check it out: https://forums.xilinx.com/t5/Embedded-Development-Tools/Use-OCM-to-share-data-between-FSBL-and-user-application/m-p/1089640/highlight/false#M52892

Does anybody have a clue on what I missed out?

Best Regards,

Stonebull

Addition:

I know that the FSBL from Trenz does write the MAC address to the Ethernet PHY after reading it out from the EEPROM (using: XEmacPs_SetMacAddress(...)). The problem is that when I am in the Application and try to read out the MAC Address that should be stored inside the PHY (using (XEmacPs_GetMacAddress(...)) I get back only zeros. Looks like the PHY is reset during switch from FSBL to application.

Is this the reason for the MAC address to vanish from the PHY?

Thanks,

JH

Hi,
FSBL does not write MAC to PHY.   

TE0720 has a CPLD, which reads a unique MAC from a EEPROM. For communication with CPLD, a MDIO interface was implemented in the CPLD design.
https://wiki.trenz-electronic.de/display/PD/TE0720+CPLD#TE0720CPLD-SCFirmwarever0.02

So Trenz FSBL reads only MAC from EEPROM over the MDIO interface of the CPLD and store it in shared Zynq register. These registers  will be read from Trenz Uboot extensions, so that uboot and linux can use the EEPROM MAC instead of the generated one from petalinux.
https://wiki.trenz-electronic.de/display/PD/TE0720+Test+Board#TE0720TestBoard-zynq_fsbl.1
https://wiki.trenz-electronic.de/display/PD/TE0720+Test+Board#TE0720TestBoard-U-Boot

uboot and linux handle complete communication was the ETH PHY

br
John
So