支持2K大页面NAND FLASH驱动的NBOOT改进源码

来自http://bbs.driverdevelop.com/read.php?tid-98338.html                         感谢zhengshijie

之前提供了2K大页面的WINCE5.0/4.2的驱动源码,并告知了eboot的修改,可能又很多网友是从nand flash启动的,nboot也需要修改,现在一并把源码发上来,与之前的驱动配套使用,nboot中有nand.h,选相应的FLASH类型设为1,如果都为0,则表示nboot只能用于小页面的K9S1208,否则就是2K大页面的,
#define K9F1G08_SUPPORT    (0)
#define K9F2G08_SUPPORT    (0)
#define K9F4G08_SUPPORT    (1) /*选定512M的*/
#define K9F8G08_SUPPORT    (0)
在NBOOT中只能设定一种FLASH类型,不支持动态识别,因为代码大小限制的原因,我不能把他们的处理接口同时编译进来,会超出4K的代码限制。
把该NBOOT解压到你的SMDK2440/目录下,它编译的时候会找loader.h,请确认是否能找到。
2440loader.c中存在一个bug,有个全局变量
TOC toc;
这个结构大小是512字节的,但把它的地址传入FMD_ReadSector(TOC_SECTOR,
                (LPBYTE)&toc,
                NULL, 1)
对于2K大页面的FLASH,它会越界,可能引起问题,建议修改如下:
代码
1 BYTE toc[2048];
2 TOC *ptoc=(TOC *)toc; // made global because it's too big for our tiny stack
3  
4 DWORD
5 ReadImageFromNand(DWORD dwEntry, DWORD dwSig)
6 {
7 DWORD dwSectorsNeeded;
8 DWORD dwSector, dwLength; // Start Sector & Length
9   DWORD dwRAM, i;
10
11 if ( !FMD_ReadSector(TOC_SECTOR,
12 (LPBYTE)ptoc,
13 NULL, 1) )
14 {
15 Uart_SendString("ERR_DISK_OP_FAIL1\n");
16 return ERR_DISK_OP_FAIL1;
17 }
18
19 if ( !VALID_TOC(ptoc) ) {
20 Uart_SendString("ERR_INVALID_TOC: ");
21 Uart_SendDWORD(ptoc->dwSignature, TRUE);
22 return ERR_INVALID_TOC;
23 }
24
25 if ( !(ptoc->id[dwEntry].dwImageType & IMAGE_TYPE_RAMIMAGE) ) {
26 Uart_SendString("ERR_INVALID_FILE_TYPE: ");
27 Uart_SendDWORD(ptoc->id[dwEntry].dwImageType, TRUE);
28 return ERR_INVALID_FILE_TYPE;
29 }
30
31  // ??
32  // if ( !(toc.id[dwEntry].dwImageType & IMAGE_TYPE_BINFS) ) {
33  // dwSectorsNeeded = toc.id[dwEntry].dwTtlSectors;
34  // } else {
35   dwSectorsNeeded = ptoc->id[dwEntry].dwTtlSectors; // xipkernel size = 0x9B4
36  // }
37  
38 Uart_SendString("Sector addr on NAND: ");
39 Uart_SendDWORD(ptoc->id[dwEntry].sgList[0].dwSector, TRUE);
40 Uart_SendString("TotalSector: ");
41 Uart_SendDWORD(dwSectorsNeeded, TRUE);
42
43 dwRAM = VIRTUAL_TO_PHYSICAL(ptoc->id[dwEntry].dwLoadAddress);
44
45 JumpAddr = ptoc->id[dwEntry].dwJumpAddress ? VIRTUAL_TO_PHYSICAL(ptoc->id[dwEntry].dwJumpAddress) :
46 VIRTUAL_TO_PHYSICAL(ptoc->id[dwEntry].dwLoadAddress);
47
48 //
49 // Load the disk image directly into RAM
50 // BUGBUG: recover from read failures
51 //
52   Uart_SendString("Reading Kernel Image from NAND\r\n");
53 i = 0;
54 while (dwSectorsNeeded && i < MAX_SG_SECTORS)
55 {
56 dwSector = ptoc->id[dwEntry].sgList.dwSector;
57 dwLength = ptoc->id[dwEntry].sgList.dwLength;
58
59 Uart_SendString(" dwSector: ");
60 Uart_SendDWORD(dwSector, TRUE);
61 Uart_SendString(" dwLength: ");
62 Uart_SendDWORD(dwLength, TRUE);
63 Uart_SendString(" dwRAM: ");
64 Uart_SendDWORD(dwRAM, TRUE);
65
66 // read each sg segment
67   while (dwLength) {
68 if ( !FMD_ReadSector(dwSector,
69 (LPBYTE)dwRAM,
70 NULL, 1) )
71 {
72 Uart_SendString("ERR_DISK_OP_FAIL2: ");
73 Uart_SendDWORD(dwSector, TRUE);
74
75 dwSector++;
76 continue;
77
78  // return ERR_DISK_OP_FAIL2;
79   }
80
81 dwSector++;
82 dwLength--;
83 dwRAM += SECTOR_SIZE;
84 }
85
86 dwSectorsNeeded -= ptoc->id[dwEntry].sgList.dwLength;
87 i++;
88 }
89
90 // We only do this if the dwRAM is not zero (The default tocblock1
91 // set the dwRAM to be 0)
92   if (ptoc->chainInfo.dwLoadAddress == 0) {
93 return ERR_SUCCESS;
94 }
95
96 // Load the Chain.bin stored on NAND to the SDRAM
97  // if ( toc.id[dwEntry].dwImageType == 6 ) // For WinCE 4.2 Image
98  // if ( 1 ) // For WinCE 4.2 Image
99  // {
100  // dwRAM = VIRTUAL_TO_PHYSICAL(toc.id[dwEntry].dwLoadAddress);
101  // dwSectorsNeeded = toc.id[dwEntry].sgList->dwLength;
102  // dwSector = toc.id[dwEntry].sgList->dwSector;
103  // }
104  // else
105 {
106 dwRAM = VIRTUAL_TO_PHYSICAL(ptoc->chainInfo.dwLoadAddress); // 0x303c0000
107 dwSectorsNeeded = ptoc->chainInfo.dwLength; // 0x20
108 dwSector = ptoc->chainInfo.dwFlashAddress; // 0x103c0
109
110 // dwSectorsNeeded = 0x20;
111 // dwSector = 0x104C0;
112 }

 

posted on 2010-05-02 10:29  EmbeddedBoy_jsu_xtw  阅读(639)  评论(0)    收藏  举报

导航