blob: e2e9b3f0f78c3d4d5139a639e7ed1048da8c2059 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekaf482d52012-09-28 09:56:37 +00002/*
3 * (C) Copyright 2012 Michal Simek <monstr@monstr.eu>
Michal Simek98d0f1f2018-01-17 07:37:47 +01004 * (C) Copyright 2013 - 2018 Xilinx, Inc.
Michal Simekaf482d52012-09-28 09:56:37 +00005 */
6
7#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Michal Simekbab07b62020-07-28 12:45:47 +02009#include <log.h>
Michal Simek309ef802018-02-21 17:04:28 +010010#include <dm/uclass.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Ashok Reddy Soma909546d2021-02-23 08:07:45 -070012#include <env_internal.h>
Michal Simek65ef52f2014-02-24 11:16:32 +010013#include <fdtdec.h>
Michal Simek0f796702014-04-25 13:51:17 +020014#include <fpga.h>
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053015#include <malloc.h>
Michal Simek0f796702014-04-25 13:51:17 +020016#include <mmc.h>
Michal Simekc07b2252018-06-08 13:45:14 +020017#include <watchdog.h>
Michal Simek309ef802018-02-21 17:04:28 +010018#include <wdt.h>
Michal Simek15d654c2013-04-22 15:43:02 +020019#include <zynqpl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060020#include <asm/global_data.h>
Michal Simek242192b2013-04-12 16:33:08 +020021#include <asm/arch/hardware.h>
22#include <asm/arch/sys_proto.h>
Michal Simek705d44a2020-03-31 12:39:37 +020023#include "../common/board.h"
Michal Simekaf482d52012-09-28 09:56:37 +000024
25DECLARE_GLOBAL_DATA_PTR;
26
27int board_init(void)
28{
Michal Simekae9dc112021-02-02 16:34:48 +010029 if (IS_ENABLED(CONFIG_SPL_BUILD))
30 printf("Silicon version:\t%d\n", zynq_get_silicon_version());
31
Michal Simekaf482d52012-09-28 09:56:37 +000032 return 0;
33}
34
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053035int board_late_init(void)
36{
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053037 int env_targets_len = 0;
38 const char *mode;
39 char *new_targets;
40 char *env_targets;
41
Michal Simekbab07b62020-07-28 12:45:47 +020042 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
43 debug("Saved variables - Skipping\n");
44 return 0;
45 }
46
47 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
48 return 0;
49
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053050 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek19356712016-12-16 13:16:14 +010051 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053052 mode = "qspi";
Simon Glass6a38e412017-08-03 12:22:09 -060053 env_set("modeboot", "qspiboot");
Michal Simek19356712016-12-16 13:16:14 +010054 break;
55 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053056 mode = "nand";
Simon Glass6a38e412017-08-03 12:22:09 -060057 env_set("modeboot", "nandboot");
Michal Simek19356712016-12-16 13:16:14 +010058 break;
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053059 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053060 mode = "nor";
Simon Glass6a38e412017-08-03 12:22:09 -060061 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053062 break;
63 case ZYNQ_BM_SD:
Michal Simek9541d0b2019-09-11 12:51:49 +020064 mode = "mmc0";
Simon Glass6a38e412017-08-03 12:22:09 -060065 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053066 break;
67 case ZYNQ_BM_JTAG:
T Karthik Reddy6c28c292019-11-13 21:13:44 -070068 mode = "jtag pxe dhcp";
Simon Glass6a38e412017-08-03 12:22:09 -060069 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053070 break;
71 default:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053072 mode = "";
Simon Glass6a38e412017-08-03 12:22:09 -060073 env_set("modeboot", "");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053074 break;
75 }
76
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053077 /*
78 * One terminating char + one byte for space between mode
79 * and default boot_targets
80 */
81 env_targets = env_get("boot_targets");
82 if (env_targets)
83 env_targets_len = strlen(env_targets);
84
85 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
86 if (!new_targets)
87 return -ENOMEM;
88
89 sprintf(new_targets, "%s %s", mode,
90 env_targets ? env_targets : "");
91
92 env_set("boot_targets", new_targets);
93
Michal Simek705d44a2020-03-31 12:39:37 +020094 return board_late_init_xilinx();
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053095}
Michal Simekaf482d52012-09-28 09:56:37 +000096
Michal Simekf4780a72016-04-01 15:56:33 +020097#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -060098int dram_init_banksize(void)
Nathan Rossic12892b2016-12-04 19:33:22 +100099{
Michal Simekd5b7de62017-11-03 15:25:51 +0100100 return fdtdec_setup_memory_banksize();
Tom Riniedcfdbd2016-12-09 07:56:54 -0500101}
Michal Simekf4780a72016-04-01 15:56:33 +0200102
Tom Riniedcfdbd2016-12-09 07:56:54 -0500103int dram_init(void)
104{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530105 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi58ea0d82016-12-19 00:03:34 +1000106 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500107
108 zynq_ddrc_init();
109
110 return 0;
Michal Simekf4780a72016-04-01 15:56:33 +0200111}
Michal Simekf4780a72016-04-01 15:56:33 +0200112#else
113int dram_init(void)
114{
Michal Simek1b846212018-04-11 16:12:28 +0200115 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
116 CONFIG_SYS_SDRAM_SIZE);
Michal Simekf4780a72016-04-01 15:56:33 +0200117
Michal Simekf5ff7bc2013-06-17 14:37:01 +0200118 zynq_ddrc_init();
119
Michal Simekaf482d52012-09-28 09:56:37 +0000120 return 0;
121}
Michal Simekf4780a72016-04-01 15:56:33 +0200122#endif
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700123
124enum env_location env_get_location(enum env_operation op, int prio)
125{
126 u32 bootmode = zynq_slcr_get_boot_mode() & ZYNQ_BM_MASK;
127
128 if (prio)
129 return ENVL_UNKNOWN;
130
131 switch (bootmode) {
132 case ZYNQ_BM_SD:
133 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
134 return ENVL_FAT;
135 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
136 return ENVL_EXT4;
137 return ENVL_UNKNOWN;
138 case ZYNQ_BM_NAND:
139 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
140 return ENVL_NAND;
141 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
142 return ENVL_UBI;
143 return ENVL_UNKNOWN;
144 case ZYNQ_BM_NOR:
145 case ZYNQ_BM_QSPI:
146 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
147 return ENVL_SPI_FLASH;
148 return ENVL_UNKNOWN;
149 case ZYNQ_BM_JTAG:
150 default:
151 return ENVL_NOWHERE;
152 }
153}