]> git.sur5r.net Git - u-boot/blob - arch/arm/mach-imx/spl.c
efi_selftest: correctly check return values
[u-boot] / arch / arm / mach-imx / spl.c
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 #include <g_dnl.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 #if defined(CONFIG_MX6)
22 /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
23 u32 spl_boot_device(void)
24 {
25         unsigned int bmode = readl(&src_base->sbmr2);
26         u32 reg = imx6_src_get_boot_mode();
27
28         /*
29          * Check for BMODE if serial downloader is enabled
30          * BOOT_MODE - see IMX6DQRM Table 8-1
31          */
32         if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
33                 return BOOT_DEVICE_BOARD;
34
35         /*
36          * The above method does not detect that the boot ROM used
37          * serial downloader in case the boot ROM decided to use the
38          * serial downloader as a fall back (primary boot source failed).
39          *
40          * Infer that the boot ROM used the USB serial downloader by
41          * checking whether the USB PHY is currently active... This
42          * assumes that SPL did not (yet) initialize the USB PHY...
43          */
44         if (is_usbotg_phy_active())
45                 return BOOT_DEVICE_BOARD;
46
47         /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
48         switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
49          /* EIM: See 8.5.1, Table 8-9 */
50         case IMX6_BMODE_EMI:
51                 /* BOOT_CFG1[3]: NOR/OneNAND Selection */
52                 switch ((reg & IMX6_BMODE_EMI_MASK) >> IMX6_BMODE_EMI_SHIFT) {
53                 case IMX6_BMODE_ONENAND:
54                         return BOOT_DEVICE_ONENAND;
55                 case IMX6_BMODE_NOR:
56                         return BOOT_DEVICE_NOR;
57                 break;
58                 }
59         /* Reserved: Used to force Serial Downloader */
60         case IMX6_BMODE_RESERVED:
61                 return BOOT_DEVICE_BOARD;
62         /* SATA: See 8.5.4, Table 8-20 */
63 #if !defined(CONFIG_MX6UL) && !defined(CONFIG_MX6ULL)
64         case IMX6_BMODE_SATA:
65                 return BOOT_DEVICE_SATA;
66 #endif
67         /* Serial ROM: See 8.5.5.1, Table 8-22 */
68         case IMX6_BMODE_SERIAL_ROM:
69                 /* BOOT_CFG4[2:0] */
70                 switch ((reg & IMX6_BMODE_SERIAL_ROM_MASK) >>
71                         IMX6_BMODE_SERIAL_ROM_SHIFT) {
72                 case IMX6_BMODE_ECSPI1:
73                 case IMX6_BMODE_ECSPI2:
74                 case IMX6_BMODE_ECSPI3:
75                 case IMX6_BMODE_ECSPI4:
76                 case IMX6_BMODE_ECSPI5:
77                         return BOOT_DEVICE_SPI;
78                 case IMX6_BMODE_I2C1:
79                 case IMX6_BMODE_I2C2:
80                 case IMX6_BMODE_I2C3:
81                         return BOOT_DEVICE_I2C;
82                 }
83                 break;
84         /* SD/eSD: 8.5.3, Table 8-15  */
85         case IMX6_BMODE_SD:
86         case IMX6_BMODE_ESD:
87                 return BOOT_DEVICE_MMC1;
88         /* MMC/eMMC: 8.5.3 */
89         case IMX6_BMODE_MMC:
90         case IMX6_BMODE_EMMC:
91                 return BOOT_DEVICE_MMC1;
92         /* NAND Flash: 8.5.2, Table 8-10 */
93         case IMX6_BMODE_NAND:
94                 return BOOT_DEVICE_NAND;
95         }
96         return BOOT_DEVICE_NONE;
97 }
98
99 #ifdef CONFIG_SPL_USB_GADGET_SUPPORT
100 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
101 {
102         put_unaligned(CONFIG_G_DNL_PRODUCT_NUM + 0xfff, &dev->idProduct);
103
104         return 0;
105 }
106 #endif
107 #endif
108
109 #if defined(CONFIG_SPL_MMC_SUPPORT)
110 /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
111 u32 spl_boot_mode(const u32 boot_device)
112 {
113         switch (spl_boot_device()) {
114         /* for MMC return either RAW or FAT mode */
115         case BOOT_DEVICE_MMC1:
116         case BOOT_DEVICE_MMC2:
117 #if defined(CONFIG_SPL_FAT_SUPPORT)
118                 return MMCSD_MODE_FS;
119 #elif defined(CONFIG_SUPPORT_EMMC_BOOT)
120                 return MMCSD_MODE_EMMCBOOT;
121 #else
122                 return MMCSD_MODE_RAW;
123 #endif
124                 break;
125         default:
126                 puts("spl: ERROR:  unsupported device\n");
127                 hang();
128         }
129 }
130 #endif
131
132 #if defined(CONFIG_SECURE_BOOT)
133
134 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
135 {
136         typedef void __noreturn (*image_entry_noargs_t)(void);
137
138         image_entry_noargs_t image_entry =
139                 (image_entry_noargs_t)(unsigned long)spl_image->entry_point;
140
141         debug("image entry point: 0x%lX\n", spl_image->entry_point);
142
143         /* HAB looks for the CSF at the end of the authenticated data therefore,
144          * we need to subtract the size of the CSF from the actual filesize */
145         if (authenticate_image(spl_image->load_addr,
146                                spl_image->size - CONFIG_CSF_SIZE)) {
147                 image_entry();
148         } else {
149                 puts("spl: ERROR:  image authentication unsuccessful\n");
150                 hang();
151         }
152 }
153
154 #endif
155
156 #if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
157 int dram_init_banksize(void)
158 {
159         gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
160         gd->bd->bi_dram[0].size = imx_ddr_size();
161
162         return 0;
163 }
164 #endif