Neil Armstrong | 7914a9a | 2024-09-17 14:34:45 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2016 BayLibre, SAS |
| 4 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
| 5 | */ |
| 6 | |
| 7 | #include <dm.h> |
| 8 | #include <env.h> |
| 9 | #include <init.h> |
| 10 | #include <net.h> |
Neil Armstrong | 1fce231 | 2024-09-17 14:34:46 +0200 | [diff] [blame] | 11 | #include <efi_loader.h> |
Neil Armstrong | 7914a9a | 2024-09-17 14:34:45 +0200 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/gx.h> |
| 14 | #include <asm/arch/sm.h> |
| 15 | #include <asm/arch/eth.h> |
| 16 | #include <asm/arch/mem.h> |
| 17 | |
| 18 | #define EFUSE_SN_OFFSET 20 |
| 19 | #define EFUSE_SN_SIZE 16 |
| 20 | #define EFUSE_MAC_OFFSET 52 |
| 21 | #define EFUSE_MAC_SIZE 6 |
| 22 | |
Neil Armstrong | 1fce231 | 2024-09-17 14:34:46 +0200 | [diff] [blame] | 23 | struct efi_fw_image fw_images[] = { |
| 24 | { |
| 25 | .fw_name = u"AML_S805X_AC_BOOT", |
| 26 | .image_index = 1, |
| 27 | }, |
| 28 | }; |
| 29 | |
| 30 | struct efi_capsule_update_info update_info = { |
| 31 | .dfu_string = "sf 0:0=u-boot-bin raw 0 0x10000", |
| 32 | .num_images = ARRAY_SIZE(fw_images), |
| 33 | .images = fw_images, |
| 34 | }; |
| 35 | |
| 36 | #if IS_ENABLED(CONFIG_SET_DFU_ALT_INFO) |
| 37 | void set_dfu_alt_info(char *interface, char *devstr) |
| 38 | { |
| 39 | if (strcmp(interface, "ram") == 0) |
| 40 | env_set("dfu_alt_info", "fitimage ram 0x08080000 0x4000000"); |
| 41 | else if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) |
| 42 | env_set("dfu_alt_info", update_info.dfu_string); |
| 43 | } |
| 44 | #endif |
| 45 | |
Neil Armstrong | 7914a9a | 2024-09-17 14:34:45 +0200 | [diff] [blame] | 46 | int misc_init_r(void) |
| 47 | { |
| 48 | u8 mac_addr[EFUSE_MAC_SIZE + 1]; |
| 49 | char serial[EFUSE_SN_SIZE + 1]; |
| 50 | ssize_t len; |
| 51 | |
| 52 | if (!eth_env_get_enetaddr("ethaddr", mac_addr)) { |
| 53 | len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, |
| 54 | mac_addr, EFUSE_MAC_SIZE); |
| 55 | mac_addr[len] = '\0'; |
| 56 | if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr)) |
| 57 | eth_env_set_enetaddr("ethaddr", mac_addr); |
| 58 | else |
| 59 | meson_generate_serial_ethaddr(); |
| 60 | } |
| 61 | |
| 62 | if (!env_get("serial#")) { |
| 63 | len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, |
| 64 | EFUSE_SN_SIZE); |
| 65 | serial[len] = '\0'; |
| 66 | if (len == EFUSE_SN_SIZE) |
| 67 | env_set("serial#", serial); |
| 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |