歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> FL2440的U-boot-2010.09移植(六)NAND FLash啟動支持

FL2440的U-boot-2010.09移植(六)NAND FLash啟動支持

日期:2017/3/1 10:18:21   编辑:Linux編程
從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. #define BWSCON 0x48000000
  5. ldr r0, =BWSCON
  6. ldr r0, [r0]
  7. ands r0, r0, #0x6
  8. tst r0, #0x0
  9. bne norflash_boot /*OM[1:0] != 0, 跳轉到NOR FLASH 啟動處*/
  10. /*判斷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. @reset NAND
  10. mov r1,#NAND_CTL_BASE
  11. ldr r2,=((7<<12)|(7<<8)|(7<<4))
  12. str r2,[r1,#oNFCONF]
  13. ldr r2,[r1,#oNFCONF]
  14. ldr r2,=((1<<4)|(1<<1)|(1<<0)) @Active low CE control
  15. str r2,[r1,#oNFCONT]
  16. ldr r2,[r1,#oNFCONT]
  17. @ get read to call C functions
  18. ldr sp,DW_STACK_START @setup stack point
  19. mov fp,#0 @no previous frame, so fp = 0
  20. @copy Uboot to ram
  21. ldr r0, =TEXT_BASE
  22. mov r1,#0x0
  23. mov r2,#LENGTH_UBOOT
  24. bl nand_read_ll
  25. tst r0,#0x0
  26. beq ok_nand_read
  27. bad_nand_read:
  28. loop2:
  29. b loop2 @infinite loop
  30. ok_nand_read:
  31. @verify
  32. mov r0,#0
  33. ldr r1,=TEXT_BASE
  34. mov r2,#0x400 @ compare 4k code from sram to sdram
  35. go_next:
  36. ldr r3, [r0], #4
  37. ldr r4, [r1], #4
  38. teq r3, r4
  39. bne notmatch
  40. subs r2,r2,#4
  41. tst r2,#0x0 @do not forget the instruction if have not this command the uboot can't break the loop
  42. beq stack_setup
  43. bne go_next
  44. notmatch:
  45. loop3:
  46. b loop3 @infinite loop
  47. /*****************************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源代碼下載地址 http://www.linuxidc.com/Linux/2011-07/38897.htm

FL2440的U-boot-2010.09移植(一)http://www.linuxidc.com/Linux/2012-06/63755.htm
FL2440的U-boot-2010.09移植(二)http://www.linuxidc.com/Linux/2012-06/63756.htm
FL2440的U-boot-2010.09移植(三)DM9000網卡及開發板相關配置 http://www.linuxidc.com/Linux/2012-07/64155.htm
FL2440的U-boot-2010.09移植(四) 添加NOR FLash啟動支持 http://www.linuxidc.com/Linux/2012-07/64156.htm
FL2440的U-boot-2010.09移植(五)uboot架構中NAND FLash驅動修改 http://www.linuxidc.com/Linux/2012-07/64157.htm
FL2440的U-boot-2010.09移植(六)NAND FLash啟動支持 http://www.linuxidc.com/Linux/2012-07/641587.htm
FL2440的U-boot-2010.09移植(七)LCD的支持 http://www.linuxidc.com/Linux/2012-07/641587.htm
針對FL2440開發板的u-boot-2010.09版本補丁 http://www.linuxidc.com/Linux/2012-07/64116.htm

Copyright © Linux教程網 All Rights Reserved