blob: 1111ad6fca9c4ea5c29c0b317595c9018dd351d4 [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 Simek2a7d9522021-08-27 12:53:32 +020016#include <memalign.h>
Michal Simek0f796702014-04-25 13:51:17 +020017#include <mmc.h>
Michal Simekc07b2252018-06-08 13:45:14 +020018#include <watchdog.h>
Michal Simek309ef802018-02-21 17:04:28 +010019#include <wdt.h>
Michal Simek15d654c2013-04-22 15:43:02 +020020#include <zynqpl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060021#include <asm/global_data.h>
Michal Simek242192b2013-04-12 16:33:08 +020022#include <asm/arch/hardware.h>
23#include <asm/arch/sys_proto.h>
Michal Simek705d44a2020-03-31 12:39:37 +020024#include "../common/board.h"
Michal Simekaf482d52012-09-28 09:56:37 +000025
26DECLARE_GLOBAL_DATA_PTR;
27
28int board_init(void)
29{
Michal Simekae9dc112021-02-02 16:34:48 +010030 if (IS_ENABLED(CONFIG_SPL_BUILD))
31 printf("Silicon version:\t%d\n", zynq_get_silicon_version());
32
Michal Simekaf482d52012-09-28 09:56:37 +000033 return 0;
34}
35
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053036int board_late_init(void)
37{
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053038 int env_targets_len = 0;
39 const char *mode;
40 char *new_targets;
41 char *env_targets;
42
Michal Simekbab07b62020-07-28 12:45:47 +020043 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
44 debug("Saved variables - Skipping\n");
45 return 0;
46 }
47
48 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
49 return 0;
50
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053051 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek19356712016-12-16 13:16:14 +010052 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053053 mode = "qspi";
Simon Glass6a38e412017-08-03 12:22:09 -060054 env_set("modeboot", "qspiboot");
Michal Simek19356712016-12-16 13:16:14 +010055 break;
56 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053057 mode = "nand";
Simon Glass6a38e412017-08-03 12:22:09 -060058 env_set("modeboot", "nandboot");
Michal Simek19356712016-12-16 13:16:14 +010059 break;
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053060 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053061 mode = "nor";
Simon Glass6a38e412017-08-03 12:22:09 -060062 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053063 break;
64 case ZYNQ_BM_SD:
Michal Simek9541d0b2019-09-11 12:51:49 +020065 mode = "mmc0";
Simon Glass6a38e412017-08-03 12:22:09 -060066 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053067 break;
68 case ZYNQ_BM_JTAG:
T Karthik Reddy6c28c292019-11-13 21:13:44 -070069 mode = "jtag pxe dhcp";
Simon Glass6a38e412017-08-03 12:22:09 -060070 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053071 break;
72 default:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053073 mode = "";
Simon Glass6a38e412017-08-03 12:22:09 -060074 env_set("modeboot", "");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053075 break;
76 }
77
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053078 /*
79 * One terminating char + one byte for space between mode
80 * and default boot_targets
81 */
82 env_targets = env_get("boot_targets");
83 if (env_targets)
84 env_targets_len = strlen(env_targets);
85
86 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
87 if (!new_targets)
88 return -ENOMEM;
89
90 sprintf(new_targets, "%s %s", mode,
91 env_targets ? env_targets : "");
92
93 env_set("boot_targets", new_targets);
94
Michal Simek705d44a2020-03-31 12:39:37 +020095 return board_late_init_xilinx();
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053096}
Michal Simekaf482d52012-09-28 09:56:37 +000097
Michal Simekf4780a72016-04-01 15:56:33 +020098#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -060099int dram_init_banksize(void)
Nathan Rossic12892b2016-12-04 19:33:22 +1000100{
Michal Simekd5b7de62017-11-03 15:25:51 +0100101 return fdtdec_setup_memory_banksize();
Tom Riniedcfdbd2016-12-09 07:56:54 -0500102}
Michal Simekf4780a72016-04-01 15:56:33 +0200103
Tom Riniedcfdbd2016-12-09 07:56:54 -0500104int dram_init(void)
105{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530106 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi58ea0d82016-12-19 00:03:34 +1000107 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500108
109 zynq_ddrc_init();
110
111 return 0;
Michal Simekf4780a72016-04-01 15:56:33 +0200112}
Michal Simekf4780a72016-04-01 15:56:33 +0200113#else
114int dram_init(void)
115{
Michal Simek1b846212018-04-11 16:12:28 +0200116 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
117 CONFIG_SYS_SDRAM_SIZE);
Michal Simekf4780a72016-04-01 15:56:33 +0200118
Michal Simekf5ff7bc2013-06-17 14:37:01 +0200119 zynq_ddrc_init();
120
Michal Simekaf482d52012-09-28 09:56:37 +0000121 return 0;
122}
Michal Simekf4780a72016-04-01 15:56:33 +0200123#endif
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700124
125enum env_location env_get_location(enum env_operation op, int prio)
126{
127 u32 bootmode = zynq_slcr_get_boot_mode() & ZYNQ_BM_MASK;
128
129 if (prio)
130 return ENVL_UNKNOWN;
131
132 switch (bootmode) {
133 case ZYNQ_BM_SD:
134 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
135 return ENVL_FAT;
136 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
137 return ENVL_EXT4;
Mike Looijmans682cf082021-07-02 10:28:36 +0200138 return ENVL_NOWHERE;
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700139 case ZYNQ_BM_NAND:
140 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
141 return ENVL_NAND;
142 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
143 return ENVL_UBI;
Mike Looijmans682cf082021-07-02 10:28:36 +0200144 return ENVL_NOWHERE;
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700145 case ZYNQ_BM_NOR:
146 case ZYNQ_BM_QSPI:
147 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
148 return ENVL_SPI_FLASH;
Mike Looijmans682cf082021-07-02 10:28:36 +0200149 return ENVL_NOWHERE;
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700150 case ZYNQ_BM_JTAG:
151 default:
152 return ENVL_NOWHERE;
153 }
154}
Michal Simek2a7d9522021-08-27 12:53:32 +0200155
156#if defined(CONFIG_SET_DFU_ALT_INFO)
157
158#define DFU_ALT_BUF_LEN SZ_1K
159
160void set_dfu_alt_info(char *interface, char *devstr)
161{
162 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
163
164 if (env_get("dfu_alt_info"))
165 return;
166
167 memset(buf, 0, sizeof(buf));
168
169 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
170 case ZYNQ_BM_SD:
171 snprintf(buf, DFU_ALT_BUF_LEN,
172 "mmc 0:1=boot.bin fat 0 1;"
173 "u-boot.img fat 0 1");
174 break;
175 case ZYNQ_BM_QSPI:
176 snprintf(buf, DFU_ALT_BUF_LEN,
177 "sf 0:0=boot.bin raw 0 0x1500000;"
178 "u-boot.img raw 0x%x 0x500000",
179 CONFIG_SYS_SPI_U_BOOT_OFFS);
180 break;
181 default:
182 return;
183 }
184
185 env_set("dfu_alt_info", buf);
186 puts("DFU alt info setting: done\n");
187}
188#endif