分类: 嵌入式
2009-07-30 17:17:11
#include
#include
#if defined(CONFIG_AT91RM9200DK)
#include
#endif
......
/*
* the actual start code
*/
start_code:
/*
* set the cpu to SVC32 mode
*/
mrs r0,cpsr
bic r0,r0,#0x
orr r0,r0,#0xd3
msr cpsr,r0
#if defined(CONFIG_AT91RM9200DK)
bl coloured_LED_init
bl red_LED_on
#endif
1) 修改寄存器地址定义
#if defined(CONFIG_S
/* turn off the watchdog */
#if defined(CONFIG_S
#define pWTCON 0x15300000
#define INTMSK 0x14400008 /* Interupt-Controller base addresses */
#define CLKDIVN 0x14800014 /* clock divisor register */
#else
#define pWTCON 0x53000000
#define INTMSK 0x
#define INTSUBMSK 0x
#define CLKDIVN 0x
#endif
#define CLK_CTL_BASE 0x
#define MDIV_405 0x
#define PSDIV_405 0x21 /* Embest */
#define MDIV_200 0xa1 << 12 /* Embest */
#define PSDIV_200 0x31 /* Embest */
......
2) 修改中断禁止部分
#if defined(CONFIG_S
ldr r1, =0x7ff /*根据2410芯片手册,INTSUBMSK有11位可用,
vivi也是0x7ff,U-Boot一直没改过来。*/
ldr r0, =INTSUBMSK
str r1, [r0]
#endif
3) 修改时钟设置
/* FCLK:HCLK:PCLK = 1:2:4 */
/* default FCLK is 12 MHz ! 在这里U-Boot有一个错误:以为默认时钟为120MHz。其实如果没有添加以下设置FCLK的语句,芯片内部的PLL是无效的,即FCLK为 12MHz。S
ldr r0, =CLKDIVN
mov r1, #3
str r1, [r0]
mrc p15, 0, r1, c1, c0, 0 /*read ctrl register Embest*/
orr r1, r1, #0xc0000000 /*Asynchronous Embest*/
mcr p15, 0, r1, c1, c0, 0 /*write ctrl register Embest*/
/*now, CPU clock is 202.8 Mhz Embest*/
mov r1, #CLK_CTL_BASE /* Embest*/
mov r2, #MDIV_200 /* mpll_200mhz Embest*/
add r2, r2, #PSDIV_200 /* mpll_200mhz Embest*/
str r2, [r1, #0x04]
#endif /* CONFIG_S
4) 将从Flash启动改成从NAND Flash启动。
在以下U-Boot的重定向语句段:
#ifdef CONFIG_AT91RM9200
#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 {r3-r10} /* copy from source address [r0] */
stmia {r3-r10} /* copy to target address [r1] */
cmp r0, r2 /* until source end addreee [r2] */
ble copy_loop
#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
#endif
的后面添加上:
#ifdef CONFIG_S
@ 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
nand1:
add r3, r3, #0x1
cmp r3, #0xa
blt nand1
nand2:
ldr r2, [r1, #oNFSTAT] @ wait ready
tst r2, #0x1
beq nand2
ldr r2, [r1, #oNFCONF]
orr r2, r2, #0x800 @ disable chip
str r2, [r1, #oNFCONF]
@ get read to call C s (for nand_read())
ldr sp, DW_STACK_START @ setup stack pointer
mov fp, #0 @ no previous , so fp=0
@ copy U-Boot to RAM
ldr r0, =TEXT_BASE
mov r1, #0x0
mov r2, #0x30000
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 @ CONFIG_S
在“ldr pc, _start_armboot”之前加入:
# if defined(CONFIG_edukit2410_LED)
@ LED1 on u-boot stage 1 is
ldr r0, =0x56000060
ldr r1, =0xff4af769
str r1, [r0]
ldr r0, =0x56000068
ldr r1, =0xffff
str r1, [r0]
ldr r0, =0x21180000
ldr r1, =0xfc
strb r1, [r0]
#endif
//修改目的:如果看到只有LED1亮了,说明U-Boot的第一阶段已完成!
在 “ _start_armboot: .word start_armboot ” 后加入:
.align 2
DW_STACK_START: .word STACK_BASE+STACK_SIZE-4
在board/Embest/edukit2410加入NAND Flash读函数文件,拷贝vivi中的nand_read.c文件到此文件夹即可:
#include
#define __REGb(x) (*(volatile unsigned char *)(x))
#define __REGi(x) (*(volatile unsigned int *)(x))
#define NF_BASE 0x4e000000
# if defined(CONFIG_S
#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++);
}
/* low level nand read */
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;
}
# endif
......
OBJS := edukit2410.o nand_read.o flash.o
......
1) 在文件末添加如下内容:
......
/*
* Nandflash Boot
*/
#define STACK_BASE 0x
#define STACK_SIZE 0x8000
//#define UBOOT_RAM_BASE 0x
/* NAND Flash Controller */
#define NAND_CTL_BASE 0x4E000000
#define bINT_CTL(Nb) __REG(INT_CTL_BASE + (Nb))
/* Offset */
#define oNFCONF 0x00
# if defined(CONFIG_S
#define CONFIG_S
/* Offset */
#define oNFCONF 0x00
#define oNFCMD 0x04
#define oNFADDR 0x08
#define oNFDATA 0x
#define oNFSTAT 0x10
#define oNFECC 0x14
#define rNFCONF (*(volatile unsigned int *)0x4e000000)
#define rNFCMD (*(volatile unsigned char *)0x4e000004)
#define rNFADDR (*(volatile unsigned char *)0x4e000008)
#define rNFDATA (*(volatile unsigned char *)0x4e
#define rNFSTAT (*(volatile unsigned int *)0x4e000010)
#define rNFECC (*(volatile unsigned int *)0x4e000014)
#define rNFECC0 (*(volatile unsigned char *)0x4e000014)
#define rNFECC1 (*(volatile unsigned char *)0x4e000015)
#define rNFECC2 (*(volatile unsigned char *)0x4e000016)
#endif
/*JFFS2 Support */
#undef CONFIG_JFFS2_CMDLINE
#define CONFIG_JFFS2_NAND 1
#define CONFIG_JFFS2_DEV "nand0"
#define CONFIG_JFFS2_PART_SIZE 0x
#define CONFIG_JFFS2_PART_OFFSET 0x40000
/*JFFS2 Support */
/* USB Support 080218 */
#define CONFIG_USB_OHCI
#define CONFIG_USB_STORAGE
#define CONFIG_USB_KEYBOARD
#define CONFIG_DOS_PARTITION
#define CFG_DEVICE_DEREGISTER
#define CONFIG_SUPPORT_VFAT
#define LITTLEENDIAN
/* USB Support 080218 */
/*yaffs support*/
#define CFG_NAND_YAFFS1_NEW_OOB_LAYOUT 1
#define ENABLE_CMD_NAND_YAFFS 1
#define ENABLE_CMD_NAND_YAFFS_SKIPFB 1
#define CFG_NAND_YAFFS1_NEW_OOB_LAYOUT 1
/*yaffs support*/
#endif /* __CONFIG_H */
2) 选择串口端口,使信息能够通过uart1进行打印
因为linux内核中配置的打印端口为uart1。
/*
* select serial console configuration
*/
#define CONFIG_SERIAL2 1 /* we use SERIAL 2(uart1) on edukit */