uboot for yangchu总结.docx
《uboot for yangchu总结.docx》由会员分享,可在线阅读,更多相关《uboot for yangchu总结.docx(42页珍藏版)》请在冰豆网上搜索。
![uboot for yangchu总结.docx](https://file1.bdocx.com/fileroot1/2023-2/25/2834e9e6-755f-4b82-b3a6-955e41496bd1/2834e9e6-755f-4b82-b3a6-955e41496bd11.gif)
ubootforyangchu总结
U-BOOTFOR阳初2410v2.3
BYwmmwang8/29/2007
工作环境:
RedHatLinux9
交叉编译器:
自己编译的交叉编译器arm-linux-gcc4.1.1(glibc2.3.2)
U-BOOT版本:
1.2.0
目标板:
阳初2410开发板,v2.3版
此文包含4部分:
1、NANDFLASH启动部分
2、NANDFLASH驱动部分
3、SAVEENV到NANDFLASH部分
4、UBOOT引导内核部分
参考文章:
1、NANDFLASH启动部分:
2、NANDFLASH驱动部分:
3、SAVEENV到NANDFLASH部分:
注意文中的红色部分,为添加或修改或值得注意部分!
!
!
前奏:
1、建立阳初2410的配置:
(1)拷贝board/smdk2410到board/yangchu2410;
(2)拷贝include/configs/smdk2410.h到include/configs/yangchu2410.h
2、修改文件:
(1)include/configs/yangchu2410.h:
修改:
#defineCFG_PROMPT“SMDK2410#”
为:
#defineCFG_PROMPT“YANGCHU2410#”
(2)Makefile:
smdk2410_config:
unconfig
@$(MKCONFIG)$(@:
_config=)armarm920tsmdk2410NULLs3c24x0
yangchu2410_config:
unconfig
@$(MKCONFIG)$(@:
_config=)armarm920tyangchu2410NULLs3c24x0
一、使U-BOOT能从NANDFLASH启动起来
添加的代码主要来自于VIVI。
1、在cpu/arm920t/start.s中修改如下:
……
#ifndefCONFIG_SKIP_RELOCATE_UBOOT
relocate:
/*relocateU-BoottoRAM*/
adrr0,_start/*r0<-currentpositionofcode*/
ldrr1,_TEXT_BASE/*testifwerunfromflashorRAM*/
cmpr0,r1/*don'trelocduringdebug*/
beqstack_setup
@ldrr2,_armboot_start
@ldrr3,_bss_start
@subr2,r3,r2/*r2<-sizeofarmboot*/
@addr2,r0,r2/*r2<-sourceendaddress*/
@copy_loop:
@ldmiar0!
{r3-r10}/*copyfromsourceaddress[r0]*/
@stmiar1!
{r3-r10}/*copytotargetaddress[r1]*/
@cmpr0,r2/*untilsourceendaddreee[r2]*/
@blecopy_loop
#ifdefCONFIG_S3C2410_NAND_BOOT
blcopy_myself
#endif/*CONFIG_S3C2410_NAND_BOOT*/
//这个一定要放在堆栈设置之前,否则添加NANDFLASH驱动后U-BOOT启动时会死掉
#endif/*CONFIG_SKIP_RELOCATE_UBOOT*/
……
……
……
/**************************************************************************
*
*copyu-boottoram
*
*************************************************************************
*/
//这段代码放在start.s的靠后的适当位置
#ifdefCONFIG_S3C2410_NAND_BOOT
@
@copy_myself:
copyu-boottoram
@
copy_myself:
movr10,lr
@resetNAND
movr1,#NAND_CTL_BASE
ldrr2,=0xf830@initialvalue
strr2,[r1,#oNFCONF]
ldrr2,[r1,#oNFCONF]
bicr2,r2,#0x800@enablechip
strr2,[r1,#oNFCONF]
movr2,#0xff@RESETcommand
strbr2,[r1,#oNFCMD]
movr3,#0@wait
1:
addr3,r3,#0x1
cmpr3,#0xa
blt1b
2:
ldrr2,[r1,#oNFSTAT]@waitready
tstr2,#0x1
beq2b
ldrr2,[r1,#oNFCONF]
orrr2,r2,#0x800@disablechip
strr2,[r1,#oNFCONF]
@getreadtocallCfunctions
ldrsp,DW_STACK_START@setupstackpointer
movfp,#0@nopreviousframe,sofp=0
@copyUBOOTtoRAM
ldrr0,_TEXT_BASE
movr1,#0x0
movr2,#0x20000
blnand_read_ll
teqr0,#0x0
beqok_nand_read
bad_nand_read:
1:
b1b@infiniteloop
ok_nand_read:
@verify
movr0,#0
ldrr1,_TEXT_BASE
movr2,#0x400@4bytes*1024=4K-bytes
go_next:
ldrr3,[r0],#4
ldrr4,[r1],#4
teqr3,r4
bnenotmatch
subsr2,r2,#4
beqdone_nand_read
bnego_next
notmatch:
1:
b1b
done_nand_read:
movpc,r10
#endif
@CONFIG_S3C2440_NAND_BOOT
DW_STACK_START:
.wordSTACK_BASE+STACK_SIZE-4
2、修改include/configs/yangchu2410.h
#ifndef__CONFIG_H
#define__CONFIG_H
/*
*HighLevelConfigurationOptions
*(easytochange)
*/
#defineCONFIG_ARM920T1/*ThisisanARM920TCore*/
#defineCONFIG_S3C24101/*inaSAMSUNGS3C2410SoC*/
#defineCONFIG_SMDK24101/*onaSAMSUNGSMDK2410Board*/
……
……
……
/*-----------------------------------------------------------------------
*FLASHandenvironmentorganization
*/
#defineCONFIG_AMD_LV4001/*uncommentthisifyouhaveaLV400flash*/
#if0
#defineCONFIG_AMD_LV8001/*uncommentthisifyouhaveaLV800flash*/
#endif
#defineCFG_MAX_FLASH_BANKS1/*maxnumberofmemorybanks*/
#ifdefCONFIG_AMD_LV800
#definePHYS_FLASH_SIZE0x00100000/*1MB*/
#defineCFG_MAX_FLASH_SECT(19)/*maxnumberofsectorsononechip*/
#defineCFG_ENV_ADDR(CFG_FLASH_BASE+0x0F0000)/*addrofenvironment*/
#endif
#ifdefCONFIG_AMD_LV400
#definePHYS_FLASH_SIZE0x00080000/*512KB*/
#defineCFG_MAX_FLASH_SECT(11)/*maxnumberofsectorsononechip*/
#defineCFG_ENV_ADDR(CFG_FLASH_BASE+0x070000)/*addrofenvironment*/
#endif
/*timeoutvaluesareinticks*/
#defineCFG_FLASH_ERASE_TOUT(5*CFG_HZ)/*TimeoutforFlashErase*/
#defineCFG_FLASH_WRITE_TOUT(5*CFG_HZ)/*TimeoutforFlashWrite*/
#defineCFG_ENV_IS_IN_FLASH1
#defineCFG_ENV_SIZE0x10000/*TotalSizeofEnvironmentSector*/
/*-----------------------------------------------------------------------
*NANDFLASHBOOT
*/
#defineCONFIG_S3C2410_NAND_BOOT1
#defineSTACK_BASE0x33f00000
#defineSTACK_SIZE0x8000
#defineNAND_CTL_BASE0x4e000000
#definebINT_CTL(Nb)_REG(INT_CTL_BASE+(Nb))
#defineoNFCONF0x00
#defineoNFCMD0x04
#defineoNFADDR0x08
#defineoNFDATA0x0c
#defineoNFSTAT0x10
#defineoNFECC0x14
/*-----------------------------------------------------------------------
*NANDflashsettings
*/
#defineNAND_MAX_CHIPS1
3、在board/yangchu2410/中添加nand_read.c文件:
#include
#include"linux/mtd/mtd.h"
#include"linux/mtd/nand.h"
//#defineLARGEPAGE_FLASH
#define__REGb(x)(*(volatileunsignedchar*)(x))
#define__REGi(x)(*(volatileunsignedint*)(x))
#defineNF_BASE0x4e000000
#defineNFCONF__REGi(NF_BASE+0x0)
#defineNFCMD__REGb(NF_BASE+0x4)
#defineNFADDR__REGb(NF_BASE+0x8)
#defineNFDATA__REGb(NF_BASE+0xc)
#defineNFSTAT__REGb(NF_BASE+0x10)
#defineBUSY1
inlinevoidwait_idle(void){
inti;
while(!
(NFSTAT&BUSY))
for(i=0;i<10;i++);
}
#ifndefLARGEPAGE_FLASH
#defineNAND_SECTOR_SIZE512
#else
#defineNAND_SECTOR_SIZE2048
#endif
#defineNAND_BLOCK_MASK(NAND_SECTOR_SIZE-1)
/*lowlevelnandreadfunction*/
int
nand_read_ll(unsignedchar*buf,unsignedlongstart_addr,intsize)
{
inti,j;
if((start_addr&NAND_BLOCK_MASK)||(size&NAND_BLOCK_MASK)){
//if((start_addr&NAND_BLOCK_MASK)/*||(size>SZ_1M)*/){
return-1;/*invalidalignment*/
}
/*chipEnable*/
NFCONF&=~0x800;
for(i=0;i<10;i++);
for(i=start_addr;i<(start_addr+size);){
/*READ0*/
NFCMD=NAND_CMD_READ0;
/*WriteAddress*/
#ifndefLARGEPAGE_FLASH
NFADDR=i&0xff;
NFADDR=(i>>9)&0xff;
NFADDR=(i>>17)&0xff;
NFADDR=(i>>25)&0xff;
#else
NFADDR=i&0xff;
NFADDR=(i>>8)&0x07;
NFADDR=(i>>11)&0xff;
NFADDR=(i>>19)&0xff;
NFADDR=(i>>27)&0x3;
NFCMD=NAND_CMD_READSTART;
#endif
wait_idle();
for(j=0;j*buf=(NFDATA&0xff);
buf++;
}
i+=NAND_SECTOR_SIZE;
}
/*chipDisable*/
NFCONF|=0x800;/*chipdisable*/
return0;
}
4、修改board/yangchu2410/Makefile:
COBJS:
=smdk2410.oflash.onand_read.o//添加nand_read.o
OK,这边就编译一下,就可以烧到NANDFLASH运行了。
二、为U-BOOT添加NANDFLASH驱动,能够使CFG_CMD_NAND的命令奏效
添加的代码主要来自于U-BOOT中其他的板子(board/mpl/vcma9)
1、在drivers/nand_legacy/nand_legacy.c中添加如下:
这边所有添加的代码放在nand_legacy.c文件的开头部分,因为下面有函数要调用到这边添加的函数;否则,会出错
/**********************************************************************/
/*MyADD*/
#if(CONFIG_SMDK2410)
#include
#if(CONFIG_COMMANDS&CFG_CMD_NAND)
/*typedefenum{
NFCE_LOW,
NFCE_HIGH
}NFCE_STATE;*/
staticinlinevoidNF_Conf(u16conf)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
nand->NFCONF=conf;
}
staticinlinevoidNF_Cmd(u8cmd)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
nand->NFCMD=cmd;
}
staticinlinevoidNF_CmdW(u8cmd)
{
NF_Cmd(cmd);
udelay
(1);
}
staticinlinevoidNF_Addr(u8addr)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
nand->NFADDR=addr;
}
//staticinlinevoidNF_SetCE(NFCE_STATEs)
staticinlinevoidNF_SetCE(ints)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
switch(s){
caseNFCE_LOW:
nand->NFCONF&=~(1<<11);
break;
caseNFCE_HIGH:
nand->NFCONF|=(1<<11);
break;
}
}
staticinlinevoidNF_WaitRB(void)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
while(!
(nand->NFSTAT&(1<<0)));
}
staticinlinevoidNF_Write(u8data)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
nand->NFDATA=data;
}
staticinlineu8NF_Read(void)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
return(nand->NFDATA);
}
staticinlinevoidNF_Init_ECC(void)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
nand->NFCONF|=(1<<12);
}
staticinlineu32NF_Read_ECC(void)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
return(nand->NFECC);
}
externulongnand_probe(ulongphysadr);
staticinlinevoidNF_Reset(void)
{
inti;
NF_SetCE(NFCE_LOW);
NF_Cmd(0xFF);/*resetcommand*/
for(i=0;i<10;i++);/*tWB=100ns.*/
NF_WaitRB();/*wait200~500us;*/
NF_SetCE(NFCE_HIGH);
}
staticinlinevoidNF_Init(void)
{
#if1
#defineTACLS0
#defineTWRPH03
#defineTWRPH10
#else
#defineTACLS0
#defineTWRPH04
#defineTWRPH12
#endif
NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));
/*nand->NFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);*/
/*1111,1xxx,rxxx,rxxx*/
/*En512B4stepECCRnFCE=HtACLStWRPH0tWRPH1*/
NF_Reset();
}
voidnand_init(void)
{
S3C2410_NAND*constnand=S3C2410_GetBase_NAND();
NF_Init();
#ifdefDEBUG
printf("NANDflashprobingat0x%.8lX\n",(ulong)nand);
#endif
printf("%4luMB\n",nand_probe((ulong)nand)>>20);
}
#endif/*CONFIG_COMMANDS&CFG_CMD_NAND*/
#endif/*CONFIG_SMDK23410*/
2、修改include/configs/yan