Add support for MBM29F800BA/AM29F800BB and LH28F016SUT

This commit is contained in:
splash5 2019-09-26 18:33:08 +08:00
parent a5f629df78
commit edcbc842b3

View File

@ -12,7 +12,7 @@ byte secondID = 1;
unsigned long time; unsigned long time;
unsigned long blank; unsigned long blank;
unsigned long sectorSize; unsigned long sectorSize;
byte bufferSize; uint16_t bufferSize;
boolean hiROM = 1; boolean hiROM = 1;
/****************************************** /******************************************
@ -106,10 +106,7 @@ void flashromMenu8() {
println_Msg(F("Blankcheck")); println_Msg(F("Blankcheck"));
display_Update(); display_Update();
time = millis(); time = millis();
if (flashromType == 1) resetFlash8();
resetFlash29F032();
else
resetFlash29F1610();
blankcheck_Flash(); blankcheck_Flash();
break; break;
@ -119,26 +116,21 @@ void flashromMenu8() {
println_Msg(F("Please wait...")); println_Msg(F("Please wait..."));
display_Update(); display_Update();
time = millis(); time = millis();
if (flashromType == 1) {
eraseFlash29F032(); switch (flashromType) {
} case 1: eraseFlash29F032(); break;
else { case 2: eraseFlash29F1610(); break;
eraseFlash29F1610(); case 3: eraseFlash28FXXX(); break;
} }
println_Msg(F("Flashrom erased")); println_Msg(F("Flashrom erased"));
display_Update(); display_Update();
if (flashromType == 1) resetFlash8();
resetFlash29F032();
else
resetFlash29F1610();
break; break;
case 2: case 2:
time = millis(); time = millis();
if (flashromType == 1) resetFlash8();
resetFlash29F032();
else
resetFlash29F1610();
readFlash(); readFlash();
break; break;
@ -148,30 +140,39 @@ void flashromMenu8() {
fileBrowser(F("Select file")); fileBrowser(F("Select file"));
display_Clear(); display_Clear();
time = millis(); time = millis();
if (flashromType == 1)
writeFlash29F032(); switch (flashromType) {
else if (flashromType == 2) { case 1:
if (strcmp(flashid, "C2F3") == 0) writeFlash29F032();
writeFlash29F1601(); break;
else if ((strcmp(flashid, "C2F1") == 0) || (strcmp(flashid, "C2F9") == 0)) case 2:
writeFlash29F1610(); if (strcmp(flashid, "C2F3") == 0)
else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) || (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) || (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) writeFlash29F1601();
writeFlash29LV640(); else if ((strcmp(flashid, "C2F1") == 0) || (strcmp(flashid, "C2F9") == 0))
else if (strcmp(flashid, "017E") == 0) { writeFlash29F1610();
// sector size, write buffer size else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) ||
writeFlash29GL(sectorSize, bufferSize); (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) ||
} (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0))
writeFlash29LV640();
else if (strcmp(flashid, "017E") == 0) {
// sector size, write buffer size
writeFlash29GL(sectorSize, bufferSize);
}
else if ((strcmp(flashid, "0458") == 0) || (strcmp(flashid, "0158") == 0))
writeFlash29F800();
break;
case 3:
writeFlash28FXXX();
break;
} }
delay(100); delay(100);
// Reset twice just to be sure // Reset twice just to be sure
if (flashromType == 1) resetFlash8();
resetFlash29F032(); resetFlash8();
else
resetFlash29F1610();
if (flashromType == 1)
resetFlash29F032();
else
resetFlash29F1610();
verifyFlash(); verifyFlash();
break; break;
@ -179,20 +180,18 @@ void flashromMenu8() {
time = 0; time = 0;
display_Clear(); display_Clear();
println_Msg(F("ID Flashrom")); println_Msg(F("ID Flashrom"));
if (flashromType == 1) switch (flashromType) {
idFlash29F032(); case 1: idFlash29F032(); break;
else case 2: idFlash29F1610(); break;
idFlash29F1610(); case 3: idFlash28FXXX(); break;
}
println_Msg(F("")); println_Msg(F(""));
printFlash(40); printFlash(40);
println_Msg(F("")); println_Msg(F(""));
display_Update(); display_Update();
if (flashromType == 1) resetFlash8();
resetFlash29F032();
else
resetFlash29F1610();
break; break;
case 5: case 5:
@ -200,10 +199,7 @@ void flashromMenu8() {
display_Clear(); display_Clear();
println_Msg(F("Print first 70Bytes")); println_Msg(F("Print first 70Bytes"));
display_Update(); display_Update();
if (flashromType == 1) resetFlash8();
resetFlash29F032();
else
resetFlash29F1610();
printFlash(70); printFlash(70);
break; break;
@ -211,10 +207,7 @@ void flashromMenu8() {
time = 0; time = 0;
display_Clear(); display_Clear();
display_Update(); display_Update();
if (flashromType == 1) resetFlash8();
resetFlash29F032();
else
resetFlash29F1610();
resetArduino(); resetArduino();
break; break;
} }
@ -468,6 +461,16 @@ idtheflash:
flashSize = 4194304; flashSize = 4194304;
flashromType = 1; flashromType = 1;
} }
else if (strcmp(flashid, "0458") == 0) {
println_Msg(F("MBM29F800BA detected"));
flashSize = 1048576;
flashromType = 2;
}
else if (strcmp(flashid, "0158") == 0) {
println_Msg(F("AM29F800BB detected"));
flashSize = 1048576;
flashromType = 2;
}
else if (strcmp(flashid, "017E") == 0) { else if (strcmp(flashid, "017E") == 0) {
// S29GL032M // S29GL032M
if (readByte_Flash(28) == 0x1A) { if (readByte_Flash(28) == 0x1A) {
@ -486,11 +489,26 @@ idtheflash:
println_Msg(F("ATTENTION 3.3V")); println_Msg(F("ATTENTION 3.3V"));
flashromType = 2; flashromType = 2;
} }
else if (secondID) { else if (strcmp(flashid, "B088") == 0) {
// LH28F016SUT
println_Msg(F("LH28F016SUT detected"));
println_Msg(F("ATTENTION 3/5 setting"));
flashSize = 2097152;
sectorSize = 65536;
bufferSize = 256;
flashromType = 3;
}
else if (secondID == 1) {
// Backup first ID read-out // Backup first ID read-out
strncpy(vendorID, flashid, 5); strncpy(vendorID, flashid, 5);
// Read ID a second time using a different command // Read ID a second time using a different command
idFlash29F1610(); idFlash29F1610();
secondID = 2;
goto idtheflash;
}
else if (secondID == 2) {
// test if 28FXXX series flash
idFlash28FXXX();
secondID = 0; secondID = 0;
goto idtheflash; goto idtheflash;
} }
@ -509,10 +527,8 @@ idtheflash:
println_Msg(" "); println_Msg(" ");
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
display_Update(); display_Update();
if (flashromType == 1)
resetFlash29F032(); resetFlash8();
else
resetFlash29F1610();
} }
void id_Flash16() { void id_Flash16() {
@ -1245,6 +1261,159 @@ void writeFlash29GL(unsigned long sectorSize, byte bufferSize) {
} }
} }
/******************************************
29F800 functions
*****************************************/
void writeFlash29F800() {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
println_Msg(F("Flashing file "));
println_Msg(filePath);
display_Update();
// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
if (fileSize > flashSize)
print_Error(F("File size exceeds flash size."), true);
// Set data pins to output
dataOut();
// Fill sdBuffer
for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) {
myFile.read(sdBuffer, 512);
// Blink led
if (currByte % 2048 == 0)
PORTB ^= (1 << 4);
for (int c = 0; c < 512; c++) {
// Write command sequence
writeByte_Flash(0x5555 << 1, 0xaa);
writeByte_Flash(0x2aaa << 1, 0x55);
writeByte_Flash(0x5555 << 1, 0xa0);
// Write current byte
writeByte_Flash(currByte + c, sdBuffer[c]);
busyCheck29F032(sdBuffer[c]);
}
}
// Set data pins to input again
dataIn8();
// Close the file:
myFile.close();
}
else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
}
/******************************************
28FXXX series flashrom functions
*****************************************/
void idFlash28FXXX() {
dataOut();
writeByte_Flash(0x0, 0x90);
dataIn8();
// Read the two id bytes into a string
sprintf(flashid, "%02X%02X", readByte_Flash(0), readByte_Flash(1));
}
void resetFlash28FXXX() {
dataOut();
writeByte_Flash(0x0, 0xff);
dataIn();
delay(500);
}
uint8_t statusFlash28FXXX() {
dataOut();
writeByte_Flash(0x0, 0x70);
dataIn8();
return readByte_Flash(0x0);
}
void eraseFlash28FXXX() {
// only can erase block by block
for (uint32_t ba = 0; ba < flashSize; ba += sectorSize)
{
dataOut();
writeByte_Flash(0x0, 0x20);
writeByte_Flash(ba, 0xd0);
dataIn8();
while ((readByte_Flash(ba) & 0x80) == 0x00);
// blink LED
PORTB ^= (1 << 4);
}
}
void writeFlash28FXXX() {
if ((strcmp(flashid, "B088") == 0))
writeFlashLH28F0XX();
}
void writeFlashLH28F0XX() {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
println_Msg(F("Flashing file "));
println_Msg(filePath);
display_Update();
// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
if (fileSize > flashSize)
print_Error(F("File size exceeds flash size."), true);
// Fill sdBuffer
for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) {
myFile.read(sdBuffer, 512);
// Blink led
if (currByte % 2048 == 0)
PORTB ^= (1 << 4);
for (int c = 0; c < 512; c += bufferSize) {
// sequence load to page
dataOut();
writeByte_Flash(0x0, 0xe0);
writeByte_Flash(0x0, bufferSize - 1); // BCL
writeByte_Flash(0x0, 0x00); // BCH should be 0x00
for (int d = 0; d < bufferSize; d++)
writeByte_Flash(d, sdBuffer[c + d]);
// start flashing page
writeByte_Flash(0x0, 0x0c);
writeByte_Flash(0x0, bufferSize - 1); // BCL
writeByte_Flash(currByte + c, 0x00); // BCH should be 0x00
// waiting for finishing
dataIn8();
while ((readByte_Flash(currByte + c) & 0x80) == 0x00);
}
}
dataIn8();
// Close the file:
myFile.close();
}
else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
}
/****************************************** /******************************************
Common flashrom functions Common flashrom functions
*****************************************/ *****************************************/
@ -1363,6 +1532,14 @@ void printFlash(int numBytes) {
display_Update(); display_Update();
} }
void resetFlash8() {
switch (flashromType) {
case 1: resetFlash29F032(); break;
case 2: resetFlash29F1610(); break;
case 3: resetFlash28FXXX(); break;
}
}
/****************************************** /******************************************
29L3211 16bit flashrom functions 29L3211 16bit flashrom functions
*****************************************/ *****************************************/