?? flashutil.c
字號:
chipEraseM29W,
writeWordM29W16
},
{
M28W320CB,
"M28W320CB",
NULL,
0x88BB88BB,
1024 * 1024 * 8,
0,
M28W320CB_blockInfo,
resetM29W,
blockUnprotectCFI,
blockEraseCFI,
chipEraseSimple,
writeWordCFI
},
{
E28F640J3Ax16,
"E28F640J3Ax16/M58LW064Ax16/MT28F640J3RGx16",
NULL,
0x00000017,
1024 * 1024 * 8,
0,
E28F640J3A16_blockInfo,
resetM58LW16,
blockUnprotectCFI16,
blockEraseCFI16,
chipEraseSimple,
writeWordCFI16
},
{
E28F640J3A,
"E28F640J3x/M58LW064x/MT28F640J3RG",
NULL,
0x00170017,
1024 * 1024 * 16,
0,
E28F640J3A_blockInfo,
resetM58LW,
blockUnprotectCFI,
blockEraseCFI,
chipEraseSimple,
writeWordCFI
},
{
M58LW064Cx16,
"M58LW064Cx16",
NULL,
0x00008820,
1024 * 1024 * 8,
0,
M58LW064C_blockInfo,
resetM58LW16,
blockUnprotectCFI16,
blockEraseCFI16,
chipEraseSimple,
writeWordCFI16
},
{
M58LW032A,
"M58LW032A",
NULL,
0x88168816,
1024 * 1024 * 8,
0,
M58LW032A_blockInfo,
resetM58LW,
blockUnprotectCFI,
blockEraseCFI,
chipEraseSimple,
writeWordCFI
},
{
M29DW324DB,
"M29DW324DB",
NULL,
0x225D225D,
1024 * 1024 * 8,
0,
M29DW324DB_blockInfo,
resetM29W,
NULL,
blockEraseM29W,
chipEraseSimple,
writeWordM29W
},
{
M29DW324DBx16,
"M29DW324DBx16",
NULL,
0x0000225D,
1024 * 1024 * 4,
0,
M29DW324DB16_blockInfo,
resetM29W16,
NULL,
blockEraseM29W16,
chipEraseSimple,
writeWordM29W16
},
{
M29KW064E,
"M29KW064E",
NULL,
0x000088AF,
1024 * 1024 * 8,
0,
M29KW064E_blockInfo,
resetM29W16,
NULL,
blockEraseM29W16,
chipEraseSimple,
writeWordM29W16
},
{
M28W640FSUx16,
"M28W640FSUx16",
NULL,
0x00008857,
1024 * 1024 * 8,
0,
M28W640FSUx16_blockInfo,
resetM58LW16,
blockUnprotectCFI16,
blockEraseCFI16,
chipEraseSimple,
writeWordCFI16
},
{
S29GL064A,
"S29GL064A",
NULL,
0x0000227e,
1024 * 1024 * 8,
0,
M29W640DB_blockInfo /*M29W640DT_blockInfo*/,
resetM29W16,
NULL,
blockEraseM29W16,
chipEraseM29W,
writeWordM29W16
},
{0}
};
/*
* Our supported boards
*/
static flashTarget_t supportedTargets[] = {
#if defined(__st200__)
#if defined(__stm8000__)
{"mb379", 2, writeEnable_mb379, writeDisable_mb379, NULL, NULL},
{"mb392", 1, writeEnable_mb392, writeDisable_mb392, NULL, NULL},
#elif defined(__stb5301__)
{"mb390", 1, writeEnable_mb390, writeDisable_mb390, NULL, NULL},
{"mb424", 1, NULL, NULL, NULL, NULL},
{"mb435", 1, NULL, NULL, NULL, NULL},
#elif defined(__stm8010__)
{"mb421", 1, writeEnable_mb421, writeDisable_mb421, NULL, NULL},
{"mb426", 1, writeEnable_mb426, writeDisable_mb426, NULL, NULL},
#elif defined(__stx5525__)
{"mb428", 1, NULL, NULL, switchOnVDD_mb428, switchOffVDD_mb428},
#endif
#else
#if defined(__st40ra__)
{"db457", 2, NULL, NULL, NULL, NULL},
{"mb293", 2, writeEnable_mb293, writeDisable_mb293, NULL, NULL},
{"mb350", 2, writeEnable_mb293, writeDisable_mb293, NULL, NULL},
{"mb360", 1, NULL, NULL, NULL, NULL},
{"mb374", 2, writeEnable_mb374, writeDisable_mb374, NULL, NULL},
#elif defined(__st40gx1__)
{"mb317a", 1, NULL, NULL, switchOnVDD_mb317, switchOffVDD_mb317},
{"mb317b", 1, NULL, NULL, switchOnVDD_mb317, switchOffVDD_mb317},
{"mediaref", 1, NULL, NULL, NULL, NULL},
#elif defined(__sti5528__)
{"espresso", 1, NULL, NULL, NULL, NULL},
{"mb376", 1, writeEnable_mb376, writeDisable_mb376, switchOnVDD_mb376, switchOffVDD_mb376},
#elif defined(__stm8000__)
{"mb379", 2, writeEnable_mb379, writeDisable_mb379, NULL, NULL},
{"mb392", 1, writeEnable_mb392, writeDisable_mb392, NULL, NULL},
{"tmmidr04", 1, writeEnable_tmmidr04, writeDisable_tmmidr04, NULL, NULL},
{"tmmlr1", 1, writeEnable_tmmidr04, writeDisable_tmmidr04, NULL, NULL},
{"tmmlr2", 1, writeEnable_tmmlr2, writeDisable_tmmlr2, NULL, NULL},
#elif defined(__stb7100__)
{"mb411", 1, writeEnable_mb411, writeDisable_mb411, NULL, NULL},
{"mb411stb7100", 1, writeEnable_mb411, writeDisable_mb411, NULL, NULL},
{"mb442", 1, NULL, NULL, NULL, NULL},
{"mb442stb7100", 1, NULL, NULL, NULL, NULL},
{"stb7100ref", 1, NULL, NULL, NULL, NULL},
#elif defined(__stb7109__)
{"mb411stb7109", 1, writeEnable_mb411, writeDisable_mb411, NULL, NULL},
{"mb442stb7109", 1, NULL, NULL, NULL, NULL},
{"mb448", 1, NULL, NULL, NULL, NULL},
#elif defined(__sti7200__)
{"mb519", 1, writeEnable_mb519, writeDisable_mb519, NULL, NULL},
#elif defined(__stv0498__)
{"mb521", 1, NULL, NULL, NULL, NULL},
#elif defined(__std1000__)
{"mb548", 1, NULL, NULL, NULL, NULL},
#elif defined(__std2000__)
{"mb422", 1, NULL, NULL, NULL, NULL},
#endif
#endif
{0}
};
/*
* Routine to dump a FLASH block map file to a given FILE*
* Note that this file format doesn't cope with any gaps between FLASH chips in
* the address map.
*/
void dumpBlockMap(flashDevice_t** devices, FILE* fp)
{
int i, j;
unsigned int lastAddr = 0;
for (i = 0; devices[i]; i++)
{
fprintf(fp, "# FLASH block layout for %s FLASH chip\n", devices[i]->deviceName);
lastAddr = devices[i]->baseAddress;
for (j = 0; devices[i]->blockInfo[j].offset != 0; j++)
{
fprintf(fp, "0x%08x, 0x%08x\n", lastAddr, devices[i]->blockInfo[j].size);
lastAddr = devices[i]->baseAddress + devices[i]->blockInfo[j].offset;
}
}
fprintf(fp, "0x%08x, 0x%08x ## End of FLASH\n", lastAddr, 0);
}
/*
* Routine to show progress of an operation.
* Calls back to user supplied hook.
*/
static void showProgress(flashProgress_t progressFn, unsigned int done, unsigned int total)
{
if (progressFn)
{
progressFn(done, total);
}
}
/*
* Routine to perform a FLASH reset
*/
static void reset(flashDevice_t* device)
{
if (device->reset)
{
device->reset(device);
}
}
/*
* Routine to unprotect a block of FLASH
*/
static void blockUnprotect(flashDevice_t* device, unsigned int blockAddress)
{
if (device->blockUnprotect)
{
device->blockUnprotect(device, blockAddress);
}
}
/*
* Routine to put the FLASH back into read mode.
* Using 16 bit accesses
*/
static void resetM58LT16(flashDevice_t* device)
{
volatile unsigned short* commandPtr;
int n;
commandPtr = (volatile unsigned short*)physToUncachedFlashAddr(device->baseAddress);
/* The M58LT has 16 internal banks and we reset all of them */
for (n = 0; n < 16; n++)
{
*commandPtr = CMD_READ_ARRAY16;
commandPtr += (device->bankSize / 16) / sizeof(*commandPtr);
}
task_delay(PAUSE_PERIOD);
}
/*
* Routine to put the FLASH back into read mode.
*/
static void resetM58LW(flashDevice_t* device)
{
volatile unsigned int* commandPtr;
commandPtr = (volatile unsigned int*)physToUncachedFlashAddr(device->baseAddress);
*commandPtr = CMD_READ_ARRAY;
task_delay(PAUSE_PERIOD);
}
/*
* Routine to put the FLASH back into read mode.
* Using 16 bit accesses
*/
static void resetM58LW16(flashDevice_t* device)
{
volatile unsigned short* commandPtr;
commandPtr = (volatile unsigned short*)physToUncachedFlashAddr(device->baseAddress);
*commandPtr = CMD_READ_ARRAY16;
task_delay(PAUSE_PERIOD);
}
/*
* Routine to put the FLASH back into read mode.
*/
static void resetM29W(flashDevice_t* device)
{
volatile unsigned int* commandPtr1;
volatile unsigned int* commandPtr2;
commandPtr1 = (volatile unsigned int*)physToUncachedFlashAddr(device->baseAddress + 0x1554);
commandPtr2 = (volatile unsigned int*)physToUncachedFlashAddr(device->baseAddress + 0x2AA8);
*commandPtr1 = 0x00AA00AA;
*commandPtr2 = 0x00550055;
*commandPtr1 = 0x00F000F0;
task_delay(PAUSE_PERIOD);
}
/*
* Routine to put the FLASH back into read mode. (16 bit version)
*/
static void resetM29W16(flashDevice_t* device)
{
volatile unsigned short* commandPtr1;
volatile unsigned short* commandPtr2;
commandPtr1 = (volatile unsigned short*)physToUncachedFlashAddr(device->baseAddress + 0x1554);
commandPtr2 = (volatile unsigned short*)physToUncachedFlashAddr(device->baseAddress + 0x2AA8);
*commandPtr1 = 0x00AA;
*commandPtr2 = 0x0055;
*commandPtr1 = 0x00F0;
task_delay(PAUSE_PERIOD);
}
/*
* Routine to write a word of data to an M29W type of FLASH
*/
static void writeWordM29W(flashDevice_t* device, unsigned int address, unsigned int value)
{
volatile unsigned int* command1Ptr;
volatile unsigned int* command2Ptr;
volatile unsigned int* dataPtr;
osclock_t endTime;
/* Don't bother writing words which are the default erased value */
if (value == 0xFFFFFFFF)
return;
command1Ptr = (volatile unsigned int*)physToUncachedFlashAddr(device->baseAddress + 0x1554);
command2Ptr = (volatile unsigned int*)physToUncachedFlashAddr(device->baseAddress + 0x2AA8);
dataPtr = (volatile unsigned int*)physToUncachedFlashAddr(address);
/*
* Write flash-unlock sequence to device
*/
*command1Ptr = 0x00AA00AA;
*command2Ptr = 0x00550055;
*command1Ptr = 0x00A000A0;
*dataPtr = value;
/*
* Poll the FLASH to wait for the value to stabilise
*/
endTime = time_plus(time_now(), time_ticks_per_sec() * WRITE_TIMEOUT);
while ((*dataPtr != value) && !time_after(time_now(), endTime))
{
}
if (*dataPtr != value)
{
fprintf(stderr, "\nError writing to %s @ 0x%08x\n", device->deviceName, address);
fprintf(stderr, "\nWrote %08x, read %08x\n", value, *dataPtr);
exit(1);
}
}
/*
* Routine to write a word of data to an M29W type of FLASH
*/
static void writeM29W16(flashDevice_t* device, unsigned int address, unsigned short value)
{
volatile unsigned short* command1Ptr;
volatile unsigned short* command2Ptr;
volatile unsigned short* dataPtr;
osclock_t endTime;
command1Ptr = (volatile unsigned short*)physToUncachedFlashAddr(device->baseAddress + 0xAAA);
command2Ptr = (volatile unsigned short*)physToUncachedFlashAddr(device->baseAddress + 0x554);
dataPtr = (volatile unsigned short*)physToUncachedFlashAddr(address);
/*
* Write flash-unlock sequence to device
*/
*command1Ptr = 0x00AA;
*command2Ptr = 0x0055;
*command1Ptr = 0x00A0;
*dataPtr = value;
/*
* Poll the FLASH to wait for the value to stabilise
*/
endTime = time_plus(time_now(), time_ticks_per_sec() * WRITE_TIMEOUT);
while ((*dataPtr != value) && !time_after(time_now(), endTime))
{
}
if (*dataPtr != value)
{
fprintf(stderr, "\nError writing to %s @ 0x%08x\n", device->deviceName, address);
fprintf(stderr, "\nWrote %04x, read %04x\n", value, *dataPtr);
exit(1);
}
}
static void writeWordM29W16(flashDevice_t* device, unsigned int address, unsigned int value)
{
/* Don't bother writing words which are the default erased value */
if (value == 0xFFFFFFFF)
return;
writeM29W16(device, address + 2, (unsigned short)((value >> 16)));
writeM29W16(device, address, (unsigned short)(value & 0xFFFF));
}
/*
* Routine to write a 32-bit word of data to a CFI device
*/
static void writeWordCFI(flashDevice_t* device, unsigned int address, unsigned int value)
{
volatile unsigned int* dataPtr;
osclock_t endTime;
/* Don't bother writing words which are the default erased value */
if (value == 0xFFFFFFFF)
return;
dataPtr = (volatile unsigned int*)physToUncachedFlashAddr(address);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -