📄 flashop_amd_.c
字号:
base&=0x1fffffff;
base|=0xa0000000;
if (base < (CS0_BASE + MIN_BOOT_BLOCK_SIZE)) // by Oleg if you want to flash Adam if (base < CS0_BASE)
return(0);
if (base >= (CS0_BASE + CS0_SIZE))
return(0);
return (1);
}
int FWBGetBlockSize(bit32u base)
{
int itmp;
base&=0x1fffffff;
base|=0xa0000000;
if ((base>=CS0_BASE)&&(base<(CS0_BASE+CS0_SIZE)))
{
base&=0x03ffffff;
itmp=(64*1024);
if (base<(64*1024)) itmp=(8*1024); // by Oleg for DSL-500T at49bv322a
// if (base<(64*1024)) itmp=(32*1024);
// if (base<(32*1024)) itmp=(8*1024);
// if (base<(16*1024)) itmp=(16*1024);
if (EMIF_ASYNC_CS0&0x2)
itmp*=2; /*Dual devices */
return(itmp);
}
return(0);
}
int FWBErase(bit32u base,int size,int verbose)
{
bit32u i,sts,blocksize,from,to;
FWBopen=FALSE;
if (size==0)
return(0);
size--;
from=base;
blocksize=FWBGetBlockSize(from);
if (blocksize==0)
{
sys_printf("Invalid flash address %x\n",from);
return(0);
}
from&=~(blocksize-1);
to=base+size;
blocksize=FWBGetBlockSize(to);
if (blocksize==0)
{
sys_printf("invalid flash address %x\n",to);
return(0);
}
to |= (blocksize-1);
if (verbose) sys_printf("FlashEraseBlock(%08x,%08x);\n",from,to);
for(i=from,sts=0;(i<to)&&(!sts);)
{
MEM_WRITE16(0xb0000000+(0x555<<1),0x00aa);
MEM_WRITE16(0xb0000000+(0x2aa<<1),0x0055);
MEM_WRITE16(0xb0000000+(0x555<<1),0x0080);
MEM_WRITE16(0xb0000000+(0x555<<1),0x00aa);
MEM_WRITE16(0xb0000000+(0x2aa<<1),0x0055);
MEM_WRITE16(i,0x0030);
sts=_FlashOperationComplete(i,0xffff,FLASH_MAX_WAIT*5000000);
_FlashErrorOut("Erase Block",sts);
if (verbose) sys_printf(".");
blocksize=FWBGetBlockSize(i);
i+=blocksize;
if (blocksize==0)
{
if (verbose) sys_printf("invalid flash address %x\n",i);
return(0);
}
}
return(sts==0);
}
int FWBOpen(bit32u base)
{
FWBopen=FALSE;
if (FWBGetBlockSize(base)==0)
return(FALSE);
FWBopen=TRUE;
return(TRUE);
}
int FWBWriteByte(bit32u adr, bit8 cVal)
{
int sts,i;
bit16u *isp,*idp;
if (!FWBopen)
return(FALSE);
sts=TRUE;
isp=(bit16u *)(adr&~1);
idp=(bit16u *)FWBwdata;
*idp=*isp;
i=adr&1;
FWBwdata[i]=cVal;
MEM_WRITE16(0xb0000000+(0x555<<1),0x00aa);
MEM_WRITE16(0xb0000000+(0x2aa<<1),0x0055);
MEM_WRITE16(0xb0000000+(0x555<<1),0x00a0);
MEM_WRITE16(isp,*idp);
sts=_FlashOperationComplete(adr&~1,*idp,FLASH_MAX_WAIT*5000);
_FlashErrorOut("Write Byte",sts);
return(sts==0);
}
int FWBClose(void)
{
if (!FWBopen)
return(FALSE);
FWBopen=FALSE;
return(TRUE);
}
/*Used to decode Flash error values */
void _FlashErrorOut(char *str,int sts)
{
if (sts)
sys_printf("Flash '%s' operation Failed: sts=%08x\n",str,sts);
}
/*Returns 0 for success and !=0 for failure */
int _FlashOperationComplete(bit32u adr,bit16u dat,int timeoutloops)
{
bit16u fnd,fnd2;
int icount;
int err;
icount=0;
fnd2=MEM_READ16(adr);
do
{
if (++icount>timeoutloops)
{
MEM_WRITE16(adr,0x00f0); /*Reset to read mode */
return(0xeeee0001);
}
fnd=fnd2;
fnd2=MEM_READ16(adr);
if (fnd2==dat)
return(0);
if ((dat&0x80)!=(fnd2&0x80))
{
if (fnd2&0x20)
{
err=fnd2&0x20;
fnd2=MEM_READ16(adr);
if (fnd2==dat)
return(0);
MEM_WRITE16(adr,0x00f0); /*Reset to read mode */
return(err);
}
}
}while(1);
}
int FWBUnLock(bit32u adr,bit32 size)
{
return(TRUE);
}
/*Returns TRUE for success and FALSE for failure */
int FWBLock(bit32u from,bit32 size)
{
return(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -