标签:
检测步骤:在启动的时候,将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
-
- adr r0, _start
- 11
- ldr r1, _TEXT_BASE
- cmp r0, r1
- beq stack_setup
-
如果代码当前位置不在内存中,就判断启动方式为Nand Flash 或者Nor Flash
-
- ldr r1, =( (4<<28)|(3<<4)|(3<<2) )
- mov r0, #0
- str r0, [r1]
- mov r1, #0x3c
- ldr r0, [r1]
- cmp r0, #0
- bne relocate
-
- ldr r0, =(0xdeadbeef)
- ldr r1, =( (4<<28)|(3<<4)|(3<<2) )
- str r0, [r1]
在Nand Flash 中启动的话,那么Nand Flash 搬移代码如下:
定义u-boot在Nand flash中存放的长度为#define LENGTH_UBOOT 0x100000,可以方便修改
u-boot因为裁剪和增添大小的改变而占的长度
-
- #define LENGTH_UBOOT 0x100000
- #define NAND_CTL_BASE 0x4E000000
-
- #ifdef CONFIG_S3C2440
-
- #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
在Nor Flash 中启动的话,那么Nor Flash 搬移代码如下:
-
- relocate:
-
- ldr r1, =(0xdeadbeef)
- cmp r0, r1
- bne loop3
-
- adr r0, _start
- ldr r1, _TEXT_BASE
- ldr r2, _armboot_start
- ldr r3, _bss_start
- sub r2, r3, r2
- add r2, r0, r2
- copy_loop:
- ldmia r0!, {r3-r10}
- stmia r1!, {r3-r10}
- cmp r0, r2
- ble copy_loop
- SetBootFlag:
- ldr r0, =bBootFrmNORFlash
- mov r1, #1
- str r1, [r0]
-
将下面的代码全部删掉:
- #ifndef CONFIG_SKIP_RELOCATE_UBOOT
- relocate:
- adr r0, _start
- ldr r1, _TEXT_BASE
- cmp r0, r1
- beq stack_setup
- ldr r2, _armboot_start
- ldr r3, _bss_start
- sub r2, r3, r2
- add r2, r0, r2
- copy_loop:
- ldmia r0!, {r3-r10}
- stmia r1!, {r3-r10}
- cmp r0, 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
标签:
原文地址:http://www.cnblogs.com/liuchengchuxiao/p/4210288.html