- 积分
- 1
贡献0
飞刀0 FD
注册时间2010-11-25
在线时间1 小时
扫一扫,手机访问本帖
|
我的板子是08年买的OK2440-II , 现在好像都停产了.
最近想移植个uboot上去跑跑. 用的是uboot-1.1.4. 交叉工具链: 2.95.3
因为板子上用的是NAND Flash, 所以uboot需要自拷贝代码到RAM中.
我按照网上的做法, 折腾了好久(快一星期), 还是没能跑起来, 通过LED点灯提示,
发现uboot只停在了函数 nand_read_ll() 函数里.下面贴出两块主要代码段:
代码段1: ../cpu/arm920t/start.S
......
reset:
/*
* set the cpu to SVC32 mode
*/
mrs r0,cpsr
bic r0,r0,#0x1f
orr r0,r0,#0xd3
msr cpsr,r0
/* turn off the watchdog */
# define pWTCON 0x53000000
# define INTMSK 0x4A000008 /* Interupt-Controller base addresses */
# define INTSUBMSK 0x4A00001C
# define CLKDIVN 0x4C000014 /* clock divisor register */
#define CLK_CTL_BASE 0x4C000000 /* tekkaman */
#define MDIV_405 0x7f << 12 /* tekkaman */
#define PSDIV_405 0x21 /* tekkaman */
#define MPLLCON 0x4c000004
#define UPLLCON 0x4c000008
#define CAMDIVN 0x4c000018
/*板子上LED灯的相关地址*/
#define GPFCON 0x56000050
#define GPFDAT 0x56000054
#define GPFUP 0x56000058
/*turn off watchdog*/
ldr r0, =pWTCON
mov r1, #0x0
str r1, [r0]
/*
* mask all IRQs by setting all bits in the INTMR - default
*/
mov r1, #0xffffffff
ldr r0, =INTMSK
str r1, [r0]
ldr r1, =0x7fff
ldr r0, =INTSUBMSK
str r1, [r0]
/* FCLK:HCLK:PCLK = 1:4:8 */
ldr r0, =CLKDIVN
mov r1, #5
str r1, [r0]
mrc p15, 0, r1, c1, c0, 0
orr r1, r1, #0xc0000000
mcr p15, 0, r1, c1, c0, 0
mov r1, #CLK_CTL_BASE
mov r2, #MDIV_405
add r2, r2, #PSDIV_405
str r2, [r1, #0x04] /* MPLLCON tekkaman */
#ifndef CONFIG_SKIP_LOWLEVEL_INIT
bl cpu_init_crit
#endif
#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 */
/* Set up the stack */
stack_setup:
ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
#ifdef CONFIG_USE_IRQ
sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
#endif
sub sp, r0, #12 /* leave 3 words for abort-stack */
clear_bss:
ldr r0, _bss_start /* find start of bss segment */
ldr r1, _bss_end /* stop here */
mov r2, #0x00000000 /* clear */
clbss_l:
str r2, [r0] /* clear loop... */
add r0, r0, #4
cmp r0, r1
ble clbss_l
/*自己添加的LED灯初始化*/
leds_init:
ldr r0, =GPFUP
ldr r1, =0xff7f
str r1, [r0]
ldr r0, =GPFCON
ldr r1, =0x5540
str r1, [r0]
ldr r0, =GPFDAT
ldr r1, =0xf7 /*1111_0111 点亮led0 测试*/
str r1, [r0]
/*****************下面是把uboot拷贝到RAM的代码段 (开始)****************************************/
#ifdef CONFIG_S3C2440_NAND_BOOT
@ 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 /*r0 : 把u-boot复制到ram的那个位置, TEXT_BASE 为 0x33F80000*/
mov r1, #0x0 /*r1 : 从falsh的那个位置开始复制*/
mov r2, #0x20000 /*r2 : 复制多大的内, 暂设128KB, 因为我的u-boot.bin代码就112KB*/
bl nand_read_ll /*跳转到C函数, 拷贝uboot, 该函数下面会粘出*/
tst r0, #0x0 /*这里特别注意r0的值是指nand_read_ll 执行完以后的返回值*/
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 @CONFIG_S3C2440_NAND_BOOT
/***************** uboot 拷贝到RAM (结束)*************************************************/
ldr r0, =GPFDAT
ldr r1, =0x07 /*0000_0111*/ /*进入start_armboot前, 把LED0~LED4, 五个灯全点亮*/
str r1, [r0]
ldr pc, _start_armboot
_start_armboot: .word start_armboot
.align 2
DW_STACK_START:.word STACK_BASE+STACK_SIZE-4
代码段2: board/OK2440/nand_read.c
#include <config.h>
#include <common.h>
#include <s3c2410.h>
#include <s3c24x0.h>
#define __REGb(x) (*(volatile unsigned char *)(x))
#define __REGi(x) (*(volatile unsigned int *)(x))
#define NF_BASE 0x4e000000
#define NFCONF __REGi(NF_BASE + 0x0)
#define NFCONT __REGi(NF_BASE + 0x4)
#define NFCMD __REGb(NF_BASE + 0x8)
#define NFADDR __REGb(NF_BASE + 0xC)
#define NFDATA __REGb(NF_BASE + 0x10)
#define NFSTAT __REGb(NF_BASE + 0x20)
#define NAND_CHIP_ENABLE (NFCONT &= ~(1<<1))
#define NAND_CHIP_DISABLE (NFCONT |= (1<<1))
#define NAND_CLEAR_RB (NFSTAT |= (1<<2))
#define NAND_DETECT_RB { while(! (NFSTAT&(1<<2)) );}
#define BUSY 4
inline void wait_idle(void)
{
while(!(NFSTAT & BUSY));
NFSTAT |= BUSY;
}
#define NAND_SECTOR_SIZE 512
#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)
/* low level nand read function */
/* buf: 0x33f80000 (r0)
start_addr: 0x0 (r1)
size: 0x20000 (r2)
*/
int
nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;
DECLARE_GLOBAL_DATA_PTR;
/*初始化LED灯*/
S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
gpio->GPFUP &=0xffffff07;
gpio->GPFCON &= 0x3f;
gpio->GPFCON |= 0x5540;
if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {
return -1; /* invalid alignment */
}
/* chip Enable */
NAND_CHIP_ENABLE;
for(i=0; i<10; i++);
for(i=start_addr; i < (start_addr + size);)
{
NAND_CLEAR_RB;
/* READ0 */
NFCMD = 0;
/* Write Address */
NFADDR = i & 0xff;
NFADDR = (i >> 9) & 0xff;
NFADDR = (i >> 17) & 0xff;
NFADDR = (i >> 25) & 0xff;
NAND_DETECT_RB;
for(j=0; j < NAND_SECTOR_SIZE; j++, i++)
{
gpio->GPFDAT = 0xef; /*1110_1111, 点亮LED1 */ /*烧完uboot后, 板子重新上电, 结果灯就一直亮在这里....*/
*buf = (NFDATA & 0xff);
buf++;
}
}
/* chip Disable */
NAND_CHIP_DISABLE;
gpio->GPFDAT = 0xdf; /*1101_1111, 点亮LED2*/
return 0;
}
主要代码就上述这些, 因为uboot就停在了 nand_read_ll() 函数里... 一直没有找到为什么...?
肯定是拷贝uboot出错了. ...
目前不知道如何解决...请各位大侠帮忙分析....
另外, 不知道有谁移植过uboot到OK2440-II上的? 如果谁有, 帮我解决一下啊.. 谢谢了...
祝各位工作顺利! |
|