Jump to content
  • 0

How to obtain the MAC address of Zybo


Sophia_123

Question

1 answer to this question

Recommended Posts

Posted

Hi,

there are two cases one for "bare metal" one for "linux" :

"bare metal"

Add this code to FSL bootloader (this code from Digilent source), Zybo board have I2C eeprom that have unique MAC address:

/******************************************************************************
* This function is the hook which will be called  before the FSBL does a handoff
* to the application. The user can add all the customized code required to be
* executed before the handoff to this routine.
*
* @param None
*
* @return
*		- XST_SUCCESS to indicate success
*		- XST_FAILURE.to indicate failure
*
****************************************************************************/
u32 FsblHookBeforeHandoff(void)
{
	u32 Status;

	Status = XST_SUCCESS;

	/*
	 * User logic to be added here.
	 * Errors to be stored in the status variable and returned
	 */
	fsbl_printf(DEBUG_INFO,"In FsblHookBeforeHandoff function \r\n");

	/* Read Out MAC Address */
	{
		int Status;
		XIicPs Iic;
		XIicPs_Config *Iic_Config;
		XEmacPs Emac;
		XEmacPs_Config *Mac_Config;

		unsigned char mac_addr[6];
		int i = 0;

		fsbl_printf(DEBUG_GENERAL,"Look Up I2C Configuration\n\r");
		Iic_Config = XIicPs_LookupConfig(XPAR_PS7_I2C_0_DEVICE_ID);
		if(Iic_Config == NULL) {
			return XST_FAILURE;
		}

		fsbl_printf(DEBUG_GENERAL,"I2C Initialization\n\r");
		Status = XIicPs_CfgInitialize(&Iic, Iic_Config, Iic_Config->BaseAddress);
		if(Status != XST_SUCCESS) {
			return XST_FAILURE;
		}

		fsbl_printf(DEBUG_GENERAL,"Set I2C Clock\n\r");
		XIicPs_SetSClk(&Iic, 200000);

		mac_addr[0] = 0xFA;

		fsbl_printf(DEBUG_GENERAL,"Set Memory Read Address\n\r");
		XIicPs_MasterSendPolled(&Iic, mac_addr, 1, 0x50);
		while(XIicPs_BusIsBusy(&Iic));
		fsbl_printf(DEBUG_GENERAL,"Get Mac Address\n\r");
		XIicPs_MasterRecvPolled(&Iic, mac_addr, 6, 0x50);
		while(XIicPs_BusIsBusy(&Iic));

		fsbl_printf(DEBUG_GENERAL,"MAC Addr: ");
		for(i = 0; i < 6; i++) {
			fsbl_printf(DEBUG_GENERAL,"%02x ", mac_addr[i]);
		}
		fsbl_printf(DEBUG_GENERAL,"\n\r");

		fsbl_printf(DEBUG_GENERAL,"Look Up Emac Configuration\n\r");
		Mac_Config = XEmacPs_LookupConfig(XPAR_PS7_ETHERNET_0_DEVICE_ID);
		if(Mac_Config == NULL) {
			return XST_FAILURE;
		}

		fsbl_printf(DEBUG_GENERAL,"Emac Initialization\n\r");
		Status = XEmacPs_CfgInitialize(&Emac, Mac_Config, Mac_Config->BaseAddress);
		if(Status != XST_SUCCESS){
			return XST_FAILURE;
		}

		fsbl_printf(DEBUG_GENERAL,"Set Emac MAC Address\n\r");
		Status = XEmacPs_SetMacAddress(&Emac, mac_addr, 1);
		if(Status != XST_SUCCESS){
			return XST_FAILURE;
		}

		fsbl_printf(DEBUG_GENERAL,"Verify Emac MAC Address\n\r");
		XEmacPs_GetMacAddress(&Emac, mac_addr, 1);
		if(Status != XST_SUCCESS){
			return XST_FAILURE;
		}
	}

          return (Status);
}

"linux"

To get actual MAC address

zybo:~# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:11:22:33:44:55
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:333436242 errors:0 dropped:111 overruns:0 frame:0
          TX packets:166776007 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3075863808 (2.8 GiB)  TX bytes:462587297 (441.1 MiB)
          Interrupt:54 Base address:0xb000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:432 errors:0 dropped:0 overruns:0 frame:0
          TX packets:432 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:31127 (30.3 KiB)  TX bytes:31127 (30.3 KiB)

To set new MAC address

zybo:~# ifconfig eth0 hw ether 00:11:22:33:44:55

I hope I was helpful.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...