Vyacheslav Bocharov | b0b643d | 2021-10-29 10:08:20 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2021 Vyacheslav Bocharov |
| 4 | * Author: Vyacheslav Bocharov <adeep@lexina.in> |
| 5 | */ |
| 6 | |
Vyacheslav Bocharov | b0b643d | 2021-10-29 10:08:20 +0300 | [diff] [blame] | 7 | #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 | |
| 17 | int misc_init_r(void) |
| 18 | { |
Neil Armstrong | bfbe81a | 2024-03-20 09:46:11 +0100 | [diff] [blame] | 19 | u8 mac_addr[ARP_HLEN + 1]; |
Vyacheslav Bocharov | b0b643d | 2021-10-29 10:08:20 +0300 | [diff] [blame] | 20 | 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 Armstrong | bfbe81a | 2024-03-20 09:46:11 +0100 | [diff] [blame] | 36 | mac_addr[ARP_HLEN] = '\0'; |
Vyacheslav Bocharov | b0b643d | 2021-10-29 10:08:20 +0300 | [diff] [blame] | 37 | |
| 38 | eth_env_set_enetaddr("ethaddr", mac_addr); |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |