blob: b770a1f8c537275a439d4bd2ee104ad3557a0b6a [file] [log] [blame]
Vyacheslav Bocharovb0b643d2021-10-29 10:08:20 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2021 Vyacheslav Bocharov
4 * Author: Vyacheslav Bocharov <adeep@lexina.in>
5 */
6
Vyacheslav Bocharovb0b643d2021-10-29 10:08:20 +03007#include <dm.h>
8#include <init.h>
9#include <net.h>
10#include <asm/io.h>
11#include <asm/arch/axg.h>
12#include <asm/arch/sm.h>
13#include <asm/arch/eth.h>
14#include <asm/arch/mem.h>
15#include <u-boot/crc.h>
16
17int misc_init_r(void)
18{
Neil Armstrongbfbe81a2024-03-20 09:46:11 +010019 u8 mac_addr[ARP_HLEN + 1];
Vyacheslav Bocharovb0b643d2021-10-29 10:08:20 +030020 char serial[SM_SERIAL_SIZE];
21 u32 sid;
22
23 if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
24 sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
25 /* Ensure the NIC specific bytes of the mac are not all 0 */
26 if ((sid & 0xffff) == 0)
27 sid |= 0x800000;
28
29 /* OUI registered MAC address */
30 mac_addr[0] = 0x10;
31 mac_addr[1] = 0x27;
32 mac_addr[2] = 0xBE;
33 mac_addr[3] = (sid >> 16) & 0xff;
34 mac_addr[4] = (sid >> 8) & 0xff;
35 mac_addr[5] = (sid >> 0) & 0xff;
Neil Armstrongbfbe81a2024-03-20 09:46:11 +010036 mac_addr[ARP_HLEN] = '\0';
Vyacheslav Bocharovb0b643d2021-10-29 10:08:20 +030037
38 eth_env_set_enetaddr("ethaddr", mac_addr);
39 }
40
41 return 0;
42}