1 /* 2 * Copyright (C) 2014 Gateworks Corporation 3 * Copyright (C) 2011-2012 Freescale Semiconductor, Inc. 4 * 5 * Author: Tim Harvey <tharvey@gateworks.com> 6 * 7 * SPDX-License-Identifier: GPL-2.0+ 8 */ 9 10 #include <common.h> 11 #include <asm/io.h> 12 #include <asm/arch/imx-regs.h> 13 #include <asm/arch/sys_proto.h> 14 #include <asm/spl.h> 15 #include <spl.h> 16 #include <asm/mach-imx/hab.h> 17 18 #if defined(CONFIG_MX6) 19 /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */ 20 u32 spl_boot_device(void) 21 { 22 unsigned int bmode = readl(&src_base->sbmr2); 23 u32 reg = imx6_src_get_boot_mode(); 24 25 /* 26 * Check for BMODE if serial downloader is enabled 27 * BOOT_MODE - see IMX6DQRM Table 8-1 28 */ 29 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */ 30 return BOOT_DEVICE_BOARD; 31 32 /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */ 33 switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) { 34 /* EIM: See 8.5.1, Table 8-9 */ 35 case IMX6_BMODE_EMI: 36 /* BOOT_CFG1[3]: NOR/OneNAND Selection */ 37 switch ((reg & IMX6_BMODE_EMI_MASK) >> IMX6_BMODE_EMI_SHIFT) { 38 case IMX6_BMODE_ONENAND: 39 return BOOT_DEVICE_ONENAND; 40 case IMX6_BMODE_NOR: 41 return BOOT_DEVICE_NOR; 42 break; 43 } 44 /* Reserved: Used to force Serial Downloader */ 45 case IMX6_BMODE_RESERVED: 46 return BOOT_DEVICE_BOARD; 47 /* SATA: See 8.5.4, Table 8-20 */ 48 #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL) 49 case IMX6_BMODE_SATA: 50 return BOOT_DEVICE_SATA; 51 #endif 52 /* Serial ROM: See 8.5.5.1, Table 8-22 */ 53 case IMX6_BMODE_SERIAL_ROM: 54 /* BOOT_CFG4[2:0] */ 55 switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >> 56 IMX6_BMODE_SERIAL_ROM_SHIFT) { 57 case IMX6_BMODE_ECSPI1: 58 case IMX6_BMODE_ECSPI2: 59 case IMX6_BMODE_ECSPI3: 60 case IMX6_BMODE_ECSPI4: 61 case IMX6_BMODE_ECSPI5: 62 return BOOT_DEVICE_SPI; 63 case IMX6_BMODE_I2C1: 64 case IMX6_BMODE_I2C2: 65 case IMX6_BMODE_I2C3: 66 return BOOT_DEVICE_I2C; 67 } 68 break; 69 /* SD/eSD: 8.5.3, Table 8-15 */ 70 case IMX6_BMODE_SD: 71 case IMX6_BMODE_ESD: 72 return BOOT_DEVICE_MMC1; 73 /* MMC/eMMC: 8.5.3 */ 74 case IMX6_BMODE_MMC: 75 case IMX6_BMODE_EMMC: 76 return BOOT_DEVICE_MMC1; 77 /* NAND Flash: 8.5.2, Table 8-10 */ 78 case IMX6_BMODE_NAND: 79 return BOOT_DEVICE_NAND; 80 } 81 return BOOT_DEVICE_NONE; 82 } 83 #endif 84 85 #if defined(CONFIG_SPL_MMC_SUPPORT) 86 /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */ 87 u32 spl_boot_mode(const u32 boot_device) 88 { 89 switch (spl_boot_device()) { 90 /* for MMC return either RAW or FAT mode */ 91 case BOOT_DEVICE_MMC1: 92 case BOOT_DEVICE_MMC2: 93 #if defined(CONFIG_SPL_FAT_SUPPORT) 94 return MMCSD_MODE_FS; 95 #elif defined(CONFIG_SUPPORT_EMMC_BOOT) 96 return MMCSD_MODE_EMMCBOOT; 97 #else 98 return MMCSD_MODE_RAW; 99 #endif 100 break; 101 default: 102 puts("spl: ERROR: unsupported device\n"); 103 hang(); 104 } 105 } 106 #endif 107 108 #if defined(CONFIG_SECURE_BOOT) 109 110 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) 111 { 112 typedef void __noreturn (*image_entry_noargs_t)(void); 113 114 image_entry_noargs_t image_entry = 115 (image_entry_noargs_t)(unsigned long)spl_image->entry_point; 116 117 debug("image entry point: 0x%lX\n", spl_image->entry_point); 118 119 /* HAB looks for the CSF at the end of the authenticated data therefore, 120 * we need to subtract the size of the CSF from the actual filesize */ 121 if (authenticate_image(spl_image->load_addr, 122 spl_image->size - CONFIG_CSF_SIZE)) { 123 image_entry(); 124 } else { 125 puts("spl: ERROR: image authentication unsuccessful\n"); 126 hang(); 127 } 128 } 129 130 #endif 131