#include #include #include char LINUX[] = "vmlinux.bin"; char COMMAND[] = "console=ttySC1,38400n81 root=/dev/h8mmc2"; #define RAM_VECTOR_BASE 0xfffd20 #define COMMAND_START2M ((unsigned char *)(0x600000 - 0x200)) #define COMMAND_START ((unsigned char *)(0x800000 - 0x200)) #define ADD_DRAM_BASE 0x600000 #define SRAM_START (0xffdf10 + 0xb00) #define SIZECOUNT (*(int *)SRAM_START) #define SIZECOUNT1 (*(int *)(SRAM_START + 4)) #define DIR (*(char **)(SRAM_START + 8)) #define SRC (*(char **)(SRAM_START + 12)) #define SRC1 (*(char **)(SRAM_START + 16)) #define BOOTPROG ((void (*)())(SRAM_START + 20)) #define BLOCKSIZE 20480 #define MAXBLOCK 60 //#define SYSCR (*(volatile unsigned char *)0xfee012) #define ISCR (*(volatile unsigned char *)0xfee014) #define IER (*(volatile unsigned char *)0xfee015) #define ISR (*(volatile unsigned char *)0xfee016) #define IPRA (*(volatile unsigned char *)0xfee018) #define IPRB (*(volatile unsigned char *)0xfee019) void readblock(int fd, unsigned char *buffer, int size){ int dsize; while(size){ dsize = (size > BLOCKSIZE)? BLOCKSIZE : size; read(fd, buffer, dsize); size -= dsize; buffer += dsize; printf("."); } printf("\n\r"); } void readbin( char *inFileName ) { unsigned char *buffer, *buffer1; int fd, size, size1; printf("\n\r"); fd = open(inFileName, OptRead); if(fd <= 0) { printf("Open error!!\n\r"); SIZECOUNT = 0; SIZECOUNT1 = 0; return; } size1 = 0; buffer1 = (unsigned char *)ADD_DRAM_BASE; size = GetFileSize(fd); printf("File [%s] size: %d\n\r", inFileName, size); if(size > BLOCKSIZE * MAXBLOCK) { size1 = size - BLOCKSIZE * MAXBLOCK; size = BLOCKSIZE * MAXBLOCK; } buffer = malloc(size); if(!buffer){ printf("no enough memory\n\r"); SIZECOUNT = 0; SIZECOUNT1 = 0; return; } readblock(fd, buffer, size); readblock(fd, buffer1, size1); close(fd); SIZECOUNT = size; SIZECOUNT1 = size1; SRC = buffer; SRC1 = buffer1; return; } void movbin() { while(SIZECOUNT --) *DIR++ = *SRC++; while(SIZECOUNT1 --) *DIR++ = *SRC1++; asm("jmp @0x400000"); } int main(int argv, char *argc[]) { volatile char w; int i; char *str; unsigned short *ret_import; unsigned long *ram_vectors, vector; set_buswidth(ADD_DRAM_BASE, 8, 0); //enable DRAM at CS3 DRCRB = 0x98; DRCRA = 0x58; memcpy(BOOTPROG, movbin, 0x100); if(argv >= 3){ str = COMMAND_START2M; for(i = 2; i < argv; i ++){ strcpy(str, argc[i]); str += strlen(str); *str++ = ' '; *str = 0; } } else{ strcpy(COMMAND_START2M, COMMAND); } strcpy(COMMAND_START, COMMAND_START2M); if(argv < 2) str = LINUX; else str = argc[1]; readbin(str); printf("Start Linux...\n\r"); DIR = (char *)0x400000; if(!(SIZECOUNT + SIZECOUNT1)) return 0; int_disable(); TCSR_WR = 0xa500 | 0x1b; //close watch dog timer w = TCSR_RD; TCSR_WR = 0xa500 | 0x1b; *((unsigned short *)(RAM_VECTOR_BASE + 0x100)) = 0x5670; //RTE *((unsigned short *)(RAM_VECTOR_BASE + 0x100 + 2)) = 0x5470; //RTS ram_vectors = (unsigned long *)RAM_VECTOR_BASE; for(i = 0; i < 64; i ++){ vector = ram_vectors[i]; if((vector & 0xffff0000) != 0x5a000000) ram_vectors[i] = 0x5a000000 + RAM_VECTOR_BASE + 0x100 + 2; } ISCR = 0; IER = 0; ISR = 0; IPRA = 0; IPRB = 0; BOOTPROG(); return 0; }