1 /************************************************************************************
2 * FILE PURPOSE: Wrapper for the TI boot table processor
3 ************************************************************************************
4 * FILE NAME: btblwrap.c
5 *
6 * DESCRIPTION: The IBL wrapper for the boot table processor.
7 *
8 ************************************************************************************/
9 #include "types.h"
10 #include "ibl.h"
11 #include "iblloc.h"
12 #include "btblwrap.h"
13 #include "btbl.h"
14 #include "btblloc.h"
15 #include "iblbtbl.h"
16 #include <stdlib.h>
17 #include <string.h>
20 /* Globals used by the TI boot table processor */
22 BOOT_TBL_CB_T tiBootTable;
23 bootStats_t bootStats;
24 Uint32 btblEcode;
25 Int32 btblWrapEcode;
28 #define MIN(a,b) ((a) < (b)) ? (a) : (b)
31 /************************************************************************************
32 * FUNCTION PURPOSE: The main boot wrapper for the TI boot table processor
33 ************************************************************************************
34 * DESCRIPTION: Interfaces the IBL to the TI boot table driver.
35 * The TI boot table driver operates in a push data mode, the
36 * IBL operates in a pull data mode. This function pulls data
37 * from the interface and pushes is to the TI driver. To do this
38 * the internal state of the TI boot table driver is used
39 * to determine how much data to pull.
40 ************************************************************************************/
41 void iblBootBtbl (BOOT_MODULE_FXN_TABLE *bootFxn, Uint32 *entry_point)
42 {
43 Uint32 readSize;
44 Uint32 blockSize;
45 Uint32 blockSize16;
46 Uint8 *data;
47 Uint16 *data16;
48 Uint16 t16;
50 Int32 i, j;
52 *entry_point = 0;
53 btblEcode = 0;
54 btblWrapEcode = 0;
56 /* Initialize stats and btbl state */
57 iblMemset (&bootStats, 0, sizeof(bootStats_t));
59 boot_init_boot_tbl_inst (&tiBootTable);
61 data = iblMalloc (TI_BTBL_BLOCK_SIZE);
62 if (data == NULL) {
63 btblWrapEcode = BTBL_WRAP_ECODE_MALLOC_FAIL;
64 return;
65 }
67 data16 = (Uint16 *)data;
69 while ((tiBootTable.state != BOOT_TBL_STATE_FLUSH) && (btblEcode == 0)) {
71 switch (tiBootTable.state) {
73 case BOOT_TBL_STATE_PAD: readSize = 2;
74 break;
76 case BOOT_TBL_STATE_INIT:
77 case BOOT_TBL_STATE_SIZE:
78 case BOOT_TBL_STATE_ADDR: readSize = 4;
79 break;
81 case BOOT_TBL_STATE_DATA: readSize = tiBootTable.section_size_bytes;
82 break;
83 }
86 while (readSize > 0) {
88 blockSize = MIN(readSize, TI_BTBL_BLOCK_SIZE);
89 blockSize16 = (blockSize + 1) >> 1;
91 /* No recovery on block read failure */
92 if ((*bootFxn->read)(data, blockSize) < 0) {
93 btblWrapEcode = BTBL_WRAP_ECODE_READ_FAIL;
94 iblFree (data);
95 return;
96 }
98 /* The data has been read as a byte stream. This data must
99 * be re-formatted as a 16 bit word stream */
100 for (j = i = 0; j < blockSize16; j++, i += 2) {
102 t16 = (data[i+0] << 8) | data[i+1];
103 data16[j] = t16;
105 }
108 /* Process the block */
109 boot_proc_boot_tbl (&tiBootTable, data16, blockSize16);
111 readSize = readSize - blockSize;
113 }
115 }
117 if (btblEcode == 0)
118 *entry_point = tiBootTable.code_start_addr;
120 iblFree (data);
122 }
124 /***********************************************************************************
125 * FUNCTION PURPOSE: Handle a fatal error from the boot table processor
126 ***********************************************************************************
127 * DESCRIPTION: The error code is stored. Processing is terminated
128 * through the global ecode value.
129 ***********************************************************************************/
130 void btblBootException (UINT32 ecode)
131 {
132 btblEcode = ecode;
133 btblWrapEcode = BTBL_WRAP_ECODE_BTBL_FAIL;
134 }