首页 > 代码库 > (二)识别NAND Flash Nor Flash
(二)识别NAND Flash Nor Flash
检测步骤:在启动的时候,将0x4000003c位置开始的四个字节清零,然后读取0x0000003c位置开始的四个字节。
如果回读的结果为零,说明是Nand boot,否则就是Nor boot
修改start.S
第90 行左右添加一个Flash 启动标志,从Nand 启动时将其设置为0 ,从Nor 启动时将其设置为1
- .globl _bss_start
- _bss_start:
- .word __bss_start
- .globl _bss_end
- _bss_end:
- .word _end
- .globl bBootFrmNORFlash
- bBootFrmNORFlash:
- .word 0
从第224 行左右开始,添加代码为:
判断当前代码位置,如果在内存,直接跳到stack_setup
- #ifndef CONFIG_SKIP_LOWLEVEL_INIT
- bl cpu_init_crit
- #endif
- /***************** CHECK_CODE_POSITION***************************************/
- adr r0, _start /* r0 <- current position of code */
- 11
- ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
- cmp r0, r1 /* don‘t reloc during debug */
- beq stack_setup
- /***************** CHECK_CODE_POSITION*************************************/
如果代码当前位置不在内存中,就判断启动方式为Nand Flash 或者Nor Flash
- /***************** CHECK_BOOT_FLASH ******************************************/
- ldr r1, =( (4<<28)|(3<<4)|(3<<2) ) /* address of Internal SRAM 0x4000003C*/
- mov r0, #0 /* r0 = 0 */
- str r0, [r1]
- mov r1, #0x3c /* address of 0x0000003C*/
- ldr r0, [r1]
- cmp r0, #0 /* 判断0x0000003C所指向的4个字节是否被清0*/
- bne relocate /* 没有被清0,就是在Nor Flash中启动,则跳到Nor Flash的重定向代码处relocate*/
- /* recovery */
- ldr r0, =(0xdeadbeef) /* 被清0,就是在Nand Flash中启动*/
- ldr r1, =( (4<<28)|(3<<4)|(3<<2) ) /* 恢复0x4000003C指向的4字节的数据0xdeadbeef*/
- str r0, [r1]
- /***************** CHECK_BOOT_FLASH ******************************************/
在Nand Flash 中启动的话,那么Nand Flash 搬移代码如下:
定义u-boot在Nand flash中存放的长度为#define LENGTH_UBOOT 0x100000,可以方便修改
u-boot因为裁剪和增添大小的改变而占的长度
- /***************** NAND_BOOT *************************************************/
- #define LENGTH_UBOOT 0x100000
- #define NAND_CTL_BASE 0x4E000000
- #ifdef CONFIG_S3C2440
- /* Offset */
- #define oNFCONF 0x00
- #define oNFCONT 0x04
- #define oNFCMD 0x08
- #define oNFSTAT 0x20
- @ reset NAND
- mov r1, #NAND_CTL_BASE
- ldr r2, =( (7<<12)|(7<<8)|(7<<4)|(0<<0) )
- str r2, [r1, #oNFCONF]
- ldr r2, [r1, #oNFCONF]
- ldr r2, =( (1<<4)|(0<<1)|(1<<0) ) @ Active low CE Control
- str r2, [r1, #oNFCONT]
- ldr r2, [r1, #oNFCONT]
- ldr r2, =(0x6) @ RnB Clear
- str r2, [r1, #oNFSTAT]
- ldr r2, [r1, #oNFSTAT]
- mov r2, #0xff @ RESET command
- strb r2, [r1, #oNFCMD]
- mov r3, #0 @ wait
- nand1:
- add r3, r3, #0x1
- cmp r3, #0xa
- blt nand1
- nand2:
- ldr r2, [r1, #oNFSTAT] @ wait ready
- tst r2, #0x4
- beq nand2
- ldr r2, [r1, #oNFCONT]
- orr r2, r2, #0x2 @ Flash Memory Chip Disable
- str r2, [r1, #oNFCONT]
- @ get read to call C functions (for nand_read())
- ldr sp, DW_STACK_START @ setup stack pointer
- mov fp, #0 @ no previous frame, so fp=0
- @ copy U-Boot to RAM
- ldr r0, =TEXT_BASE
- mov r1, #0x0
- mov r2, #LENGTH_UBOOT
- bl nand_read_ll
- tst r0, #0x0
- beq ok_nand_read
- bad_nand_read:
- loop2:
- b loop2 @ infinite loop
- ok_nand_read:
- @ verify
- mov r0, #0
- ldr r1, =TEXT_BASE
- mov r2, #0x400 @ 4 bytes * 1024 = 4K-bytes
- go_next:
- ldr r3, [r0], #4
- ldr r4, [r1], #4
- teq r3, r4
- bne notmatch
- subs r2, r2, #4
- beq stack_setup
- bne go_next
- notmatch:
- loop3:
- b loop3 @ infinite loop
- #endif
- /***************** NAND_BOOT *************************************************/
在Nor Flash 中启动的话,那么Nor Flash 搬移代码如下:
- /***************** NOR_BOOT *************************************************/
- relocate: /* relocate U-Boot to RAM */
- /*********** CHECK_FOR_MAGIC_NUMBER***************/
- ldr r1, =(0xdeadbeef)
- cmp r0, r1
- bne loop3
- /*********** CHECK_FOR_MAGIC_NUMBER***************/
- adr r0, _start /* r0 <- current position of code */
- ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
- ldr r2, _armboot_start
- ldr r3, _bss_start
- sub r2, r3, r2 /* r2 <- size of armboot */
- add r2, r0, r2 /* r2 <- source end address */
- copy_loop:
- ldmia r0!, {r3-r10} /* copy from source address [r0] */
- stmia r1!, {r3-r10} /* copy to target address [r1] */
- cmp r0, r2 /* until source end addreee [r2] */
- ble copy_loop
- SetBootFlag:
- ldr r0, =bBootFrmNORFlash
- mov r1, #1 /*从Nor启动,将标志设置为1*/
- str r1, [r0]
- /***************** NOR_BOOT *************************************************/
将下面的代码全部删掉:
- #ifndef CONFIG_SKIP_RELOCATE_UBOOT
- relocate: /* relocate U-Boot to RAM */
- adr r0, _start /* r0 <- current position of code */
- ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
- cmp r0, r1 /* don‘t reloc during debug */
- beq stack_setup
- ldr r2, _armboot_start
- ldr r3, _bss_start
- sub r2, r3, r2 /* r2 <- size of armboot */
- add r2, r0, r2 /* r2 <- source end address */
- copy_loop:
- ldmia r0!, {r3-r10} /* copy from source address [r0] */
- stmia r1!, {r3-r10} /* copy to target address [r1] */
- cmp r0, r2 /* until source end addreee [r2] */
- ble copy_loop
- #endif /* CONFIG_SKIP_RELOCATE_UBOOT *
第378 行左右添加代码:
- _start_armboot: .word start_armboot
- #define STACK_BASE 0x33f00000
- #define STACK_SIZE 0x10000
- .align 2
- DW_STACK_START: .word STACK_BASE+STACK_SIZE-4
(二)识别NAND Flash Nor Flash
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。