xilinx: Introduce board_late_init_xilinx()
[oweals/u-boot.git] / board / xilinx / common / board.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2014 - 2019 Xilinx, Inc.
4  * Michal Simek <michal.simek@xilinx.com>
5  */
6
7 #include <common.h>
8 #include <asm/sections.h>
9 #include <dm/uclass.h>
10 #include <i2c.h>
11 #include "board.h"
12
13 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
14 {
15         int ret = -EINVAL;
16
17 #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
18         struct udevice *dev;
19         ofnode eeprom;
20
21         eeprom = ofnode_get_chosen_node("xlnx,eeprom");
22         if (!ofnode_valid(eeprom))
23                 return -ENODEV;
24
25         debug("%s: Path to EEPROM %s\n", __func__,
26               ofnode_read_chosen_string("xlnx,eeprom"));
27
28         ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
29         if (ret)
30                 return ret;
31
32         ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6);
33         if (ret)
34                 debug("%s: I2C EEPROM MAC address read failed\n", __func__);
35         else
36                 debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr);
37 #endif
38
39         return ret;
40 }
41
42 #if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
43 void *board_fdt_blob_setup(void)
44 {
45         static void *fdt_blob;
46
47 #if !defined(CONFIG_VERSAL_NO_DDR) && !defined(CONFIG_ZYNQMP_NO_DDR)
48         fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR;
49
50         if (fdt_magic(fdt_blob) == FDT_MAGIC)
51                 return fdt_blob;
52
53         debug("DTB is not passed via %p\n", fdt_blob);
54 #endif
55
56 #ifdef CONFIG_SPL_BUILD
57         /* FDT is at end of BSS unless it is in a different memory region */
58         if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
59                 fdt_blob = (ulong *)&_image_binary_end;
60         else
61                 fdt_blob = (ulong *)&__bss_end;
62 #else
63         /* FDT is at end of image */
64         fdt_blob = (ulong *)&_end;
65 #endif
66
67         if (fdt_magic(fdt_blob) == FDT_MAGIC)
68                 return fdt_blob;
69
70         debug("DTB is also not passed via %p\n", fdt_blob);
71
72         return NULL;
73 }
74 #endif
75
76 int board_late_init_xilinx(void)
77 {
78         env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
79
80         return 0;
81 }