Christian Hewitt | af47f62 | 2020-12-18 08:45:42 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2020 BayLibre, SAS |
| 4 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
| 5 | */ |
| 6 | |
Christian Hewitt | af47f62 | 2020-12-18 08:45:42 +0000 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <env.h> |
| 9 | #include <init.h> |
| 10 | #include <net.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/sm.h> |
| 13 | #include <asm/arch/eth.h> |
| 14 | #include <asm/arch/boot.h> |
| 15 | |
| 16 | #define EFUSE_MAC_OFFSET 20 |
| 17 | #define EFUSE_MAC_SIZE 12 |
| 18 | #define MAC_ADDR_LEN 6 |
| 19 | |
| 20 | int misc_init_r(void) |
| 21 | { |
Neil Armstrong | bfbe81a | 2024-03-20 09:46:11 +0100 | [diff] [blame] | 22 | u8 mac_addr[MAC_ADDR_LEN + 1]; |
Christian Hewitt | af47f62 | 2020-12-18 08:45:42 +0000 | [diff] [blame] | 23 | char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3]; |
| 24 | ssize_t len; |
| 25 | |
| 26 | if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) && |
| 27 | meson_get_soc_rev(tmp, sizeof(tmp)) > 0) |
| 28 | env_set("soc_rev", tmp); |
| 29 | |
Christian Hewitt | af47f62 | 2020-12-18 08:45:42 +0000 | [diff] [blame] | 30 | if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { |
| 31 | len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, |
| 32 | efuse_mac_addr, EFUSE_MAC_SIZE); |
| 33 | if (len != EFUSE_MAC_SIZE) |
| 34 | return 0; |
| 35 | |
| 36 | /* MAC is stored in ASCII format, 1bytes = 2characters */ |
| 37 | for (int i = 0; i < 6; i++) { |
| 38 | tmp[0] = efuse_mac_addr[i * 2]; |
| 39 | tmp[1] = efuse_mac_addr[i * 2 + 1]; |
| 40 | tmp[2] = '\0'; |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 41 | mac_addr[i] = hextoul(tmp, NULL); |
Christian Hewitt | af47f62 | 2020-12-18 08:45:42 +0000 | [diff] [blame] | 42 | } |
Neil Armstrong | bfbe81a | 2024-03-20 09:46:11 +0100 | [diff] [blame] | 43 | mac_addr[MAC_ADDR_LEN] = '\0'; |
Christian Hewitt | af47f62 | 2020-12-18 08:45:42 +0000 | [diff] [blame] | 44 | |
| 45 | if (is_valid_ethaddr(mac_addr)) |
| 46 | eth_env_set_enetaddr("ethaddr", mac_addr); |
| 47 | else |
| 48 | meson_generate_serial_ethaddr(); |
| 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |