Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014 Gateworks Corporation |
| 4 | * Copyright (C) 2011-2012 Freescale Semiconductor, Inc. |
| 5 | * |
| 6 | * Author: Tim Harvey <tharvey@gateworks.com> |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 9 | #include <config.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 10 | #include <hang.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/imx-regs.h> |
Jagan Teki | e5f970b | 2017-02-24 15:45:12 +0530 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 17 | #include <asm/spl.h> |
| 18 | #include <spl.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 19 | #include <asm/mach-imx/hab.h> |
Uri Mashiach | 5dd4689 | 2017-09-24 09:00:24 +0300 | [diff] [blame] | 20 | #include <asm/mach-imx/boot_mode.h> |
Fabio Estevam | a0e462b | 2017-09-05 20:46:39 -0300 | [diff] [blame] | 21 | #include <g_dnl.h> |
Alexandru Gagniuc | 44af2a5 | 2021-01-20 10:46:49 -0600 | [diff] [blame] | 22 | #include <linux/libfdt.h> |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 23 | #include <memalign.h> |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 24 | |
Jagan Teki | 7bb61bb | 2017-08-28 16:45:47 +0530 | [diff] [blame] | 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
Peng Fan | cffe732 | 2019-08-27 06:25:07 +0000 | [diff] [blame] | 27 | __weak int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 28 | { |
Ye Li | 732d6e6 | 2022-07-26 16:40:34 +0800 | [diff] [blame] | 29 | switch (boot_dev_spl) { |
| 30 | #if defined(CONFIG_MX7) |
| 31 | case SD1_BOOT: |
| 32 | case MMC1_BOOT: |
| 33 | case SD2_BOOT: |
| 34 | case MMC2_BOOT: |
| 35 | case SD3_BOOT: |
| 36 | case MMC3_BOOT: |
| 37 | return BOOT_DEVICE_MMC1; |
| 38 | #elif defined(CONFIG_IMX8) |
| 39 | case MMC1_BOOT: |
| 40 | return BOOT_DEVICE_MMC1; |
| 41 | case SD2_BOOT: |
| 42 | return BOOT_DEVICE_MMC2_2; |
| 43 | case SD3_BOOT: |
| 44 | return BOOT_DEVICE_MMC1; |
| 45 | case FLEXSPI_BOOT: |
| 46 | return BOOT_DEVICE_SPI; |
| 47 | #elif defined(CONFIG_IMX8M) |
| 48 | case SD1_BOOT: |
| 49 | case MMC1_BOOT: |
| 50 | return BOOT_DEVICE_MMC1; |
| 51 | case SD2_BOOT: |
| 52 | case MMC2_BOOT: |
| 53 | return BOOT_DEVICE_MMC2; |
| 54 | #endif |
| 55 | case NAND_BOOT: |
| 56 | return BOOT_DEVICE_NAND; |
| 57 | case SPI_NOR_BOOT: |
| 58 | return BOOT_DEVICE_SPI; |
| 59 | case QSPI_BOOT: |
| 60 | return BOOT_DEVICE_NOR; |
| 61 | case USB_BOOT: |
| 62 | return BOOT_DEVICE_BOARD; |
| 63 | default: |
| 64 | return BOOT_DEVICE_NONE; |
| 65 | } |
Peng Fan | cffe732 | 2019-08-27 06:25:07 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 68 | #if defined(CONFIG_MX6) |
Nikita Kiryanov | 9fba842 | 2014-10-29 19:28:33 +0200 | [diff] [blame] | 69 | /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */ |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 70 | u32 spl_boot_device(void) |
| 71 | { |
Jagan Teki | c981a94 | 2017-02-24 15:45:15 +0530 | [diff] [blame] | 72 | unsigned int bmode = readl(&src_base->sbmr2); |
Jagan Teki | e5f970b | 2017-02-24 15:45:12 +0530 | [diff] [blame] | 73 | u32 reg = imx6_src_get_boot_mode(); |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 74 | |
Stefano Babic | 587e72e | 2015-12-11 17:30:42 +0100 | [diff] [blame] | 75 | /* |
| 76 | * Check for BMODE if serial downloader is enabled |
| 77 | * BOOT_MODE - see IMX6DQRM Table 8-1 |
| 78 | */ |
Stefan Agner | 1539096 | 2016-12-27 17:01:42 +0100 | [diff] [blame] | 79 | if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */ |
Stefan Agner | a0a50ce | 2017-08-15 17:49:43 -0700 | [diff] [blame] | 80 | return BOOT_DEVICE_BOARD; |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 81 | |
Stefan Agner | 47f547e | 2017-09-13 14:29:45 -0700 | [diff] [blame] | 82 | /* |
| 83 | * The above method does not detect that the boot ROM used |
| 84 | * serial downloader in case the boot ROM decided to use the |
| 85 | * serial downloader as a fall back (primary boot source failed). |
| 86 | * |
| 87 | * Infer that the boot ROM used the USB serial downloader by |
| 88 | * checking whether the USB PHY is currently active... This |
| 89 | * assumes that SPL did not (yet) initialize the USB PHY... |
| 90 | */ |
| 91 | if (is_usbotg_phy_active()) |
| 92 | return BOOT_DEVICE_BOARD; |
| 93 | |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 94 | /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */ |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 95 | switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) { |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 96 | /* EIM: See 8.5.1, Table 8-9 */ |
Harald Seiler | 808c5d6 | 2021-12-01 10:02:54 +0100 | [diff] [blame] | 97 | case IMX6_BMODE_EIM: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 98 | /* BOOT_CFG1[3]: NOR/OneNAND Selection */ |
Harald Seiler | 808c5d6 | 2021-12-01 10:02:54 +0100 | [diff] [blame] | 99 | switch ((reg & IMX6_BMODE_EIM_MASK) >> IMX6_BMODE_EIM_SHIFT) { |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 100 | case IMX6_BMODE_ONENAND: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 101 | return BOOT_DEVICE_ONENAND; |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 102 | case IMX6_BMODE_NOR: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 103 | return BOOT_DEVICE_NOR; |
| 104 | break; |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 105 | } |
Stefan Agner | 1539096 | 2016-12-27 17:01:42 +0100 | [diff] [blame] | 106 | /* Reserved: Used to force Serial Downloader */ |
Stefan Agner | 53456f5 | 2017-08-15 17:49:42 -0700 | [diff] [blame] | 107 | case IMX6_BMODE_RESERVED: |
Stefan Agner | a0a50ce | 2017-08-15 17:49:43 -0700 | [diff] [blame] | 108 | return BOOT_DEVICE_BOARD; |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 109 | /* SATA: See 8.5.4, Table 8-20 */ |
Stefan Agner | 34da473 | 2017-08-29 09:10:11 -0700 | [diff] [blame] | 110 | #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL) |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 111 | case IMX6_BMODE_SATA: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 112 | return BOOT_DEVICE_SATA; |
Stefan Agner | 34da473 | 2017-08-29 09:10:11 -0700 | [diff] [blame] | 113 | #endif |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 114 | /* Serial ROM: See 8.5.5.1, Table 8-22 */ |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 115 | case IMX6_BMODE_SERIAL_ROM: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 116 | /* BOOT_CFG4[2:0] */ |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 117 | switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >> |
| 118 | IMX6_BMODE_SERIAL_ROM_SHIFT) { |
| 119 | case IMX6_BMODE_ECSPI1: |
| 120 | case IMX6_BMODE_ECSPI2: |
| 121 | case IMX6_BMODE_ECSPI3: |
| 122 | case IMX6_BMODE_ECSPI4: |
| 123 | case IMX6_BMODE_ECSPI5: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 124 | return BOOT_DEVICE_SPI; |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 125 | case IMX6_BMODE_I2C1: |
| 126 | case IMX6_BMODE_I2C2: |
| 127 | case IMX6_BMODE_I2C3: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 128 | return BOOT_DEVICE_I2C; |
| 129 | } |
| 130 | break; |
| 131 | /* SD/eSD: 8.5.3, Table 8-15 */ |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 132 | case IMX6_BMODE_SD: |
| 133 | case IMX6_BMODE_ESD: |
Adam Ford | a2a91e2 | 2019-10-08 07:56:44 -0500 | [diff] [blame] | 134 | return BOOT_DEVICE_MMC1; |
| 135 | /* MMC/eMMC: 8.5.3 */ |
Jagan Teki | 32a7114 | 2017-02-24 15:45:14 +0530 | [diff] [blame] | 136 | case IMX6_BMODE_MMC: |
| 137 | case IMX6_BMODE_EMMC: |
Adam Ford | a2a91e2 | 2019-10-08 07:56:44 -0500 | [diff] [blame] | 138 | return BOOT_DEVICE_MMC1; |
Jagan Teki | 4191b22 | 2017-02-24 15:45:13 +0530 | [diff] [blame] | 139 | /* NAND Flash: 8.5.2, Table 8-10 */ |
Eran Matityahu | 5fa7ca6 | 2017-12-14 20:20:02 +0200 | [diff] [blame] | 140 | case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX: |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 141 | return BOOT_DEVICE_NAND; |
Stefan Roese | fe41e32 | 2019-09-20 18:09:08 +0200 | [diff] [blame] | 142 | #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL) |
| 143 | /* QSPI boot */ |
| 144 | case IMX6_BMODE_QSPI: |
| 145 | return BOOT_DEVICE_SPI; |
| 146 | #endif |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 147 | } |
| 148 | return BOOT_DEVICE_NONE; |
| 149 | } |
Fabio Estevam | a0e462b | 2017-09-05 20:46:39 -0300 | [diff] [blame] | 150 | |
Peng Fan | bbcd2c4 | 2022-07-26 16:40:39 +0800 | [diff] [blame] | 151 | #elif defined(CONFIG_MX7) || defined(CONFIG_IMX8M) || defined(CONFIG_IMX8) || defined(CONFIG_IMX9) |
Peng Fan | 39945c1 | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 152 | /* Translate iMX7/i.MX8M boot device to the SPL boot device enumeration */ |
Uri Mashiach | 5dd4689 | 2017-09-24 09:00:24 +0300 | [diff] [blame] | 153 | u32 spl_boot_device(void) |
| 154 | { |
Eran Matityahu | 52fef1c | 2018-03-06 16:38:00 +0200 | [diff] [blame] | 155 | #if defined(CONFIG_MX7) |
| 156 | unsigned int bmode = readl(&src_base->sbmr2); |
| 157 | |
| 158 | /* |
| 159 | * Check for BMODE if serial downloader is enabled |
| 160 | * BOOT_MODE - see IMX7DRM Table 6-24 |
| 161 | */ |
| 162 | if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */ |
| 163 | return BOOT_DEVICE_BOARD; |
| 164 | |
| 165 | /* |
| 166 | * The above method does not detect that the boot ROM used |
| 167 | * serial downloader in case the boot ROM decided to use the |
| 168 | * serial downloader as a fall back (primary boot source failed). |
| 169 | * |
| 170 | * Infer that the boot ROM used the USB serial downloader by |
| 171 | * checking whether the USB PHY is currently active... This |
| 172 | * assumes that SPL did not (yet) initialize the USB PHY... |
| 173 | */ |
| 174 | if (is_boot_from_usb()) |
| 175 | return BOOT_DEVICE_BOARD; |
| 176 | #endif |
| 177 | |
Uri Mashiach | 5dd4689 | 2017-09-24 09:00:24 +0300 | [diff] [blame] | 178 | enum boot_device boot_device_spl = get_boot_device(); |
| 179 | |
Ye Li | 732d6e6 | 2022-07-26 16:40:34 +0800 | [diff] [blame] | 180 | return spl_board_boot_device(boot_device_spl); |
Uri Mashiach | 5dd4689 | 2017-09-24 09:00:24 +0300 | [diff] [blame] | 181 | } |
Peng Fan | 9d5bc07 | 2018-12-21 06:21:23 +0000 | [diff] [blame] | 182 | #endif /* CONFIG_MX7 || CONFIG_IMX8M || CONFIG_IMX8 */ |
Uri Mashiach | 5dd4689 | 2017-09-24 09:00:24 +0300 | [diff] [blame] | 183 | |
Jean-Jacques Hiblot | 6a22852 | 2019-01-10 15:44:13 +0100 | [diff] [blame] | 184 | #ifdef CONFIG_SPL_USB_GADGET |
Fabio Estevam | a0e462b | 2017-09-05 20:46:39 -0300 | [diff] [blame] | 185 | int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) |
| 186 | { |
Maxime Ripard | 7f78b9d | 2017-09-07 08:58:08 +0200 | [diff] [blame] | 187 | put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM + 0xfff, &dev->idProduct); |
Fabio Estevam | a0e462b | 2017-09-05 20:46:39 -0300 | [diff] [blame] | 188 | |
| 189 | return 0; |
| 190 | } |
Peng Fan | 8f97c26 | 2020-08-18 18:16:47 +0800 | [diff] [blame] | 191 | |
| 192 | #define SDPV_BCD_DEVICE 0x500 |
| 193 | int g_dnl_get_board_bcd_device_number(int gcnum) |
| 194 | { |
| 195 | return SDPV_BCD_DEVICE; |
| 196 | } |
Fabio Estevam | a0e462b | 2017-09-05 20:46:39 -0300 | [diff] [blame] | 197 | #endif |
Tim Harvey | 354a7e3 | 2014-06-02 16:13:20 -0700 | [diff] [blame] | 198 | |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 199 | #if defined(CONFIG_SPL_MMC) |
Fabio Estevam | 550b52e | 2018-02-15 12:41:40 -0200 | [diff] [blame] | 200 | /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */ |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 201 | u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
Fabio Estevam | 550b52e | 2018-02-15 12:41:40 -0200 | [diff] [blame] | 202 | { |
Peng Fan | 1dd4cc3 | 2019-10-16 10:24:25 +0000 | [diff] [blame] | 203 | #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M) || defined(CONFIG_IMX8) |
| 204 | switch (get_boot_device()) { |
| 205 | /* for MMC return either RAW or FAT mode */ |
| 206 | case SD1_BOOT: |
| 207 | case SD2_BOOT: |
| 208 | case SD3_BOOT: |
Harald Seiler | fbbb318 | 2020-04-23 13:07:53 +0200 | [diff] [blame] | 209 | if (IS_ENABLED(CONFIG_SPL_FS_FAT)) |
Harald Seiler | 5152681 | 2020-04-23 13:07:52 +0200 | [diff] [blame] | 210 | return MMCSD_MODE_FS; |
| 211 | else |
| 212 | return MMCSD_MODE_RAW; |
Peng Fan | 1dd4cc3 | 2019-10-16 10:24:25 +0000 | [diff] [blame] | 213 | case MMC1_BOOT: |
| 214 | case MMC2_BOOT: |
| 215 | case MMC3_BOOT: |
Harald Seiler | fbbb318 | 2020-04-23 13:07:53 +0200 | [diff] [blame] | 216 | if (IS_ENABLED(CONFIG_SPL_FS_FAT)) |
Harald Seiler | 5152681 | 2020-04-23 13:07:52 +0200 | [diff] [blame] | 217 | return MMCSD_MODE_FS; |
| 218 | else if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) |
| 219 | return MMCSD_MODE_EMMCBOOT; |
| 220 | else |
| 221 | return MMCSD_MODE_RAW; |
Peng Fan | 1dd4cc3 | 2019-10-16 10:24:25 +0000 | [diff] [blame] | 222 | default: |
| 223 | puts("spl: ERROR: unsupported device\n"); |
| 224 | hang(); |
| 225 | } |
| 226 | #else |
Anatolij Gustschin | 62499ff | 2020-04-23 13:07:49 +0200 | [diff] [blame] | 227 | switch (boot_device) { |
Fabio Estevam | 550b52e | 2018-02-15 12:41:40 -0200 | [diff] [blame] | 228 | /* for MMC return either RAW or FAT mode */ |
| 229 | case BOOT_DEVICE_MMC1: |
| 230 | case BOOT_DEVICE_MMC2: |
Peng Fan | 9d5bc07 | 2018-12-21 06:21:23 +0000 | [diff] [blame] | 231 | case BOOT_DEVICE_MMC2_2: |
Harald Seiler | 5152681 | 2020-04-23 13:07:52 +0200 | [diff] [blame] | 232 | if (IS_ENABLED(CONFIG_SPL_FS_FAT)) |
| 233 | return MMCSD_MODE_FS; |
| 234 | else if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) |
| 235 | return MMCSD_MODE_EMMCBOOT; |
| 236 | else |
| 237 | return MMCSD_MODE_RAW; |
Fabio Estevam | 550b52e | 2018-02-15 12:41:40 -0200 | [diff] [blame] | 238 | default: |
| 239 | puts("spl: ERROR: unsupported device\n"); |
| 240 | hang(); |
| 241 | } |
Peng Fan | 1dd4cc3 | 2019-10-16 10:24:25 +0000 | [diff] [blame] | 242 | #endif |
Fabio Estevam | 550b52e | 2018-02-15 12:41:40 -0200 | [diff] [blame] | 243 | } |
| 244 | #endif |
| 245 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 246 | #if defined(CONFIG_IMX_HAB) |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 247 | |
Bryan O'Donoghue | 8891996 | 2018-01-12 12:40:01 +0000 | [diff] [blame] | 248 | /* |
| 249 | * +------------+ 0x0 (DDR_UIMAGE_START) - |
| 250 | * | Header | | |
| 251 | * +------------+ 0x40 | |
| 252 | * | | | |
| 253 | * | | | |
| 254 | * | | | |
| 255 | * | | | |
| 256 | * | Image Data | | |
| 257 | * . | | |
| 258 | * . | > Stuff to be authenticated ----+ |
| 259 | * . | | | |
| 260 | * | | | | |
| 261 | * | | | | |
| 262 | * +------------+ | | |
| 263 | * | | | | |
| 264 | * | Fill Data | | | |
| 265 | * | | | | |
| 266 | * +------------+ Align to ALIGN_SIZE | | |
| 267 | * | IVT | | | |
| 268 | * +------------+ + IVT_SIZE - | |
| 269 | * | | | |
| 270 | * | CSF DATA | <---------------------------------------------------------+ |
| 271 | * | | |
| 272 | * +------------+ |
| 273 | * | | |
| 274 | * | Fill Data | |
| 275 | * | | |
| 276 | * +------------+ + CSF_PAD_SIZE |
| 277 | */ |
| 278 | |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 279 | __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 280 | { |
| 281 | typedef void __noreturn (*image_entry_noargs_t)(void); |
Bryan O'Donoghue | 8891996 | 2018-01-12 12:40:01 +0000 | [diff] [blame] | 282 | uint32_t offset; |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 283 | |
| 284 | image_entry_noargs_t image_entry = |
| 285 | (image_entry_noargs_t)(unsigned long)spl_image->entry_point; |
| 286 | |
Tom Rini | f1c2fc0 | 2017-01-11 10:45:48 -0500 | [diff] [blame] | 287 | debug("image entry point: 0x%lX\n", spl_image->entry_point); |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 288 | |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 289 | if (spl_image->flags & SPL_FIT_FOUND) { |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 290 | image_entry(); |
| 291 | } else { |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 292 | /* |
| 293 | * HAB looks for the CSF at the end of the authenticated |
| 294 | * data therefore, we need to subtract the size of the |
| 295 | * CSF from the actual filesize |
| 296 | */ |
| 297 | offset = spl_image->size - CONFIG_CSF_SIZE; |
| 298 | if (!imx_hab_authenticate_image(spl_image->load_addr, |
| 299 | offset + IVT_SIZE + |
| 300 | CSF_PAD_SIZE, offset)) { |
| 301 | image_entry(); |
| 302 | } else { |
Marek Vasut | 579fd51 | 2020-05-30 20:29:00 +0200 | [diff] [blame] | 303 | panic("spl: ERROR: image authentication fail\n"); |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
Ricardo Salveti | d7d649c | 2019-09-02 18:18:52 -0300 | [diff] [blame] | 308 | #if !defined(CONFIG_SPL_FIT_SIGNATURE) |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 309 | ulong board_spl_fit_size_align(ulong size) |
| 310 | { |
| 311 | /* |
| 312 | * HAB authenticate_image requests the IVT offset is |
| 313 | * aligned to 0x1000 |
| 314 | */ |
| 315 | |
| 316 | size = ALIGN(size, 0x1000); |
| 317 | size += CONFIG_CSF_SIZE; |
| 318 | |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 319 | if (size > CONFIG_SYS_BOOTM_LEN) |
| 320 | panic("spl: ERROR: image too big\n"); |
Ye Li | 9d5b0f4 | 2018-11-17 09:10:25 +0000 | [diff] [blame] | 321 | |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 322 | return size; |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 323 | } |
Ricardo Salveti | d7d649c | 2019-09-02 18:18:52 -0300 | [diff] [blame] | 324 | #endif |
Sven Ebenfeld | eba5e33 | 2016-11-06 16:37:55 +0100 | [diff] [blame] | 325 | |
Heiko Schocher | 7d7c367 | 2021-08-17 08:17:18 +0200 | [diff] [blame] | 326 | void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len) |
| 327 | { |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 328 | #if defined(CONFIG_SPL_LOAD_FIT_ADDRESS) |
| 329 | return (void *)CONFIG_SPL_LOAD_FIT_ADDRESS; |
| 330 | #else |
| 331 | return (void *)(CONFIG_TEXT_BASE + CONFIG_SYS_BOOTM_LEN); |
Jagan Teki | 7bb61bb | 2017-08-28 16:45:47 +0530 | [diff] [blame] | 332 | #endif |
Jagan Teki | 7bb61bb | 2017-08-28 16:45:47 +0530 | [diff] [blame] | 333 | } |
Heiko Schocher | f3c450b | 2021-08-06 06:44:27 +0200 | [diff] [blame] | 334 | /* |
| 335 | * read the address where the IVT header must sit |
| 336 | * from IVT image header, loaded from SPL into |
| 337 | * an malloced buffer and copy the IVT header |
| 338 | * to this address |
| 339 | */ |
| 340 | void *spl_load_simple_fit_fix_load(const void *fit) |
| 341 | { |
| 342 | struct ivt *ivt; |
Heiko Schocher | f3c450b | 2021-08-06 06:44:27 +0200 | [diff] [blame] | 343 | unsigned long offset; |
| 344 | unsigned long size; |
| 345 | u8 *tmp = (u8 *)fit; |
| 346 | |
| 347 | offset = ALIGN(fdt_totalsize(fit), 0x1000); |
| 348 | size = ALIGN(fdt_totalsize(fit), 4); |
| 349 | size = board_spl_fit_size_align(size); |
| 350 | tmp += offset; |
| 351 | ivt = (struct ivt *)tmp; |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 352 | |
Heiko Schocher | f3c450b | 2021-08-06 06:44:27 +0200 | [diff] [blame] | 353 | debug("%s: ivt: %p offset: %lx size: %lx\n", __func__, ivt, offset, size); |
| 354 | debug("%s: ivt self: %x\n", __func__, ivt->self); |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 355 | |
Marek Vasut | 7dc11f7 | 2023-08-31 16:57:24 +0200 | [diff] [blame] | 356 | if (imx_hab_authenticate_image((uintptr_t)fit, (uintptr_t)size, offset)) |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 357 | panic("spl: ERROR: image authentication unsuccessful\n"); |
Heiko Schocher | f3c450b | 2021-08-06 06:44:27 +0200 | [diff] [blame] | 358 | |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 359 | return (void *)fit; |
Heiko Schocher | f3c450b | 2021-08-06 06:44:27 +0200 | [diff] [blame] | 360 | } |
Marek Vasut | a7416eb | 2023-05-28 23:00:30 +0200 | [diff] [blame] | 361 | #endif /* CONFIG_IMX_HAB */ |
| 362 | |
| 363 | #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT) |
| 364 | int dram_init_banksize(void) |
| 365 | { |
| 366 | gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE; |
| 367 | gd->bd->bi_dram[0].size = imx_ddr_size(); |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | #endif |