imx8m: config: convert to bootm_size
[platform/kernel/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 <env.h>
9 #include <log.h>
10 #include <asm/sections.h>
11 #include <dm/uclass.h>
12 #include <i2c.h>
13 #include <linux/sizes.h>
14 #include "board.h"
15
16 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
17 {
18         int ret = -EINVAL;
19
20 #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
21         struct udevice *dev;
22         ofnode eeprom;
23
24         eeprom = ofnode_get_chosen_node("xlnx,eeprom");
25         if (!ofnode_valid(eeprom))
26                 return -ENODEV;
27
28         debug("%s: Path to EEPROM %s\n", __func__,
29               ofnode_read_chosen_string("xlnx,eeprom"));
30
31         ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
32         if (ret)
33                 return ret;
34
35         ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6);
36         if (ret)
37                 debug("%s: I2C EEPROM MAC address read failed\n", __func__);
38         else
39                 debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr);
40 #endif
41
42         return ret;
43 }
44
45 #if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
46 void *board_fdt_blob_setup(void)
47 {
48         static void *fdt_blob;
49
50 #if !defined(CONFIG_VERSAL_NO_DDR) && !defined(CONFIG_ZYNQMP_NO_DDR)
51         fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR;
52
53         if (fdt_magic(fdt_blob) == FDT_MAGIC)
54                 return fdt_blob;
55
56         debug("DTB is not passed via %p\n", fdt_blob);
57 #endif
58
59 #ifdef CONFIG_SPL_BUILD
60         /* FDT is at end of BSS unless it is in a different memory region */
61         if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
62                 fdt_blob = (ulong *)&_image_binary_end;
63         else
64                 fdt_blob = (ulong *)&__bss_end;
65 #else
66         /* FDT is at end of image */
67         fdt_blob = (ulong *)&_end;
68 #endif
69
70         if (fdt_magic(fdt_blob) == FDT_MAGIC)
71                 return fdt_blob;
72
73         debug("DTB is also not passed via %p\n", fdt_blob);
74
75         return NULL;
76 }
77 #endif
78
79 int board_late_init_xilinx(void)
80 {
81         ulong initrd_hi;
82
83         env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
84
85         initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
86         initrd_hi = round_down(initrd_hi, SZ_16M);
87         env_set_addr("initrd_high", (void *)initrd_hi);
88
89         return 0;
90 }