User avatar
AirRietveld
Posts: 26
Joined: Tue Jun 24, 2014 1:53 pm
Location: Groningen
Contact: Website

ENC28J60 fixed MAC with CPU ID

Mon Jul 10, 2017 1:33 pm

I'm using Pi Zero's with a ENC28J60. It's know that this causes random MAC addresses, and there's a couple of fixes.

I rather wouldn't use

Code: Select all

#!/bin/bash
raspberry="B8:27:EB:"
cpuid=$(cat /proc/cpuinfo | grep Serial | cut -c 21-26 | sed 's/\(..\)/\1:/g')
ifconfig eth0 hw ether $raspberry$cpuid
If I'm correct this can cause the MAC address to be random for a short wile when it's booting (?).

So I rather use this method with setmac.service:

Code: Select all

[Unit]
Description=DSet the MAC address for the ENC28J60 enet adapter at eth0
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device

[Service]
Type=oneshot
ExecStart=/sbin/ip link set dev eth0 address 00:00:00:00:00:00
ExecStart=/sbin/ip link set dev eth0 up

[Install]
WantedBy=multi-user.target
But... this uses a fixed MAC address. So I'm looking for a way to combine the MAC address generator from the first example with the fixed address in the second example. I've tried various ways to do this, but it doesn't seem to be possible, at least not for me. Does someone know how to combine the MAC address generator part with the code in setmac.service?

Thank you in advance.

Rallyefahrer
Posts: 3
Joined: Fri Nov 02, 2012 1:41 pm

Re: ENC28J60 fixed MAC with CPU ID

Sun Mar 18, 2018 4:28 pm

Hi,

this workaround works for me, but do you have an idea, why the enc28j60 driver generates a random MAC address ? I tried to readout the permanent MAC adress with machhanger, but it fails:

Code: Select all

sudo macchanger -s eth0
Current MAC:   7e:2d:91:ca:fd:d0 (unknown)
Permanent MAC: 00:00:00:00:00:00 (XEROX CORPORATION)
Is there maybe a bug in the enc28j60 driver, which doesn't readout the MAC correctly from the corresp. registers on the enc28j60 ?

sotto
Posts: 1
Joined: Tue Mar 20, 2018 10:05 am

Re: ENC28J60 fixed MAC with CPU ID

Tue Mar 20, 2018 10:38 am

Rallyefahrer wrote:
Sun Mar 18, 2018 4:28 pm
Is there maybe a bug in the enc28j60 driver, which doesn't readout the MAC correctly from the corresp. registers on the enc28j60 ?
Contrary to the datasheet where it says "Integrated MAC and 10BASE-T PH" the ENC28J60 does not have a MAC address when it is manufactured.
The enc424j600 and enc624j600 models have.
In those tech specs "factory preprogrammed unique MAC address" is listed as a feature.

Dont know if the newer ones work under raspbian. Have not seen an overlay file for it, but kernel drivers.

Anyway the working solution i´ve come up with is a combination of a startup service like yours which invokes a bash script.

/lib/systemd/system/setmac.service

Code: Select all

[Unit]
Description=DSet the MAC address for the ENC28J60 enet adapter at eth0
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device

[Service]
Type=oneshot
ExecStart=/usr/local/bin/setmac

[Install]
WantedBy=multi-user.target
/usr/local/bin/setmac.sh

Code: Select all

#! /bin/sh
sudo /sbin/ip link set dev eth0 address `sed -n "s/Serial.*: 00000000..\(..\)\(..\)\(..\)/b8:27:eb:\1:\2:\3/p" /proc/cpuinfo`
you can not use ExecStart=/sbin/ip link set dev eth0 address `sed -n "s/Serial.*: 00000000..\(..\)\(..\)\(..\)/b8:27:eb:\1:\2:\3/p" /proc/cpuinfo` directly in the service so thats why i use the script.

dont forget to enable the service with
sudo systemctl enable setmac.service
and make the bash script executable
sudo chmod +x /usr/local/bin/setmac.sh

Tested with a Raspberry Compute Modul 3 and ENC28J60

Return to “Advanced users”

Who is online

Users browsing this forum: asandford, Douglas6 and 7 guests