blob: 3b6581e3046232cbf833f13a26b37486a75b4f6e [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>
Algapally Santosh Sagar25903c52023-06-14 03:03:59 -06008#include <debug_uart.h>
9#include <dfu.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Michal Simekbab07b62020-07-28 12:45:47 +020011#include <log.h>
Michal Simek309ef802018-02-21 17:04:28 +010012#include <dm/uclass.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060013#include <env.h>
Ashok Reddy Soma909546d2021-02-23 08:07:45 -070014#include <env_internal.h>
Michal Simek65ef52f2014-02-24 11:16:32 +010015#include <fdtdec.h>
Michal Simek0f796702014-04-25 13:51:17 +020016#include <fpga.h>
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053017#include <malloc.h>
Michal Simek2a7d9522021-08-27 12:53:32 +020018#include <memalign.h>
Michal Simek0f796702014-04-25 13:51:17 +020019#include <mmc.h>
Michal Simekc07b2252018-06-08 13:45:14 +020020#include <watchdog.h>
Michal Simek309ef802018-02-21 17:04:28 +010021#include <wdt.h>
Michal Simek15d654c2013-04-22 15:43:02 +020022#include <zynqpl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Michal Simek242192b2013-04-12 16:33:08 +020024#include <asm/arch/hardware.h>
25#include <asm/arch/sys_proto.h>
Michal Simek705d44a2020-03-31 12:39:37 +020026#include "../common/board.h"
Michal Simekaf482d52012-09-28 09:56:37 +000027
28DECLARE_GLOBAL_DATA_PTR;
29
Michal Simek7659fe42022-02-17 14:28:41 +010030#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_DEBUG_UART_BOARD_INIT)
31void board_debug_uart_init(void)
32{
33 /* Add initialization sequence if UART is not configured */
34}
35#endif
36
Michal Simekaf482d52012-09-28 09:56:37 +000037int board_init(void)
38{
Michal Simekae9dc112021-02-02 16:34:48 +010039 if (IS_ENABLED(CONFIG_SPL_BUILD))
40 printf("Silicon version:\t%d\n", zynq_get_silicon_version());
41
Michal Simek1eb7b222022-09-27 09:55:46 +020042 if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
43 xilinx_read_eeprom();
44
Michal Simekaf482d52012-09-28 09:56:37 +000045 return 0;
46}
47
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053048int board_late_init(void)
49{
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053050 int env_targets_len = 0;
51 const char *mode;
52 char *new_targets;
53 char *env_targets;
54
Michal Simekbab07b62020-07-28 12:45:47 +020055 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
56 debug("Saved variables - Skipping\n");
57 return 0;
58 }
59
Simon Glass094778f2023-02-05 15:39:49 -070060 if (!IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG))
Michal Simekbab07b62020-07-28 12:45:47 +020061 return 0;
62
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053063 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek19356712016-12-16 13:16:14 +010064 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053065 mode = "qspi";
Simon Glass6a38e412017-08-03 12:22:09 -060066 env_set("modeboot", "qspiboot");
Michal Simek19356712016-12-16 13:16:14 +010067 break;
68 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053069 mode = "nand";
Simon Glass6a38e412017-08-03 12:22:09 -060070 env_set("modeboot", "nandboot");
Michal Simek19356712016-12-16 13:16:14 +010071 break;
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053072 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053073 mode = "nor";
Simon Glass6a38e412017-08-03 12:22:09 -060074 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053075 break;
76 case ZYNQ_BM_SD:
Michal Simek9541d0b2019-09-11 12:51:49 +020077 mode = "mmc0";
Simon Glass6a38e412017-08-03 12:22:09 -060078 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053079 break;
80 case ZYNQ_BM_JTAG:
T Karthik Reddy6c28c292019-11-13 21:13:44 -070081 mode = "jtag pxe dhcp";
Simon Glass6a38e412017-08-03 12:22:09 -060082 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053083 break;
84 default:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053085 mode = "";
Simon Glass6a38e412017-08-03 12:22:09 -060086 env_set("modeboot", "");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053087 break;
88 }
89
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053090 /*
91 * One terminating char + one byte for space between mode
92 * and default boot_targets
93 */
94 env_targets = env_get("boot_targets");
95 if (env_targets)
96 env_targets_len = strlen(env_targets);
97
98 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
99 if (!new_targets)
100 return -ENOMEM;
101
102 sprintf(new_targets, "%s %s", mode,
103 env_targets ? env_targets : "");
104
105 env_set("boot_targets", new_targets);
106
Michal Simek705d44a2020-03-31 12:39:37 +0200107 return board_late_init_xilinx();
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +0530108}
Michal Simekaf482d52012-09-28 09:56:37 +0000109
Tom Rinibb4dd962022-11-16 13:10:37 -0500110#if !defined(CFG_SYS_SDRAM_BASE) && !defined(CFG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600111int dram_init_banksize(void)
Nathan Rossic12892b2016-12-04 19:33:22 +1000112{
Michal Simekd5b7de62017-11-03 15:25:51 +0100113 return fdtdec_setup_memory_banksize();
Tom Riniedcfdbd2016-12-09 07:56:54 -0500114}
Michal Simekf4780a72016-04-01 15:56:33 +0200115
Tom Riniedcfdbd2016-12-09 07:56:54 -0500116int dram_init(void)
117{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530118 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi58ea0d82016-12-19 00:03:34 +1000119 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500120
121 zynq_ddrc_init();
122
123 return 0;
Michal Simekf4780a72016-04-01 15:56:33 +0200124}
Michal Simekf4780a72016-04-01 15:56:33 +0200125#else
126int dram_init(void)
127{
Tom Rinibb4dd962022-11-16 13:10:37 -0500128 gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE,
129 CFG_SYS_SDRAM_SIZE);
Michal Simekf4780a72016-04-01 15:56:33 +0200130
Michal Simekf5ff7bc2013-06-17 14:37:01 +0200131 zynq_ddrc_init();
132
Michal Simekaf482d52012-09-28 09:56:37 +0000133 return 0;
134}
Michal Simekf4780a72016-04-01 15:56:33 +0200135#endif
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700136
137enum env_location env_get_location(enum env_operation op, int prio)
138{
139 u32 bootmode = zynq_slcr_get_boot_mode() & ZYNQ_BM_MASK;
140
141 if (prio)
142 return ENVL_UNKNOWN;
143
144 switch (bootmode) {
145 case ZYNQ_BM_SD:
146 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
147 return ENVL_FAT;
148 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
149 return ENVL_EXT4;
Mike Looijmans682cf082021-07-02 10:28:36 +0200150 return ENVL_NOWHERE;
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700151 case ZYNQ_BM_NAND:
152 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
153 return ENVL_NAND;
154 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
155 return ENVL_UBI;
Mike Looijmans682cf082021-07-02 10:28:36 +0200156 return ENVL_NOWHERE;
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700157 case ZYNQ_BM_NOR:
158 case ZYNQ_BM_QSPI:
159 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
160 return ENVL_SPI_FLASH;
Mike Looijmans682cf082021-07-02 10:28:36 +0200161 return ENVL_NOWHERE;
Ashok Reddy Soma909546d2021-02-23 08:07:45 -0700162 case ZYNQ_BM_JTAG:
163 default:
164 return ENVL_NOWHERE;
165 }
166}
Michal Simek2a7d9522021-08-27 12:53:32 +0200167
168#if defined(CONFIG_SET_DFU_ALT_INFO)
169
170#define DFU_ALT_BUF_LEN SZ_1K
171
172void set_dfu_alt_info(char *interface, char *devstr)
173{
174 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
175
Michal Simekf0d6f462022-08-09 16:32:52 +0200176 if (env_get("dfu_alt_info"))
Michal Simek2a7d9522021-08-27 12:53:32 +0200177 return;
178
179 memset(buf, 0, sizeof(buf));
180
181 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
182 case ZYNQ_BM_SD:
183 snprintf(buf, DFU_ALT_BUF_LEN,
Michal Simek3e09d192022-08-09 16:32:54 +0200184 "mmc 0=boot.bin fat 0 1;"
Michal Simekca1b5d02022-08-09 16:32:53 +0200185 "%s fat 0 1", CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
Michal Simek2a7d9522021-08-27 12:53:32 +0200186 break;
187 case ZYNQ_BM_QSPI:
188 snprintf(buf, DFU_ALT_BUF_LEN,
189 "sf 0:0=boot.bin raw 0 0x1500000;"
Michal Simekca1b5d02022-08-09 16:32:53 +0200190 "%s raw 0x%x 0x500000",
191 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
Michal Simek2a7d9522021-08-27 12:53:32 +0200192 CONFIG_SYS_SPI_U_BOOT_OFFS);
193 break;
194 default:
195 return;
196 }
197
198 env_set("dfu_alt_info", buf);
199 puts("DFU alt info setting: done\n");
200}
201#endif