Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Michal Simek <monstr@monstr.eu> |
Michal Simek | 98d0f1f | 2018-01-17 07:37:47 +0100 | [diff] [blame] | 4 | * (C) Copyright 2013 - 2018 Xilinx, Inc. |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Michal Simek | bab07b6 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 9 | #include <log.h> |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 10 | #include <dm/uclass.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Ashok Reddy Soma | 909546d | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 12 | #include <env_internal.h> |
Michal Simek | 65ef52f | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 13 | #include <fdtdec.h> |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 14 | #include <fpga.h> |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 15 | #include <malloc.h> |
Michal Simek | 2a7d952 | 2021-08-27 12:53:32 +0200 | [diff] [blame] | 16 | #include <memalign.h> |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 17 | #include <mmc.h> |
Michal Simek | c07b225 | 2018-06-08 13:45:14 +0200 | [diff] [blame] | 18 | #include <watchdog.h> |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 19 | #include <wdt.h> |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 20 | #include <zynqpl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Michal Simek | 242192b | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 22 | #include <asm/arch/hardware.h> |
| 23 | #include <asm/arch/sys_proto.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 24 | #include "../common/board.h" |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Michal Simek | 7659fe4 | 2022-02-17 14:28:41 +0100 | [diff] [blame] | 28 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_DEBUG_UART_BOARD_INIT) |
| 29 | void board_debug_uart_init(void) |
| 30 | { |
| 31 | /* Add initialization sequence if UART is not configured */ |
| 32 | } |
| 33 | #endif |
| 34 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 35 | int board_init(void) |
| 36 | { |
Michal Simek | ae9dc11 | 2021-02-02 16:34:48 +0100 | [diff] [blame] | 37 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 38 | printf("Silicon version:\t%d\n", zynq_get_silicon_version()); |
| 39 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 43 | int board_late_init(void) |
| 44 | { |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 45 | int env_targets_len = 0; |
| 46 | const char *mode; |
| 47 | char *new_targets; |
| 48 | char *env_targets; |
| 49 | |
Michal Simek | bab07b6 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 50 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 51 | debug("Saved variables - Skipping\n"); |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 56 | return 0; |
| 57 | |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 58 | switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) { |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 59 | case ZYNQ_BM_QSPI: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 60 | mode = "qspi"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 61 | env_set("modeboot", "qspiboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 62 | break; |
| 63 | case ZYNQ_BM_NAND: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 64 | mode = "nand"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 65 | env_set("modeboot", "nandboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 66 | break; |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 67 | case ZYNQ_BM_NOR: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 68 | mode = "nor"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 69 | env_set("modeboot", "norboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 70 | break; |
| 71 | case ZYNQ_BM_SD: |
Michal Simek | 9541d0b | 2019-09-11 12:51:49 +0200 | [diff] [blame] | 72 | mode = "mmc0"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 73 | env_set("modeboot", "sdboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 74 | break; |
| 75 | case ZYNQ_BM_JTAG: |
T Karthik Reddy | 6c28c29 | 2019-11-13 21:13:44 -0700 | [diff] [blame] | 76 | mode = "jtag pxe dhcp"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 77 | env_set("modeboot", "jtagboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 78 | break; |
| 79 | default: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 80 | mode = ""; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 81 | env_set("modeboot", ""); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 82 | break; |
| 83 | } |
| 84 | |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 85 | /* |
| 86 | * One terminating char + one byte for space between mode |
| 87 | * and default boot_targets |
| 88 | */ |
| 89 | env_targets = env_get("boot_targets"); |
| 90 | if (env_targets) |
| 91 | env_targets_len = strlen(env_targets); |
| 92 | |
| 93 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2); |
| 94 | if (!new_targets) |
| 95 | return -ENOMEM; |
| 96 | |
| 97 | sprintf(new_targets, "%s %s", mode, |
| 98 | env_targets ? env_targets : ""); |
| 99 | |
| 100 | env_set("boot_targets", new_targets); |
| 101 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 102 | return board_late_init_xilinx(); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 103 | } |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 104 | |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 105 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 106 | int dram_init_banksize(void) |
Nathan Rossi | c12892b | 2016-12-04 19:33:22 +1000 | [diff] [blame] | 107 | { |
Michal Simek | d5b7de6 | 2017-11-03 15:25:51 +0100 | [diff] [blame] | 108 | return fdtdec_setup_memory_banksize(); |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 109 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 110 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 111 | int dram_init(void) |
| 112 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 113 | if (fdtdec_setup_mem_size_base() != 0) |
Nathan Rossi | 58ea0d8 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 114 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 115 | |
| 116 | zynq_ddrc_init(); |
| 117 | |
| 118 | return 0; |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 119 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 120 | #else |
| 121 | int dram_init(void) |
| 122 | { |
Michal Simek | 1b84621 | 2018-04-11 16:12:28 +0200 | [diff] [blame] | 123 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 124 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 125 | |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 126 | zynq_ddrc_init(); |
| 127 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 128 | return 0; |
| 129 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 130 | #endif |
Ashok Reddy Soma | 909546d | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 131 | |
| 132 | enum env_location env_get_location(enum env_operation op, int prio) |
| 133 | { |
| 134 | u32 bootmode = zynq_slcr_get_boot_mode() & ZYNQ_BM_MASK; |
| 135 | |
| 136 | if (prio) |
| 137 | return ENVL_UNKNOWN; |
| 138 | |
| 139 | switch (bootmode) { |
| 140 | case ZYNQ_BM_SD: |
| 141 | if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) |
| 142 | return ENVL_FAT; |
| 143 | if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4)) |
| 144 | return ENVL_EXT4; |
Mike Looijmans | 682cf08 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 145 | return ENVL_NOWHERE; |
Ashok Reddy Soma | 909546d | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 146 | case ZYNQ_BM_NAND: |
| 147 | if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND)) |
| 148 | return ENVL_NAND; |
| 149 | if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) |
| 150 | return ENVL_UBI; |
Mike Looijmans | 682cf08 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 151 | return ENVL_NOWHERE; |
Ashok Reddy Soma | 909546d | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 152 | case ZYNQ_BM_NOR: |
| 153 | case ZYNQ_BM_QSPI: |
| 154 | if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) |
| 155 | return ENVL_SPI_FLASH; |
Mike Looijmans | 682cf08 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 156 | return ENVL_NOWHERE; |
Ashok Reddy Soma | 909546d | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 157 | case ZYNQ_BM_JTAG: |
| 158 | default: |
| 159 | return ENVL_NOWHERE; |
| 160 | } |
| 161 | } |
Michal Simek | 2a7d952 | 2021-08-27 12:53:32 +0200 | [diff] [blame] | 162 | |
| 163 | #if defined(CONFIG_SET_DFU_ALT_INFO) |
| 164 | |
| 165 | #define DFU_ALT_BUF_LEN SZ_1K |
| 166 | |
| 167 | void set_dfu_alt_info(char *interface, char *devstr) |
| 168 | { |
| 169 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); |
| 170 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame^] | 171 | if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) && |
| 172 | env_get("dfu_alt_info")) |
Michal Simek | 2a7d952 | 2021-08-27 12:53:32 +0200 | [diff] [blame] | 173 | return; |
| 174 | |
| 175 | memset(buf, 0, sizeof(buf)); |
| 176 | |
| 177 | switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) { |
| 178 | case ZYNQ_BM_SD: |
| 179 | snprintf(buf, DFU_ALT_BUF_LEN, |
| 180 | "mmc 0:1=boot.bin fat 0 1;" |
| 181 | "u-boot.img fat 0 1"); |
| 182 | break; |
| 183 | case ZYNQ_BM_QSPI: |
| 184 | snprintf(buf, DFU_ALT_BUF_LEN, |
| 185 | "sf 0:0=boot.bin raw 0 0x1500000;" |
| 186 | "u-boot.img raw 0x%x 0x500000", |
| 187 | CONFIG_SYS_SPI_U_BOOT_OFFS); |
| 188 | break; |
| 189 | default: |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | env_set("dfu_alt_info", buf); |
| 194 | puts("DFU alt info setting: done\n"); |
| 195 | } |
| 196 | #endif |