comparison src/cs/system/Main/mem_load.c @ 0:b6a5e36de839

src/cs: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:39:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
1 /************* Revision Controle System Header *************
2 * GSM Layer 1 software
3 * MEM_LOAD.C
4 *
5 * Filename mem_load.c
6 * Version 1.6
7 * Date 06/20/01
8 *
9 ************* Revision Controle System Header *************/
10
11 #ifndef _WINDOWS
12 #include "chipset.cfg"
13 #include "board.cfg"
14 #include "swconfig.cfg"
15 #endif
16
17 #include "l1sw.cfg" /* OP_L1_STANDALONE definition */
18
19 #if ((((CHIPSET == 3) || (CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || \
20 (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11)) && (LONG_JUMP != 0)) || \
21 (CHIPSET == 12) ||(CHIPSET == 15))
22 /*
23 * USE_GZIP flag is used by modem binaries compression feature on P2.
24 * For P2 build variants it is defined globally - either in master.cfg (HBB)
25 * or P2's configdef *.xml files (UBB).
26 * The following definition is for all other platforms - just to
27 * suppress compilation warnings.
28 */
29 #ifndef USE_GZIP
30 #define USE_GZIP 0
31 #endif
32
33 #if (OP_L1_STANDALONE == 1)
34 #define D_LOAD_START _470_INT_MEM_out_call_load_start
35 #define D_RUN_START _470_INT_MEM_out_call_run_start
36 #define D_RUN_END _470_INT_MEM_out_call_run_end
37 #else
38 #define D_LOAD_START _470_S_MEM_out_call_load_start
39 #define D_RUN_START _470_S_MEM_out_call_run_start
40 #define D_RUN_END _470_S_MEM_out_call_run_end
41 #endif
42
43 typedef unsigned char UWORD8;
44 typedef unsigned short int UWORD16;
45 typedef unsigned long int UWORD32;
46
47
48 UWORD16 d_checksum1;
49 UWORD16 d_checksum2;
50
51 /* NEW COMPILER MANAGEMENT
52 * INT_memset and INT_memcpy, respectively identical to memset and
53 * memcpy from the rts library of compiler V2.51, are defined in int.s.
54 * They are used to make the initialization of the .bss section and the load
55 * of the internal ram code not dependent to the 32-bit alignment.
56 * The old code used for the initialization and the load used a loop with
57 * 4-byte increment, assuming the 32-bit alignment of the .bss section.
58 * This alignment is not true with compiler V2.51.
59 * This change applies whatever the compiler version.
60 * INT_memset replaces f_zero
61 * INT_memcpy replaces f_download
62 */
63 extern void INT_memset(void *s, int c, UWORD32 n);
64 extern void INT_memcpy(void *s1, void *s2, UWORD32 n);
65
66 #if (OP_L1_STANDALONE == 0) && (BOARD == 35) && (USE_GZIP == 1)
67 extern void decompress(unsigned long input_start,
68 unsigned long input_length,
69 unsigned long output_start);
70 #else
71
72 UWORD16 f_checksum(UWORD8 *p_begin,
73 UWORD32 d_length) {
74 UWORD16 d_checksum = 0x0000;
75
76 while(d_length > 0) {
77 d_checksum += *(p_begin++);
78 d_length --;
79 }
80
81 return(d_checksum);
82 }
83
84 #endif
85
86 #if (CHIPSET == 12) || (CHIPSET == 15)
87 /*
88 * Load start address of the interrupt vector table from FLASH into Internal SRAM
89 */
90 #define C_NUMBER_OF_INTERRUPT_VECTOR 7
91 #pragma DATA_SECTION(d_interrupt_load_start,".intload")
92 const UWORD32 d_interrupt_load_start=0L;
93 extern const UWORD32 IndirectVectorTable[C_NUMBER_OF_INTERRUPT_VECTOR * 2];
94
95 #define C_INTERRUPT_VECTOR_LOAD_START (UWORD32)((UWORD32)(&d_interrupt_load_start) + 4)
96 #define C_INTERRUPT_VECTOR_RUN_START (UWORD32)((UWORD32)&IndirectVectorTable[0])
97 #define C_INTERRUPT_VECTOR_LENGTH (UWORD32)(C_NUMBER_OF_INTERRUPT_VECTOR * 2 * sizeof(UWORD32))
98 #endif /* (CHIPSET == 12) || (CHIPSET == 15)*/
99
100
101 #if ((LONG_JUMP == 3) || (((CHIPSET==15)||(CHIPSET == 12)) && (LONG_JUMP == 0)))
102 /*
103 * Load start address of the code downloaded from FLASH into Internal SRAM
104 */
105 #pragma DATA_SECTION(d_application_load_start,".ldfl")
106 const UWORD32 d_application_load_start=0L;
107 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
108 #if (TOOL_CHOICE == 0)
109 /* NEW COMPILER MANAGEMENT
110 * If use of VISUAL LINKER, needs to manage trampoline download.
111 * Case of:
112 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
113 */
114 #if !(((CHIPSET == 12) || (CHIPSET==15)) && (LONG_JUMP == 0))
115 extern UWORD8 D_LOAD_START;
116 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */
117 #endif /* (TOOL_CHOICE == 0) */
118 #endif /* (OP_WCP == 0) */
119
120 /*
121 * Run start address of the code downloaded from FLASH into Internal SRAM
122 */
123 #pragma DATA_SECTION(d_application_run_start,"S_P_Mem")
124 const UWORD32 d_application_run_start = 0L;
125 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
126 #if (TOOL_CHOICE == 0)
127 /* NEW COMPILER MANAGEMENT
128 * If use of VISUAL LINKER, needs to manage trampoline download.
129 * Case of:
130 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
131 */
132 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))
133 extern UWORD8 D_RUN_START;
134 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */
135 #endif /* (TOOL_CHOICE == 0) */
136 #endif /* (OP_WCP == 0) */
137
138 /*
139 * Run end address of the code downloaded from FLASH into Internal SRAM
140 */
141 #pragma DATA_SECTION(d_application_run_end,"E_P_Mem")
142 const UWORD32 d_application_run_end = 0L;
143 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
144 #if (TOOL_CHOICE == 0)
145 /* NEW COMPILER MANAGEMENT
146 * If use of VISUAL LINKER, needs to manage trampoline download.
147 * Case of:
148 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
149 */
150 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))
151 extern UWORD8 D_RUN_END;
152 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */
153 #endif /* (TOOL_CHOICE == 0) */
154 #endif /* (OP_WCP == 0) */
155
156 /*
157 * Application download
158 */
159 #define C_APPLICATION_LOAD_START (UWORD32)((UWORD32 *)(&d_application_load_start) + 2)
160 #define C_APPLICATION_RUN_START (UWORD32)((UWORD32)(&d_application_run_start) + sizeof(UWORD32))
161 #define C_APPLICATION_RUN_END (UWORD32)((UWORD32)(&d_application_run_end) + sizeof(UWORD32))
162 #define C_APPLICATION_LENGTH (UWORD32)(C_APPLICATION_RUN_END - C_APPLICATION_RUN_START - sizeof(UWORD32))
163
164 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
165 #if (TOOL_CHOICE == 0)
166 /* NEW COMPILER MANAGEMENT
167 * If use of VISUAL LINKER, needs to manage trampoline download.
168 * Case of:
169 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
170 */
171 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))
172 /*
173 * Trampoline download
174 */
175 #define C_TRAMPOLINE_LOAD_START (UWORD32)(&D_LOAD_START)
176 #define C_TRAMPOLINE_RUN_START (UWORD32)(&D_RUN_START)
177 #define C_TRAMPOLINE_RUN_END (UWORD32)(&D_RUN_END)
178 #define C_TRAMPOLINE_LENGTH (UWORD32)(&D_RUN_END - &D_RUN_START)
179 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */
180 #endif /* (TOOL_CHOICE == 0) */
181 #endif /* (OP_WCP == 0) */
182
183 void f_load_int_mem(void) {
184 /*
185 * Reset checksum of code downloaded
186 */
187 d_checksum1 = 0; /* Load checksum */
188 d_checksum2 = 0; /* Run checksum */
189
190 /*
191 * Reset the Internal memory where the code must be downloaded
192 */
193 INT_memset((void *)(C_APPLICATION_RUN_START),0,C_APPLICATION_LENGTH);
194 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
195 #if (TOOL_CHOICE == 0)
196 /* NEW COMPILER MANAGEMENT
197 * If use of VISUAL LINKER, needs to manage trampoline download.
198 * Case of:
199 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
200 */
201 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))
202 INT_memset((void *)(C_TRAMPOLINE_RUN_START),0,C_TRAMPOLINE_LENGTH);
203 #endif
204 #endif /* (TOOL_CHOICE == 0) */
205
206 #if ((CHIPSET == 12)||(CHIPSET==15))
207 INT_memset((void *)(C_INTERRUPT_VECTOR_RUN_START),0,C_INTERRUPT_VECTOR_LENGTH);
208 #endif
209 #endif /* (OP_WCP == 0) */
210
211 #if (OP_L1_STANDALONE == 0) && (BOARD == 35) && (USE_GZIP == 1)
212 #define C_GZIP_START (C_APPLICATION_LOAD_START)
213 #define C_GZIP_LENGTH (*(UWORD32*)C_APPLICATION_LOAD_START)
214 #define C_GZIP_OUT (C_APPLICATION_RUN_START - sizeof(UWORD32))
215
216 /* De-compress on-the-fly and load to internal RAM */
217 decompress(C_GZIP_START, /* load start (compressed) */
218 C_GZIP_LENGTH, /* compressed length */
219 C_GZIP_OUT); /* run start */
220 #else
221 /*
222 * Compute checksum on code in FLASH (code and trampoline functions)
223 */
224 d_checksum1 = f_checksum((UWORD8 *)(C_APPLICATION_LOAD_START), C_APPLICATION_LENGTH);
225 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
226 #if (TOOL_CHOICE == 0)
227 /* NEW COMPILER MANAGEMENT
228 * If use of VISUAL LINKER, needs to manage trampoline download.
229 * Case of:
230 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
231 */
232 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))
233 d_checksum1 += f_checksum((UWORD8 *)(C_TRAMPOLINE_LOAD_START), C_TRAMPOLINE_LENGTH);
234 #endif
235 #endif /* (TOOL_CHOICE == 0) */
236
237 #if ((CHIPSET == 12)||(CHIPSET==15))
238 d_checksum1 += f_checksum((UWORD8 *)(C_INTERRUPT_VECTOR_LOAD_START), C_INTERRUPT_VECTOR_LENGTH);
239 #endif
240 #endif /* (OP_WCP == 0) */
241
242
243 /*
244 * Download code from FLASH into Internal RAM (both code and trampoline functions)
245 */
246 INT_memcpy((void *)(C_APPLICATION_RUN_START),(void *)(C_APPLICATION_LOAD_START),C_APPLICATION_LENGTH);
247 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
248 #if (TOOL_CHOICE == 0)
249 /* NEW COMPILER MANAGEMENT
250 * If use of VISUAL LINKER, needs to manage trampoline download.
251 * Case of:
252 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
253 */
254 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))
255 INT_memcpy((void *)(C_TRAMPOLINE_RUN_START),(void *)(C_TRAMPOLINE_LOAD_START),C_TRAMPOLINE_LENGTH);
256 #endif
257 #endif /* (TOOL_CHOICE == 0) */
258
259 #if ((CHIPSET == 12)||(CHIPSET==15))
260 INT_memcpy((void *)(C_INTERRUPT_VECTOR_RUN_START),(void *)(C_INTERRUPT_VECTOR_LOAD_START),C_INTERRUPT_VECTOR_LENGTH);
261 #endif
262 #endif /* (OP_WCP == 0) */
263
264
265 /*
266 * Compute checksum on code in FLASH (code and trampoline functions)
267 */
268 d_checksum2 = f_checksum((UWORD8 *)(C_APPLICATION_RUN_START), C_APPLICATION_LENGTH);
269 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1))
270 #if (TOOL_CHOICE == 0)
271 /* NEW COMPILER MANAGEMENT
272 * If use of VISUAL LINKER, needs to manage trampoline download.
273 * Case of:
274 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902
275 */
276 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))
277 d_checksum2 += f_checksum((UWORD8 *)(C_TRAMPOLINE_RUN_START), C_TRAMPOLINE_LENGTH);
278 #endif
279 #endif /* (TOOL_CHOICE == 0) */
280
281 #if ((CHIPSET == 12)||(CHIPSET==15))
282 d_checksum2 += f_checksum((UWORD8 *)(C_INTERRUPT_VECTOR_RUN_START), C_INTERRUPT_VECTOR_LENGTH);
283 #endif
284 #endif /* (OP_WCP == 0) */
285
286 #endif /* (OP_L1_STANDALONE == 0) && (BOARD == 35) && (USE_GZIP == 1) */
287
288 } /* f_load_int_mem() */
289 #endif /* ((LONG_JUMP == 3) || (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))) */
290 #endif /* ((((CHIPSET == 3) || (CHIPSET == 4) || ... (CHIPSET == 12) || (CHIPSET == 15)) */