]> git.zerfleddert.de Git - linexec-j720/blob - boot.cpp
1204c7973214a7d2f6a756f8792133f2c071f99e
[linexec-j720] / boot.cpp
1 #include "stdafx.h"
2 #include "tester1.h"
3 #include <commctrl.h>
4 //#include <aygshell.h>
5 #include <sipapi.h>
6 #include "setup.h"
7
8
9 #define BOOT_LOGO_PATH "\\My Documents\\booting.bmp"
10 #define BOOT_LOGO_PATH_CF "\\CF Card\\booting.bmp"
11 #define BOOT_LOGO_DONE_PATH "\\My Documents\\done.bmp"
12 #define BOOT_LOGO_DONE_PATH_CF "\\CF Card\\done.bmp"
13 #define DONE1_X 100
14 #define DONE1_Y 100
15 #define DONE2_X 100
16 #define DONE2_Y 130
17
18
19 void setup_linux_params(long bootimg_dest, UINT32 initrd,UINT32 initrdl, long dram_size, const char *cmdline, char*base)
20 {
21 int rootdev = 0x00ff;
22 struct tag *tag;
23 int newcmdlinelen = 0;
24 char *newcmdline = NULL;
25
26
27 tag = (struct tag *)(base+0x100);
28
29 tag->hdr.tag = ATAG_CORE;
30 tag->hdr.size = tag_size(tag_core);
31 tag->u.core.flags =0;
32 tag->u.core.pagesize = 0x00001000;
33 tag->u.core.rootdev = rootdev;
34 tag = tag_next(tag);
35
36 // now the cmdline tag
37 tag->hdr.tag = ATAG_CMDLINE;
38 // must be at least +3!! 1 for the null and 2 for the ???
39 tag->hdr.size = (strlen(cmdline) + 3 + sizeof(struct tag_header)) >> 2;
40 //tag->hdr.size = (strlen(cmdline) + 10 + sizeof(struct tag_header)) >> 2;
41 strcpy(tag->u.cmdline.cmdline,cmdline);
42 tag = tag_next(tag);
43
44
45 // now the mem32 tag
46 tag->hdr.tag = ATAG_MEM;
47 tag->hdr.size = tag_size(tag_mem32);
48 tag->u.mem.size = dram_size;
49 tag->u.mem.start = MEM_START;
50 tag = tag_next(tag);
51
52
53 /* and now the initrd tag */
54 if (initrdl) {
55 tag->hdr.tag = INITRD_TAG;
56 tag->hdr.size = tag_size(tag_initrd);
57 tag->u.initrd.start = initrd;
58 tag->u.initrd.size = initrdl;
59 tag = tag_next(tag);
60 }
61
62 tag->hdr.tag = ATAG_VIDEOTEXT;
63 tag->hdr.size = tag_size(tag_videotext);
64 tag->u.videotext.video_lines = 40;
65 tag->u.videotext.video_cols = 30;
66 tag = tag_next(tag);
67
68 // now the NULL tag
69 tag->hdr.tag = ATAG_NONE;
70 tag->hdr.size = 0;
71 }
72
73
74
75
76
77 /* loading process:
78 function do_it is loaded onto address KERNELCOPY along with parameters(offset=0x100) and
79 kernel image(offset=0x8000). Afterwards DRAMloader is called; it disables MMU and
80 jumps onto KERNELCOPY. Function do_it then copies kernel image to its proper address(0xA0008000)
81 and calls it.
82 Initrd is loaded onto address INITRD and the address is passed to kernel via ATAG
83 */
84
85
86 // This resets some devices
87 void ResetDevices()
88 {
89 #ifndef STRONGARM
90 WritePhysical(0x4050000C,0); // Reset AC97
91 WritePhysical(0x48000014,0); // Reset PCMCIA
92 for(int i=0;i<0x3C;i+=4)
93 WritePhysical(0x40000000,8); // Set DMAs to Stop state
94 WritePhysical(0x400000F0,0); // DMA do not gen interrupt
95 SetGPIOio(28,0); // AC97
96 SetGPIOio(29,0); // AC97/I2S
97 SetGPIOio(30,0); // I2S/AC97
98 SetGPIOio(31,0); // I2S/AC97
99 SetGPIOio(32,0); // AC97/I2S
100 SetGPIOalt(28,0);
101 SetGPIOalt(29,0);
102 SetGPIOalt(30,0);
103 SetGPIOalt(31,0);
104 SetGPIOalt(32,0);
105 #endif
106 }
107
108
109
110
111 void mymemcpy(char* a, char* b, int size);
112
113 void boot_linux(char *filename,char* initrd,char *param)
114 {
115 FILE *fd=fopen(filename,"rb");
116 int ret;
117
118 FILE* fd1;
119
120 long initrdl;
121 long len;
122
123 #ifndef STRONGARM
124 Image image;
125 Image image_done;
126 #endif
127
128
129
130 if(!fd)
131 {
132 FILE *logfd=fopen("\\bootlog.txt","a");
133 fprintf(logfd, "Booting: ***FAILED TO OPEN %s***\n",filename);
134 fclose(logfd);
135 return;
136 }
137
138 fseek(fd,0,SEEK_END);
139 len=ftell(fd);
140 fseek(fd,0,SEEK_SET);
141
142 fd1=fopen(initrd,"rb");
143 initrdl=0;
144 if(fd1)
145 {
146 fseek(fd1,0,SEEK_END);
147 initrdl=ftell(fd1);
148 fseek(fd1,0,SEEK_SET);
149 }
150 FILE *logfd=fopen("\\bootlog.txt","a");
151 fprintf(logfd, "Booting: Images.");
152 fclose(logfd);
153
154
155 #ifndef STRONGARM
156 /* i haven't ported this to strongarm, hope this is not important to
157 * anyone */
158 init_fb();
159 try_fb();
160
161 image=ReadBMP(BOOT_LOGO_PATH);
162 if (!image.p) image=ReadBMP(BOOT_LOGO_PATH_CF);
163 image_done=ReadBMP(BOOT_LOGO_DONE_PATH);
164 if (!image_done.p) image_done = ReadBMP(BOOT_LOGO_DONE_PATH_CF);
165 if (image.p) ShowImage(image.p,image.x,image.y);
166 #endif
167
168 logfd=fopen("\\bootlog.txt","a");
169 fprintf(logfd, "Booting: entering supervisor mode.");
170 fclose(logfd);
171
172 /* now becoming supervisor. */
173 SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);
174 // CeSetThreadQuantum(GetCurrentThread(),0);
175 SetKMode(1);
176 SetProcPermissions(0xffffffff);
177 /* <ibot> rooooooooot has landed! */
178
179 logfd=fopen("\\bootlog.txt","a");
180 fprintf(logfd, "Booting: supervisor mode.");
181 fclose(logfd);
182
183 void *mmu=(void*)read_mmu();
184 UINT32 *data=NULL,*lcd=NULL,*intr=NULL,*_mmu=NULL;
185 char *watch=NULL,*krnl=NULL;
186
187
188 IntOff();
189
190
191 char *kernel_copy2=(char*)VirtualAlloc((void*)0x0,0x8000+len, MEM_RESERVE|MEM_TOP_DOWN,PAGE_READWRITE);
192 ret=VirtualCopy((void*)kernel_copy2,(void *) (KERNELCOPY/256), 0x8000+len, PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
193
194 char *initrd_copy2;
195
196
197 if(fd1)
198 {
199 initrd_copy2=(char*)VirtualAlloc((void*)0x0,initrdl, MEM_RESERVE|MEM_TOP_DOWN,PAGE_READWRITE);
200 ret=VirtualCopy((void*)initrd_copy2,(void *) (INITRD/256), initrdl, PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
201 }
202
203 void(*relmemcpy)(char*,char*,int);
204 relmemcpy=(void (__cdecl *)(char *,char *,int))VirtualAlloc((void*)0x0, 1024, MEM_RESERVE|MEM_TOP_DOWN,PAGE_READWRITE);
205
206 /* ask joshua */
207 #ifndef STRONGARM
208 ret=VirtualCopy((void*)relmemcpy,(void *) (0xa0001000/256), 1024, PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
209 #else
210 ret=VirtualCopy((void*)relmemcpy,(void *) (0xc0001000/256), 1024, PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
211 #endif
212
213 if(!kernel_copy2) return;
214
215
216 UINT32 phys_addr;
217 phys_addr=KERNELCOPY;
218
219
220 char *data1,*data2;
221
222 data1=(char*)malloc(len);
223
224 char *initrd1=NULL;
225
226 if(fd1) initrd1=(char*)malloc(initrdl);
227
228 if(!data1) return;
229
230 if(!ret) return;
231
232 data2= (char*)do_it;
233
234
235 fread(data1,len,1,fd);
236 fclose(fd);
237
238
239 if(fd1)
240 {
241 fread(initrd1,initrdl,1,fd1);
242 fclose(fd1);
243 }
244
245 // Do not block interrupts before they are needed anymore
246 // Like reading the SD card.
247 intr=(UINT32*)VirtualAlloc((void*)0x0,0x100, MEM_RESERVE,PAGE_READWRITE);
248
249 // Interrupt control registers
250 ret=VirtualCopy((void*)intr,(void *) (ICIP/256), 0x100, PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
251
252 intr[1]=0;
253
254 // ResetDevices();
255
256 UART_puts("LinExec: Passing the point of no return.. Now.\r\n");
257
258 UINT32 crc=0;
259
260 setup_linux_params(BOOTIMG, INITRD,initrdl, MEM_SIZE*1024*1024 , param,kernel_copy2);
261
262 memcpy(relmemcpy,mymemcpy,1024);
263 relmemcpy(kernel_copy2,data2,0x100);
264
265 if(fd1)
266 relmemcpy(initrd_copy2,initrd1,initrdl);
267
268 relmemcpy(kernel_copy2+0x8000,data1,len);
269
270 UART_puts("LinExec: Entering DRAMloader...\r\n");
271
272 DRAMloader(phys_addr, MACH_TYPE);
273 }
274
275 void mymemcpy(char* a, char* b, int size)
276 {
277 while (size)
278 {
279 *a=*b;
280 size--;
281 a++; b++;
282 };
283 };
284
285 /*
286 Loads parameters from file given.
287 The file has to be:
288 kernel image
289 initrd
290 kernel cmdline
291 */
292
293 void load_boot(char *ParamFile)
294 {
295 FILE *stream;
296
297 UART_setup();
298
299 stream=fopen(ParamFile,"r");
300 if(!stream) {
301 FILE *logfd=fopen("\\bootlog.txt","a");
302 fprintf(logfd, "Booting: ***FAILED TO OPEN %s***\n",ParamFile);
303 fclose(logfd);
304 return;
305 }
306 char cmd[200],image[50],initrd[50];
307
308 fgets(image,50,stream);
309 image[strlen(image)-1]=0; // remove \n from the end
310
311 fgets(initrd,50,stream);
312 initrd[strlen(initrd)-1]=0;
313
314 fgets(cmd,200,stream);
315 cmd[strlen(cmd)-1]=0;
316
317 fclose(stream);
318
319 UART_puts("LinExec: Beginning boot_linux.\r\n");
320 boot_linux(image,initrd,cmd);
321 }
Impressum, Datenschutz