Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 2 | /* |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 3 | * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de> |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Marek Behún | 90555af | 2022-02-17 13:54:42 +0100 | [diff] [blame] | 7 | #include <cpu_func.h> |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 8 | #include <dm.h> |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 9 | #include <fdtdec.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 10 | #include <hang.h> |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 14 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/arch/cpu.h> |
| 18 | #include <asm/arch/soc.h> |
| 19 | |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 20 | #if defined(CONFIG_SPL_SPI_FLASH_SUPPORT) || defined(CONFIG_SPL_MMC) || \ |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 21 | defined(CONFIG_SPL_SATA) |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * When loading U-Boot via SPL from SPI NOR, CONFIG_SYS_SPI_U_BOOT_OFFS must |
| 25 | * point to the offset of kwbimage main header which is always at offset zero |
| 26 | * (defined by BootROM). Therefore other values of CONFIG_SYS_SPI_U_BOOT_OFFS |
| 27 | * makes U-Boot non-bootable. |
| 28 | */ |
| 29 | #ifdef CONFIG_SPL_SPI_FLASH_SUPPORT |
| 30 | #if defined(CONFIG_SYS_SPI_U_BOOT_OFFS) && CONFIG_SYS_SPI_U_BOOT_OFFS != 0 |
| 31 | #error CONFIG_SYS_SPI_U_BOOT_OFFS must be set to 0 |
| 32 | #endif |
| 33 | #endif |
| 34 | |
| 35 | /* |
| 36 | * When loading U-Boot via SPL from eMMC (in Marvell terminology SDIO), the |
| 37 | * kwbimage main header is stored at sector 0. U-Boot SPL needs to parse this |
| 38 | * header and figure out at which sector the U-Boot proper binary is stored. |
| 39 | * Partition booting is therefore not supported and CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR |
| 40 | * and CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET need to point to the |
| 41 | * kwbimage main header. |
| 42 | */ |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 43 | #ifdef CONFIG_SPL_MMC |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 44 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
| 45 | #error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION is unsupported |
| 46 | #endif |
| 47 | #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR) && CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR != 0 |
| 48 | #error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR must be set to 0 |
| 49 | #endif |
Marek Behún | 3a7bbd8 | 2022-01-14 14:31:45 +0100 | [diff] [blame] | 50 | #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET) && \ |
| 51 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET != 0 |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 52 | #error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET must be set to 0 |
| 53 | #endif |
| 54 | #endif |
| 55 | |
| 56 | /* |
| 57 | * When loading U-Boot via SPL from SATA disk, the kwbimage main header is |
| 58 | * stored at sector 1. Therefore CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be |
| 59 | * set to 1. Otherwise U-Boot SPL would not be able to load U-Boot proper. |
| 60 | */ |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 61 | #ifdef CONFIG_SPL_SATA |
Marek Behún | 3a7bbd8 | 2022-01-14 14:31:45 +0100 | [diff] [blame] | 62 | #if !defined(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR) || \ |
| 63 | !defined(CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR) || CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR != 1 |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 64 | #error CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be set to 1 |
| 65 | #endif |
| 66 | #endif |
| 67 | |
| 68 | /* Boot Type - block ID */ |
| 69 | #define IBR_HDR_I2C_ID 0x4D |
| 70 | #define IBR_HDR_SPI_ID 0x5A |
| 71 | #define IBR_HDR_NAND_ID 0x8B |
| 72 | #define IBR_HDR_SATA_ID 0x78 |
| 73 | #define IBR_HDR_PEX_ID 0x9C |
| 74 | #define IBR_HDR_UART_ID 0x69 |
| 75 | #define IBR_HDR_SDIO_ID 0xAE |
| 76 | |
Pali Rohár | 0f7df22 | 2021-10-22 12:41:10 +0200 | [diff] [blame] | 77 | /* Structure of the main header, version 1 (Armada 370/XP/375/38x/39x) */ |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 78 | struct kwbimage_main_hdr_v1 { |
Marek Behún | 031d172 | 2022-01-14 14:31:43 +0100 | [diff] [blame] | 79 | u8 blockid; /* 0x0 */ |
| 80 | u8 flags; /* 0x1 */ |
| 81 | u16 nandpagesize; /* 0x2-0x3 */ |
| 82 | u32 blocksize; /* 0x4-0x7 */ |
| 83 | u8 version; /* 0x8 */ |
| 84 | u8 headersz_msb; /* 0x9 */ |
| 85 | u16 headersz_lsb; /* 0xA-0xB */ |
| 86 | u32 srcaddr; /* 0xC-0xF */ |
| 87 | u32 destaddr; /* 0x10-0x13 */ |
| 88 | u32 execaddr; /* 0x14-0x17 */ |
| 89 | u8 options; /* 0x18 */ |
| 90 | u8 nandblocksize; /* 0x19 */ |
| 91 | u8 nandbadblklocation; /* 0x1A */ |
| 92 | u8 reserved4; /* 0x1B */ |
| 93 | u16 reserved5; /* 0x1C-0x1D */ |
| 94 | u8 ext; /* 0x1E */ |
| 95 | u8 checksum; /* 0x1F */ |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 96 | } __packed; |
| 97 | |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 98 | #ifdef CONFIG_SPL_MMC |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 99 | u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 100 | { |
| 101 | return MMCSD_MODE_RAW; |
| 102 | } |
| 103 | #endif |
| 104 | |
Pali Rohár | 8242056 | 2022-01-14 14:31:41 +0100 | [diff] [blame] | 105 | static u32 checksum32(void *start, u32 len) |
| 106 | { |
| 107 | u32 csum = 0; |
| 108 | u32 *p = start; |
| 109 | |
| 110 | while (len > 0) { |
| 111 | csum += *p++; |
| 112 | len -= sizeof(u32); |
| 113 | }; |
| 114 | |
| 115 | return csum; |
| 116 | } |
| 117 | |
| 118 | int spl_check_board_image(struct spl_image_info *spl_image, |
| 119 | const struct spl_boot_device *bootdev) |
| 120 | { |
| 121 | u32 csum = *(u32 *)(spl_image->load_addr + spl_image->size - 4); |
| 122 | |
| 123 | if (checksum32((void *)spl_image->load_addr, |
| 124 | spl_image->size - 4) != csum) { |
| 125 | printf("ERROR: Invalid data checksum in kwbimage\n"); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 132 | int spl_parse_board_header(struct spl_image_info *spl_image, |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 133 | const struct spl_boot_device *bootdev, |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 134 | const void *image_header, size_t size) |
| 135 | { |
| 136 | const struct kwbimage_main_hdr_v1 *mhdr = image_header; |
| 137 | |
| 138 | if (size < sizeof(*mhdr)) { |
| 139 | /* This should be compile time assert */ |
| 140 | printf("FATAL ERROR: Image header size is too small\n"); |
| 141 | hang(); |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Very basic check for image validity. We cannot check mhdr->checksum |
| 146 | * as it is calculated also from variable length extended headers |
| 147 | * (including SPL content) which is not included in U-Boot image_header. |
| 148 | */ |
| 149 | if (mhdr->version != 1 || |
Pali Rohár | a157e12 | 2022-01-14 14:31:39 +0100 | [diff] [blame] | 150 | ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr)) { |
| 151 | printf("ERROR: Invalid kwbimage v1\n"); |
| 152 | return -EINVAL; |
| 153 | } |
| 154 | |
Marek Behún | 556eab6 | 2022-01-14 14:31:44 +0100 | [diff] [blame] | 155 | if (IS_ENABLED(CONFIG_SPL_SPI_FLASH_SUPPORT) && |
| 156 | bootdev->boot_device == BOOT_DEVICE_SPI && |
Pali Rohár | a157e12 | 2022-01-14 14:31:39 +0100 | [diff] [blame] | 157 | mhdr->blockid != IBR_HDR_SPI_ID) { |
| 158 | printf("ERROR: Wrong blockid (0x%x) in SPI kwbimage\n", |
| 159 | mhdr->blockid); |
| 160 | return -EINVAL; |
| 161 | } |
Pali Rohár | a157e12 | 2022-01-14 14:31:39 +0100 | [diff] [blame] | 162 | |
Marek Behún | 556eab6 | 2022-01-14 14:31:44 +0100 | [diff] [blame] | 163 | if (IS_ENABLED(CONFIG_SPL_SATA) && |
| 164 | bootdev->boot_device == BOOT_DEVICE_SATA && |
Pali Rohár | a157e12 | 2022-01-14 14:31:39 +0100 | [diff] [blame] | 165 | mhdr->blockid != IBR_HDR_SATA_ID) { |
| 166 | printf("ERROR: Wrong blockid (0x%x) in SATA kwbimage\n", |
| 167 | mhdr->blockid); |
| 168 | return -EINVAL; |
| 169 | } |
Pali Rohár | a157e12 | 2022-01-14 14:31:39 +0100 | [diff] [blame] | 170 | |
Marek Behún | 556eab6 | 2022-01-14 14:31:44 +0100 | [diff] [blame] | 171 | if (IS_ENABLED(CONFIG_SPL_MMC) && |
| 172 | (bootdev->boot_device == BOOT_DEVICE_MMC1 || |
Pali Rohár | a157e12 | 2022-01-14 14:31:39 +0100 | [diff] [blame] | 173 | bootdev->boot_device == BOOT_DEVICE_MMC2 || |
| 174 | bootdev->boot_device == BOOT_DEVICE_MMC2_2) && |
| 175 | mhdr->blockid != IBR_HDR_SDIO_ID) { |
| 176 | printf("ERROR: Wrong blockid (0x%x) in SDIO kwbimage\n", |
| 177 | mhdr->blockid); |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 178 | return -EINVAL; |
| 179 | } |
| 180 | |
| 181 | spl_image->offset = mhdr->srcaddr; |
| 182 | |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 183 | /* |
| 184 | * For SATA srcaddr is specified in number of sectors. |
| 185 | * The main header is must be stored at sector number 1. |
| 186 | * This expects that sector size is 512 bytes and recalculates |
| 187 | * data offset to bytes relative to the main header. |
| 188 | */ |
Marek Behún | 556eab6 | 2022-01-14 14:31:44 +0100 | [diff] [blame] | 189 | if (IS_ENABLED(CONFIG_SPL_SATA) && mhdr->blockid == IBR_HDR_SATA_ID) { |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 190 | if (spl_image->offset < 1) { |
Marek Behún | 46c871a | 2022-01-14 14:31:42 +0100 | [diff] [blame] | 191 | printf("ERROR: Wrong srcaddr (0x%08x) in SATA kwbimage\n", |
| 192 | spl_image->offset); |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 193 | return -EINVAL; |
| 194 | } |
| 195 | spl_image->offset -= 1; |
| 196 | spl_image->offset *= 512; |
| 197 | } |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 198 | |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 199 | /* |
| 200 | * For SDIO (eMMC) srcaddr is specified in number of sectors. |
| 201 | * This expects that sector size is 512 bytes and recalculates |
| 202 | * data offset to bytes. |
| 203 | */ |
Marek Behún | 556eab6 | 2022-01-14 14:31:44 +0100 | [diff] [blame] | 204 | if (IS_ENABLED(CONFIG_SPL_MMC) && mhdr->blockid == IBR_HDR_SDIO_ID) |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 205 | spl_image->offset *= 512; |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 206 | |
Pali Rohár | eb7e1fc | 2022-01-14 14:31:37 +0100 | [diff] [blame] | 207 | if (spl_image->offset % 4 != 0) { |
| 208 | printf("ERROR: Wrong srcaddr (0x%08x) in kwbimage\n", |
| 209 | spl_image->offset); |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | |
| 213 | if (mhdr->blocksize <= 4 || mhdr->blocksize % 4 != 0) { |
| 214 | printf("ERROR: Wrong blocksize (0x%08x) in kwbimage\n", |
| 215 | mhdr->blocksize); |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 219 | spl_image->size = mhdr->blocksize; |
| 220 | spl_image->entry_point = mhdr->execaddr; |
| 221 | spl_image->load_addr = mhdr->destaddr; |
| 222 | spl_image->os = IH_OS_U_BOOT; |
| 223 | spl_image->name = "U-Boot"; |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 228 | u32 spl_boot_device(void) |
| 229 | { |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 230 | u32 boot_device = get_boot_device(); |
| 231 | |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 232 | switch (boot_device) { |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 233 | /* |
| 234 | * Return to the BootROM to continue the Marvell xmodem |
| 235 | * UART boot protocol. As initiated by the kwboot tool. |
| 236 | * |
| 237 | * This can only be done by the BootROM since the beginning |
| 238 | * of the image is already read and interpreted by the BootROM. |
| 239 | * SPL has no chance to receive this information. So we |
| 240 | * need to return to the BootROM to enable this xmodem |
| 241 | * UART download. Use SPL infrastructure to return to BootROM. |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 242 | */ |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 243 | case BOOT_DEVICE_UART: |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 244 | return BOOT_DEVICE_BOOTROM; |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 245 | |
| 246 | /* |
| 247 | * If SPL is compiled with chosen boot_device support |
| 248 | * then use SPL driver for loading U-Boot proper. |
| 249 | */ |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 250 | #ifdef CONFIG_SPL_MMC |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 251 | case BOOT_DEVICE_MMC1: |
| 252 | return BOOT_DEVICE_MMC1; |
| 253 | #endif |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 254 | #ifdef CONFIG_SPL_SATA |
Pali Rohár | 90a8898 | 2021-10-29 14:09:48 +0200 | [diff] [blame] | 255 | case BOOT_DEVICE_SATA: |
| 256 | return BOOT_DEVICE_SATA; |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 257 | #endif |
| 258 | #ifdef CONFIG_SPL_SPI_FLASH_SUPPORT |
| 259 | case BOOT_DEVICE_SPI: |
| 260 | return BOOT_DEVICE_SPI; |
| 261 | #endif |
| 262 | |
| 263 | /* |
| 264 | * If SPL is not compiled with chosen boot_device support |
| 265 | * then return to the BootROM. BootROM supports loading |
| 266 | * U-Boot proper from any valid boot_device present in SAR |
| 267 | * register. |
| 268 | */ |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 269 | default: |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 270 | return BOOT_DEVICE_BOOTROM; |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 271 | } |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Pali Rohár | d0f064d | 2022-08-02 11:55:19 +0200 | [diff] [blame] | 274 | void board_boot_order(u32 *spl_boot_list) |
| 275 | { |
| 276 | spl_boot_list[0] = spl_boot_device(); |
| 277 | if (spl_boot_list[0] != BOOT_DEVICE_BOOTROM) |
| 278 | spl_boot_list[1] = BOOT_DEVICE_BOOTROM; |
| 279 | } |
| 280 | |
Marek Behún | ee76b4a | 2021-08-16 15:19:37 +0200 | [diff] [blame] | 281 | #else |
| 282 | |
| 283 | u32 spl_boot_device(void) |
| 284 | { |
| 285 | return BOOT_DEVICE_BOOTROM; |
| 286 | } |
| 287 | |
| 288 | #endif |
| 289 | |
Pali Rohár | a3a38e5 | 2021-07-23 11:14:25 +0200 | [diff] [blame] | 290 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 291 | struct spl_boot_device *bootdev) |
| 292 | { |
Tom Rini | a276bc7 | 2022-05-24 09:57:18 -0400 | [diff] [blame] | 293 | u32 *regs = *(u32 **)(CONFIG_SPL_STACK + 4); |
Pali Rohár | a3a38e5 | 2021-07-23 11:14:25 +0200 | [diff] [blame] | 294 | |
| 295 | printf("Returning to BootROM (return address 0x%08x)...\n", regs[13]); |
| 296 | return_to_bootrom(); |
| 297 | |
| 298 | /* NOTREACHED - return_to_bootrom() does not return */ |
| 299 | hang(); |
| 300 | } |
| 301 | |
Pali Rohár | 322d8da | 2022-08-08 19:13:43 +0200 | [diff] [blame] | 302 | /* |
| 303 | * SPI0 CS0 Flash is mapped to address range 0xD4000000 - 0xD7FFFFFF by BootROM. |
| 304 | * Proper U-Boot removes this direct mapping. So it is available only in SPL. |
| 305 | */ |
| 306 | #if defined(CONFIG_SPL_ENV_IS_IN_SPI_FLASH) && \ |
| 307 | CONFIG_ENV_SPI_BUS == 0 && CONFIG_ENV_SPI_CS == 0 && \ |
| 308 | CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE <= 64*1024*1024 |
| 309 | void *env_sf_get_env_addr(void) |
| 310 | { |
| 311 | return (void *)0xD4000000 + CONFIG_ENV_OFFSET; |
| 312 | } |
| 313 | #endif |
| 314 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 315 | void board_init_f(ulong dummy) |
| 316 | { |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 317 | int ret; |
| 318 | |
Stefan Roese | d7f2c12 | 2015-04-17 18:13:06 +0200 | [diff] [blame] | 319 | /* |
| 320 | * Pin muxing needs to be done before UART output, since |
| 321 | * on A38x the UART pins need some re-muxing for output |
| 322 | * to work. |
| 323 | */ |
| 324 | board_early_init_f(); |
| 325 | |
Stefan Roese | 85bddff | 2019-04-12 16:42:28 +0200 | [diff] [blame] | 326 | /* |
| 327 | * Use special translation offset for SPL. This needs to be |
| 328 | * configured *before* spl_init() is called as this function |
| 329 | * calls dm_init() which calls the bind functions of the |
| 330 | * device drivers. Here the base address needs to be configured |
| 331 | * (translated) correctly. |
| 332 | */ |
| 333 | gd->translation_offset = 0xd0000000 - 0xf1000000; |
| 334 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 335 | ret = spl_init(); |
| 336 | if (ret) { |
Pali Rohár | 6e86351 | 2021-12-17 18:31:14 +0100 | [diff] [blame] | 337 | printf("spl_init() failed: %d\n", ret); |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 338 | hang(); |
| 339 | } |
| 340 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 341 | preloader_console_init(); |
| 342 | |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 343 | /* Armada 375 does not support SerDes and DDR3 init yet */ |
| 344 | #if !defined(CONFIG_ARMADA_375) |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 345 | /* First init the serdes PHY's */ |
| 346 | serdes_phy_config(); |
| 347 | |
| 348 | /* Setup DDR */ |
Pali Rohár | c87978a | 2021-08-09 17:44:35 +0200 | [diff] [blame] | 349 | ret = ddr3_init(); |
| 350 | if (ret) { |
Pali Rohár | 6e86351 | 2021-12-17 18:31:14 +0100 | [diff] [blame] | 351 | printf("ddr3_init() failed: %d\n", ret); |
Marek Behún | 90555af | 2022-02-17 13:54:42 +0100 | [diff] [blame] | 352 | if (IS_ENABLED(CONFIG_DDR_RESET_ON_TRAINING_FAILURE) && |
| 353 | get_boot_device() != BOOT_DEVICE_UART) |
| 354 | reset_cpu(); |
| 355 | else |
| 356 | hang(); |
Pali Rohár | c87978a | 2021-08-09 17:44:35 +0200 | [diff] [blame] | 357 | } |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 358 | #endif |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 359 | |
Baruch Siach | 056e107 | 2019-07-10 18:23:04 +0300 | [diff] [blame] | 360 | /* Initialize Auto Voltage Scaling */ |
| 361 | mv_avs_init(); |
| 362 | |
Chris Packham | 3667bec | 2020-02-26 19:53:50 +1300 | [diff] [blame] | 363 | /* Update read timing control for PCIe */ |
| 364 | mv_rtc_config(); |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 365 | } |