UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
16,354 Views
Registered: ‎10-30-2009

Perm changing the MAC address

Jump to solution

Hey,

 

I was wondering how I would go about changing the MAC address permanently.   It is a value set in a known register before the kernel boots and I would like to reflect that in the kernel after boot.  Is this some setting in the dts file or a configurable param in the kernel?

 

I am running an ml507 board (and eventually a custom board) and the linux-2.6 kernel (with a buildroot generated initramfs).  

 

I could probably write a little program that would read the memory address, take the interface down, change it, and put it back.  But that seems so....cluuuuuuggggyyyyy.

 

Any advice would be really helpful!!  Thanks again! this board has been saving my life!!!

0 Kudos
1 Solution

Accepted Solutions
Newbie fossinater
Newbie
11,589 Views
Registered: ‎03-05-2010

Re: Perm changing the MAC address

Jump to solution

I was able to solve the problem by doing a few things.

 

First in dev.c: the function dev_ifsioc does find the SIOCSIFHWADDR so it calls a function, which in turn checks to see if the following function exists:

ops->ndo_set_mac_address

 

since this is never defined, it returns that the operation is not supported and never gets to the other function mentioned above: xemaclite_ioctl

 

So I added a function in xlltemac_main.c

static int xenet_set_mac_addr (struct net_device *dev, struct sockaddr *sa) { /* configure new MAC address */ struct net_local *lp = (struct net_local *) netdev_priv(dev); // copy usr space data to kernel ( the mac addr ) memcpy(dev->dev_addr, sa->sa_data, IFHWADDRLEN); if (_XLlTemac_SetMacAddress(&lp->Emac, dev->dev_addr) != XST_SUCCESS) { dev_err(&lp->ndev->dev, "SIOCSIFHWADDR\n"); return -EFAULT; } return 0; }

 

 

and then set the following in the definition of the xilinx_netdev_ops

 

.ndo_set_mac_address = xenet_set_mac_addr,

 

static struct net_device_ops xilinx_netdev_ops = { .ndo_open = xenet_open, .ndo_stop = xenet_close, .ndo_set_mac_address = xenet_set_mac_addr, .ndo_start_xmit = 0, .ndo_do_ioctl = xenet_ioctl, .ndo_change_mtu = xenet_change_mtu, .ndo_tx_timeout = xenet_tx_timeout, .ndo_get_stats = xenet_get_stats, };

 

11 Replies
Xilinx Employee
Xilinx Employee
16,339 Views
Registered: ‎09-10-2008

Re: Perm changing the MAC address

Jump to solution

The mac address is in the device tree. The device tree generator creates it each time you generate a device tree, part of the mac address is xilinx specific, and part is random so that multiple boards don't get the same mac address.

 

The mac address for the board is stored in the i2c eeprom on the board, but the kernel itself does not pull it out. U-boot does pull the mac address from the i2c eeprom and alters the device tree before passing to the kernel.  It's viewed as a boot loader job to do that, but not the kernel.

 

Hope that helps.

0 Kudos
16,337 Views
Registered: ‎10-30-2009

Re: Perm changing the MAC address

Jump to solution

That does help a TON!

 

The question arrises though, what if I am not using uboot?  It would be then my responsibility to extract the MAC from the known memory location (in the ml507 - the EEPROM) and the alter the dts file, before launching the kernel?

 

I have to write a bootloader that will get the kernel elf file from a known location (via a weird exchange), write it into memory, and then "boot" the kernel (change the PC to be at the start of the memory location and release the PPC from reset).  

0 Kudos
Xilinx Employee
Xilinx Employee
16,333 Views
Registered: ‎09-10-2008

Re: Perm changing the MAC address

Jump to solution

You're right, you're job to get mac address out of i2c eeprom, you could use edk standalone drivers to do that probably.

 

I haven't looked at code that messes with device tree before passing it to the kernel, but my guess is it might be a pain. You could get an idea for that looking at the u-boot code.

 

Hope that helps.

0 Kudos
16,227 Views
Registered: ‎10-30-2009

Re: Perm changing the MAC address

Jump to solution

Hey,

 

So I've gone back and forth with this whole MAC address question.  I've decided that the best (and easiest) way to do this is during the boot (in the rcS Scripts) is to have a script that will change the MAC there. 

 

The way that I am trying to do this is:

ifconfig eth0 down ifconfig eth0 hw ether 00:11:22:33:44:55 ifconfig eth0 up

 

This is a bandaid for what I would need to do.  I have retreived and formated the MAC already.

 

The problem is that when doing this I get:

/etc/network # ifconfig eth0 hw ether 00:11:22:33:44:55
ifconfig: SIOCSIFHWADDR: Operation not supported
/etc/network #

 Any ideas on what causes this?  or how to get it supported?

Thanks again!


 

0 Kudos
Anonymous
Not applicable
16,218 Views

Re: Perm changing the MAC address

Jump to solution

Looks like that operation is not supported by the ll_temac driver.  To do that, you'll need to modify the driver to add support for the SIOCSIFHWADDR operation and have it call  _XLlTemac_SetMacAddress to update the MAC address.

 

The other thing you can do is have your bootloader read the IIC and write the Mac address - then modify the ll_temac driver so that if there is no mac address entry in the .dts, it won't try to write the mac address..  Then remove the mac address from the .dts.

 

Both are hacks, but they'll work if you just need to get over the hump..  Ok so may be the first one isn't a hack - it should probably be supported in the driver.. 

 

Terry

 

Message Edited by toneal on 02-26-2010 03:06 PM
0 Kudos
16,211 Views
Registered: ‎10-30-2009

Re: Perm changing the MAC address

Jump to solution

I prefer to fix the driver, so I went into the driver section of the kernel (drivers/net/xilinx_lltemac/xlltemac_main.c) and added these lines to the xenet_ioctl function:

 

 

3152 case SIOCSIFHWADDR: /* configure new MAC address */
3153 if (_XLlTemac_SetMacAddress(&lp->Emac, dev->dev_addr) != XST_SUCCESS) {
3154 return -EFAULT;
3155 }
3156 return 0;

 

Yet I still get the same error.  I see it recompile when I rebuild the kernel.

 

  CC      drivers/net/xilinx_lltemac/xlltemac_main.o
  LD      drivers/net/xilinx_lltemac/xilinx_temac.o

 

Am I maybe adding it in the wrong place?  I think that I am having a lot of problems because I don't know what the calling function is ( can't find the ifconfig src....)

 

Sorry I am such a newbie!  Thanks for your help!

 

 

 / # ifconfig eth0 hw ether 11:22:33:44:55:66
ifconfig: SIOCSIFHWADDR: Operation not supported

Message Edited by thelonesquirrely on 02-26-2010 03:18 PM
0 Kudos
Xilinx Employee
Xilinx Employee
16,205 Views
Registered: ‎09-10-2008

Re: Perm changing the MAC address

Jump to solution

It wasn't clear to me from your code below that you copied the h/w mac address from user space to kernel space before setting it.

 

I copied in the function from xilinx_emaclite.c as it does this so you can cheat a little.

 

Thanks. 

 

 

static int xemaclite_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
 struct net_local *lp = (struct net_local *) netdev_priv(dev);
 struct hw_addr_data *hw_addr = (struct hw_addr_data *) &rq->ifr_hwaddr;

 switch (cmd) {
 case SIOCETHTOOL:
  return -EIO;

 case SIOCSIFHWADDR:
  dev_err(&lp->ndev->dev, "SIOCSIFHWADDR\n");

  /* Copy MAC address in from user space */
  copy_from_user((void __force *) dev->dev_addr,
          (void __user __force *) hw_addr,
          IFHWADDRLEN);
  xemaclite_set_mac_address(lp, dev->dev_addr);
  break;
 default:
  return -EOPNOTSUPP;
 }

 return 0;
}

0 Kudos
16,203 Views
Registered: ‎10-30-2009

Re: Perm changing the MAC address

Jump to solution

You're right!  I forgot that very vital step.....

 

After another take on it I changed it to this:  

3152 case SIOCSIFHWADDR: /* configure new MAC address */ 3153 { 3154 struct hw_addr_data *hw_addr; 3155 hw_addr=(struct hw_addr_data*)&rq->ifr_hwaddr; 3156 printk ("dealing with %d in ioctl", cmd); 3157 3158 if (copy_from_user((void __force*)dev->dev_addr, (void __user __force*)hw_addr, IFHWADDRLEN)) { 3159 return -EFAULT; 3160 } 3161 3162 if (_XLlTemac_SetMacAddress(&lp->Emac, dev->dev_addr) != XST_SUCCESS) { 3163 dev_err(&lp->ndev->dev, "SIOCSIFHWADDR\n"); 3164 return -EFAULT; 3165 } 3166 return 0; 3167 }

 

The problem is that when I issue the cmd: ifconfig eth0 hw ether 11:22:33:44:55:66

 I still get the mesg "ifconfig: SIOCSIFHWADDR: Operation not supported"

 Is it still even getting to my code?  

 

Also I put in that printk and i don't see it appear in my dmesg...am I editing the wrong file (it does get recompiled)?


 

0 Kudos
Xilinx Employee
Xilinx Employee
16,201 Views
Registered: ‎09-10-2008

Re: Perm changing the MAC address

Jump to solution

I'm not an expert on this, but it looks pretty simple.

 

Did you verify the file got recompiled?  Look at the date on the *.o files in the driver directory.

 

I can't think of anything else.

0 Kudos
Newbie fossinater
Newbie
11,590 Views
Registered: ‎03-05-2010

Re: Perm changing the MAC address

Jump to solution

I was able to solve the problem by doing a few things.

 

First in dev.c: the function dev_ifsioc does find the SIOCSIFHWADDR so it calls a function, which in turn checks to see if the following function exists:

ops->ndo_set_mac_address

 

since this is never defined, it returns that the operation is not supported and never gets to the other function mentioned above: xemaclite_ioctl

 

So I added a function in xlltemac_main.c

static int xenet_set_mac_addr (struct net_device *dev, struct sockaddr *sa) { /* configure new MAC address */ struct net_local *lp = (struct net_local *) netdev_priv(dev); // copy usr space data to kernel ( the mac addr ) memcpy(dev->dev_addr, sa->sa_data, IFHWADDRLEN); if (_XLlTemac_SetMacAddress(&lp->Emac, dev->dev_addr) != XST_SUCCESS) { dev_err(&lp->ndev->dev, "SIOCSIFHWADDR\n"); return -EFAULT; } return 0; }

 

 

and then set the following in the definition of the xilinx_netdev_ops

 

.ndo_set_mac_address = xenet_set_mac_addr,

 

static struct net_device_ops xilinx_netdev_ops = { .ndo_open = xenet_open, .ndo_stop = xenet_close, .ndo_set_mac_address = xenet_set_mac_addr, .ndo_start_xmit = 0, .ndo_do_ioctl = xenet_ioctl, .ndo_change_mtu = xenet_change_mtu, .ndo_tx_timeout = xenet_tx_timeout, .ndo_get_stats = xenet_get_stats, };

 

Participant jakubon2
Participant
4,113 Views
Registered: ‎04-02-2013

Re: Perm changing the MAC address

Jump to solution

Hi there,

 

Since few years passed from this post, at the moment already mentioned option in Linux:

 

ifconfig eth0 down

ifconfig eth0 hw ether 00:11:22:33:44:55

ifconfig eth0 up

 

is assigning the new MAC address successfully.

 

Ondrej

Ondrej
0 Kudos