Skip to content

Commit

Permalink
Merge pull request #2551 from ANTodorov/show_JEDEC_data
Browse files Browse the repository at this point in the history
show SPI flash JEDEC data
  • Loading branch information
iceman1001 authored Oct 2, 2024
2 parents 57ae167 + 7ffab48 commit c083d31
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...

## [unreleased][unreleased]
- show SPI flash JEDEC Manufacturer ID and Device ID in `hw status` output (@ANTodorov)
- Improved `hf iclass configcards` to support generating config cards using a different key than the default k0 as the card's key (@antiklesys)
- Added maur keys (@iceman1001)
- Fixed `hf mfu pwdgen` for the 7 byte UID (@ANTodorov)
Expand Down
37 changes: 27 additions & 10 deletions common_arm/flashmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,28 @@ void FlashmemSetSpiBaudrate(uint32_t baudrate) {
}

// read ID out
bool Flash_ReadID_90(flash_device_type_90_t *result) {
bool Flash_ReadID(flash_device_type_t *result, bool read_jedec ) {

if (Flash_CheckBusy(BUSY_TIMEOUT)) return false;

// Manufacture ID / device ID
FlashSendByte(ID);
FlashSendByte(0x00);
FlashSendByte(0x00);
FlashSendByte(0x00);

result->manufacturer_id = FlashSendByte(0xFF);
result->device_id = FlashSendLastByte(0xFF);
if ( read_jedec) {
// 0x9F JEDEC
FlashSendByte(JEDECID);

result->manufacturer_id = FlashSendByte(0xFF);
result->device_id = FlashSendByte(0xFF);
result->device_id2 = FlashSendLastByte(0xFF);
} else {
// 0x90 Manufacture ID / device ID
FlashSendByte(ID);
FlashSendByte(0x00);
FlashSendByte(0x00);
FlashSendByte(0x00);

result->manufacturer_id = FlashSendByte(0xFF);
result->device_id = FlashSendLastByte(0xFF);
}

return true;
}
Expand Down Expand Up @@ -346,8 +356,8 @@ void Flashmem_print_status(void) {

// NOTE: It would likely be more useful to use JDEC ID command 9F,
// as it provides a third byte indicative of capacity.
flash_device_type_90_t device_type = {0};
if (!Flash_ReadID_90(&device_type)) {
flash_device_type_t device_type = {0};
if (!Flash_ReadID(&device_type, false)) {
DbpString(" Device ID............... " _RED_(" --> Not Found <--"));
} else {
if (device_type.manufacturer_id == WINBOND_MANID) {
Expand All @@ -370,6 +380,13 @@ void Flashmem_print_status(void) {
device_type.device_id
);
}
if (Flash_ReadID(&device_type, true)) {
Dbprintf(" JEDEC Mfr ID / Dev ID... " _YELLOW_("%02X / %02X%02X"),
device_type.manufacturer_id,
device_type.device_id,
device_type.device_id2
);
}
}

uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
Expand Down
5 changes: 3 additions & 2 deletions common_arm/flashmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ bool Flash_Erase64k(uint8_t block);
typedef struct {
uint8_t manufacturer_id;
uint8_t device_id;
} flash_device_type_90_t; // to differentiate from JDEC ID via cmd 9F
bool Flash_ReadID_90(flash_device_type_90_t *result);
uint8_t device_id2;
} flash_device_type_t; // extra device_id used for the JEDEC ID read via cmd 9F
bool Flash_ReadID(flash_device_type_t *result, bool read_jedec);

uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len);
uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len);
Expand Down

0 comments on commit c083d31

Please sign in to comment.