c0fb4ce3c08230ca8bc3f400a5c7c28f27f73934
1 /*****************************************************************************************
2 * FILE PURPOSE: Perform the top level boot
3 *****************************************************************************************
4 * FILE NAME: iblmain.c
5 *
6 * DESCRIPTION: The top level boot examines the boot configuration and performs boot
7 * based on this configuration
8 *
9 * @file iblmain.c
10 *
11 * @brief
12 * This file is used to launch a boot based on the boot configuration structure
13 *
14 *****************************************************************************************/
15 #include "ibl.h"
16 #include "iblloc.h"
17 #include "iblcfg.h"
18 #include "device.h"
19 #include "ethboot.h"
20 #include "bis.h"
21 #include "coffwrap.h"
22 #include "iblbtbl.h"
23 #include "iblblob.h"
24 #include "timer.h"
25 #include "i2c.h"
26 #include "ibl_elf.h"
27 #include <string.h>
30 /**
31 * @brief The ibl table is declared.
32 *
33 * @details
34 * The ibl table is declared uninitialized by this ibl program. An external
35 * initialization can be performed if the default operation of the ibl is
36 * not desired.
37 */
38 #pragma DATA_SECTION(ibl, ".ibl_config_table")
39 ibl_t ibl;
42 /**
43 * @brief The ibl status table is declared.
44 *
45 * @details
46 * The ibl status table is declared. It is initialized at run time
47 * in function main.
48 */
49 #pragma DATA_SECTION(iblStatus, ".ibl_status_table")
50 iblStatus_t iblStatus;
53 /* Eat printfs */
54 void mprintf(char *x, ...) { }
56 /**
57 * @b Description
58 * @n
59 *
60 * Returns TRUE if the input priority is valid and enabled
61 */
62 BOOL iblPriorityIsValid (uint32 priority)
63 {
64 if ( (priority >= ibl_HIGHEST_PRIORITY) &&
65 (priority <= ibl_LOWEST_PRIORITY) )
67 return (TRUE);
70 return (FALSE);
72 }
74 /**
75 * @b Description
76 * @n
77 *
78 * Returns TRUE if the mac address is 0
79 */
80 BOOL iblMacAddrIsZero (uint8 *maddr)
81 {
82 int32 i;
84 for (i = 0; i < 6; i++)
85 if (maddr[i] != 0)
86 return (FALSE);
88 return (TRUE);
90 }
93 /**
94 * @b Description
95 * @n
96 *
97 * The main function kicks off the boot. If it does not find the magic value in the
98 * configuration array then default values are loaded. This default load
99 * is done only once at the start of boot.
100 *
101 * @retval
102 * None
103 */
104 void main (void)
105 {
106 int32 i, j;
108 /* Initialize the status structure */
109 memset (&iblStatus, 0, sizeof(iblStatus_t));
110 iblStatus.iblMagic = ibl_MAGIC_VALUE;
112 /* Initialize the system timer (software tracking of the hardware timer state */
113 timer_init ();
115 #if 0
116 /* If there is no magic value in the ibl configuration structure then a default
117 * table is used. */
118 if (ibl.iblMagic != ibl_MAGIC_VALUE) {
119 deviceLoadDefaultIblTable();
120 iblStatus.noMagic = 1;
121 ibl.iblMagic = ibl_MAGIC_VALUE;
122 }
123 #endif
125 /* Load the default configuration table from the i2c. The actual speed of the device
126 * isn't really known here, since it is part of the table, so a compile time
127 * value is used (the pll may have been configured during the initial load) */
128 hwI2Cinit (IBL_I2C_DEV_FREQ_MHZ, /* The CPU frequency during I2C data load */
129 DEVICE_I2C_MODULE_DIVISOR, /* The divide down of CPU that drives the i2c */
130 IBL_I2C_CLK_FREQ_KHZ, /* The I2C data rate used during table load */
131 IBL_I2C_OWN_ADDR); /* The address used by this device on the i2c bus */
133 if (hwI2cMasterRead (IBL_I2C_CFG_TABLE_DATA_ADDR, /* The address on the eeprom of the table */
134 sizeof(ibl_t), /* The number of bytes to read */
135 (UINT8 *)&ibl, /* Where to store the bytes */
136 IBL_I2C_CFG_EEPROM_BUS_ADDR, /* The bus address of the eeprom */
137 IBL_I2C_CFG_ADDR_DELAY) /* The delay between sending the address and reading data */
139 != I2C_RET_OK) {
141 /* There is no recovery if the load of the configuration table failed */
142 iblStatus.tableLoadFail = 0x11111111;
143 for (;;);
144 }
146 /* Load default mac addresses for ethernet boot if requested */
147 for (i = 0; i < ibl_N_ETH_PORTS; i++) {
149 if ( (iblPriorityIsValid (ibl.ethConfig[i].ethPriority) ) &&
150 (iblMacAddrIsZero (ibl.ethConfig[i].ethInfo.hwAddress) ) )
152 deviceLoadDefaultEthAddress (ibl.ethConfig[i].ethInfo.hwAddress);
154 }
157 /* Pll configuration is device specific */
158 devicePllConfig ();
160 /* DDR configuration is device specific */
161 deviceDdrConfig ();
163 /* Try booting forever */
164 for (;;) {
166 /* Start looping through the boot modes to find the one with the lowest priority
167 * value, and try to boot it */
168 for (i = ibl_HIGHEST_PRIORITY; i < ibl_LOWEST_PRIORITY; i++) {
170 for (j = 0; j < ibl_N_ETH_PORTS; j++) {
171 if (ibl.ethConfig[j].ethPriority == i)
172 iblEthBoot (j);
173 }
175 if (ibl.nandConfig.nandPriority == i)
176 iblNandBoot ();
178 iblStatus.heartBeat += 1;
179 }
181 }
184 } /* main */
188 /**
189 * @b Description
190 * @n
191 *
192 * The ibl boot function links a device to a data format. The data format
193 * parser pulls data from the boot device
194 *
195 * @param[in] bootFxn The structure containing the boot device functions
196 *
197 * @retval
198 * None
199 */
200 Uint32 iblBoot (BOOT_MODULE_FXN_TABLE *bootFxn, Int32 dataFormat, void *formatParams)
201 {
202 Uint32 entry = 0;
204 union {
206 Uint8 dataBuf[4]; /* Place holder */
207 Uint32 bisValue;
208 Uint16 coffVer;
210 } fid;
213 /* Determine the data format if required */
214 if (dataFormat == ibl_BOOT_FORMAT_AUTO) {
216 (*bootFxn->peek)((Uint8 *)&fid, sizeof(fid));
218 /* BIS */
219 if (fid.bisValue == BIS_MAGIC_NUMBER)
220 dataFormat = ibl_BOOT_FORMAT_BIS;
222 if (iblIsCoff (fid.coffVer))
223 dataFormat = ibl_BOOT_FORMAT_COFF;
225 else {
226 iblStatus.autoDetectFailCnt += 1;
227 return (0);
228 }
229 }
232 /* Invoke the parser */
233 switch (dataFormat) {
235 case ibl_BOOT_FORMAT_BIS:
236 iblBootBis (bootFxn, &entry);
237 break;
239 case ibl_BOOT_FORMAT_COFF:
240 iblBootCoff (bootFxn, &entry);
241 break;
243 case ibl_BOOT_FORMAT_BTBL:
244 iblBootBtbl (bootFxn, &entry);
245 break;
247 case ibl_BOOT_FORMAT_BBLOB:
248 iblBootBlob (bootFxn, &entry, formatParams);
249 break;
251 case ibl_BOOT_FORMAT_ELF:
252 iblBootElf (bootFxn, &entry);
253 break;
255 default:
256 iblStatus.invalidDataFormatSpec += 1;
257 break;
259 }
262 return (entry);
264 }