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 // tag header, zero-terminated string and round size to 32-bit words
39 tag
->hdr
.size
= (sizeof (struct tag_header
) + strlen (cmdline
) + 1 + 3) >> 2;
40 strcpy(tag
->u
.cmdline
.cmdline
,cmdline
);
45 tag
->hdr
.tag
= ATAG_MEM
;
46 tag
->hdr
.size
= tag_size(tag_mem32
);
47 tag
->u
.mem
.size
= dram_size
;
48 tag
->u
.mem
.start
= MEM_START
;
52 /* and now the initrd tag */
54 tag
->hdr
.tag
= INITRD_TAG
;
55 tag
->hdr
.size
= tag_size(tag_initrd
);
56 tag
->u
.initrd
.start
= INITRD
;
57 tag
->u
.initrd
.size
= initrdl
;
61 tag
->hdr
.tag
= ATAG_VIDEOTEXT
;
62 tag
->hdr
.size
= tag_size(tag_videotext
);
63 tag
->u
.videotext
.video_lines
= 40;
64 tag
->u
.videotext
.video_cols
= 30;
68 tag
->hdr
.tag
= ATAG_NONE
;
77 function do_it is loaded onto address KERNELCOPY along with parameters(offset=0x100) and
78 kernel image(offset=0x8000). Afterwards DRAMloader is called; it disables MMU and
79 jumps onto KERNELCOPY. Function do_it then copies kernel image to its proper address(0xA0008000)
81 Initrd is loaded onto address INITRD and the address is passed to kernel via ATAG
85 // This resets some devices
89 WritePhysical(0x4050000C,0); // Reset AC97
90 WritePhysical(0x48000014,0); // Reset PCMCIA
91 for(int i
=0;i
<0x3C;i
+=4)
92 WritePhysical(0x40000000,8); // Set DMAs to Stop state
93 WritePhysical(0x400000F0,0); // DMA do not gen interrupt
94 SetGPIOio(28,0); // AC97
95 SetGPIOio(29,0); // AC97/I2S
96 SetGPIOio(30,0); // I2S/AC97
97 SetGPIOio(31,0); // I2S/AC97
98 SetGPIOio(32,0); // AC97/I2S
110 void mymemcpy(char* a
, char* b
, int size
);
112 void boot_linux(char *filename
,char* initrd
,char *param
)
114 FILE *fd
=fopen(filename
,"rb");
131 FILE *logfd
=fopen("\\bootlog.txt","a");
132 fprintf(logfd
, "Booting: ***FAILED TO OPEN %s***\n",filename
);
137 fseek(fd
,0,SEEK_END
);
139 fseek(fd
,0,SEEK_SET
);
141 fd1
=fopen(initrd
,"rb");
145 fseek(fd1
,0,SEEK_END
);
147 fseek(fd1
,0,SEEK_SET
);
149 FILE *logfd
=fopen("\\bootlog.txt","a");
150 fprintf(logfd
, "Booting: Images.");
155 /* i haven't ported this to strongarm, hope this is not important to
160 image
=ReadBMP(BOOT_LOGO_PATH
);
161 if (!image
.p
) image
=ReadBMP(BOOT_LOGO_PATH_CF
);
162 image_done
=ReadBMP(BOOT_LOGO_DONE_PATH
);
163 if (!image_done
.p
) image_done
= ReadBMP(BOOT_LOGO_DONE_PATH_CF
);
164 if (image
.p
) ShowImage(image
.p
,image
.x
,image
.y
);
167 logfd
=fopen("\\bootlog.txt","a");
168 fprintf(logfd
, "Booting: entering supervisor mode.");
171 /* now becoming supervisor. */
172 SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL
);
173 // CeSetThreadQuantum(GetCurrentThread(),0);
175 SetProcPermissions(0xffffffff);
176 /* <ibot> rooooooooot has landed! */
178 logfd
=fopen("\\bootlog.txt","a");
179 fprintf(logfd
, "Booting: supervisor mode.");
182 void *mmu
=(void*)read_mmu();
183 UINT32
*data
=NULL
,*lcd
=NULL
,*intr
=NULL
,*_mmu
=NULL
;
184 char *watch
=NULL
,*krnl
=NULL
;
190 char *kernel_copy2
=(char*)VirtualAlloc((void*)0x0,0x8000+len
, MEM_RESERVE
|MEM_TOP_DOWN
,PAGE_READWRITE
);
191 ret
=VirtualCopy((void*)kernel_copy2
,(void *) (KERNELCOPY
/256), 0x8000+len
, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
198 initrd_copy2
=(char*)VirtualAlloc((void*)0x0,initrdl
, MEM_RESERVE
|MEM_TOP_DOWN
,PAGE_READWRITE
);
199 ret
=VirtualCopy((void*)initrd_copy2
,(void *) (INITRD
/256), initrdl
, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
202 void(*relmemcpy
)(char*,char*,int);
203 relmemcpy
=(void (__cdecl
*)(char *,char *,int))VirtualAlloc((void*)0x0, 1024, MEM_RESERVE
|MEM_TOP_DOWN
,PAGE_READWRITE
);
207 ret
=VirtualCopy((void*)relmemcpy
,(void *) (0xa0001000/256), 1024, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
209 ret
=VirtualCopy((void*)relmemcpy
,(void *) (0xc0001000/256), 1024, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
212 if(!kernel_copy2
) return;
216 phys_addr
=KERNELCOPY
;
221 data1
=(char*)malloc(len
);
225 if(fd1
) initrd1
=(char*)malloc(initrdl
);
234 fread(data1
,len
,1,fd
);
240 fread(initrd1
,initrdl
,1,fd1
);
244 // Do not block interrupts before they are needed anymore
245 // Like reading the SD card.
246 intr
=(UINT32
*)VirtualAlloc((void*)0x0,0x100, MEM_RESERVE
,PAGE_READWRITE
);
248 // Interrupt control registers
249 ret
=VirtualCopy((void*)intr
,(void *) (ICIP
/256), 0x100, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
255 UART_puts("LinExec: Passing the point of no return.. Now.\r\n");
259 setup_linux_params(BOOTIMG
, INITRD
,initrdl
, MEM_SIZE
*1024*1024 , param
,kernel_copy2
);
261 memcpy(relmemcpy
,mymemcpy
,1024);
262 relmemcpy(kernel_copy2
,data2
,0x100);
265 relmemcpy(initrd_copy2
,initrd1
,initrdl
);
267 relmemcpy(kernel_copy2
+0x8000,data1
,len
);
269 UART_puts("LinExec: Entering DRAMloader...\r\n");
271 DRAMloader(phys_addr
, MACH_TYPE
);
274 void mymemcpy(char* a
, char* b
, int size
)
285 Loads parameters from file given.
292 void load_boot(char *ParamFile
)
298 stream
=fopen(ParamFile
,"r");
300 FILE *logfd
=fopen("\\bootlog.txt","a");
301 fprintf(logfd
, "Booting: ***FAILED TO OPEN %s***\n",ParamFile
);
305 char cmd
[200],image
[50],initrd
[50];
307 fgets(image
,50,stream
);
308 image
[strlen(image
)-1]=0; // remove \n from the end
310 fgets(initrd
,50,stream
);
311 initrd
[strlen(initrd
)-1]=0;
313 fgets(cmd
,200,stream
);
314 if (cmd
[strlen(cmd
)-1] == 0x0a)
316 cmd
[strlen(cmd
)-1]=0;
317 if (cmd
[strlen(cmd
)-2] == 0x0d)
318 cmd
[strlen(cmd
)-2]=0;
323 UART_puts("LinExec: Beginning boot_linux.\r\n");
324 boot_linux(image
,initrd
,cmd
);