微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > u-boot在s3c2410开发板上移植过程

u-boot在s3c2410开发板上移植过程

时间:11-10 来源:互联网 点击:

#define __REGb(x)(*(volatile unsigned char *)(x))
#define __REGi(x)(*(volatile unsigned int *)(x))
#define NF_BASE0x4e000000
#define NFCONF__REGi(NF_BASE + 0x0)
#define NFCMD__REGb(NF_BASE + 0x4)
#define NFADDR__REGb(NF_BASE + 0x8)
#define NFDATA__REGb(NF_BASE + 0xc)
#define NFSTAT__REGb(NF_BASE + 0x10)

#define BUSY 1
inline void wait_idle(void) {
int i;

while(!(NFSTAT & BUSY))
for(i=0; i<10; i++);
}

#define NAND_SECTOR_SIZE512
#define NAND_BLOCK_MASK(NAND_SECTOR_SIZE - 1)

/* low level nand read function */
int
nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;

if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {
return -1;/* invalid alignment */
}

/* chip Enable */
NFCONF &= ~0x800;
for(i=0; i<10; i++);

for(i=start_addr; i < (start_addr + size);) {
/* READ0 */
NFCMD = 0;

/* Write Address */
NFADDR = i & 0xff;
NFADDR = (i >> 9) & 0xff;
NFADDR = (i >> 17) & 0xff;
NFADDR = (i >> 25) & 0xff;

wait_idle();

for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
*buf = (NFDATA & 0xff);
buf++;
}
}

/* chip Disable */
NFCONF |= 0x800;/* chip disable */

return 0;
}

9)修改board/bks2410/Makefile为
OBJS:= bks2410.o flash.o nand_read.o

10)修改cpu/arm920t/start.S文件
在ldrpc, _start_armboot之前加入:
#ifdef CONFIG_S3C2410_NAND_BOOT
bl copy_myself

@ jump to ram
ldr r1, =on_the_ram
add pc, r1, #0
nop
nop
1: b 1b @ infinite loop

on_the_ram:
#endif

在_start_armboot:.word start_armboot之后加入:
#ifdef CONFIG_S3C2410_NAND_BOOT
copy_myself:
mov r10, lr
@ reset NAND
mov r1, #NAND_CTL_BASE
ldr r2, =0xf830 @ initial value
str r2, [r1, #oNFCONF]
ldr r2, [r1, #oNFCONF]
bic r2, r2, #0x800 @ enable chip
str r2, [r1, #oNFCONF]
mov r2, #0xff @ RESET command
strb r2, [r1, #oNFCMD]
mov r3, #0 @ wait

1:add r3, r3, #0x1
cmp r3, #0xa
blt 1b
2:ldr r2, [r1, #oNFSTAT] @ wait ready
tst r2, #0x1
beq 2b
ldr r2, [r1, #oNFCONF]
orr r2, r2, #0x800 @ disable chip
str r2, [r1, #oNFCONF]

@ 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 vivi to RAM
ldr r0, =UBOOT_RAM_BASE
mov r1, #0x0
mov r2, #0x20000
bl nand_read_ll
tst r0, #0x0
beq ok_nand_read

#ifdef CONFIG_DEBUG_LL
bad_nand_read:
ldr r0, STR_FAIL
ldr r1, SerBase
bl PrintWord
1:b 1b @ infinite loop
#endif

ok_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr r0, STR_OK
ldr r1, SerBase
bl PrintWord
#endif

@ verify
mov r0, #0
ldr r1, =UBOOT_RAM_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 done_nand_read
bne go_next

notmatch:
#ifdef CONFIG_DEBUG_LL
sub r0, r0, #4
ldr r1, SerBase
bl PrintHexWord
ldr r0, STR_FAIL
ldr r1, SerBase
bl PrintWord
#endif
1:b 1b
done_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr r0, STR_OK
ldr r1, SerBase
bl PrintWord
#endif
mov pc, r10
@ clear memory
@ r0: start address
@ r1: length
mem_clear:
mov r2, #0
mov r3, r2
mov r4, r2
mov r5, r2
mov r6, r2
mov r7, r2
mov r8, r2
mov r9, r2

clear_loop:
stmia r0!, {r2-r9}
subs r1, r1, #(8 * 4)
bne clear_loop
mov pc, lr

#endif @ CONFIG_S3C2410_NAND_BOOT

在文件的最后加入:
.align 2
DW_STACK_START:
.word STACK_BASE+STACK_SIZE-4

11)修改include/configs/bks2410.h文件,添加如下内容:
/*
* Nandflash Boot
*/
#define CONFIG_S3C2410_NAND_BOOT 1
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x8000
#define UBOOT_RAM_BASE 0x33f80000
/* NAND Flash Controller */
#define NAND_CTL_BASE 0x4E000000
#define bINT_CTL(Nb) __REG(INT_CTL_BASE + (Nb))
/* Offset */
#define oNFCONF 0x00
#define oNFCMD 0x04
#define oNFADDR 0x08
#define oNFDATA 0x0c
#define oNFSTAT 0x10
#define oNFECC 0x14

12)重新编译u-boot
make all ARCH=arm

13)通过jtag将u-boot烧写到flash中就可以从NAND flash启动了

我的u-boot启动信息:

U-Boot 1.1.3 (May 6 2006 - 18:13:59)

U-Boot code: 33F80000 -> 33F967C4 BSS: -> 33F9AAAC
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
*** Warning - bad CRC, using default environment

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top