Changing the device MAC address

gonium edited this page Mar 2, 2012 · 8 revisions
Clone this wiki locally

If you have a device without an "official" MAC address, you might want to change the preprogrammed MAC address. A MAC address is a 48bit identifier and unique to the device. For example, CC:B5:5A:0B:03:01 is an official MAC address of the Fraunhofer ITWM. (Note: If you're with ITWM, you can get a development address from Mathias. All other people: DON'T USE THIS ONE!)

For 6LoWPAN, the MAC address needs to be entered in 64bit-format. Therefore, the MAC address needs to be adjusted as follows:

  1. Put the padding bytes 0xFF:0xFE in the middle of the MAC address, i.e. CC:B5:5A:FF:FE:0B:03:01
  2. Change the first two bytes to 0x02 (this is defined to be a 6LoWPAN MAC): 02:B5:5A:FF:FE:0B:03:01

The MAC address is stored in the EEPROM and can be changed like this:

The single-byte write eeprom solution (recommended)

If you see the message

warning: OCDEN fuse not programmed, single-byte EEPROM updates not possible

you have to set the OCDEN fuse in order to enable the EEPROM single-byte updates:

avrdude -c jtag2 -P usb -p atmega1284p -U hfuse:w:0x10:m -F

Then, you can use the terminal mode of avrdude to update the values:

avrdude -p atmega1284p -P usb -c jtagmkII -t -F to enter terminal mode

dump eeprom 1 8 to view the current MAC address

write eeprom 1 <Byte1> ... <Byte8> to set a new MAC address


write eeprom 7 <Byte7> <Byte8> if you only want to change the last two bytes

Note: The byte values have to be in decimal format! If you want to write the address using hexadecimal values, you need to prepend 0x. Example:

write eeprom 1 0x02 0xb5 0x5a 0xff 0xfe 0x0b 0x03 0x01

for writing the MAC address 02:b5:5a:ff:fe:0b:03:01

The EEP image write way

Writing the eeprom using avrdude -p atmega1284p -P usb -c jtagmkII -U eeprom:w:Bootloader.eep doesn't seem to work anymore. TODO: Needs moar evaluation.

Recovering a board

Sometimes, it happens that the EEPROM of a board cannot be written. Avrdude reports write errors in specific EEPROM cells. To change the EEPROM content on such a board, you have to erase the EEPROM completely and upload a (patched) backup of the previous content. Here's how:

First, you have to make a raw copy of the EEPROM in a local file:

$ avrdude -p atmega1284p -P usb -c dragon_jtag -F -U eeprom:r:eeprom.raw:r

You can edit this file using a hex editor, i.e.

$ ghex2 eeprom.raw

Then, unset the EESAVE fuse. This fuse protects the EEPROM from being deleted when the chip is erased. By unsetting it, you allow EEPROM deletion.

$ avrdude -c dragon_jtag -P usb -F -p atmega1284p -U hfuse:w:0x98:m

Now delete the chip:

$ avrdude -c dragon_jtag -P usb -F -p atmega1284p -e

Write the (edited) EEPROM image back into the chip:

$ avrdude -p atmega1284p -P usb -F -c dragon_jtag -U eeprom:w:eeprom.raw:r

Last step: Protect the EEPROM from being deleted again.

$ avrdude -c dragon_jtag -P usb -F -p atmega1284p -U hfuse:w:0x90:m