📄 flash.cpp
字号:
#include "bastype.h"
#include "mcf5206.h"
#include "main.h"
#include "graph.h"
#include "flash.h"
// -----------------------------------------------------------------------------------------
// start address about eight blocks of lastest
// because these addresses are not same in different PCB Layout
//----------------------------------------------------------------------------------------------------------
UINT32 g_nFlashCircuitType;
UINT32 g_nFlashSizeType;
UINT32 g_anFlashTailAddr[8];
UINT32 g_nSecondAddr;
static UCHAR s_acFlashBlockBuffer[FLASH_NORMAL_BLOCK_SIZE + 1];
/*********************************************************************
* 函数名称: JudgeLayOut
* 说 明: 1、通过CFI Identification来鉴别主控板版本种有关FLASH地址线连接不同的种类
* 目前有两种:D版本和D版本以前
* 8000D版本以前: FLASH(A0-A14, A15-A20)分别对应CPU(A16-A2, a17-a22),注意前面15根线是倒序对应
* 8000D版本: FLASH(A0-A2, A3-A11, A12-A20)分别对应CPU(A2-A4, A13-A5, a14-a22),注意中间A3-A11是倒序对应
* 6000: FLASH(A15-A20)对应CPU(A17-A22),FLASH(A0-A14)对应CPU地址如下:
* A0(A16),A1(A14),A2(A15),A3(A13),A4(A11), A5(A9), A6(A6), A7(A4),
* A8(A2), A9(A3), A10(A5),A11(A7),A12(A8),A13(A10),A14(A12)
* 2、区分2M和4M的FLASH
* 注意由于FLASH是由两片组成的32位操作,所以2M的device ID应该两个连续的1M的DEVICE ID
* 入口参数: void -- 无
* 返 回 值:
* BOOL -- 1, success; 0, failure
* 作 者: Shi Liangcai
* 时 间: 2003-02-13 14:36:00
*********************************************************************/
BOOL JudgeLayOut()
{
UINT* puState;
UINT unTemp;
int i;
// 先判断是否是INTELFLASH
// enter Configuration mode
puState = (UINT*)(0x850000); //-----Any address
*puState = 0x00900090;
if (*((UINT32*)(0x800000)) != 0x00890089)
return FALSE;
// 判断FLASH走线方式,先判断是否是D版本
// CFI Identification, 这是手册上的指定值,为了防止巧合,读0x10-0x1f一共16个字节来判断
UINT32 anCfiDef[] =
{
0x00510051, 0x00520052, 0x00590059, 0x00030003, 0x00000000, 0x00350035, 0x0000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00270027, 0x00360036, 0x00b400b4, 0x00c600c6, 0x00050005
};
// enter query mode
puState = (UINT*)(0x850000); //-----Any address
*puState = 0x00980098;
g_nFlashCircuitType = FLASH_CIRCUIT_NULL;
// 先判断是否是8000主控板D版本
if (g_nFlashCircuitType == FLASH_CIRCUIT_NULL)
{
UINT32 anCfiAddr[] = // 8000主控板D版本FLASH(0x10 - 0x1f)对应的CPU地址
{
0x1000, 0x1004, 0x1008, 0x100c, 0x1010, 0x1014, 0x1018, 0x101c,
0x3000, 0x3004, 0x3008, 0x300c, 0x3010, 0x3014, 0x3018, 0x301c
};
for (i = 0; i < 16; i ++)
{
if (*((UINT32*)(anCfiAddr[i] + FLASH_BASE_ADDRESS)) != anCfiDef[i])
break;
}
if (i == 16)
g_nFlashCircuitType = FLASH_CIRCUIT_VER_8000_D;
}
// 再判断是否是8000主控板D版本以前的版本
if (g_nFlashCircuitType == FLASH_CIRCUIT_NULL)
{
UINT32 anCfiAddr[] = // 8000主控板D版本以前版本FLASH(0x10 - 0x1f)对应的CPU地址
{
0x1000, 0x11000, 0x9000, 0x19000, 0x5000, 0x15000, 0xd000, 0x1d000,
0x3000, 0x13000, 0xb000, 0x1b000, 0x7000, 0x17000, 0xf000, 0x1f000
};
for (i = 0; i < 16; i ++)
{
if (*((UINT32*)(anCfiAddr[i] + FLASH_BASE_ADDRESS)) != anCfiDef[i])
break;
}
if (i == 16)
g_nFlashCircuitType = FLASH_CIRCUIT_VER_8000_D_BEFORE;
}
// 再判断是否是6000主控板
if (g_nFlashCircuitType == FLASH_CIRCUIT_NULL)
{
UINT32 anCfiAddr[] = // 6000主控板FLASH(0x10 - 0x1f)对应的CPU地址
{
0x800, 0x10800, 0x4800, 0x14800, 0x8800, 0x18800, 0xC800, 0x1c800,
0x2800, 0x12800, 0x6800, 0x16800, 0xA800, 0x1A800, 0xE800, 0x1E800
};
for (i = 0; i < 16; i ++)
{
if (*((UINT32*)(anCfiAddr[i] + FLASH_BASE_ADDRESS)) != anCfiDef[i])
break;
}
if (i == 16)
g_nFlashCircuitType = FLASH_CIRCUIT_VER_6000;
}
if (g_nFlashCircuitType == FLASH_CIRCUIT_NULL)
return FALSE;
// 再判断FLASH容量,利用查询模式中的地址0x01
// enter Configuration mode
puState = (UINT*)(0x850000); //-----Any address
*puState = 0x00900090;
g_nFlashSizeType = FLASH_SIZE_NULL;
UINT32 nDeviceIDAddr;
switch (g_nFlashCircuitType)
{
case FLASH_CIRCUIT_VER_8000_D:
nDeviceIDAddr = 0x04;
break;
case FLASH_CIRCUIT_VER_8000_D_BEFORE:
nDeviceIDAddr = 0x10000;
break;
case FLASH_CIRCUIT_VER_6000:
nDeviceIDAddr = 0x10000;
break;
default:
nDeviceIDAddr = 0x04;
break;
}
switch (*((UINT*)(nDeviceIDAddr + FLASH_BASE_ADDRESS)))
{
case 0x88c288c2:
g_nFlashSizeType = FLASH_SIZE_4M;
break;
case 0x88c088c0:
g_nFlashSizeType = FLASH_SIZE_2M;
break;
default:
g_nFlashSizeType = FLASH_SIZE_NULL;
break;
}
if (g_nFlashSizeType == NULL)
return FALSE;
// 尾参数BLOCK,大小为16K(两个8K),所以对于CPU来说地址为:
// {0x00,0x4000,0x8000,0xc000,0x10000,0x14000,0x18000,0x1c000};
// 转化为FLASH的地址的方法:先按对应关系转化,然后左移两位(因为FLASH以32位操作)
// 该扇区的第二个地址(WORD),即0x02,在unlock时需要
puState = (UINT*)(0x850000); //-----Any address
*puState = 0xffffffff; // enter read mode
if (g_nFlashCircuitType == FLASH_CIRCUIT_VER_8000_D)
{
UINT32 nFlashAddr[8] = {0x00,0x4000,0x8000,0xc000,0x10000,0x14000,0x18000,0x1c000};
memcpy(g_anFlashTailAddr, nFlashAddr, 8 * sizeof(UINT32));
g_nSecondAddr = 0x08;
}
if (g_nFlashCircuitType == FLASH_CIRCUIT_VER_8000_D_BEFORE)
{
UINT32 nFlashAddr[8] = {0x00,0x10,0x08,0x10+0x08,0x04,0x4+0x10,0x04+0x08,0x04+0x08+0x10};
memcpy(g_anFlashTailAddr, nFlashAddr, 8 * sizeof(UINT32));
g_nSecondAddr = 0x8000;
}
if (g_nFlashCircuitType == FLASH_CIRCUIT_VER_6000)
{
UINT32 nFlashAddr[8] = {0x00,0x100, 0x0400, 0x100 + 0x0400,
0x1000, 0x1000+0x100, 0x1000+0x400,0x1000+0x400+0x100};
memcpy(g_anFlashTailAddr, nFlashAddr, 8 * sizeof(UINT32));
g_nSecondAddr = 0x4000;
}
UINT32 nFlashTailAddr;
if (g_nFlashSizeType == FLASH_SIZE_4M)
nFlashTailAddr = 0xbe0000;
if (g_nFlashSizeType == FLASH_SIZE_2M)
nFlashTailAddr = 0x9e0000;
for (i = 0; i < 8; i ++)
{
g_anFlashTailAddr[i] += nFlashTailAddr;
}
return TRUE;
}
//*********************************************************
// MACHINE ID不再从FLASH中取,而是根据CPU寄存器来取一个随机值
/*
VOID GetCurBedNo(UCHAR* pucMonitorID)
{
unsigned int * puState;
unsigned int uFacValue[4] = { 0, 0, 0, 0};
puState = (unsigned int *)(0x850000); //-----Any address
*puState = 0x00900090;
// 从FLASH地址的0x81-0x88读出
// WORD操作,0x81、0x83、0x85、0x87
switch (g_nFlashCircuitType)
{
case FLASH_CIRCUIT_VER_8000_D:
uFacValue[0] = *((unsigned int *)(0x800204));
uFacValue[1] = *((unsigned int *)(0x800208));
uFacValue[2] = *((unsigned int *)(0x80020C));
uFacValue[3] = *((unsigned int *)(0x800210));
break;
case FLASH_CIRCUIT_VER_8000_D_BEFORE:
uFacValue[0] = *((unsigned int *)(0x810200));
uFacValue[1] = *((unsigned int *)(0x808200));
uFacValue[2] = *((unsigned int *)(0x818200));
uFacValue[3] = *((unsigned int *)(0x804200));
break;
case FLASH_CIRCUIT_VER_6000:
uFacValue[0] = *((unsigned int *)(0x810010));
uFacValue[1] = *((unsigned int *)(0x804010));
uFacValue[2] = *((unsigned int *)(0x814010));
uFacValue[3] = *((unsigned int *)(0x808010));
break;
default:
break;
}
*puState = 0xffffffff; //Return to read array mode
pucMonitorID[0] = uFacValue[0] >> 24;
pucMonitorID[1] = (uFacValue[0] >> 16) & 0x00ff;
pucMonitorID[2] = uFacValue[1] >> 24;
pucMonitorID[3] = (uFacValue[1] >> 16) & 0x00ff;
pucMonitorID[4] = uFacValue[2] >> 24;
pucMonitorID[5] = (uFacValue[2] >> 16) & 0x00ff;
pucMonitorID[6] = uFacValue[3] >> 24;
pucMonitorID[7] = (uFacValue[3] >> 16) & 0x00ff;
return;
}
*/
/*********************************************************************
* 函数名称: WriteFlash
* 说 明: 将信息写入FLASH
* 入口参数:
* UINT32 nAddr flash's postion which info should be written in
* UCHAR* pInfo info which should be written in flash
* UINT32 nLen info's length
* 返 回 值:
* BOOL success and right of write operation
* 作 者: Shi Liangcai
* 时 间: 2002-07-17 15:57:40
*********************************************************************/
/*********************************************************************
* 函数名称: WriteFlash
* 说 明: 将信息写入FLASH
* 入口参数:
* UINT32 nAddr flash's postion which info should be written in
* UCHAR* pInfo info which should be written in flash
* UINT32 nLen info's length
* 返 回 值:
* BOOL success and right of write operation
* 作 者: Shi Liangcai
* 时 间: 2002-07-17 15:57:40
*********************************************************************/
BOOL WriteFlash(UINT32 nAddr, UCHAR* pInfo, UINT32 nLen)
{
UINT32 nTempAddr, nTempAddr1;
UINT32 *pStates;
UINT32 *pLockStatus;
UINT32* pFlashROM;
UINT32 status1, status2;
UINT32 lTempLen, lTempLen1;
UINT32 nStartIndexInTail;
UINT32 nEndIndexInTail;
UINT32 i, j;
UINT32* pSourceStart;
UINT32* sourceEnd;
UINT32* pDestineStart;
UCHAR* pTempStr;
UCHAR* pTempStr1;
UCHAR* pTempStr2;
pTempStr2 = pInfo;
nTempAddr = nAddr;
nTempAddr += FLASH_BASE_ADDRESS;
lTempLen = nLen;
if ((nTempAddr + lTempLen) > (g_anFlashTailAddr[0] + FLASH_NORMAL_BLOCK_SIZE))
return 0;
CHIP_UNPROTECT;
while (lTempLen > 0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -