blob: f58ecd1590c91d99c383cd94b5b004e741b3bcd9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek952d5142007-03-11 13:42:58 +01002/*
Michal Simek4e39ea82018-07-13 08:26:28 +02003 * (C) Copyright 2007-2018 Michal Simek
Michal Simek952d5142007-03-11 13:42:58 +01004 *
Michal Simek4e39ea82018-07-13 08:26:28 +02005 * Michal SIMEK <monstr@monstr.eu>
Michal Simek952d5142007-03-11 13:42:58 +01006 */
7
Shreenidhi Shediffced402018-07-15 02:34:35 +05308/*
9 * This is a board specific file. It's OK to include board specific
10 * header files
11 */
Michal Simek952d5142007-03-11 13:42:58 +010012
13#include <common.h>
Michal Simekdda9bd82007-03-30 22:52:09 +020014#include <config.h>
Simon Glassed38aef2020-05-10 11:40:03 -060015#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070016#include <init.h>
Michal Simekdba00ff2022-03-01 09:13:20 +010017#include <image.h>
18#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060020#include <asm/global_data.h>
Michal Simek4e39ea82018-07-13 08:26:28 +020021#include <dm/lists.h>
Michal Simek65e915c2014-05-08 16:08:44 +020022#include <fdtdec.h>
Michal Simek360da4b2019-09-25 11:00:17 +020023#include <linux/sizes.h>
Michal Simek9ccfcae2020-10-23 07:54:18 +020024#include "../common/board.h"
Michal Simek23ccda02013-04-24 10:01:20 +020025
Michal Simek65e915c2014-05-08 16:08:44 +020026DECLARE_GLOBAL_DATA_PTR;
27
Simon Glass2f949c32017-03-31 08:40:32 -060028int dram_init_banksize(void)
Michal Simek65e915c2014-05-08 16:08:44 +020029{
Michal Simekfdf3d802018-11-22 12:39:18 +010030 return fdtdec_setup_memory_banksize();
Michal Simek65e915c2014-05-08 16:08:44 +020031}
32
33int dram_init(void)
34{
Michal Simekfdf3d802018-11-22 12:39:18 +010035 if (fdtdec_setup_mem_size_base() != 0)
36 return -EINVAL;
Michal Simek65e915c2014-05-08 16:08:44 +020037
38 return 0;
39};
Michal Simek65e915c2014-05-08 16:08:44 +020040
Michal Simekdba00ff2022-03-01 09:13:20 +010041ulong board_get_usable_ram_top(ulong total_size)
42{
43 phys_size_t size;
44 phys_addr_t reg;
45 struct lmb lmb;
46
47 /* found enough not-reserved memory to relocated U-Boot */
48 lmb_init(&lmb);
49 lmb_add(&lmb, gd->ram_base, gd->ram_size);
50 boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);
51 size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE);
52 reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE);
53
54 if (!reg)
55 reg = gd->ram_top - size;
56
57 return reg + size;
58}
59
Michal Simek01525242015-12-11 15:01:28 +010060int board_late_init(void)
Michal Simek9cabb362012-07-04 13:12:37 +020061{
Michal Simek9ccfcae2020-10-23 07:54:18 +020062 ulong max_size;
T Karthik Reddy51d78152020-09-22 05:18:53 -060063 u32 status = 0;
Michal Simek360da4b2019-09-25 11:00:17 +020064
Michal Simek4e39ea82018-07-13 08:26:28 +020065#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SYSRESET_MICROBLAZE)
66 int ret;
Shreenidhi Shedi1f8fcbb2018-07-15 02:05:40 +053067
Michal Simek4e39ea82018-07-13 08:26:28 +020068 ret = device_bind_driver(gd->dm_root, "mb_soft_reset",
69 "reset_soft", NULL);
70 if (ret)
71 printf("Warning: No reset driver: ret=%d\n", ret);
72#endif
Michal Simek360da4b2019-09-25 11:00:17 +020073
74 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
75 debug("Saved variables - Skipping\n");
76 return 0;
77 }
78
79 max_size = gd->start_addr_sp - CONFIG_STACK_SIZE;
80 max_size = round_down(max_size, SZ_16M);
81
T Karthik Reddya95a5bc2020-09-22 05:18:54 -060082 status |= env_set_hex("scriptaddr", max_size + SZ_2M);
83
84 status |= env_set_hex("pxefile_addr_r", max_size + SZ_1M);
85
86 status |= env_set_hex("kernel_addr_r", gd->ram_base + SZ_32M);
87
88 status |= env_set_hex("fdt_addr_r", gd->ram_base + SZ_32M - SZ_1M);
89
90 status |= env_set_hex("ramdisk_addr_r",
91 gd->ram_base + SZ_32M + SZ_4M + SZ_2M);
T Karthik Reddy78aae962020-12-17 03:15:55 -070092 if (IS_ENABLED(CONFIG_MTD_NOR_FLASH))
93 status |= env_set_hex("script_offset_nor",
94 gd->bd->bi_flashstart +
95 CONFIG_BOOT_SCRIPT_OFFSET);
T Karthik Reddy51d78152020-09-22 05:18:53 -060096 if (status)
97 printf("%s: Saving run time variables FAILED\n", __func__);
Michal Simek360da4b2019-09-25 11:00:17 +020098
Michal Simek9ccfcae2020-10-23 07:54:18 +020099 return board_late_init_xilinx();
Michal Simek9cabb362012-07-04 13:12:37 +0200100}