# include "def. H"
# include "nand h"
# include "244 x_lib. H
"# include "s3c2440. H"
# include "the parameters h"
The static inline void MMU_EnableICache (void)
{
Asm (
"MRC p15, 0 r0, c1, c0, 0 \ n", "
"ORR r0, r0, # (1 & lt; <12) \ n
""MCR p15, 0 r0, c1, c0, 0 \ n", "
);
}
The static inline void MMU_EnableDCache (void)
{
Asm (
"MRC p15, 0 r0, c1, c0, 0 \ n", "
"ORR r0, r0, # (1 & lt; <2) \ n
""MCR p15, 0 r0, c1, c0, 0 \ n", "
);
}
The static void CallLinux (void)
{
Struct param_struct {
The union {
Struct {
Unsigned long page_size;/* */0
Unsigned long nr_pages;/* */4
Unsigned long ramdisk_size;/* 8 */
Unsigned long flags;/* 12 */
Unsigned long rootdev;/* 16 */
Unsigned long video_num_cols;/* */20
Unsigned long video_num_rows;/* */24
Unsigned long video_x; 28 *//*
Unsigned long video_y;/* 32 */
Unsigned long memc_control_reg;/* 36 */
Unsigned char sounddefault;/* 40 */
Unsigned char adfsdrives;/* */41
Unsigned char bytes_per_char_h;/* */42
Unsigned char bytes_per_char_v;/* */43
Unsigned long pages_in_bank [4]. 44 *//*
Unsigned long pages_in_vram;/* 60 */
Unsigned long initrd_start;/* */64
Unsigned long initrd_size;/* */68
Unsigned long rd_start;/* */72
Unsigned long system_rev;/* */76
Unsigned long system_serial_low;/* */80
Unsigned long system_serial_high;/* */84
Unsigned long mem_fclk_21285;/* */88
} s;
Char unused [256].
} u1.
The union {
Char paths [8] [128].
Struct {
Unsigned long magic;
Char n [1024 - sizeof (unsigned long)];
} s;
} u2.
Char commandline [1024].
};
Struct param_struct * p=(struct param_struct *) 0 x30000100;
Memset (p, 0, sizeof (* p));
Memcpy (p - & gt; Commandline g_linux_cmd_line, sizeof (g_linux_cmd_line));
P - & gt; U1. Supachai panitchpakdi age_size=4 * 1024;
P - & gt; U1. S.n r_pages=64 * 1024 * 1024/(4 * 1024);
{
Unsigned int * pp=(unsigned int *) (0 x30008024);
If (pp [0]==0 x016f2818) {//Magic number of zImage
//Uart_SendString (" \ n \ rOk \ n \ r ");
} else {
Uart_SendString (" \ n \ rWrong Linux Kernel \ n \ r ");
For (;; );
}
}
Asm (
"% 2 \ n mov r5,"
"% 0 \ n mov r0,"
"% 1 \ n mov r1,"
"# 0 \ n mov IP,"
"Mov PC, r5 \ n"
"The nop \ n" "the nop \ n" : no outpus/* */
: "r" (0), the "r" (1999), "r" (g_os_ram_start)
);
}
Void ReadImageFromNand (void)
{
Unsigned int Length;
U8 * RAM;
Unsigned BlockNum;
Unsigned pos.
Length=g_os_length;
Length=(Length + BLOCK_SIZE - 1) & gt;> (BYTE_SECTOR_SHIFT + SECTOR_BLOCK_SHIFT) & lt; <(BYTE_SECTOR_SHIFT + SECTOR_BLOCK_SHIFT);//the align to Block Size
BlockNum=g_os_start & gt;> (BYTE_SECTOR_SHIFT + SECTOR_BLOCK_SHIFT);
RAM=(U8 *) g_os_ram_start;
For (pos=0; Pos & lt; Length; Pos +={BLOCK_SIZE)
Unsigned int I;
//the skip badblock
For (;; ) {
If (NandIsGoodBlock
(BlockNum & lt;
(BYTE_SECTOR_SHIFT + SECTOR_BLOCK_SHIFT))) {
break;
}
BlockNum++;//try next
}
For (I=0; i
NandReadOneSector (RAM,
(BlockNum & lt;
(BYTE_SECTOR_SHIFT +
SECTOR_BLOCK_SHIFT)) + I);
RAM +=SECTOR_SIZE;
Ret=0;
}
BlockNum++;
}
CallLinux ();
}
The static inline void GetParameters (void)
{
U32 Buf [2048].
G_os_type=OS_LINUX;
G_os_start=0 x60000;
G_os_length=0 x500000;
G_os_ram_start=0 x30008000;
//vivi LINUX CMD LINE
NandReadOneSector (Buf U8 *, 0 x48000);
If (Buf [0]==0 x49564956 & amp; & Buf [1]==0 x4c444d43) {
Memcpy (g_linux_cmd_line, (char *) & amp; (Buf [2]), sizeof g_linux_cmd_line);
}
}
Void Main (void)
{
MMU_EnableICache ();
MMU_EnableDCache ();
Port_Init ();
NandInit ();
If (g_page_type==PAGE_UNKNOWN) {
Uart_SendString (" \ r \ nunsupport NAND \ r \ n ");
For (;; );
}
GetParameters ();
Uart_SendString (" load Image of Linux... \n\r");
ReadImageFromNand ();
}