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