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


从NAND Flash启动的原理很简单,就是利用S3C2440内部4K大小的SRAM,存储在NAND Flash中的代码不能被执行,而S3C2440在从NAND Flash启动把NAND Flash的前4k代码复制到SRAM中运行,U-boot支持从NAND Flash启动的方法就是利用这前4K代码完成SDRAM的初始化(SDRAM有64M),然后还要完成从U-boot代码从NAND Flash中复制到SDRAM中,然后再跳转到SDRAM中去运行完整的U-boot。

为了便于系统启动的方便,可以在start.S文件中添加代码以识别系统是从NAND Flash启动还是从NOR Flash启动,从S3C2440芯片手册中可以看到

到OM[1:0]都为0时,说明是从NAND Flash启动,01和10都是从NOR Flash启动,OM[1:0]就是寄存器BWSCON的第2位~第1位(DW0)

一、添加NOR Flash启动和NAND Flash启动的识别

修改arch/arm/cpu/arm920t/start.S,首先将217行附近修改为:

  1. #ifndef CONFIG_SKIP_LOWLEVEL_INIT   
  2.     bl  cpu_init_crit  
  3. #endif   
  4.   
  5. #define BWSCON 0x48000000   
  6.         ldr     r0, =BWSCON  
  7.         ldr     r0, [r0]  
  8.         ands    r0, r0, #0x6  
  9.         tst     r0, #0x0  
  10.         bne     norflash_boot             /*OM[1:0] != 0, 跳转到NOR FLASH 启动处*/  
  11. /*判断uboot是从nand flash启动还是从 nor flash启动*/  

在220行附近将:

  1. #ifndef CONFIG_SKIP_RELOCATE_UBOOT   
  2. relocate:  

修改为

  1. norflash_boot:  
  2. #ifndef CONFIG_SKIP_RELOCATE_UBOOT  
  3. relocate:  

二、添加NAND Flash的U-boot代码从NAND FLash到SDRAM搬移的代码
在前面修改的 bne norflash_boot ,227行后添加

  1. /*****************************nand boot**************************/  
  2. nandflash_boot:  
  3. #define LENGTH_UBOOT 0x40000   
  4. #define NAND_CTL_BASE 0x4e000000   
  5. #define oNFCONF 0x00   
  6. #define oNFCONT 0x04   
  7. #define oNFCMD  0x08   
  8. #define oNFSTAT 0x20   
  9.   
  10.         @reset NAND  
  11.         mov     r1,#NAND_CTL_BASE  
  12.         ldr     r2,=((7<<12)|(7<<8)|(7<<4))  
  13.         str     r2,[r1,#oNFCONF]  
  14.         ldr     r2,[r1,#oNFCONF]  
  15.           
  16.         ldr     r2,=((1<<4)|(1<<1)|(1<<0)) @Active low CE control  
  17.         str     r2,[r1,#oNFCONT]  
  18.         ldr     r2,[r1,#oNFCONT]  
  19.           
  20.         @ get read to call C functions  
  21.         ldr     sp,DW_STACK_START   @setup stack point  
  22.         mov     fp,#0               @no previous frame, so fp = 0  
  23.           
  24.         @copy Uboot to ram  
  25.         ldr     r0, =TEXT_BASE  
  26.         mov     r1,#0x0  
  27.         mov     r2,#LENGTH_UBOOT  
  28.         bl      nand_read_ll  
  29.         tst     r0,#0x0  
  30.         beq     ok_nand_read  
  31.   
  32. bad_nand_read:  
  33. loop2:  
  34.         b       loop2     @infinite loop  
  35.   
  36. ok_nand_read:  
  37.         @verify  
  38.         mov     r0,#0  
  39.         ldr     r1,=TEXT_BASE  
  40.         mov     r2,#0x400     @ compare 4k code from sram to sdram  
  41.   
  42. go_next:  
  43.         ldr     r3, [r0], #4  
  44.         ldr     r4, [r1], #4  
  45.         teq     r3, r4  
  46.         bne     notmatch  
  47.         subs    r2,r2,#4  
  48.         tst     r2,#0x0   @do not forget the instruction if have not this command the uboot can't break the loop  
  49.         beq     stack_setup  
  50.         bne     go_next  
  51.   
  52. notmatch:  
  53. loop3:  
  54.         b       loop3 @infinite loop  
  55. /*****************************nand boot**************************/  

上面这部分代码首先初始化了NAND Flash寄存器,然后进行了一个函数调用(这个函数中完成了代码搬移)后面则是对复制出来的数据进行一个简单的校验。在327行附近添加为:

  1. _start_armboot: .word start_armboot  
  2. #define  STACK_BASE 0x33f00000   
  3. #define  STACK_SIZE 0x10000   
  4.         .align 2  
  5. DW_STACK_START: .word STACK_BASE+STACK_SIZE-4  

添加函数的栈调用空间

相关阅读:

U-Boot源代码下载地址

FL2440的U-boot-2010.09移植(一)
FL2440的U-boot-2010.09移植(二)
FL2440的U-boot-2010.09移植(三)DM9000网卡及开发板相关配置
FL2440的U-boot-2010.09移植(四) 添加NOR FLash启动支持
FL2440的U-boot-2010.09移植(五)uboot架构中NAND FLash驱动修改
FL2440的U-boot-2010.09移植(六)NAND FLash启动支持
FL2440的U-boot-2010.09移植(七)LCD的支持
针对FL2440开发板的u-boot-2010.09版本补丁

  • 1
  • 2
  • 下一页

相关内容