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>
11 #include <efi_loader.h>
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 
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)
set_dfu_alt_info(char * interface,char * devstr)37 void set_dfu_alt_info(char *interface, char *devstr)
38 {
39 	if (interface && strcmp(interface, "ram") == 0)
40 		env_set("dfu_alt_info", "fitimage ram 0x08080000 0x4000000");
41 }
42 #endif
43 
misc_init_r(void)44 int 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 }
70