Fix MAC from U-Boot

NOTE: Altering your MAC address may result in a different IP address being assigned, and conflicts on your network.

NOTE: We recommend using the MAC address that was assigned to your 4Kopen board at all times (look for a sticker).


If you find that your 4Kopen board's MAC address changes on each boot, then it may be necessary to re-program it.

A symptom of this is that the board's IP is different each time it boots as well.


You should be able to locate your MAC address on a sticker on your board - it should be six groups of two hexadecimal digits (0-9, A-F).


The following procedure will re-write the MAC address to the board's SPI flash.

Probe Flash and Disable Write Protection

Probe for devices and then disable write protection for the SPI flash.

NOTE: If you disable write protection (using the mw commands below) and then run sf probe, the flash interface will be misconfigured.

4KOpen> sf probe
SPI is boot device.
FSM SF: Detected ST N25Q256 with sector size 64 KiB, total 32 MiB
4KOpen> mw 0x09230028 0x10
4KOpen> mw 0x09230038 0x10
4KOpen> mw 0x09230044 0x10
4KOpen> mw 0x09230004 0x10

Erase the Region of Flash

Flash can only be erased in full pages (aka sectors), which in this situation means we must erase a full 64 KB page, even though we only need to store ~30 bytes.

Erase the page and confirm (output should be all ones / 0xFF):

4KOpen> sf erase 0xD0000 0x00010000
SF: 65536 bytes @ 0xd0000 Erased: OK
4KOpen> sf read 0x97000000 0xD0000 40

SF: 64 bytes @ 0xd0000 Read: OK
4KOpen> md.b 0x97000000 40
97000000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
97000010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
97000020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
97000030: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................

Write the MAC Address to Flash

Write and confirm:

4KOpen> setenv ethaddr 12:34:56:78:9a:bc
4KOpen> env export -t 0x98000000 ethaddr
4KOpen> sf write 0x98000000 0xD0000 ${filesize}
SF: 29 bytes @ 0xd0000 Written: OK
4KOpen> sf read 0x97000000 0xD0000 ${filesize}

SF: 29 bytes @ 0xd0000 Read: OK
4KOpen> md.b 0x97000000 ${filesize}
97000000: 65 74 68 61 64 64 72 3d 31 32 3a 33 34 3a 35 36 ethaddr=12:34:56
97000010: 3a 37 38 3a 39 61 3a 62 63 0a 00 00 00 :78:9a:bc....

Verify Write

Verify - it's only a small amount of data, but if you'd prefer to run a command than check byte-by-byte:

4KOpen> sf read 0x9A000000 0xD0000 ${filesize}
SF: 29 bytes @ 0xd0000 Read: OK
4KOpen> cmp.b 0x98000000 0x9A000000 ${filesize}
Total of 29 byte(s) were the same