[PATCH 4/5] ARM: novena: Read Ethernet MAC address from EEPROM

Sascha Hauer sha at pengutronix.de
Mon Jan 23 01:33:05 PST 2023


On Mon, Jan 23, 2023 at 04:51:40AM +1100, John Watts wrote:
> The Novena has an EEPROM used for storing information about the board,
> including the Ethernet MAC address.
> 
> The reference for the EEPROM fields is the novena-eeprom source code.
> 
> Signed-off-by: John Watts <contact at jookia.org>
> ---
>  arch/arm/boards/novena/board.c | 68 ++++++++++++++++++++++++++++++++++
>  arch/arm/dts/imx6q-novena.dts  | 15 ++++++++
>  2 files changed, 83 insertions(+)
> 
> diff --git a/arch/arm/boards/novena/board.c b/arch/arm/boards/novena/board.c
> index 186f91093f..0341117c46 100644
> --- a/arch/arm/boards/novena/board.c
> +++ b/arch/arm/boards/novena/board.c
> @@ -2,12 +2,80 @@
>  // SPDX-FileCopyrightText: 2023 John Watts
>  
>  #include <common.h>
> +#include <fs.h>
> +#include <libfile.h>
> +#include <net.h>
> +
> +struct novena_eeprom {
> +	uint8_t signature[6]; /* 'Novena' */
> +	uint8_t version; /* 1 or 2, not checked */
> +	uint8_t page_size; /* v2 only: EEPROM read/write page */
> +	uint32_t serial; /* 32-bit serial number */
> +	uint8_t mac[6]; /* Gigabit MAC address */
> +	uint16_t features; /* features */
> +	/* ... extra fields omitted ... */
> +} __packed;
> +
> +static struct novena_eeprom *novena_read_eeprom(void)
> +{
> +	size_t read;
> +	loff_t max = sizeof(struct novena_eeprom);
> +	void *eeprom;
> +
> +	int rc = read_file_2("/dev/eeprom0", &read, &eeprom, max);

And here is the point where you have to request that the EEPROM is
actually availabe to support the deep probe mechanism. Before reading
the EEPROM add a call to:

	of_device_ensure_probed_by_alias("eeprom0");

Nowadays the read-MAC-address-from-EEPROM thingy would likely be done
using nvmem cells which would boil this code down to device tree changes
only. If you're feeling brave you could change this, I won't insist on
it though.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list