a8ac4d44ca4ca36009fcdc1f7b2bb17446e884f4
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 memset (&bootStats, 0, sizeof(bootStats_t));
59 boot_init_boot_tbl_inst (&tiBootTable);
61 data = malloc (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_INIT:
74 case BOOT_TBL_STATE_SIZE:
75 case BOOT_TBL_STATE_ADDR: readSize = 4;
76 break;
78 case BOOT_TBL_STATE_DATA: readSize = tiBootTable.section_size_bytes;
79 break;
80 }
83 while (readSize > 0) {
85 blockSize = MIN(readSize, TI_BTBL_BLOCK_SIZE);
86 blockSize16 = (blockSize + 1) >> 1;
88 /* No recovery on block read failure */
89 if ((*bootFxn->read)(data, blockSize) < 0) {
90 btblWrapEcode = BTBL_WRAP_ECODE_READ_FAIL;
91 free (data);
92 return;
93 }
95 /* The data has been read as a byte stream. This data must
96 * be re-formatted as a 16 bit word stream */
97 for (j = i = 0; j < blockSize16; j++, i += 2) {
99 t16 = (data[i+0] << 8) | data[i+1];
100 data16[j] = t16;
102 }
105 /* Process the block */
106 boot_proc_boot_tbl (&tiBootTable, data16, blockSize16);
108 readSize = readSize - blockSize;
110 }
112 }
114 if (btblEcode == 0)
115 *entry_point = tiBootTable.code_start_addr;
117 free (data);
119 }
121 /***********************************************************************************
122 * FUNCTION PURPOSE: Handle a fatal error from the boot table processor
123 ***********************************************************************************
124 * DESCRIPTION: The error code is stored. Processing is terminated
125 * through the global ecode value.
126 ***********************************************************************************/
127 void btblBootException (UINT32 ecode)
128 {
129 btblEcode = ecode;
130 btblWrapEcode = BTBL_WRAP_ECODE_BTBL_FAIL;
131 }