mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
rework addressing the review comments
Reverted 'mfr_id' to 'manufacturer_id'
Moved devices table definition to flashmem.h
Single global variable 'spi_flash_pages64k'
The local structure holding the actual device data is used in firmware.c only
difference in code:
```
text data bss dec hex filename
223189 138560 6067 367816 59cc8 ./armsrc/obj/fullimage.elf <-- c9e751d
darkside: fix backdoor support
223437 138624 6075 368136 59e08 ./armsrc/obj/fullimage.elf <-- this commit
======================================
+248 +64 +8 +320
```
This commit is contained in:
parent
3b6530cb92
commit
76aaef96cc
6 changed files with 76 additions and 74 deletions
|
@ -2748,11 +2748,11 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload->startidx == DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_p->p64k)) {
|
if (payload->startidx == DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_pages64k)) {
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
Flash_WriteEnable();
|
Flash_WriteEnable();
|
||||||
Flash_Erase4k(3, 0xC);
|
Flash_Erase4k(3, 0xC);
|
||||||
} else if (payload->startidx == DEFAULT_MF_KEYS_OFFSET_P(spi_flash_p->p64k)) {
|
} else if (payload->startidx == DEFAULT_MF_KEYS_OFFSET_P(spi_flash_pages64k)) {
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
Flash_WriteEnable();
|
Flash_WriteEnable();
|
||||||
Flash_Erase4k(3, 0x8);
|
Flash_Erase4k(3, 0x8);
|
||||||
|
@ -2762,11 +2762,11 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
Flash_WriteEnable();
|
Flash_WriteEnable();
|
||||||
Flash_Erase4k(3, 0xA);
|
Flash_Erase4k(3, 0xA);
|
||||||
} else if (payload->startidx == DEFAULT_ICLASS_KEYS_OFFSET_P(spi_flash_p->p64k)) {
|
} else if (payload->startidx == DEFAULT_ICLASS_KEYS_OFFSET_P(spi_flash_pages64k)) {
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
Flash_WriteEnable();
|
Flash_WriteEnable();
|
||||||
Flash_Erase4k(3, 0xB);
|
Flash_Erase4k(3, 0xB);
|
||||||
} else if (payload->startidx == FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_p->p64k)) {
|
} else if (payload->startidx == FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_pages64k)) {
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
Flash_WriteEnable();
|
Flash_WriteEnable();
|
||||||
Flash_Erase4k(3, 0xF);
|
Flash_Erase4k(3, 0xF);
|
||||||
|
@ -2789,7 +2789,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (page < spi_flash_p->p64k-1) {
|
if (page < spi_flash_pages64k-1) {
|
||||||
isok = Flash_WipeMemoryPage(page);
|
isok = Flash_WipeMemoryPage(page);
|
||||||
// let spiffs check and update its info post flash erase
|
// let spiffs check and update its info post flash erase
|
||||||
rdv40_spiffs_check();
|
rdv40_spiffs_check();
|
||||||
|
@ -2836,7 +2836,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
rdv40_validation_t *info = (rdv40_validation_t *)BigBuf_malloc(sizeof(rdv40_validation_t));
|
rdv40_validation_t *info = (rdv40_validation_t *)BigBuf_malloc(sizeof(rdv40_validation_t));
|
||||||
|
|
||||||
bool isok = Flash_ReadData(FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_p->p64k), info->signature, FLASH_MEM_SIGNATURE_LEN);
|
bool isok = Flash_ReadData(FLASH_MEM_SIGNATURE_OFFSET_P(spi_flash_pages64k), info->signature, FLASH_MEM_SIGNATURE_LEN);
|
||||||
|
|
||||||
if (FlashInit()) {
|
if (FlashInit()) {
|
||||||
Flash_UniqueID(info->flashid);
|
Flash_UniqueID(info->flashid);
|
||||||
|
@ -2856,11 +2856,11 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
if (FlashInit()) {
|
if (FlashInit()) {
|
||||||
isok = true;
|
isok = true;
|
||||||
if (g_dbglevel >= DBG_DEBUG) {
|
if (g_dbglevel >= DBG_DEBUG) {
|
||||||
Dbprintf(" CMD_FLASHMEM_PAGE64K 0x%02x (%d 64k pages)", spi_flash_p->p64k, spi_flash_p->p64k);
|
Dbprintf(" CMD_FLASHMEM_PAGE64K 0x%02x (%d 64k pages)", spi_flash_pages64k, spi_flash_pages64k);
|
||||||
}
|
}
|
||||||
FlashStop();
|
FlashStop();
|
||||||
}
|
}
|
||||||
reply_mix(CMD_ACK, isok, 0, 0, &spi_flash_p->p64k, sizeof(uint8_t));
|
reply_mix(CMD_ACK, isok, 0, 0, &spi_flash_pages64k, sizeof(uint8_t));
|
||||||
|
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -2148,7 +2148,7 @@ void T55xx_ChkPwds(uint8_t flags, bool ledcontrol) {
|
||||||
BigBuf_Clear_EM();
|
BigBuf_Clear_EM();
|
||||||
uint16_t isok = 0;
|
uint16_t isok = 0;
|
||||||
uint8_t counter[2] = {0x00, 0x00};
|
uint8_t counter[2] = {0x00, 0x00};
|
||||||
isok = Flash_ReadData(DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_p->p64k), counter, sizeof(counter));
|
isok = Flash_ReadData(DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_pages64k), counter, sizeof(counter));
|
||||||
if (isok != sizeof(counter))
|
if (isok != sizeof(counter))
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
|
||||||
|
@ -2164,7 +2164,7 @@ void T55xx_ChkPwds(uint8_t flags, bool ledcontrol) {
|
||||||
// adjust available pwd_count
|
// adjust available pwd_count
|
||||||
pwd_count = pwd_size_available / 4;
|
pwd_count = pwd_size_available / 4;
|
||||||
|
|
||||||
isok = Flash_ReadData(DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_p->p64k) + 2, pwds, pwd_size_available);
|
isok = Flash_ReadData(DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_pages64k) + 2, pwds, pwd_size_available);
|
||||||
if (isok != pwd_size_available)
|
if (isok != pwd_size_available)
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
|
||||||
|
|
|
@ -1789,7 +1789,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
BigBuf_free();
|
BigBuf_free();
|
||||||
uint16_t isok = 0;
|
uint16_t isok = 0;
|
||||||
uint8_t size[2] = {0x00, 0x00};
|
uint8_t size[2] = {0x00, 0x00};
|
||||||
isok = Flash_ReadData(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_p->p64k), size, 2);
|
isok = Flash_ReadData(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_pages64k), size, 2);
|
||||||
if (isok != 2)
|
if (isok != 2)
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
|
||||||
|
@ -1808,7 +1808,7 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
|
||||||
if (datain == NULL)
|
if (datain == NULL)
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
|
||||||
isok = Flash_ReadData(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_p->p64k) + 2, datain, key_mem_available);
|
isok = Flash_ReadData(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_pages64k) + 2, datain, key_mem_available);
|
||||||
if (isok != key_mem_available)
|
if (isok != key_mem_available)
|
||||||
goto OUT;
|
goto OUT;
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,7 @@ typedef uint8_t u8_t;
|
||||||
// Instead of giving parameters in config struct, singleton build must
|
// Instead of giving parameters in config struct, singleton build must
|
||||||
// give parameters in defines below.
|
// give parameters in defines below.
|
||||||
#ifndef SPIFFS_CFG_PHYS_SZ
|
#ifndef SPIFFS_CFG_PHYS_SZ
|
||||||
#define SPIFFS_CFG_PHYS_SZ(ignore) (1024 * 64 * (spi_flash_p->p64k - 1))
|
#define SPIFFS_CFG_PHYS_SZ(ignore) (1024 * 64 * (spi_flash_pages64k - 1))
|
||||||
#endif
|
#endif
|
||||||
#ifndef SPIFFS_CFG_PHYS_ERASE_SZ
|
#ifndef SPIFFS_CFG_PHYS_ERASE_SZ
|
||||||
#define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (4*1024)
|
#define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (4*1024)
|
||||||
|
|
|
@ -43,34 +43,9 @@ static uint32_t FLASHMEM_SPIBAUDRATE = FLASH_BAUD;
|
||||||
|
|
||||||
#ifndef AS_BOOTROM
|
#ifndef AS_BOOTROM
|
||||||
|
|
||||||
const spi_flash_t SpiFlashTable[] = {
|
|
||||||
// first element is the default of 4 * 64kB pages (256kB)
|
|
||||||
{ 0x00, 0x00, 0x0000, 4, "unknown" }, // 256k
|
|
||||||
// Manufacturer: Puya
|
|
||||||
{ 0x85, 0x00, 0x6015, 32, "P25Q16H" }, // 2048k
|
|
||||||
/// Manufacturer: Renesas
|
|
||||||
{ 0x1F, 0x46, 0x0000, 32, "AT25XE161D" }, // 2048k
|
|
||||||
{ 0x1F, 0x47, 0x0000, 64, "AT25XE321D" }, // 4096k
|
|
||||||
// Manufacturer: Winbond
|
|
||||||
{ 0xEF, 0x00, 0x3012, 4, "W25X20BV" }, // 256k
|
|
||||||
{ 0xEF, 0x00, 0x3013, 8, "W25X40BV" }, // 512k
|
|
||||||
|
|
||||||
{ 0xEF, 0x00, 0x4013, 8, "W25Q40BV" }, // 512k
|
|
||||||
{ 0xEF, 0x00, 0x4014, 16, "W25Q80BV" }, // 1024k
|
|
||||||
{ 0xEF, 0x14, 0x4015, 32, "W25Q16BV" }, // 2048k
|
|
||||||
{ 0xEF, 0x15, 0x4016, 64, "W25Q32BV" }, // 4096k
|
|
||||||
|
|
||||||
{ 0xEF, 0x21, 0x7022, 4, "W25Q02JV" },
|
|
||||||
// identified by Manufacturer /Device ID
|
|
||||||
// { 0xEF, 0x05, 0x0000, 1, "Winbond!!!" },
|
|
||||||
{ 0xEF, 0x10, 0x0000, 2, "W25*10BV!!!" }, // 128k
|
|
||||||
{ 0xEF, 0x11, 0x0000, 4, "W25*20BV" }, // 256k
|
|
||||||
{ 0xEF, 0x12, 0x0000, 8, "W25*40BV" }, // 512k
|
|
||||||
{ 0xEF, 0x13, 0x0000, 16, "W25*80BV" } // 1024k
|
|
||||||
};
|
|
||||||
const spi_flash_t *spi_flash_p = SpiFlashTable;
|
|
||||||
spi_flash_t spi_flash_data = {0};
|
spi_flash_t spi_flash_data = {0};
|
||||||
|
uint8_t spi_flash_pages64k = 4;
|
||||||
|
|
||||||
void FlashmemSetSpiBaudrate(uint32_t baudrate) {
|
void FlashmemSetSpiBaudrate(uint32_t baudrate) {
|
||||||
FLASHMEM_SPIBAUDRATE = baudrate;
|
FLASHMEM_SPIBAUDRATE = baudrate;
|
||||||
|
@ -87,7 +62,7 @@ bool Flash_ReadID(flash_device_type_t *result, bool read_jedec) {
|
||||||
// 0x9F JEDEC
|
// 0x9F JEDEC
|
||||||
FlashSendByte(JEDECID);
|
FlashSendByte(JEDECID);
|
||||||
|
|
||||||
result->mfr_id = (FlashSendByte(0xFF) & 0xFF);
|
result->manufacturer_id = (FlashSendByte(0xFF) & 0xFF);
|
||||||
result->device_id = (FlashSendByte(0xFF) & 0xFF);
|
result->device_id = (FlashSendByte(0xFF) & 0xFF);
|
||||||
result->device_id2 = (FlashSendLastByte(0xFF) & 0xFF);
|
result->device_id2 = (FlashSendLastByte(0xFF) & 0xFF);
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,7 +72,7 @@ bool Flash_ReadID(flash_device_type_t *result, bool read_jedec) {
|
||||||
FlashSendByte(0x00);
|
FlashSendByte(0x00);
|
||||||
FlashSendByte(0x00);
|
FlashSendByte(0x00);
|
||||||
|
|
||||||
result->mfr_id = (FlashSendByte(0xFF) & 0xFF);
|
result->manufacturer_id = (FlashSendByte(0xFF) & 0xFF);
|
||||||
result->device_id = (FlashSendLastByte(0xFF) & 0xFF);
|
result->device_id = (FlashSendLastByte(0xFF) & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,8 +154,8 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// out-of-range
|
// out-of-range
|
||||||
if (((address >> 16) & 0xFF) > spi_flash_p->p64k) {
|
if (((address >> 16) & 0xFF) > spi_flash_pages64k) {
|
||||||
Dbprintf("Flash_WriteData, block out-of-range %02x > %02x", (address >> 16) & 0xFF, spi_flash_p->p64k);
|
Dbprintf("Flash_WriteData, block out-of-range %02x > %02x", (address >> 16) & 0xFF, spi_flash_pages64k);
|
||||||
FlashStop();
|
FlashStop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -217,8 +192,8 @@ uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((address >> 16) & 0xFF) > spi_flash_p->p64k) {
|
if (((address >> 16) & 0xFF) > spi_flash_pages64k) {
|
||||||
Dbprintf("Flash_WriteDataCont, block out-of-range %02x > %02x", (address >> 16) & 0xFF, spi_flash_p->p64k);
|
Dbprintf("Flash_WriteDataCont, block out-of-range %02x > %02x", (address >> 16) & 0xFF, spi_flash_pages64k);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +271,7 @@ bool Flash_WipeMemory(void) {
|
||||||
|
|
||||||
// Each block is 64Kb. Four blocks
|
// Each block is 64Kb. Four blocks
|
||||||
// one block erase takes 1s ( 1000ms )
|
// one block erase takes 1s ( 1000ms )
|
||||||
for (uint8_t i=0; i < spi_flash_p->p64k; i++) {
|
for (uint8_t i=0; i < spi_flash_pages64k; i++) {
|
||||||
Flash_WriteEnable();
|
Flash_WriteEnable();
|
||||||
Flash_Erase64k(i);
|
Flash_Erase64k(i);
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
|
@ -316,7 +291,7 @@ void Flash_WriteEnable(void) {
|
||||||
// execution time: 0.8ms / 800us
|
// execution time: 0.8ms / 800us
|
||||||
bool Flash_Erase4k(uint8_t block, uint8_t sector) {
|
bool Flash_Erase4k(uint8_t block, uint8_t sector) {
|
||||||
|
|
||||||
if (block > spi_flash_p->p64k || sector > MAX_SECTORS) return false;
|
if (block > spi_flash_pages64k || sector > MAX_SECTORS) return false;
|
||||||
|
|
||||||
FlashSendByte(SECTORERASE);
|
FlashSendByte(SECTORERASE);
|
||||||
FlashSendByte(block);
|
FlashSendByte(block);
|
||||||
|
@ -351,7 +326,7 @@ bool Flash_Erase32k(uint32_t address) {
|
||||||
// 0x03 00 00 -- 0x 03 FF FF == block 3
|
// 0x03 00 00 -- 0x 03 FF FF == block 3
|
||||||
bool Flash_Erase64k(uint8_t block) {
|
bool Flash_Erase64k(uint8_t block) {
|
||||||
|
|
||||||
if (block > spi_flash_p->p64k) return false;
|
if (block > spi_flash_pages64k) return false;
|
||||||
|
|
||||||
FlashSendByte(BLOCK64ERASE);
|
FlashSendByte(BLOCK64ERASE);
|
||||||
FlashSendByte(block);
|
FlashSendByte(block);
|
||||||
|
@ -379,20 +354,20 @@ void Flashmem_print_status(void) {
|
||||||
|
|
||||||
if (spi_flash_data.device_id > 0 ) {
|
if (spi_flash_data.device_id > 0 ) {
|
||||||
Dbprintf(" Mfr ID / Dev ID......... " _YELLOW_("%02X / %02X"),
|
Dbprintf(" Mfr ID / Dev ID......... " _YELLOW_("%02X / %02X"),
|
||||||
spi_flash_data.mfr_id,
|
spi_flash_data.manufacturer_id,
|
||||||
spi_flash_data.device_id
|
spi_flash_data.device_id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spi_flash_data.jedec_id > 0) {
|
if (spi_flash_data.jedec_id > 0) {
|
||||||
Dbprintf(" JEDEC Mfr ID / Dev ID... " _YELLOW_("%02X / %04X"),
|
Dbprintf(" JEDEC Mfr ID / Dev ID... " _YELLOW_("%02X / %04X"),
|
||||||
spi_flash_data.mfr_id,
|
spi_flash_data.manufacturer_id,
|
||||||
spi_flash_data.jedec_id
|
spi_flash_data.jedec_id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dbprintf(" Device.................. " _YELLOW_("%s"), spi_flash_p->desc);
|
Dbprintf(" Device.................. " _YELLOW_("%s"), spi_flash_data.device);
|
||||||
Dbprintf(" Memory size............. " _YELLOW_("%d kB (%d pages * 64k)"), spi_flash_p->p64k * 64, spi_flash_p->p64k);
|
Dbprintf(" Memory size............. " _YELLOW_("%d kB (%d pages * 64k)"), spi_flash_pages64k * 64, spi_flash_pages64k);
|
||||||
|
|
||||||
uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
Flash_UniqueID(uid);
|
Flash_UniqueID(uid);
|
||||||
|
@ -420,7 +395,7 @@ void Flashmem_print_info(void) {
|
||||||
uint16_t num;
|
uint16_t num;
|
||||||
|
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
uint16_t isok = Flash_ReadDataCont(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_p->p64k), keysum, 2);
|
uint16_t isok = Flash_ReadDataCont(DEFAULT_MF_KEYS_OFFSET_P(spi_flash_pages64k), keysum, 2);
|
||||||
if (isok == 2) {
|
if (isok == 2) {
|
||||||
num = ((keysum[1] << 8) | keysum[0]);
|
num = ((keysum[1] << 8) | keysum[0]);
|
||||||
if (num != 0xFFFF && num != 0x0)
|
if (num != 0xFFFF && num != 0x0)
|
||||||
|
@ -428,7 +403,7 @@ void Flashmem_print_info(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
isok = Flash_ReadDataCont(DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_p->p64k), keysum, 2);
|
isok = Flash_ReadDataCont(DEFAULT_T55XX_KEYS_OFFSET_P(spi_flash_pages64k), keysum, 2);
|
||||||
if (isok == 2) {
|
if (isok == 2) {
|
||||||
num = ((keysum[1] << 8) | keysum[0]);
|
num = ((keysum[1] << 8) | keysum[0]);
|
||||||
if (num != 0xFFFF && num != 0x0)
|
if (num != 0xFFFF && num != 0x0)
|
||||||
|
@ -436,7 +411,7 @@ void Flashmem_print_info(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||||
isok = Flash_ReadDataCont(DEFAULT_ICLASS_KEYS_OFFSET_P(spi_flash_p->p64k), keysum, 2);
|
isok = Flash_ReadDataCont(DEFAULT_ICLASS_KEYS_OFFSET_P(spi_flash_pages64k), keysum, 2);
|
||||||
if (isok == 2) {
|
if (isok == 2) {
|
||||||
num = ((keysum[1] << 8) | keysum[0]);
|
num = ((keysum[1] << 8) | keysum[0]);
|
||||||
if (num != 0xFFFF && num != 0x0)
|
if (num != 0xFFFF && num != 0x0)
|
||||||
|
@ -446,37 +421,40 @@ void Flashmem_print_info(void) {
|
||||||
FlashStop();
|
FlashStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FlashDetect(const spi_flash_t **spi_flash_ptr) {
|
bool FlashDetect(void) {
|
||||||
flash_device_type_t flash_data = {0};
|
flash_device_type_t flash_data = {0};
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
// read JEDEC
|
// read using 0x9F (JEDEC)
|
||||||
if (Flash_ReadID(&flash_data, true)) {
|
if (Flash_ReadID(&flash_data, true)) {
|
||||||
spi_flash_data.mfr_id = flash_data.mfr_id;
|
spi_flash_data.manufacturer_id = flash_data.manufacturer_id;
|
||||||
spi_flash_data.jedec_id = (flash_data.device_id <<8) + flash_data.device_id2;
|
spi_flash_data.jedec_id = (flash_data.device_id <<8) + flash_data.device_id2;
|
||||||
ret = true;
|
ret = true;
|
||||||
} else{
|
} else{
|
||||||
if (g_dbglevel > 3) Dbprintf("Flash_ReadID failed reading JEDEC (0x9F)");
|
if (g_dbglevel > 3) Dbprintf("Flash_ReadID failed reading JEDEC (0x9F)");
|
||||||
}
|
}
|
||||||
|
// read using 0x90 (Manufacturer / Device ID)
|
||||||
if (Flash_ReadID(&flash_data, false)) {
|
if (Flash_ReadID(&flash_data, false)) {
|
||||||
if (spi_flash_data.mfr_id == 0) {
|
if (spi_flash_data.manufacturer_id == 0) {
|
||||||
spi_flash_data.mfr_id = flash_data.mfr_id;
|
spi_flash_data.manufacturer_id = flash_data.manufacturer_id;
|
||||||
}
|
}
|
||||||
spi_flash_data.device_id = flash_data.device_id;
|
spi_flash_data.device_id = flash_data.device_id;
|
||||||
ret = true;
|
ret = true;
|
||||||
} else {
|
} else {
|
||||||
if (g_dbglevel > 3) Dbprintf("Flash_ReadID failed reading Mfr/Dev (0x90)");
|
if (g_dbglevel > 3) Dbprintf("Flash_ReadID failed reading Mfr/Dev (0x90)");
|
||||||
}
|
}
|
||||||
|
// default device is 'unknown'
|
||||||
|
spi_flash_data.device = SpiFlashTable[0].device;
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
for (int i=0; i < ARRAYLEN(SpiFlashTable); i++) {
|
for (int i=0; i < ARRAYLEN(SpiFlashTable); i++) {
|
||||||
if (SpiFlashTable[i].mfr_id == spi_flash_data.mfr_id) {
|
if (SpiFlashTable[i].manufacturer_id == spi_flash_data.manufacturer_id) {
|
||||||
if (SpiFlashTable[i].jedec_id == spi_flash_data.jedec_id) {
|
if (SpiFlashTable[i].jedec_id == spi_flash_data.jedec_id) {
|
||||||
*spi_flash_ptr = *spi_flash_ptr + i;
|
spi_flash_pages64k = SpiFlashTable[i].pages64k;
|
||||||
|
spi_flash_data.device = SpiFlashTable[i].device;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SpiFlashTable[i].device_id == spi_flash_data.device_id) {
|
if (SpiFlashTable[i].device_id == spi_flash_data.device_id) {
|
||||||
*spi_flash_ptr = *spi_flash_ptr + i;
|
spi_flash_data.device = SpiFlashTable[i].device;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -501,8 +479,8 @@ bool FlashInit(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef AS_BOOTROM
|
#ifndef AS_BOOTROM
|
||||||
if (spi_flash_data.mfr_id == 0) {
|
if (spi_flash_data.manufacturer_id == 0) {
|
||||||
if (!FlashDetect(&spi_flash_p)) {
|
if (!FlashDetect()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ bool Flash_Erase4k(uint8_t block, uint8_t sector);
|
||||||
bool Flash_Erase64k(uint8_t block);
|
bool Flash_Erase64k(uint8_t block);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t mfr_id;
|
uint8_t manufacturer_id;
|
||||||
uint8_t device_id;
|
uint8_t device_id;
|
||||||
uint8_t device_id2;
|
uint8_t device_id2;
|
||||||
} flash_device_type_t; // extra device_id used for the JEDEC ID read via cmd 9F
|
} flash_device_type_t; // extra device_id used for the JEDEC ID read via cmd 9F
|
||||||
|
@ -137,18 +137,42 @@ void Flashmem_print_status(void);
|
||||||
void Flashmem_print_info(void);
|
void Flashmem_print_info(void);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t mfr_id;
|
uint8_t manufacturer_id;
|
||||||
uint8_t device_id;
|
uint8_t device_id;
|
||||||
uint16_t jedec_id;
|
uint16_t jedec_id;
|
||||||
uint8_t p64k;
|
uint8_t pages64k;
|
||||||
char *desc;
|
char *device;
|
||||||
}spi_flash_t;
|
}spi_flash_t;
|
||||||
|
|
||||||
extern const spi_flash_t spiFlashTable[];
|
static const spi_flash_t SpiFlashTable[] = {
|
||||||
extern const spi_flash_t *spi_flash_p;
|
// first element is the default of 4 * 64kB pages (256kB)
|
||||||
extern spi_flash_t spi_flash_data;
|
{ 0x00, 0x00, 0x0000, 4, "unknown" }, // 256k
|
||||||
|
// Manufacturer: Puya
|
||||||
|
{ 0x85, 0x00, 0x6015, 32, "P25Q16H" }, // 2048k
|
||||||
|
/// Manufacturer: Renesas
|
||||||
|
{ 0x1F, 0x46, 0x0000, 32, "AT25XE161D" }, // 2048k
|
||||||
|
{ 0x1F, 0x47, 0x0000, 64, "AT25XE321D" }, // 4096k
|
||||||
|
// Manufacturer: Winbond
|
||||||
|
{ 0xEF, 0x00, 0x3012, 4, "W25X20BV" }, // 256k
|
||||||
|
{ 0xEF, 0x00, 0x3013, 8, "W25X40BV" }, // 512k
|
||||||
|
|
||||||
bool FlashDetect(const spi_flash_t **);
|
{ 0xEF, 0x00, 0x4013, 8, "W25Q40BV" }, // 512k
|
||||||
|
{ 0xEF, 0x00, 0x4014, 16, "W25Q80BV" }, // 1024k
|
||||||
|
{ 0xEF, 0x14, 0x4015, 32, "W25Q16BV" }, // 2048k
|
||||||
|
{ 0xEF, 0x15, 0x4016, 64, "W25Q32BV" }, // 4096k
|
||||||
|
|
||||||
|
{ 0xEF, 0x21, 0x7022, 4, "W25Q02JV" },
|
||||||
|
// identified by Manufacturer /Device ID
|
||||||
|
// { 0xEF, 0x05, 0x0000, 1, "Winbond!!!" },
|
||||||
|
{ 0xEF, 0x10, 0x0000, 2, "W25*10BV!!!" }, // 128k
|
||||||
|
{ 0xEF, 0x11, 0x0000, 4, "W25*20BV" }, // 256k
|
||||||
|
{ 0xEF, 0x12, 0x0000, 8, "W25*40BV" }, // 512k
|
||||||
|
{ 0xEF, 0x13, 0x0000, 16, "W25*80BV" } // 1024k
|
||||||
|
};
|
||||||
|
|
||||||
|
extern uint8_t spi_flash_pages64k;
|
||||||
|
|
||||||
|
bool FlashDetect(void);
|
||||||
|
|
||||||
#ifndef ARRAYLEN
|
#ifndef ARRAYLEN
|
||||||
# define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0]))
|
# define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0]))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue