这里用的方法,见下面的博客:
主要就是读OM1 OM0的值,若为00,则是nand启动,若不为0,则为nor启动。
主要就是修改start.s代码:
- /******************************************************************
-
*定义各模式堆栈空间
-
*******************************************************************/
-
.equ FIQ_STACK, 0x36FFF000
-
.equ IRQ_STACK, 0x36FFE000
-
.equ ABORT_STACK, 0x36FFD000
-
.equ UNDEFINE_STACK, 0x36FFC000
-
.equ USER_STACK, 0x36FFB000
-
.equ SVC_STACK, 0x36FFA000
-
/******************************************************************
-
*中断向量表
-
*******************************************************************/
-
.text
-
.global _start
-
_start: b start_code @0x00,复位异常
-
ldr pc, undefined_instruction @0x04,未定义指令异常
-
ldr pc, software_interrupt @0x08,软中断
-
ldr pc, prefetch_abort @0x0c,指令预取终止异常
-
ldr pc, data_abort @0x10,数据访问终止异常
-
ldr pc, not_used @0x14,保留
-
ldr pc, irq @0x18,中断
-
ldr pc, fiq @0x1c,快速中断
-
/******************************************************************
-
*代码开始
-
*******************************************************************/
-
start_code:
-
mrs r0, cpsr @设置为管理模式
-
bic r0, r0, #0x1F @ARM指令,禁止中断
-
orr r0, r0, #0xD3
-
msr cpsr, r0
-
-
ldr r0, =0x53000000 @关闭看门狗
-
mov r1, #0x0
-
str r1, [r0]
-
-
ldr r0, =0x4C000014 @设置时钟分频比
-
mov r1, #0x05 @FCLK:HCLK:PCLK = 1:4:8
-
str r1, [r0]
-
-
mrc p15, 0, r0, c1, c0, 0 @如果HDIVN不为0,使其从
-
orr r0, r0, #0xC0000000 @由快总线模式变为异步总线模式
-
mcr p15, 0, r0, c1, c0, 0
-
-
ldr r0, =0x4C000008 @设置UCLK=48MHz
-
ldr r1, =0x00038022 @(56<<12)|(2<<4)|(2)
-
str r1, [r0]
-
-
ldr r0, =0x4C000004 @设置FCLK=400MHz
-
ldr r1, =0x0005C011 @(92<<12)|(1<<4)|(1)
-
str r1, [r0]
-
-
mov r1, #0x48000000 @设置SDRAM
-
adrl r2, mem_cfg_val
-
add r3, r1, #52
-
1:
-
ldr r4, [r2], #4
-
str r4, [r1], #4
-
cmp r1, r3
-
bne 1b
-
/******************************************************************
-
*判断是从norflash启动还是从nandflash启动,复制代码到SDRAM,跳入第二阶段执行
-
*******************************************************************/
-
#define BWSCON 0x48000000 //判断是从norflash启动还是从nandflash启动
-
ldr r0, =BWSCON //若OM1:OM0 = 00则从nandflash启动
-
ldr r0, [r0]
-
ands r0, r0, #6
-
cmp r0, #0
-
bne relocate //不为0则从norflash启动
-
-
ldr sp, =4096 //从nandflash启动,复制代码到SDRAM
-
bl s3c2440_nand_init
-
ldr r0, =0x30000000
-
mov r1, #4096
-
mov r2, #2048
-
bl s3c2440_nand_read
-
b laststep
-
-
relocate: //从norflash启动,复制代码到SDRAM
-
ldr r0, =4096
-
ldr r1, =0x30000000
-
mov r2, #10240
-
-
copy_loop:
-
ldmia {r3-r10}
-
stmia {r3-r10}
-
cmp r0, r2
-
ble copy_loop
-
laststep:
-
ldr lr, =halt_loop
-
ldr pc, =main
-
-
halt_loop:
-
b halt_loop
-
-
/*******************************************************************
-
*存储控制器13个寄存器的设置值
-
********************************************************************/
-
.align 4
-
mem_cfg_val:
-
.long 0x22011110
-
.long 0x00000700
-
.long 0x00000700
-
.long 0x00000700
-
.long 0x00000700
-
.long 0x00000700
-
.long 0x00000700
-
.long 0x00018005
-
.long 0x00018005
-
.long 0x008C07A3
-
.long 0x000000B2
-
.long 0x00000030
-
.long 0x00000030
-
-
/******************************************************************
-
*设置各模式堆栈
-
*******************************************************************/
-
stack_setup:
-
mrs r0, cpsr
-
bic r0, r0, #0x1F
-
orr r0, r0, #0xDB
-
msr cpsr, r0
-
ldr sp, =UNDEFINE_STACK
-
-
mrs r0, cpsr
-
bic r0, r0, #0x1F
-
orr r0, r0, #0xD7
-
msr cpsr, r0
-
ldr sp, =ABORT_STACK
-
-
mrs r0, cpsr
-
bic r0, r0, #0x1F
-
orr r0, r0, #0xD2
-
msr cpsr, r0
-
ldr sp, =IRQ_STACK
-
-
mrs r0, cpsr
-
bic r0, r0, #0x1F
-
orr r0, r0, #0xD1
-
msr cpsr, r0
-
ldr sp, =FIQ_STACK
-
-
mrs r0, cpsr
-
bic r0, r0, #0x1F
-
orr r0, r0, #0xD0
-
msr cpsr, r0
-
ldr sp, =USER_STACK
-
-
mrs r0, cpsr
-
bic r0, r0, #0x1F
-
orr r0, r0, #0xD3
-
msr cpsr, r0
-
ldr sp, =SVC_STACK
-
/*******************************************************************
-
*中断处理
-
********************************************************************/
-
undefined_instruction:
-
b undefined_instruction
-
software_interrupt:
-
b software_interrupt
-
prefetch_abort:
-
b prefetch_abort
-
data_abort:
-
b data_abort
-
not_used:
-
b not_used
-
irq:
-
b irq
-
fiq:
-
b fiq
- relocate: //从norflash启动,复制代码到SDRAM
- ldr r0, =4096
- ldr r1, =0x30000000
- mov r2, #10240
若为nor启动,只复制norflash4k以后的10240长度的代码到SDRAM中,其余的代码在norflash中直接执行。
- #define BWSCON 0x48000000 //判断是从norflash启动还是从nandflash启动
- ldr r0, =BWSCON //若OM1:OM0 = 00则从nandflash启动
- ldr r0, [r0]
- ands r0, r0, #6
- cmp r0, #0
- bne relocate //不为0则从norflash启动
这就是判断的方法,只有读出00的时候与6(0110)与才为0。
代码无论是烧到NORFLASH还是NANDFLASH中都可以运行,实现了自动识别。代码以实际在mini2440开发板上测试通过。
附全部代码:
阅读(905) | 评论(0) | 转发(0) |