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