4 //#include <aygshell.h>
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"
19 void setup_linux_params(long bootimg_dest
, UINT32 initrd
,UINT32 initrdl
, long dram_size
, const char *cmdline
, char*base
)
23 int newcmdlinelen
= 0;
24 char *newcmdline
= NULL
;
27 tag
= (struct tag
*)(base
+0x100);
29 tag
->hdr
.tag
= ATAG_CORE
;
30 tag
->hdr
.size
= tag_size(tag_core
);
32 tag
->u
.core
.pagesize
= 0x00001000;
33 tag
->u
.core
.rootdev
= rootdev
;
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
);
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
;
53 /* and now the initrd tag */
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
;
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;
69 tag
->hdr
.tag
= ATAG_NONE
;
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)
82 Initrd is loaded onto address INITRD and the address is passed to kernel via ATAG
86 // This resets some devices
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
111 void mymemcpy(char* a
, char* b
, int size
);
113 void boot_linux(char *filename
,char* initrd
,char *param
)
115 FILE *fd
=fopen(filename
,"rb");
132 FILE *logfd
=fopen("\\bootlog.txt","a");
133 fprintf(logfd
, "Booting: ***FAILED TO OPEN %s***\n",filename
);
138 fseek(fd
,0,SEEK_END
);
140 fseek(fd
,0,SEEK_SET
);
142 fd1
=fopen(initrd
,"rb");
146 fseek(fd1
,0,SEEK_END
);
148 fseek(fd1
,0,SEEK_SET
);
150 FILE *logfd
=fopen("\\bootlog.txt","a");
151 fprintf(logfd
, "Booting: Images.");
156 /* i haven't ported this to strongarm, hope this is not important to
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
);
168 logfd
=fopen("\\bootlog.txt","a");
169 fprintf(logfd
, "Booting: entering supervisor mode.");
172 /* now becoming supervisor. */
173 SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL
);
174 // CeSetThreadQuantum(GetCurrentThread(),0);
176 SetProcPermissions(0xffffffff);
177 /* <ibot> rooooooooot has landed! */
179 logfd
=fopen("\\bootlog.txt","a");
180 fprintf(logfd
, "Booting: supervisor mode.");
183 void *mmu
=(void*)read_mmu();
184 UINT32
*data
=NULL
,*lcd
=NULL
,*intr
=NULL
,*_mmu
=NULL
;
185 char *watch
=NULL
,*krnl
=NULL
;
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
);
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
);
203 void(*relmemcpy
)(char*,char*,int);
204 relmemcpy
=(void (__cdecl
*)(char *,char *,int))VirtualAlloc((void*)0x0, 1024, MEM_RESERVE
|MEM_TOP_DOWN
,PAGE_READWRITE
);
208 ret
=VirtualCopy((void*)relmemcpy
,(void *) (0xa0001000/256), 1024, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
210 ret
=VirtualCopy((void*)relmemcpy
,(void *) (0xc0001000/256), 1024, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
213 if(!kernel_copy2
) return;
217 phys_addr
=KERNELCOPY
;
222 data1
=(char*)malloc(len
);
226 if(fd1
) initrd1
=(char*)malloc(initrdl
);
235 fread(data1
,len
,1,fd
);
241 fread(initrd1
,initrdl
,1,fd1
);
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
);
249 // Interrupt control registers
250 ret
=VirtualCopy((void*)intr
,(void *) (ICIP
/256), 0x100, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
256 UART_puts("LinExec: Passing the point of no return.. Now.\r\n");
260 setup_linux_params(BOOTIMG
, INITRD
,initrdl
, MEM_SIZE
*1024*1024 , param
,kernel_copy2
);
262 memcpy(relmemcpy
,mymemcpy
,1024);
263 relmemcpy(kernel_copy2
,data2
,0x100);
266 relmemcpy(initrd_copy2
,initrd1
,initrdl
);
268 relmemcpy(kernel_copy2
+0x8000,data1
,len
);
270 UART_puts("LinExec: Entering DRAMloader...\r\n");
272 DRAMloader(phys_addr
, MACH_TYPE
);
275 void mymemcpy(char* a
, char* b
, int size
)
286 Loads parameters from file given.
293 void load_boot(char *ParamFile
)
299 stream
=fopen(ParamFile
,"r");
301 FILE *logfd
=fopen("\\bootlog.txt","a");
302 fprintf(logfd
, "Booting: ***FAILED TO OPEN %s***\n",ParamFile
);
306 char cmd
[200],image
[50],initrd
[50];
308 fgets(image
,50,stream
);
309 image
[strlen(image
)-1]=0; // remove \n from the end
311 fgets(initrd
,50,stream
);
312 initrd
[strlen(initrd
)-1]=0;
314 fgets(cmd
,200,stream
);
315 cmd
[strlen(cmd
)-1]=0;
319 UART_puts("LinExec: Beginning boot_linux.\r\n");
320 boot_linux(image
,initrd
,cmd
);