1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2007-2018 Michal Simek
4 *
5 * Michal SIMEK <monstr@monstr.eu>
6 */
7
8/*
9 * This is a board specific file.  It's OK to include board specific
10 * header files
11 */
12
13#include <config.h>
14#include <env.h>
15#include <init.h>
16#include <log.h>
17#include <asm/global_data.h>
18#include <dm/lists.h>
19#include <fdtdec.h>
20#include <linux/sizes.h>
21#include "../common/board.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25int dram_init_banksize(void)
26{
27	return fdtdec_setup_memory_banksize();
28}
29
30int dram_init(void)
31{
32	if (fdtdec_setup_mem_size_base() != 0)
33		return -EINVAL;
34
35	return 0;
36};
37
38int board_late_init(void)
39{
40	ulong max_size;
41	u32 status = 0;
42
43#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SYSRESET_MICROBLAZE)
44	int ret;
45
46	ret = device_bind_driver(gd->dm_root, "mb_soft_reset",
47				 "reset_soft", NULL);
48	if (ret)
49		printf("Warning: No reset driver: ret=%d\n", ret);
50#endif
51
52	if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
53		debug("Saved variables - Skipping\n");
54		return 0;
55	}
56
57	max_size = gd->start_addr_sp - CONFIG_STACK_SIZE;
58	max_size = round_down(max_size, SZ_16M);
59
60	status |= env_set_hex("scriptaddr", max_size + SZ_2M);
61
62	status |= env_set_hex("pxefile_addr_r", max_size + SZ_1M);
63
64	status |= env_set_hex("kernel_addr_r", gd->ram_base + SZ_32M);
65
66	status |= env_set_hex("fdt_addr_r", gd->ram_base + SZ_32M - SZ_1M);
67
68	status |= env_set_hex("ramdisk_addr_r",
69			       gd->ram_base + SZ_32M + SZ_4M + SZ_2M);
70	if (IS_ENABLED(CONFIG_MTD_NOR_FLASH))
71		status |= env_set_hex("script_offset_nor",
72				       gd->bd->bi_flashstart +
73				       CONFIG_BOOT_SCRIPT_OFFSET);
74	if (status)
75		printf("%s: Saving run time variables FAILED\n", __func__);
76
77	return board_late_init_xilinx();
78}
79