16 #define puts Uart_Printf
17 #define printf Uart_Printf
18 #define getch Uart_Getch
19 #define putch Uart_SendByte
21 #define EnNandFlash() (rNFCONT |= 1)
22 #define DsNandFlash() (rNFCONT &= ~1)
23 #define NFChipEn() (rNFCONT &= ~(1<<1))
24 #define NFChipDs() (rNFCONT |= (1<<1))
25 #define InitEcc() (rNFCONT |= (1<<4))
26 #define MEccUnlock() (rNFCONT &= ~(1<<5))
27 #define MEccLock() (rNFCONT |= (1<<5))
28 #define SEccUnlock() (rNFCONT &= ~(1<<6))
29 #define SEccLock() (rNFCONT |= (1<<6))
31 #define WrNFDat8(dat) (rNFDATA8 = (dat))
32 #define WrNFDat32(dat) (rNFDATA = (dat))
33 #define RdNFDat8() (rNFDATA8) //byte access
34 #define RdNFDat32() (rNFDATA) //word access
36 #define WrNFCmd(cmd) (rNFCMD = (cmd))
37 #define WrNFAddr(addr) (rNFADDR = (addr))
38 #define WrNFDat(dat) WrNFDat8(dat)
39 #define RdNFDat() RdNFDat8() //for 8 bit nand flash, use byte access
41 #define RdNFMEcc() (rNFMECC0) //for 8 bit nand flash, only use NFMECC0
42 #define RdNFSEcc() (rNFSECC) //for 8 bit nand flash, only use low 16 bits
44 #define RdNFStat() (rNFSTAT)
45 #define NFIsBusy() (!(rNFSTAT&1))
46 #define NFIsReady() (rNFSTAT&1)
55 #define ERASECMD0 0x60
56 #define ERASECMD1 0xd0
65 #define TACLS 1//7 // 1-clk(0ns)
66 #define TWRPH0 4//7 // 3-clk(25ns)
67 #define TWRPH1 1//7 // 1-clk(10ns) //TACLS+TWRPH0+TWRPH1>=50ns
69 static void InitNandCfg(
void)
74 rNFCONT = (0<<13)|(0<<12)|(0<<10)|(0<<9)|(0<<8)|(1<<6)|(1<<5)|(1<<4)|(1<<1)|(1<<0);
79 #define WaitNFBusy() while(NFIsBusy())
81 static U32 WaitNFBusy(
void)
95 static U32 ReadChipId(
void)
110 static U16 ReadStatus(
void)
122 static U32 EraseBlock(
U32 addr)
138 #ifdef ER_BAD_BLK_TEST
139 if(!((addr+0xe0)&0xff)) stat = 1;
149 static void ReadPage(
U32 addr,
U8 *buf)
167 static U32 WritePage(
U32 addr,
U8 *buf)
189 tmp[1] = (mecc>>8)&0xff;
190 tmp[2] = (mecc>>16)&0xff;
191 tmp[3] = (mecc>>24)&0xff;
207 #ifdef WR_BAD_BLK_TEST
208 if((addr&0xff)==0x17) stat = 1;
212 printf(
"Write nand flash 0x%x fail\n", addr);
216 ReadPage(addr, RdDat);
218 if(RdDat[i]!=buf[i]) {
219 printf(
"Check data at page 0x%x, offset 0x%x fail\n", addr, i);
228 static void MarkBadBlk(
U32 addr)
254 static int CheckBadBlk(
U32 addr)
286 {0, 0x00030000,
"boot"},
287 {0x00030000, 0x001d0000,
"kernel"},
288 {0x00200000, 0x01e00000,
"rootfs"},
289 {0x02000000, 0x02000000,
"ext-fs1"},
293 static U32 StartPage, BlockCnt;
298 static int NandSelPart(
char *
info)
303 printf(
"Please select which region to %s : Esc to abort\n", info);
305 for(i=0; ptr->
size!=0; i++, ptr++)
314 if((i>=
'0')&&(i<(max_sel+
'0'))) {
316 StartPage = NandPart[i].
offset>>9;
317 BlockCnt = NandPart[i].
size>>14;
323 static void WrFileToNF(
void)
325 int nf_part, i ,
size, skip_blks;
328 nf_part = NandSelPart(
"write");
332 if(downloadFileSize>NandPart[nf_part].size) {
333 puts(
"Download file size is more large than selected partition size!!!\n");
337 printf(
"Now write nand flash page 0x%x from ram address 0x%x, filesize = %d\n", StartPage, downloadAddress, downloadFileSize);
338 puts(
"Are you sure? [y/n]\n");
341 if((c==
'y')||(c==
'Y'))
343 if((c==
'n')||(c==
'N'))
348 ram_addr = downloadAddress;
349 size = downloadFileSize;
352 if(EraseBlock(i+StartPage)) {
353 NandPart[nf_part].
size -= 32<<9;
354 if(downloadFileSize>NandPart[nf_part].size) {
355 puts(
"Program nand flash fail\n");
358 MarkBadBlk(i+StartPage);
364 if(WritePage(i+StartPage, (
U8 *)ram_addr)) {
365 ram_addr -= (i&0x1f)<<9;
368 NandPart[nf_part].
size -= 32<<9;
369 if(downloadFileSize>NandPart[nf_part].size) {
370 puts(
"Program nand flash fail\n");
373 MarkBadBlk(i+StartPage);
383 puts(
"Program nand flash partition success\n");
385 printf(
"Skiped %d bad block(s)\n", skip_blks);
388 #define LINUX_PAGE_SHIFT 12
389 #define LINUX_PAGE_SIZE (1<<LINUX_PAGE_SHIFT)
390 #define COMMAND_LINE_SIZE 1024
399 #define FLAG_READONLY 1
400 #define FLAG_RDLOAD 4
401 #define FLAG_RDPROMPT 8
428 char n[1024 -
sizeof(
unsigned long)];
437 static __inline
void cpu_arm920_cache_clean_invalidate_all(
void)
443 orr r3, r1, #63UL << 26
445 mcr p15, 0, r3, c7, c14, 2
446 subs r3, r3, #1 << 26
447 bcs cache_clean_loop2
449 bcs cache_clean_loop1
450 mcr p15, 0, r1, c7, c5, 0
451 mcr p15, 0, r1, c7, c10, 4
456 cpu_arm920_cache_clean_invalidate_all();
459 static __inline
void cpu_arm920_tlb_invalidate_all(
void)
463 mcr p15, 0, r0, c7, c10, 4
464 mcr p15, 0, r0, c8, c7, 0
470 cpu_arm920_tlb_invalidate_all();
477 void (*goto_start)(
U32,
U32);
489 mcr p15, 0, ip, c13, c0, 0
490 mcr p15, 0, ip, c7, c7, 0
491 mcr p15, 0, ip, c7, c10, 4
492 mcr p15, 0, ip, c8, c7, 0
493 mrc p15, 0, ip, c1, c0, 0
495 mcr p15, 0, ip, c1, c0, 0
505 goto_start = (void (*)(
U32,
U32))a2;
506 (*goto_start)(a0, a1);
509 extern int sprintf(
char * ,
const char * , ...);
511 static void LoadRun(
void)
513 U32 i, ram_addr, buf = 0x30245bd0;
517 char *
boot_params =
"root=/dev/mtdblock2 init=/linuxrc load_ramdisk=0 console=ttySAC1,115200 mem=65536K devfs=mount display=shp480";
519 StartPage = NandPart[1].
offset>>9;
520 size = NandPart[1].
size;
525 if(CheckBadBlk(i+StartPage)) {
526 printf(
"Skipped bad block at 0x%x\n", i+StartPage);
532 ReadPage((i+StartPage), (
U8 *)ram_addr);
539 for(i=0; i<(sizeof(struct param_struct)>>2); i++)
540 ((
U32 *)params)[i] = 0;
543 for(i=0; boot_params[i]; i++)
546 puts(
"Set boot params = ");
554 static int have_nandflash;
555 static void InitNandFlash(
int info)
562 printf(
"Read chip id = %x\n", i);
563 if((i==0x9873)||(i==0xec75))
569 puts(
"Chip id error!!!\n");
575 printf(
"Nand flash status = %x\n", ReadStatus());
586 i = NandSelPart(
"erase");
590 printf(
"Are you sure to erase nand flash from page 0x%x, block count 0x%x ? [y/n]\n", StartPage, BlockCnt);
595 if((c==
'y')||(c==
'Y'))
597 if((c==
'n')||(c==
'N'))
601 for(i=0; BlockCnt; BlockCnt--, i+=32) {
602 if(EraseBlock(i+StartPage)) {
604 puts(
"Press any key to continue...\n");
610 puts(
"Erase Nand partition completed ");
612 printf(
"with %d bad block(s)\n", err);
629 static void LoadRunWince(
void)
631 U32 i, ram_addr, buf = boot_params.initrd_addr.val;
634 printf(
"Load Kernel...\n");
636 if(boot_params.osstor.val)
637 memcpy((
void *)buf, (
void *)(0x04000000+0x00020000), 0x00fe0000);
639 StartPage = NandPart[boot_params.start.val].
offset>>9;
640 size = boot_params.initrd_len.val;
645 if(CheckBadBlk(i+StartPage)) {
646 printf(
"Skipped bad block at 0x%x\n", i+StartPage);
652 ReadPage((i+StartPage), (
U8 *)ram_addr);
659 printf(
"run 0x%08x...\n", boot_params.run_addr.val);
707 #define NOR_PARAMS_OFFSET 0x1c000
718 page = NandPart[0].
offset>>9;
719 page_cnt = NandPart[0].
size>>9;
723 ReadPage(page+page_cnt, dat);
740 for(; pPID<=&boot_params.user_params; pPIS++, pPID++)
741 if(!
strncmp(pPID->flags, pPIS->
flags,
sizeof(pPID->flags)))
743 strncpy(boot_params.string, pPIS->
flags, boot_params.user_params.val+1);
745 if(boot_params.user_params.val!=
strlen(pPID->flags)) {
746 memset(boot_params.string, 0,
sizeof(boot_params.string));
747 boot_params.user_params.val = 0;
767 memset(dat, 0,
sizeof(boot_params));
768 memcpy(dat, &boot_params,
sizeof(boot_params));
770 page = (NandPart[1].
offset>>9)-64;
772 for(page_cnt=0; page_cnt<64; page_cnt++) {
775 if(!WritePage(page+page_cnt, dat))
780 printf(
"Save boot params %s.\n", ret?
"fail":
"success");
799 printf(
"\nConfig parameters\n");
802 pPID = &boot_params.start;
803 for(i=0; pPID<=&boot_params.user_params; pPID++, i++)
804 printf(
"[%d] : %s%-8s is 0x%08x (%d)\n",
805 i, (i>9)?
"":
" ", pPID->
flags, pPID->
val, pPID->
val);
806 printf(
"[%d] : Exit\n", i);
807 if(boot_params.user_params.val)
808 printf(
"User parameters is : \"%s\"\n", boot_params.string);
810 printf(
"\nplease select item:");
811 key = Uart_GetIntNum();
814 printf(
"please enter value:");
816 if((&boot_params.start + i)==&boot_params.user_params) {
819 printf(
"1: display 240x320\n");
820 printf(
"2: display 320x240\n");
821 printf(
"3: display 480x272\n");
822 printf(
"4: display 640x480\n");
824 lcd_type = Uart_GetIntNum();
829 string =
"display=shp240";
830 strncpy(boot_params.string,
string,
strlen(
string)+1);
831 strncpy(boot_params.string,
string,
strlen(
string)+1);
835 string =
"display=shp320";
836 strncpy(boot_params.string,
string,
strlen(
string)+1);
837 boot_params.user_params.val =
strlen(
string);
840 string =
"display=shp480";
841 strncpy(boot_params.string,
string,
strlen(
string)+1);
842 boot_params.user_params.val =
strlen(
string);
845 string =
"display=shp640";
846 strncpy(boot_params.string,
string,
strlen(
string)+1);
847 boot_params.user_params.val =
strlen(
string);
856 if((&boot_params.start + i)==&boot_params.user_params) {
859 memset(cmd, 0,
sizeof(cmd));
861 strncpy(boot_params.string, cmd,
strlen(cmd)+1);
862 boot_params.user_params.val =
strlen(cmd);
865 else if(&boot_params.start + i) == &boot_params.lcd)
867 printf(
"1. lcd 240x320\n");
868 printf(
"2. lcd 320x240\n");
869 printf(
"3. lcd 480x272\n");
870 printf(
"4. lcd 640x480\n");
871 lcd_type = Uart_GetIntNum();
876 string =
"display=shp240";
879 string =
"display=shp320";
882 string =
"display=shp480";
885 string =
"display=shp640";
888 string =
"display=shp240";
891 strncpy(boot_params.string,
string,
strlen(
string)+1);
893 boot_params.lcd.val= lcd_type;
898 key = Uart_GetIntNum();
899 (&boot_params.start + i)->val = key;
906 printf(
"Do you want to save parameters? press y or Y for save.\n");
908 if(key==
'y'||key==
'Y')