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 <common.h>
14 #include <config.h>
15 #include <env.h>
16 #include <init.h>
17 #include <log.h>
18 #include <asm/global_data.h>
19 #include <dm/lists.h>
20 #include <fdtdec.h>
21 #include <linux/sizes.h>
22 #include "../common/board.h"
23 
24 DECLARE_GLOBAL_DATA_PTR;
25 
dram_init_banksize(void)26 int dram_init_banksize(void)
27 {
28 	return fdtdec_setup_memory_banksize();
29 }
30 
dram_init(void)31 int dram_init(void)
32 {
33 	if (fdtdec_setup_mem_size_base() != 0)
34 		return -EINVAL;
35 
36 	return 0;
37 };
38 
board_late_init(void)39 int board_late_init(void)
40 {
41 	ulong max_size;
42 	u32 status = 0;
43 
44 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SYSRESET_MICROBLAZE)
45 	int ret;
46 
47 	ret = device_bind_driver(gd->dm_root, "mb_soft_reset",
48 				 "reset_soft", NULL);
49 	if (ret)
50 		printf("Warning: No reset driver: ret=%d\n", ret);
51 #endif
52 
53 	if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
54 		debug("Saved variables - Skipping\n");
55 		return 0;
56 	}
57 
58 	max_size = gd->start_addr_sp - CONFIG_STACK_SIZE;
59 	max_size = round_down(max_size, SZ_16M);
60 
61 	status |= env_set_hex("scriptaddr", max_size + SZ_2M);
62 
63 	status |= env_set_hex("pxefile_addr_r", max_size + SZ_1M);
64 
65 	status |= env_set_hex("kernel_addr_r", gd->ram_base + SZ_32M);
66 
67 	status |= env_set_hex("fdt_addr_r", gd->ram_base + SZ_32M - SZ_1M);
68 
69 	status |= env_set_hex("ramdisk_addr_r",
70 			       gd->ram_base + SZ_32M + SZ_4M + SZ_2M);
71 	if (IS_ENABLED(CONFIG_MTD_NOR_FLASH))
72 		status |= env_set_hex("script_offset_nor",
73 				       gd->bd->bi_flashstart +
74 				       CONFIG_BOOT_SCRIPT_OFFSET);
75 	if (status)
76 		printf("%s: Saving run time variables FAILED\n", __func__);
77 
78 	return board_late_init_xilinx();
79 }
80