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> |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <debug_uart.h> |
| 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 |
| 50 | #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET) && CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET != 0 |
| 51 | #error CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET must be set to 0 |
| 52 | #endif |
| 53 | #endif |
| 54 | |
| 55 | /* |
| 56 | * When loading U-Boot via SPL from SATA disk, the kwbimage main header is |
| 57 | * stored at sector 1. Therefore CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be |
| 58 | * set to 1. Otherwise U-Boot SPL would not be able to load U-Boot proper. |
| 59 | */ |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 60 | #ifdef CONFIG_SPL_SATA |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 61 | #if !defined(CONFIG_SPL_SATA_RAW_U_BOOT_USE_SECTOR) || !defined(CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR) || CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR != 1 |
| 62 | #error CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR must be set to 1 |
| 63 | #endif |
| 64 | #endif |
| 65 | |
| 66 | /* Boot Type - block ID */ |
| 67 | #define IBR_HDR_I2C_ID 0x4D |
| 68 | #define IBR_HDR_SPI_ID 0x5A |
| 69 | #define IBR_HDR_NAND_ID 0x8B |
| 70 | #define IBR_HDR_SATA_ID 0x78 |
| 71 | #define IBR_HDR_PEX_ID 0x9C |
| 72 | #define IBR_HDR_UART_ID 0x69 |
| 73 | #define IBR_HDR_SDIO_ID 0xAE |
| 74 | |
Pali Rohár | 0f7df22 | 2021-10-22 12:41:10 +0200 | [diff] [blame] | 75 | /* 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] | 76 | struct kwbimage_main_hdr_v1 { |
| 77 | uint8_t blockid; /* 0x0 */ |
| 78 | uint8_t flags; /* 0x1 */ |
Pali Rohár | 7fea884 | 2021-10-22 12:37:48 +0200 | [diff] [blame] | 79 | uint16_t nandpagesize; /* 0x2-0x3 */ |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 80 | uint32_t blocksize; /* 0x4-0x7 */ |
| 81 | uint8_t version; /* 0x8 */ |
| 82 | uint8_t headersz_msb; /* 0x9 */ |
| 83 | uint16_t headersz_lsb; /* 0xA-0xB */ |
| 84 | uint32_t srcaddr; /* 0xC-0xF */ |
| 85 | uint32_t destaddr; /* 0x10-0x13 */ |
| 86 | uint32_t execaddr; /* 0x14-0x17 */ |
| 87 | uint8_t options; /* 0x18 */ |
| 88 | uint8_t nandblocksize; /* 0x19 */ |
| 89 | uint8_t nandbadblklocation; /* 0x1A */ |
| 90 | uint8_t reserved4; /* 0x1B */ |
| 91 | uint16_t reserved5; /* 0x1C-0x1D */ |
| 92 | uint8_t ext; /* 0x1E */ |
| 93 | uint8_t checksum; /* 0x1F */ |
| 94 | } __packed; |
| 95 | |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 96 | #ifdef CONFIG_SPL_MMC |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 97 | u32 spl_mmc_boot_mode(const u32 boot_device) |
| 98 | { |
| 99 | return MMCSD_MODE_RAW; |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | int spl_parse_board_header(struct spl_image_info *spl_image, |
| 104 | const void *image_header, size_t size) |
| 105 | { |
| 106 | const struct kwbimage_main_hdr_v1 *mhdr = image_header; |
| 107 | |
| 108 | if (size < sizeof(*mhdr)) { |
| 109 | /* This should be compile time assert */ |
| 110 | printf("FATAL ERROR: Image header size is too small\n"); |
| 111 | hang(); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Very basic check for image validity. We cannot check mhdr->checksum |
| 116 | * as it is calculated also from variable length extended headers |
| 117 | * (including SPL content) which is not included in U-Boot image_header. |
| 118 | */ |
| 119 | if (mhdr->version != 1 || |
| 120 | ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr) || |
| 121 | ( |
| 122 | #ifdef CONFIG_SPL_SPI_FLASH_SUPPORT |
| 123 | mhdr->blockid != IBR_HDR_SPI_ID && |
| 124 | #endif |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 125 | #ifdef CONFIG_SPL_SATA |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 126 | mhdr->blockid != IBR_HDR_SATA_ID && |
| 127 | #endif |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 128 | #ifdef CONFIG_SPL_MMC |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 129 | mhdr->blockid != IBR_HDR_SDIO_ID && |
| 130 | #endif |
| 131 | 1 |
| 132 | )) { |
| 133 | printf("ERROR: Not valid SPI/NAND/SATA/SDIO kwbimage v1\n"); |
| 134 | return -EINVAL; |
| 135 | } |
| 136 | |
| 137 | spl_image->offset = mhdr->srcaddr; |
| 138 | |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 139 | #ifdef CONFIG_SPL_SATA |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 140 | /* |
| 141 | * For SATA srcaddr is specified in number of sectors. |
| 142 | * The main header is must be stored at sector number 1. |
| 143 | * This expects that sector size is 512 bytes and recalculates |
| 144 | * data offset to bytes relative to the main header. |
| 145 | */ |
| 146 | if (mhdr->blockid == IBR_HDR_SATA_ID) { |
| 147 | if (spl_image->offset < 1) { |
| 148 | printf("ERROR: Wrong SATA srcaddr in kwbimage\n"); |
| 149 | return -EINVAL; |
| 150 | } |
| 151 | spl_image->offset -= 1; |
| 152 | spl_image->offset *= 512; |
| 153 | } |
| 154 | #endif |
| 155 | |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 156 | #ifdef CONFIG_SPL_MMC |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 157 | /* |
| 158 | * For SDIO (eMMC) srcaddr is specified in number of sectors. |
| 159 | * This expects that sector size is 512 bytes and recalculates |
| 160 | * data offset to bytes. |
| 161 | */ |
| 162 | if (mhdr->blockid == IBR_HDR_SDIO_ID) |
| 163 | spl_image->offset *= 512; |
| 164 | #endif |
| 165 | |
| 166 | spl_image->size = mhdr->blocksize; |
| 167 | spl_image->entry_point = mhdr->execaddr; |
| 168 | spl_image->load_addr = mhdr->destaddr; |
| 169 | spl_image->os = IH_OS_U_BOOT; |
| 170 | spl_image->name = "U-Boot"; |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 175 | u32 spl_boot_device(void) |
| 176 | { |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 177 | u32 boot_device = get_boot_device(); |
| 178 | |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 179 | switch (boot_device) { |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 180 | /* |
| 181 | * Return to the BootROM to continue the Marvell xmodem |
| 182 | * UART boot protocol. As initiated by the kwboot tool. |
| 183 | * |
| 184 | * This can only be done by the BootROM since the beginning |
| 185 | * of the image is already read and interpreted by the BootROM. |
| 186 | * SPL has no chance to receive this information. So we |
| 187 | * need to return to the BootROM to enable this xmodem |
| 188 | * UART download. Use SPL infrastructure to return to BootROM. |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 189 | */ |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 190 | case BOOT_DEVICE_UART: |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 191 | return BOOT_DEVICE_BOOTROM; |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * If SPL is compiled with chosen boot_device support |
| 195 | * then use SPL driver for loading U-Boot proper. |
| 196 | */ |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 197 | #ifdef CONFIG_SPL_MMC |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 198 | case BOOT_DEVICE_MMC1: |
| 199 | return BOOT_DEVICE_MMC1; |
| 200 | #endif |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 201 | #ifdef CONFIG_SPL_SATA |
Pali Rohár | 90a8898 | 2021-10-29 14:09:48 +0200 | [diff] [blame^] | 202 | case BOOT_DEVICE_SATA: |
| 203 | return BOOT_DEVICE_SATA; |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 204 | #endif |
| 205 | #ifdef CONFIG_SPL_SPI_FLASH_SUPPORT |
| 206 | case BOOT_DEVICE_SPI: |
| 207 | return BOOT_DEVICE_SPI; |
| 208 | #endif |
| 209 | |
| 210 | /* |
| 211 | * If SPL is not compiled with chosen boot_device support |
| 212 | * then return to the BootROM. BootROM supports loading |
| 213 | * U-Boot proper from any valid boot_device present in SAR |
| 214 | * register. |
| 215 | */ |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 216 | default: |
Pali Rohár | cf97b82 | 2021-07-23 11:14:29 +0200 | [diff] [blame] | 217 | return BOOT_DEVICE_BOOTROM; |
Pali Rohár | da1be86 | 2021-07-23 11:14:26 +0200 | [diff] [blame] | 218 | } |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Marek Behún | ee76b4a | 2021-08-16 15:19:37 +0200 | [diff] [blame] | 221 | #else |
| 222 | |
| 223 | u32 spl_boot_device(void) |
| 224 | { |
| 225 | return BOOT_DEVICE_BOOTROM; |
| 226 | } |
| 227 | |
| 228 | #endif |
| 229 | |
Pali Rohár | a3a38e5 | 2021-07-23 11:14:25 +0200 | [diff] [blame] | 230 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 231 | struct spl_boot_device *bootdev) |
| 232 | { |
| 233 | u32 *regs = *(u32 **)CONFIG_SPL_BOOTROM_SAVE; |
| 234 | |
| 235 | printf("Returning to BootROM (return address 0x%08x)...\n", regs[13]); |
| 236 | return_to_bootrom(); |
| 237 | |
| 238 | /* NOTREACHED - return_to_bootrom() does not return */ |
| 239 | hang(); |
| 240 | } |
| 241 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 242 | void board_init_f(ulong dummy) |
| 243 | { |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 244 | int ret; |
| 245 | |
Stefan Roese | d7f2c12 | 2015-04-17 18:13:06 +0200 | [diff] [blame] | 246 | /* |
| 247 | * Pin muxing needs to be done before UART output, since |
| 248 | * on A38x the UART pins need some re-muxing for output |
| 249 | * to work. |
| 250 | */ |
| 251 | board_early_init_f(); |
| 252 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 253 | /* Example code showing how to enable the debug UART on MVEBU */ |
| 254 | #ifdef EARLY_UART |
| 255 | /* |
| 256 | * Debug UART can be used from here if required: |
| 257 | * |
| 258 | * debug_uart_init(); |
| 259 | * printch('a'); |
| 260 | * printhex8(0x1234); |
| 261 | * printascii("string"); |
| 262 | */ |
| 263 | #endif |
| 264 | |
Stefan Roese | 85bddff | 2019-04-12 16:42:28 +0200 | [diff] [blame] | 265 | /* |
| 266 | * Use special translation offset for SPL. This needs to be |
| 267 | * configured *before* spl_init() is called as this function |
| 268 | * calls dm_init() which calls the bind functions of the |
| 269 | * device drivers. Here the base address needs to be configured |
| 270 | * (translated) correctly. |
| 271 | */ |
| 272 | gd->translation_offset = 0xd0000000 - 0xf1000000; |
| 273 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 274 | ret = spl_init(); |
| 275 | if (ret) { |
| 276 | debug("spl_init() failed: %d\n", ret); |
| 277 | hang(); |
| 278 | } |
| 279 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 280 | preloader_console_init(); |
| 281 | |
Stefan Roese | d04fe8b | 2015-07-15 15:36:52 +0200 | [diff] [blame] | 282 | timer_init(); |
| 283 | |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 284 | /* Armada 375 does not support SerDes and DDR3 init yet */ |
| 285 | #if !defined(CONFIG_ARMADA_375) |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 286 | /* First init the serdes PHY's */ |
| 287 | serdes_phy_config(); |
| 288 | |
| 289 | /* Setup DDR */ |
Pali Rohár | c87978a | 2021-08-09 17:44:35 +0200 | [diff] [blame] | 290 | ret = ddr3_init(); |
| 291 | if (ret) { |
| 292 | debug("ddr3_init() failed: %d\n", ret); |
| 293 | hang(); |
| 294 | } |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 295 | #endif |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 296 | |
Baruch Siach | 056e107 | 2019-07-10 18:23:04 +0300 | [diff] [blame] | 297 | /* Initialize Auto Voltage Scaling */ |
| 298 | mv_avs_init(); |
| 299 | |
Chris Packham | 3667bec | 2020-02-26 19:53:50 +1300 | [diff] [blame] | 300 | /* Update read timing control for PCIe */ |
| 301 | mv_rtc_config(); |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 302 | } |