你好,游客 登录 注册 搜索
背景:
阅读新闻

FL2440的U-boot-2010.09移植(六)NAND FLash启动支持

[日期:2012-07-01] 来源:Linux社区  作者:yanghao23 [字体:大 中 小]

三、添加C语言从NAND Flash搬移代码部分

首先在board/fl2440目录下新建一个名为nand_read.c的文件,其内容如下:

  1. /*  
  2.  * vivi/s3c2410/nand_read.c: Simple NAND read functions for booting from NAND 
  3.  * 
  4.  * Copyright (C) 2002 MIZI Research, Inc. 
  5.  * 
  6.  * Author: Hwang, Chideok <hwang@mizi.com> 
  7.  * Date  : $Date: 2002/08/14 10:26:47 $ 
  8.  * 
  9.  * $Revision: 1.6 $ 
  10.  * $Id: param.c,v 1.9 2002/07/11 06:17:20 nandy Exp  
  11.  * 
  12.  */  
  13.   
  14. #include <config.h>   
  15.   
  16. #define __REGb(x)   (*(volatile unsigned char *)(x))   
  17. #define __REGi(x)   (*(volatile unsigned int *)(x))   
  18. #define NF_BASE     0x4e000000   
  19.   
  20. /*S3C2440与S3C2440 nandflash控制寄存器地址不同需要进行修改*/  
  21. #define NFCONF      __REGi(NF_BASE + 0x0)   
  22. #define NFCONT          __REGi(NF_BASE + 0x4)   
  23. #define NFCMD       __REGb(NF_BASE + 0x8)   
  24. #define NFADDR      __REGb(NF_BASE + 0xc)   
  25. #define NFDATA      __REGb(NF_BASE + 0x10)   
  26. #define NFSTAT      __REGb(NF_BASE + 0x20)   
  27.   
  28. #define NAND_CHIP_ENABLE (NFCONT &= ~(1<<1))   
  29. #define NAND_CHIP_DISABLE (NFCONT |= (1<<1))   
  30. #define NAND_CLEAR_RB (NFSTAT |= (1<<2))   
  31. #define NAND_DETECT_RB {while(! (NFSTAT&(1<<2)));}   
  32. #define NAND_ECC_CLEAR (NFCONT |= 0x10)   
  33. /*see data sheet P193*/  
  34.   
  35. #define BUSY 1   
  36. static inline void wait_idle(void) {  
  37.     int i;  
  38.     while(!(NFSTAT & BUSY))  
  39.       for(i=0; i<10; i++);  
  40. }  
  41.   
  42. /*根据fl2440的nand flash 作相应修改*/  
  43. #define NAND_SECTOR_SIZE    2048   
  44. #define NAND_BLOCK_MASK     (NAND_SECTOR_SIZE - 1)   
  45.   
  46. /* low level nand read function */  
  47.  int  
  48. nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)  
  49. {  
  50.     int i, j;  
  51.     int pagenum;  
  52.   
  53.     if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {  
  54.         return -1;  /* invalid alignment */  
  55.     }  
  56.   
  57.     /* chip Enable */  
  58.     NAND_CHIP_ENABLE;  
  59.       
  60.     for(i = start_addr; i < (start_addr + size);) {  
  61.       /* READ0 */  
  62.   
  63.       NAND_CLEAR_RB;  
  64.       for(j = 0; j < 10; j++);  
  65.         
  66.       pagenum = i >> 11;  
  67.       /* Write Address  
  68.         该步骤详见nand flash(k9f2g08u0a)手册p17 
  69.         参考fl2440开发板nand_lowlevel.c文件中ReadPage函数 
  70.       */  
  71.       NFCMD = 0x0;  
  72.         
  73.       NFADDR = 0;  
  74.       NFADDR = 0;  
  75.       NFADDR = pagenum & 0xff;  
  76.       NFADDR = (pagenum >> 8) & 0xff;  
  77.       NFADDR = (pagenum >> 16) & 0xff;  
  78.       /*如果不理解见数据手册nand flashP9*/  
  79.   
  80.       NFCMD = 0x30;  
  81.       wait_idle();  
  82.   
  83.       for(j=0; j < NAND_SECTOR_SIZE; j++) {  
  84.           *buf = (NFDATA & 0xff);  
  85.            buf++;  
  86.       }  
  87.        
  88.      i += NAND_SECTOR_SIZE;  
  89.    
  90.     }  
  91.   
  92.     NAND_CHIP_DISABLE;  
  93.      
  94.     /* chip Disable */  
  95.       
  96.     return 0;  
  97. }  

    开发板的NAND Flash型号为k9f2g08u0a,它的容量是256MByte,NAND Flash的最小读取单位是以页为单位的,即2KByte(12位)每页,共128K页(17位),而地址线是8位的,因此当需要读取一页时,需分周期发送页地址,这款芯片规定前两个地址周期发送页内地址,后面的三周期发送页编号,它的流程如表1:

表1 NAND Flash地址

 

I/O 0

I/O 1

I/O 2

I/O 3

I/O 4

I/O 5

I/O 6

I/O 7

第一周期

A0

A1

A2

A3

A4

A5

A6

A7

第二周期

A8

A9

A10

A11

0

0

0

0

第三周期

A12

A13

A14

A15

A16

A17

A18

A19

第四周期

A20

A21

A22

A23

A24

A25

A26

A27

第五周期

A28

0

0

0

0

0

0

0

我们在读取uboot.bin时,直接按页读取,所以前两周期地址我们设成了全0,后面的3周期实际就是也编号。

修改board/fl2440/Makefile文件,使得nand_read.c能被编译到u-boot.bin中,修改28行为:

  1. COBJS   := fl2440.o nand_read.o flash.o  

我们还知道由于我们需要在前4K代码中完成代码的搬移,而搬移的代码集中在start.S和nand_read.c中,而U-boot的编译过程并不能保证nand_read.c能在前4K代码中,所以需要我们手动设置,修改文件arch/arm/cpu/arm920t/u-boot.lds文件40行为:

  1. .text :  
  2. {  
  3.     arch/arm/cpu/arm920t/start.o    (.text)  
  4.                board/fl2440/lowlevel_init.o (.text)  
  5.                board/fl2440/nand_read.o (.text)  
  6.     *(.text)  
  7. }  

这样,编译器在编译时能保证start.S和nand_read.c编译出的二进制代码在前4K。

修改include/configs/fl2440.h中,添加相关的宏定义以支持NAND Flash的串口操作命令:

  1. #define CONFIG_CMD_NAND   /*****add by yanghao*****/   
  2. <p>#if defined(CONFIG_CMD_NAND)</p><p>#define CONFIG_NAND_S3C2410  
  3. #define CONFIG_SYS_MAX_NAND_DEVICE   1     /* Max number of NAND devices        */   
  4. #define NAND_MAX_CHIPS   1   
  5. #define CONFIG_SYS_NAND_BASE 0x4E000000</p>#endif  

然后将开发板设置成为从NAND Flash启动,将编译出来的u-boot.bin烧写入NAND Flash,上电这样就完成了从NAND Flash的启动。

linux
相关资讯       FL2440 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款