blob: daece29984809d0ac5d184cf1adf6bbc1e2d02c8 [file] [log] [blame]
Neil Armstrong7914a9a2024-09-17 14:34:45 +02001// 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 Armstrong1fce2312024-09-17 14:34:46 +020011#include <efi_loader.h>
Neil Armstrong7914a9a2024-09-17 14:34:45 +020012#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 Armstrong1fce2312024-09-17 14:34:46 +020023struct efi_fw_image fw_images[] = {
24 {
25 .fw_name = u"AML_S805X_AC_BOOT",
26 .image_index = 1,
27 },
28};
29
30struct 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)
37void set_dfu_alt_info(char *interface, char *devstr)
38{
Neil Armstrong7f0e8362025-04-03 18:03:21 +020039 if (interface && strcmp(interface, "ram") == 0)
Neil Armstrong1fce2312024-09-17 14:34:46 +020040 env_set("dfu_alt_info", "fitimage ram 0x08080000 0x4000000");
Neil Armstrong1fce2312024-09-17 14:34:46 +020041}
42#endif
43
Neil Armstrong7914a9a2024-09-17 14:34:45 +020044int misc_init_r(void)
45{
46 u8 mac_addr[EFUSE_MAC_SIZE + 1];
47 char serial[EFUSE_SN_SIZE + 1];
48 ssize_t len;
49
50 if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
51 len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
52 mac_addr, EFUSE_MAC_SIZE);
53 mac_addr[len] = '\0';
54 if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr))
55 eth_env_set_enetaddr("ethaddr", mac_addr);
56 else
57 meson_generate_serial_ethaddr();
58 }
59
60 if (!env_get("serial#")) {
61 len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
62 EFUSE_SN_SIZE);
63 serial[len] = '\0';
64 if (len == EFUSE_SN_SIZE)
65 env_set("serial#", serial);
66 }
67
68 return 0;
69}