6eafe4cd0fd83624f599b680c833e5661ce00a75
1 /*
2 *
3 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 /**
37 * @file nor.c
38 *
39 * @brief The nor boot driver
40 */
42 #include "types.h"
43 #include "ibl.h"
44 #include "iblloc.h"
45 #include "device.h"
46 #include "nor.h"
47 #include <string.h>
48 #include <stdlib.h>
51 /**
52 * @brief The nor master control block which tracks the current nor boot information
53 */
54 typedef struct normcb_s
55 {
56 uint32 fpos; /**< Current file position. This is an absolute address, not relative to startPos */
57 uint32 startPos; /**< Initial file position */
59 norCtbl_t *nor_if; /**< Low level interface driver */
61 } normcb_t;
63 normcb_t normcb;
65 /**
66 * @brief
67 * Set the current file position
68 */
69 Int32 nor_seek (Int32 loc, Int32 from)
70 {
71 /* Can't seek from the end of the file, since the end is not known */
72 if (from == 0)
73 normcb.fpos = normcb.startPos + loc;
74 else if (from == 1)
75 normcb.fpos += loc;
76 else
77 return (-1);
79 if (normcb.fpos < normcb.startPos)
80 normcb.fpos = normcb.startPos;
82 return (0);
83 }
86 /**
87 * @brief
88 * Initialize the control structure. Note that the interface value was
89 * previously verified in the top level nor boot control.
90 */
91 Int32 nor_open (void *ptr_driver, void (*asyncComplete)(void *))
92 {
93 iblNor_t *ibln = (iblNor_t *)ptr_driver;
95 normcb.startPos = normcb.fpos = ibln->bootAddress;
96 normcb.nor_if = deviceGetNorCtbl (ibln->interface);
98 return (0);
100 }
102 /**
103 * @brief
104 * Read data from the current address. This function is used
105 * for peek as well as read.
106 */
107 Int32 nor_read (Uint8 *ptr_buf, Uint32 num_bytes)
108 {
109 Int32 ret;
111 if (normcb.nor_if == NULL)
112 return (-1);
115 ret = (*normcb.nor_if->nct_driverReadBytes)(ptr_buf, num_bytes, normcb.fpos);
117 if (ret == 0)
118 normcb.fpos += num_bytes;
120 return (ret);
122 }
124 /**
125 * @brief
126 * Return the number of bytes available for current read.
127 * Always return 1k
128 */
129 Int32 nor_query (void)
130 {
131 return (0x400);
133 }
135 /**
136 * @brief
137 * Close the nor driver
138 */
139 Int32 nor_close (void)
140 {
141 if (normcb.nor_if != NULL)
142 (*normcb.nor_if->nct_driverClose)();
144 normcb.nor_if = NULL;
145 return (0);
147 }
149 /**
150 * @brief
151 * The global nor module function table
152 */
153 BOOT_MODULE_FXN_TABLE nor_boot_module =
154 {
155 nor_open, /* Open API */
156 nor_close, /* Close API */
157 nor_read, /* Read API */
158 NULL, /* Write API */
159 nor_read, /* Peek API */
160 nor_seek, /* Seek API */
161 nor_query /* Query API */
163 };