Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2014 - 2018 Xilinx, Inc. |
Michal Simek | a8c9436 | 2023-07-10 14:35:49 +0200 | [diff] [blame] | 4 | * Michal Simek <michal.simek@amd.com> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Algapally Santosh Sagar | 3c351b2 | 2023-01-19 22:36:16 -0700 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Venkatesh Yadav Abbarapu | 88990e9 | 2025-01-06 14:36:30 +0530 | [diff] [blame] | 9 | #include <dfu.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 10 | #include <env.h> |
Michal Simek | 806be2d | 2025-02-26 16:35:45 -0600 | [diff] [blame] | 11 | #include <efi_loader.h> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 12 | #include <fdtdec.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 14 | #include <env_internal.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 16 | #include <malloc.h> |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 17 | #include <memalign.h> |
| 18 | #include <mmc.h> |
Michal Simek | 754b53c | 2024-12-05 11:38:15 +0100 | [diff] [blame] | 19 | #include <mtd.h> |
Simon Glass | 495a5dc | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 20 | #include <time.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 21 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 22 | #include <asm/global_data.h> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include <asm/arch/hardware.h> |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 25 | #include <asm/arch/sys_proto.h> |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 26 | #include <linux/sizes.h> |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 27 | #include <dm/device.h> |
| 28 | #include <dm/uclass.h> |
Siva Durga Prasad Paladugu | b739897 | 2019-08-05 15:54:59 +0530 | [diff] [blame] | 29 | #include <versalpl.h> |
Prasad Kummari | 011a746 | 2025-02-19 17:23:01 +0530 | [diff] [blame] | 30 | #include <zynqmp_firmware.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 31 | #include "../common/board.h" |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Siva Durga Prasad Paladugu | b739897 | 2019-08-05 15:54:59 +0530 | [diff] [blame] | 35 | #if defined(CONFIG_FPGA_VERSALPL) |
Oleksandr Suvorov | dae95a4 | 2022-07-22 17:16:04 +0300 | [diff] [blame] | 36 | static xilinx_desc versalpl = { |
| 37 | xilinx_versal, csu_dma, 1, &versal_op, 0, &versal_op, NULL, |
| 38 | FPGA_LEGACY |
| 39 | }; |
Siva Durga Prasad Paladugu | b739897 | 2019-08-05 15:54:59 +0530 | [diff] [blame] | 40 | #endif |
| 41 | |
Michal Simek | fec5476 | 2025-01-06 10:20:40 +0100 | [diff] [blame] | 42 | static u8 versal_get_bootmode(void) |
| 43 | { |
| 44 | u8 bootmode; |
| 45 | u32 reg = 0; |
| 46 | |
Prasad Kummari | 011a746 | 2025-02-19 17:23:01 +0530 | [diff] [blame] | 47 | if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE) && current_el() != 3) { |
| 48 | reg = zynqmp_pm_get_bootmode_reg(); |
| 49 | } else { |
| 50 | reg = readl(&crp_base->boot_mode_usr); |
| 51 | } |
Michal Simek | fec5476 | 2025-01-06 10:20:40 +0100 | [diff] [blame] | 52 | |
| 53 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 54 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 55 | |
| 56 | bootmode = reg & BOOT_MODES_MASK; |
| 57 | |
| 58 | return bootmode; |
| 59 | } |
| 60 | |
Michal Simek | 76fdafa | 2024-12-05 11:38:16 +0100 | [diff] [blame] | 61 | static u32 versal_multi_boot(void) |
| 62 | { |
Michal Simek | fec5476 | 2025-01-06 10:20:40 +0100 | [diff] [blame] | 63 | u8 bootmode = versal_get_bootmode(); |
| 64 | |
| 65 | /* Mostly workaround for QEMU CI pipeline */ |
| 66 | if (bootmode == JTAG_MODE) |
| 67 | return 0; |
| 68 | |
Michal Simek | 76fdafa | 2024-12-05 11:38:16 +0100 | [diff] [blame] | 69 | return readl(0xF1110004); |
| 70 | } |
| 71 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 72 | int board_init(void) |
| 73 | { |
| 74 | printf("EL Level:\tEL%d\n", current_el()); |
Michal Simek | 76fdafa | 2024-12-05 11:38:16 +0100 | [diff] [blame] | 75 | printf("Multiboot:\t%d\n", versal_multi_boot()); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 76 | |
Siva Durga Prasad Paladugu | b739897 | 2019-08-05 15:54:59 +0530 | [diff] [blame] | 77 | #if defined(CONFIG_FPGA_VERSALPL) |
| 78 | fpga_init(); |
| 79 | fpga_add(fpga_xilinx, &versalpl); |
| 80 | #endif |
| 81 | |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 82 | if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) |
| 83 | xilinx_read_eeprom(); |
| 84 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | int board_early_init_r(void) |
| 89 | { |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 90 | u32 val; |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 91 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 92 | if (current_el() != 3) |
| 93 | return 0; |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 94 | |
Michal Simek | f56f7d1 | 2019-01-28 11:12:41 +0100 | [diff] [blame] | 95 | debug("iou_switch ctrl div0 %x\n", |
| 96 | readl(&crlapb_base->iou_switch_ctrl)); |
| 97 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 98 | writel(IOU_SWITCH_CTRL_CLKACT_BIT | |
Michal Simek | f56f7d1 | 2019-01-28 11:12:41 +0100 | [diff] [blame] | 99 | (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT), |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 100 | &crlapb_base->iou_switch_ctrl); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 101 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 102 | /* Global timer init - Program time stamp reference clk */ |
| 103 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 104 | val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT; |
| 105 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 106 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 107 | debug("ref ctrl 0x%x\n", |
| 108 | readl(&crlapb_base->timestamp_ref_ctrl)); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 109 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 110 | /* Clear reset of timestamp reg */ |
| 111 | writel(0, &crlapb_base->rst_timestamp); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 112 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 113 | /* |
| 114 | * Program freq register in System counter and |
| 115 | * enable system counter. |
| 116 | */ |
Peng Fan | 4b3a182 | 2022-04-13 17:47:17 +0800 | [diff] [blame] | 117 | writel(CONFIG_COUNTER_FREQUENCY, |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 118 | &iou_scntr_secure->base_frequency_id_register); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 119 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 120 | debug("counter val 0x%x\n", |
| 121 | readl(&iou_scntr_secure->base_frequency_id_register)); |
| 122 | |
| 123 | writel(IOU_SCNTRS_CONTROL_EN, |
| 124 | &iou_scntr_secure->counter_control_register); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 125 | |
Michal Simek | 19f6c97 | 2019-01-28 11:08:00 +0100 | [diff] [blame] | 126 | debug("scntrs control 0x%x\n", |
| 127 | readl(&iou_scntr_secure->counter_control_register)); |
| 128 | debug("timer 0x%llx\n", get_ticks()); |
| 129 | debug("timer 0x%llx\n", get_ticks()); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
Ashok Reddy Soma | 6c19105 | 2022-05-05 23:53:45 -0600 | [diff] [blame] | 134 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
| 135 | char *const argv[]) |
| 136 | { |
| 137 | int ret = 0; |
| 138 | |
| 139 | if (current_el() > 1) { |
| 140 | smp_kick_all_cpus(); |
| 141 | dcache_disable(); |
| 142 | armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry, |
| 143 | ES_TO_AARCH64); |
| 144 | } else { |
| 145 | printf("FAIL: current EL is not above EL1\n"); |
| 146 | ret = EINVAL; |
| 147 | } |
| 148 | return ret; |
| 149 | } |
| 150 | |
Michal Simek | b163476 | 2023-09-05 13:30:07 +0200 | [diff] [blame] | 151 | static int boot_targets_setup(void) |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 152 | { |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 153 | u8 bootmode; |
| 154 | struct udevice *dev; |
| 155 | int bootseq = -1; |
| 156 | int bootseq_len = 0; |
| 157 | int env_targets_len = 0; |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 158 | const char *mode = NULL; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 159 | char *new_targets; |
| 160 | char *env_targets; |
| 161 | |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 162 | bootmode = versal_get_bootmode(); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 163 | |
| 164 | puts("Bootmode: "); |
| 165 | switch (bootmode) { |
T Karthik Reddy | facca9a | 2019-07-11 16:07:57 +0530 | [diff] [blame] | 166 | case USB_MODE: |
| 167 | puts("USB_MODE\n"); |
T Karthik Reddy | 1104faf | 2021-03-30 23:24:57 -0600 | [diff] [blame] | 168 | mode = "usb_dfu0 usb_dfu1"; |
T Karthik Reddy | facca9a | 2019-07-11 16:07:57 +0530 | [diff] [blame] | 169 | break; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 170 | case JTAG_MODE: |
| 171 | puts("JTAG_MODE\n"); |
Siva Durga Prasad Paladugu | 00784e0 | 2019-06-25 17:13:14 +0530 | [diff] [blame] | 172 | mode = "jtag pxe dhcp"; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 173 | break; |
| 174 | case QSPI_MODE_24BIT: |
| 175 | puts("QSPI_MODE_24\n"); |
Venkatesh Yadav Abbarapu | bf6e041 | 2024-05-10 08:22:38 +0200 | [diff] [blame] | 176 | if (uclass_get_device_by_name(UCLASS_SPI, |
| 177 | "spi@f1030000", &dev)) { |
| 178 | debug("QSPI driver for QSPI device is not present\n"); |
| 179 | break; |
| 180 | } |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 181 | mode = "xspi0"; |
| 182 | break; |
| 183 | case QSPI_MODE_32BIT: |
| 184 | puts("QSPI_MODE_32\n"); |
Venkatesh Yadav Abbarapu | bf6e041 | 2024-05-10 08:22:38 +0200 | [diff] [blame] | 185 | if (uclass_get_device_by_name(UCLASS_SPI, |
| 186 | "spi@f1030000", &dev)) { |
| 187 | debug("QSPI driver for QSPI device is not present\n"); |
| 188 | break; |
| 189 | } |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 190 | mode = "xspi0"; |
| 191 | break; |
| 192 | case OSPI_MODE: |
| 193 | puts("OSPI_MODE\n"); |
Venkatesh Yadav Abbarapu | bf6e041 | 2024-05-10 08:22:38 +0200 | [diff] [blame] | 194 | if (uclass_get_device_by_name(UCLASS_SPI, |
| 195 | "spi@f1010000", &dev)) { |
| 196 | debug("OSPI driver for OSPI device is not present\n"); |
| 197 | break; |
| 198 | } |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 199 | mode = "xspi0"; |
| 200 | break; |
| 201 | case EMMC_MODE: |
| 202 | puts("EMMC_MODE\n"); |
T Karthik Reddy | bc2b964 | 2019-12-16 04:44:26 -0700 | [diff] [blame] | 203 | if (uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | a12445f | 2021-11-18 12:57:20 +0100 | [diff] [blame] | 204 | "mmc@f1050000", &dev) && |
| 205 | uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | bc2b964 | 2019-12-16 04:44:26 -0700 | [diff] [blame] | 206 | "sdhci@f1050000", &dev)) { |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 207 | debug("SD1 driver for SD1 device is not present\n"); |
| 208 | break; |
T Karthik Reddy | bc2b964 | 2019-12-16 04:44:26 -0700 | [diff] [blame] | 209 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 210 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
T Karthik Reddy | bc2b964 | 2019-12-16 04:44:26 -0700 | [diff] [blame] | 211 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 212 | bootseq = dev_seq(dev); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 213 | break; |
Polak, Leszek | cddfc13 | 2023-10-08 14:34:42 +0000 | [diff] [blame] | 214 | case SELECTMAP_MODE: |
| 215 | puts("SELECTMAP_MODE\n"); |
| 216 | break; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 217 | case SD_MODE: |
| 218 | puts("SD_MODE\n"); |
| 219 | if (uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | a12445f | 2021-11-18 12:57:20 +0100 | [diff] [blame] | 220 | "mmc@f1040000", &dev) && |
| 221 | uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 222 | "sdhci@f1040000", &dev)) { |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 223 | debug("SD0 driver for SD0 device is not present\n"); |
| 224 | break; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 225 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 226 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 227 | |
| 228 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 229 | bootseq = dev_seq(dev); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 230 | break; |
| 231 | case SD1_LSHFT_MODE: |
| 232 | puts("LVL_SHFT_"); |
| 233 | /* fall through */ |
| 234 | case SD_MODE1: |
| 235 | puts("SD_MODE1\n"); |
| 236 | if (uclass_get_device_by_name(UCLASS_MMC, |
T Karthik Reddy | a12445f | 2021-11-18 12:57:20 +0100 | [diff] [blame] | 237 | "mmc@f1050000", &dev) && |
| 238 | uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 239 | "sdhci@f1050000", &dev)) { |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 240 | debug("SD1 driver for SD1 device is not present\n"); |
| 241 | break; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 242 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 243 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 244 | |
| 245 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 246 | bootseq = dev_seq(dev); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 247 | break; |
| 248 | default: |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 249 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 250 | break; |
| 251 | } |
| 252 | |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 253 | if (mode) { |
| 254 | if (bootseq >= 0) { |
| 255 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); |
| 256 | debug("Bootseq len: %x\n", bootseq_len); |
| 257 | } |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 258 | |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 259 | /* |
| 260 | * One terminating char + one byte for space between mode |
| 261 | * and default boot_targets |
| 262 | */ |
| 263 | env_targets = env_get("boot_targets"); |
| 264 | if (env_targets) |
| 265 | env_targets_len = strlen(env_targets); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 266 | |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 267 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
| 268 | bootseq_len); |
| 269 | if (!new_targets) |
| 270 | return -ENOMEM; |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 271 | |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 272 | if (bootseq >= 0) |
| 273 | sprintf(new_targets, "%s%x %s", mode, bootseq, |
| 274 | env_targets ? env_targets : ""); |
| 275 | else |
| 276 | sprintf(new_targets, "%s %s", mode, |
| 277 | env_targets ? env_targets : ""); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 278 | |
Venkatesh Yadav Abbarapu | e5dd04a | 2023-09-04 08:50:34 +0530 | [diff] [blame] | 279 | env_set("boot_targets", new_targets); |
| 280 | } |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 281 | |
Michal Simek | b163476 | 2023-09-05 13:30:07 +0200 | [diff] [blame] | 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | int board_late_init(void) |
| 286 | { |
| 287 | int ret; |
| 288 | |
Jonathan Humphreys | 531eb60 | 2025-02-26 16:35:47 -0600 | [diff] [blame] | 289 | if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) |
| 290 | configure_capsule_updates(); |
| 291 | |
Michal Simek | b163476 | 2023-09-05 13:30:07 +0200 | [diff] [blame] | 292 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 293 | debug("Saved variables - Skipping\n"); |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | if (!IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 298 | return 0; |
| 299 | |
| 300 | if (IS_ENABLED(CONFIG_DISTRO_DEFAULTS)) { |
| 301 | ret = boot_targets_setup(); |
| 302 | if (ret) |
| 303 | return ret; |
| 304 | } |
| 305 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 306 | return board_late_init_xilinx(); |
Siva Durga Prasad Paladugu | 37c2ff8 | 2019-01-31 17:28:14 +0530 | [diff] [blame] | 307 | } |
| 308 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 309 | int dram_init_banksize(void) |
| 310 | { |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 311 | int ret; |
| 312 | |
| 313 | ret = fdtdec_setup_memory_banksize(); |
| 314 | if (ret) |
| 315 | return ret; |
| 316 | |
| 317 | mem_map_fill(); |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | int dram_init(void) |
| 323 | { |
Michal Simek | 9134d4c | 2020-07-10 12:42:09 +0200 | [diff] [blame] | 324 | if (fdtdec_setup_mem_size_base_lowest() != 0) |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 325 | return -EINVAL; |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
Michal Simek | c1e98aa | 2024-10-25 13:56:07 +0200 | [diff] [blame] | 330 | #if !CONFIG_IS_ENABLED(SYSRESET) |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 331 | void reset_cpu(void) |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 332 | { |
| 333 | } |
Michal Simek | c1e98aa | 2024-10-25 13:56:07 +0200 | [diff] [blame] | 334 | #endif |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 335 | |
Michal Simek | f3a541f | 2024-03-22 12:43:17 +0100 | [diff] [blame] | 336 | #if defined(CONFIG_ENV_IS_NOWHERE) |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 337 | enum env_location env_get_location(enum env_operation op, int prio) |
| 338 | { |
| 339 | u32 bootmode = versal_get_bootmode(); |
| 340 | |
| 341 | if (prio) |
| 342 | return ENVL_UNKNOWN; |
| 343 | |
| 344 | switch (bootmode) { |
| 345 | case EMMC_MODE: |
| 346 | case SD_MODE: |
| 347 | case SD1_LSHFT_MODE: |
| 348 | case SD_MODE1: |
| 349 | if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) |
| 350 | return ENVL_FAT; |
| 351 | if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4)) |
| 352 | return ENVL_EXT4; |
T Karthik Reddy | 6f8b205 | 2021-11-24 12:16:55 +0100 | [diff] [blame] | 353 | return ENVL_NOWHERE; |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 354 | case OSPI_MODE: |
| 355 | case QSPI_MODE_24BIT: |
| 356 | case QSPI_MODE_32BIT: |
| 357 | if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) |
| 358 | return ENVL_SPI_FLASH; |
T Karthik Reddy | 6f8b205 | 2021-11-24 12:16:55 +0100 | [diff] [blame] | 359 | return ENVL_NOWHERE; |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 360 | case JTAG_MODE: |
Polak, Leszek | cddfc13 | 2023-10-08 14:34:42 +0000 | [diff] [blame] | 361 | case SELECTMAP_MODE: |
Ashok Reddy Soma | fb6b3cd | 2021-02-23 08:07:46 -0700 | [diff] [blame] | 362 | default: |
| 363 | return ENVL_NOWHERE; |
| 364 | } |
| 365 | } |
Michal Simek | f3a541f | 2024-03-22 12:43:17 +0100 | [diff] [blame] | 366 | #endif |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 367 | |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 368 | #define DFU_ALT_BUF_LEN SZ_1K |
| 369 | |
Michal Simek | 754b53c | 2024-12-05 11:38:15 +0100 | [diff] [blame] | 370 | static void mtd_found_part(u32 *base, u32 *size) |
| 371 | { |
| 372 | struct mtd_info *part, *mtd; |
| 373 | |
| 374 | mtd_probe_devices(); |
| 375 | |
| 376 | mtd = get_mtd_device_nm("nor0"); |
| 377 | if (!IS_ERR_OR_NULL(mtd)) { |
| 378 | list_for_each_entry(part, &mtd->partitions, node) { |
| 379 | debug("0x%012llx-0x%012llx : \"%s\"\n", |
| 380 | part->offset, part->offset + part->size, |
| 381 | part->name); |
| 382 | |
| 383 | if (*base >= part->offset && |
| 384 | *base < part->offset + part->size) { |
| 385 | debug("Found my partition: %d/%s\n", |
| 386 | part->index, part->name); |
| 387 | *base = part->offset; |
| 388 | *size = part->size; |
| 389 | break; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
Jonathan Humphreys | 531eb60 | 2025-02-26 16:35:47 -0600 | [diff] [blame] | 395 | void configure_capsule_updates(void) |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 396 | { |
| 397 | int bootseq = 0, len = 0; |
Michal Simek | 76fdafa | 2024-12-05 11:38:16 +0100 | [diff] [blame] | 398 | u32 multiboot = versal_multi_boot(); |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 399 | u32 bootmode = versal_get_bootmode(); |
| 400 | |
| 401 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); |
| 402 | |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 403 | memset(buf, 0, sizeof(buf)); |
| 404 | |
Michal Simek | 76fdafa | 2024-12-05 11:38:16 +0100 | [diff] [blame] | 405 | multiboot = env_get_hex("multiboot", multiboot); |
| 406 | |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 407 | switch (bootmode) { |
| 408 | case EMMC_MODE: |
| 409 | case SD_MODE: |
| 410 | case SD1_LSHFT_MODE: |
| 411 | case SD_MODE1: |
| 412 | bootseq = mmc_get_env_dev(); |
| 413 | |
| 414 | len += snprintf(buf + len, DFU_ALT_BUF_LEN, "mmc %d=boot", |
| 415 | bootseq); |
| 416 | |
Michal Simek | 76fdafa | 2024-12-05 11:38:16 +0100 | [diff] [blame] | 417 | if (multiboot) |
| 418 | len += snprintf(buf + len, DFU_ALT_BUF_LEN, |
| 419 | "%04d", multiboot); |
| 420 | |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 421 | len += snprintf(buf + len, DFU_ALT_BUF_LEN, ".bin fat %d 1", |
| 422 | bootseq); |
| 423 | break; |
Michal Simek | 754b53c | 2024-12-05 11:38:15 +0100 | [diff] [blame] | 424 | case QSPI_MODE_24BIT: |
| 425 | case QSPI_MODE_32BIT: |
| 426 | case OSPI_MODE: |
| 427 | { |
Michal Simek | 76fdafa | 2024-12-05 11:38:16 +0100 | [diff] [blame] | 428 | u32 base = multiboot * SZ_32K; |
Michal Simek | 754b53c | 2024-12-05 11:38:15 +0100 | [diff] [blame] | 429 | u32 size = 0x1500000; |
| 430 | u32 limit = size; |
| 431 | |
| 432 | mtd_found_part(&base, &limit); |
| 433 | |
| 434 | len += snprintf(buf + len, DFU_ALT_BUF_LEN, |
| 435 | "sf 0:0=boot.bin raw 0x%x 0x%x", |
| 436 | base, limit); |
| 437 | } |
| 438 | break; |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 439 | default: |
| 440 | return; |
| 441 | } |
| 442 | |
Michal Simek | 806be2d | 2025-02-26 16:35:45 -0600 | [diff] [blame] | 443 | update_info.dfu_string = strdup(buf); |
| 444 | debug("Capsule DFU: %s\n", update_info.dfu_string); |
Michal Simek | 444a70e | 2024-10-25 13:56:08 +0200 | [diff] [blame] | 445 | } |