blob: 6a2c4ad4c3c26d5bd96533ede13804ad6dce9625 [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
7#include <common.h>
8#include <dm.h>
9#include <init.h>
10#include <net.h>
11#include <asm/io.h>
12#include <asm/arch/axg.h>
13#include <asm/arch/sm.h>
14#include <asm/arch/eth.h>
15#include <asm/arch/mem.h>
16#include <u-boot/crc.h>
17
18int misc_init_r(void)
19{
20 u8 mac_addr[ARP_HLEN];
21 char serial[SM_SERIAL_SIZE];
22 u32 sid;
23
24 if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
25 sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
26 /* Ensure the NIC specific bytes of the mac are not all 0 */
27 if ((sid & 0xffff) == 0)
28 sid |= 0x800000;
29
30 /* OUI registered MAC address */
31 mac_addr[0] = 0x10;
32 mac_addr[1] = 0x27;
33 mac_addr[2] = 0xBE;
34 mac_addr[3] = (sid >> 16) & 0xff;
35 mac_addr[4] = (sid >> 8) & 0xff;
36 mac_addr[5] = (sid >> 0) & 0xff;
37
38 eth_env_set_enetaddr("ethaddr", mac_addr);
39 }
40
41 return 0;
42}