FreeCalypso > hg > fc-magnetite
comparison src/cs/system/Main/mem_load.c @ 280:081a2b303178
src/cs/system/Main/mem_load.c: import from LoCosto source
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 07 Aug 2017 05:27:26 +0000 |
parents | |
children | 852b8410431d |
comparison
equal
deleted
inserted
replaced
279:1badec9097de | 280:081a2b303178 |
---|---|
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 #ifdef USE_CHECKSUM | |
73 UWORD16 f_checksum(UWORD8 *p_begin, | |
74 UWORD32 d_length) { | |
75 UWORD16 d_checksum = 0x0000; | |
76 | |
77 while(d_length > 0) { | |
78 d_checksum += *(p_begin++); | |
79 d_length --; | |
80 } | |
81 | |
82 return(d_checksum); | |
83 } | |
84 #else | |
85 UWORD16 f_checksum(UWORD8 *p_begin, | |
86 UWORD32 d_length) { | |
87 return 0; | |
88 } | |
89 #endif | |
90 | |
91 #endif | |
92 | |
93 #if (CHIPSET == 12) || (CHIPSET == 15) | |
94 /* | |
95 * Load start address of the interrupt vector table from FLASH into Internal SRAM | |
96 */ | |
97 #define C_NUMBER_OF_INTERRUPT_VECTOR 7 | |
98 #pragma DATA_SECTION(d_interrupt_load_start,".intload") | |
99 const UWORD32 d_interrupt_load_start=0L; | |
100 extern const UWORD32 IndirectVectorTable[C_NUMBER_OF_INTERRUPT_VECTOR * 2]; | |
101 | |
102 #define C_INTERRUPT_VECTOR_LOAD_START (UWORD32)((UWORD32)(&d_interrupt_load_start) + 4) | |
103 #define C_INTERRUPT_VECTOR_RUN_START (UWORD32)((UWORD32)&IndirectVectorTable[0]) | |
104 #define C_INTERRUPT_VECTOR_LENGTH (UWORD32)(C_NUMBER_OF_INTERRUPT_VECTOR * 2 * sizeof(UWORD32)) | |
105 #endif /* (CHIPSET == 12) || (CHIPSET == 15)*/ | |
106 | |
107 | |
108 #if ((LONG_JUMP == 3) || (((CHIPSET==15)||(CHIPSET == 12)) && (LONG_JUMP == 0))) | |
109 /* | |
110 * Load start address of the code downloaded from FLASH into Internal SRAM | |
111 */ | |
112 #pragma DATA_SECTION(d_application_load_start,".ldfl") | |
113 const UWORD32 d_application_load_start=0L; | |
114 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
115 #if (TOOL_CHOICE == 0) | |
116 /* NEW COMPILER MANAGEMENT | |
117 * If use of VISUAL LINKER, needs to manage trampoline download. | |
118 * Case of: | |
119 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
120 */ | |
121 #if !(((CHIPSET == 12) || (CHIPSET==15)) && (LONG_JUMP == 0)) | |
122 extern UWORD8 D_LOAD_START; | |
123 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */ | |
124 #endif /* (TOOL_CHOICE == 0) */ | |
125 #endif /* (OP_WCP == 0) */ | |
126 | |
127 /* | |
128 * Run start address of the code downloaded from FLASH into Internal SRAM | |
129 */ | |
130 #pragma DATA_SECTION(d_application_run_start,"S_P_Mem") | |
131 const UWORD32 d_application_run_start = 0L; | |
132 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
133 #if (TOOL_CHOICE == 0) | |
134 /* NEW COMPILER MANAGEMENT | |
135 * If use of VISUAL LINKER, needs to manage trampoline download. | |
136 * Case of: | |
137 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
138 */ | |
139 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) | |
140 extern UWORD8 D_RUN_START; | |
141 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */ | |
142 #endif /* (TOOL_CHOICE == 0) */ | |
143 #endif /* (OP_WCP == 0) */ | |
144 | |
145 /* | |
146 * Run end address of the code downloaded from FLASH into Internal SRAM | |
147 */ | |
148 #pragma DATA_SECTION(d_application_run_end,"E_P_Mem") | |
149 const UWORD32 d_application_run_end = 0L; | |
150 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
151 #if (TOOL_CHOICE == 0) | |
152 /* NEW COMPILER MANAGEMENT | |
153 * If use of VISUAL LINKER, needs to manage trampoline download. | |
154 * Case of: | |
155 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
156 */ | |
157 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) | |
158 extern UWORD8 D_RUN_END; | |
159 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */ | |
160 #endif /* (TOOL_CHOICE == 0) */ | |
161 #endif /* (OP_WCP == 0) */ | |
162 | |
163 /* | |
164 * Application download | |
165 */ | |
166 #define C_APPLICATION_LOAD_START (UWORD32)((UWORD32 *)(&d_application_load_start) + 2) | |
167 #define C_APPLICATION_RUN_START (UWORD32)((UWORD32)(&d_application_run_start) + sizeof(UWORD32)) | |
168 #define C_APPLICATION_RUN_END (UWORD32)((UWORD32)(&d_application_run_end) + sizeof(UWORD32)) | |
169 #define C_APPLICATION_LENGTH (UWORD32)(C_APPLICATION_RUN_END - C_APPLICATION_RUN_START - sizeof(UWORD32)) | |
170 | |
171 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
172 #if (TOOL_CHOICE == 0) | |
173 /* NEW COMPILER MANAGEMENT | |
174 * If use of VISUAL LINKER, needs to manage trampoline download. | |
175 * Case of: | |
176 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
177 */ | |
178 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) | |
179 /* | |
180 * Trampoline download | |
181 */ | |
182 #define C_TRAMPOLINE_LOAD_START (UWORD32)(&D_LOAD_START) | |
183 #define C_TRAMPOLINE_RUN_START (UWORD32)(&D_RUN_START) | |
184 #define C_TRAMPOLINE_RUN_END (UWORD32)(&D_RUN_END) | |
185 #define C_TRAMPOLINE_LENGTH (UWORD32)(&D_RUN_END - &D_RUN_START) | |
186 #endif /* (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) */ | |
187 #endif /* (TOOL_CHOICE == 0) */ | |
188 #endif /* (OP_WCP == 0) */ | |
189 | |
190 void f_load_int_mem(void) { | |
191 /* | |
192 * Reset checksum of code downloaded | |
193 */ | |
194 d_checksum1 = 0; /* Load checksum */ | |
195 d_checksum2 = 0; /* Run checksum */ | |
196 | |
197 /* | |
198 * Reset the Internal memory where the code must be downloaded | |
199 */ | |
200 INT_memset((void *)(C_APPLICATION_RUN_START),0,C_APPLICATION_LENGTH); | |
201 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
202 #if (TOOL_CHOICE == 0) | |
203 /* NEW COMPILER MANAGEMENT | |
204 * If use of VISUAL LINKER, needs to manage trampoline download. | |
205 * Case of: | |
206 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
207 */ | |
208 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) | |
209 INT_memset((void *)(C_TRAMPOLINE_RUN_START),0,C_TRAMPOLINE_LENGTH); | |
210 #endif | |
211 #endif /* (TOOL_CHOICE == 0) */ | |
212 | |
213 #if ((CHIPSET == 12)||(CHIPSET==15)) | |
214 INT_memset((void *)(C_INTERRUPT_VECTOR_RUN_START),0,C_INTERRUPT_VECTOR_LENGTH); | |
215 #endif | |
216 #endif /* (OP_WCP == 0) */ | |
217 | |
218 #if (OP_L1_STANDALONE == 0) && (BOARD == 35) && (USE_GZIP == 1) | |
219 #define C_GZIP_START (C_APPLICATION_LOAD_START) | |
220 #define C_GZIP_LENGTH (*(UWORD32*)C_APPLICATION_LOAD_START) | |
221 #define C_GZIP_OUT (C_APPLICATION_RUN_START - sizeof(UWORD32)) | |
222 | |
223 /* De-compress on-the-fly and load to internal RAM */ | |
224 decompress(C_GZIP_START, /* load start (compressed) */ | |
225 C_GZIP_LENGTH, /* compressed length */ | |
226 C_GZIP_OUT); /* run start */ | |
227 #else | |
228 /* | |
229 * Compute checksum on code in FLASH (code and trampoline functions) | |
230 */ | |
231 d_checksum1 = f_checksum((UWORD8 *)(C_APPLICATION_LOAD_START), C_APPLICATION_LENGTH); | |
232 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
233 #if (TOOL_CHOICE == 0) | |
234 /* NEW COMPILER MANAGEMENT | |
235 * If use of VISUAL LINKER, needs to manage trampoline download. | |
236 * Case of: | |
237 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
238 */ | |
239 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) | |
240 d_checksum1 += f_checksum((UWORD8 *)(C_TRAMPOLINE_LOAD_START), C_TRAMPOLINE_LENGTH); | |
241 #endif | |
242 #endif /* (TOOL_CHOICE == 0) */ | |
243 | |
244 #if ((CHIPSET == 12)||(CHIPSET==15)) | |
245 d_checksum1 += f_checksum((UWORD8 *)(C_INTERRUPT_VECTOR_LOAD_START), C_INTERRUPT_VECTOR_LENGTH); | |
246 #endif | |
247 #endif /* (OP_WCP == 0) */ | |
248 | |
249 | |
250 /* | |
251 * Download code from FLASH into Internal RAM (both code and trampoline functions) | |
252 */ | |
253 INT_memcpy((void *)(C_APPLICATION_RUN_START),(void *)(C_APPLICATION_LOAD_START),C_APPLICATION_LENGTH); | |
254 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
255 #if (TOOL_CHOICE == 0) | |
256 /* NEW COMPILER MANAGEMENT | |
257 * If use of VISUAL LINKER, needs to manage trampoline download. | |
258 * Case of: | |
259 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
260 */ | |
261 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) | |
262 INT_memcpy((void *)(C_TRAMPOLINE_RUN_START),(void *)(C_TRAMPOLINE_LOAD_START),C_TRAMPOLINE_LENGTH); | |
263 #endif | |
264 #endif /* (TOOL_CHOICE == 0) */ | |
265 | |
266 #if ((CHIPSET == 12)||(CHIPSET==15)) | |
267 INT_memcpy((void *)(C_INTERRUPT_VECTOR_RUN_START),(void *)(C_INTERRUPT_VECTOR_LOAD_START),C_INTERRUPT_VECTOR_LENGTH); | |
268 #endif | |
269 #endif /* (OP_WCP == 0) */ | |
270 | |
271 | |
272 /* | |
273 * Compute checksum on code in FLASH (code and trampoline functions) | |
274 */ | |
275 d_checksum2 = f_checksum((UWORD8 *)(C_APPLICATION_RUN_START), C_APPLICATION_LENGTH); | |
276 #if ((OP_WCP == 0) || (OP_L1_STANDALONE == 1)) | |
277 #if (TOOL_CHOICE == 0) | |
278 /* NEW COMPILER MANAGEMENT | |
279 * If use of VISUAL LINKER, needs to manage trampoline download. | |
280 * Case of: | |
281 * - TOOL_CHOICE == 0 => compiler v1.22e with vlinker v1.9902 | |
282 */ | |
283 #if !(((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0)) | |
284 d_checksum2 += f_checksum((UWORD8 *)(C_TRAMPOLINE_RUN_START), C_TRAMPOLINE_LENGTH); | |
285 #endif | |
286 #endif /* (TOOL_CHOICE == 0) */ | |
287 | |
288 #if ((CHIPSET == 12)||(CHIPSET==15)) | |
289 d_checksum2 += f_checksum((UWORD8 *)(C_INTERRUPT_VECTOR_RUN_START), C_INTERRUPT_VECTOR_LENGTH); | |
290 #endif | |
291 #endif /* (OP_WCP == 0) */ | |
292 | |
293 #endif /* (OP_L1_STANDALONE == 0) && (BOARD == 35) && (USE_GZIP == 1) */ | |
294 | |
295 } /* f_load_int_mem() */ | |
296 #endif /* ((LONG_JUMP == 3) || (((CHIPSET == 12)||(CHIPSET==15)) && (LONG_JUMP == 0))) */ | |
297 #endif /* ((((CHIPSET == 3) || (CHIPSET == 4) || ... (CHIPSET == 12) || (CHIPSET == 15)) */ |