From b9af1e0967beb142e0eebd1399fbcc0f39da3f3f Mon Sep 17 00:00:00 2001 From: sulokutdcmago Date: Tue, 11 Sep 2012 17:41:30 +0000 Subject: [PATCH] Now shows image and inserted card serial number in raw restore mode. --- source/freetype.c | 27 +++++++++++++----- source/raw.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++- source/raw.h | 1 + 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/source/freetype.c b/source/freetype.c index f834b5d..c1719e8 100644 --- a/source/freetype.c +++ b/source/freetype.c @@ -693,7 +693,15 @@ void showCardInfo(int sel){ //START card image info START //put block 1 in cardheader SDLoadCardImageHeader((char*)filelist[sel]); - //get the serial + + //get the true serial + u64 serial1[4]; + for (i=0;i<4;i++){ + memcpy(&serial1[i], (u8*)&cardheader+(8*i), sizeof(u64)); + } + u64 serialA = serial1[0]^serial1[1]^serial1[2]^serial1[3]; + + //get the flash ID getserial(imageserial); sprintf(txt, "Card image flash ID"); @@ -708,18 +716,19 @@ void showCardInfo(int sel){ DrawText(x,y,txt); y+=20; + sprintf(txt, "Serial N.: %016llX", serialA); + DrawText(x,y,txt); + y+=20; + sprintf(txt, "Size: %d blocks", (cardheader.SizeMb[1]*16)-5); DrawText(x, y, txt); y+=40; //END card image info END //START real card info START - err = MountCard(MEM_CARD); - if (err < 0) - { - WaitCardError("CardMount", err); - return; /*** Unable to mount the card ***/ - } + + //In this call we mount the card, so we can later read the SRAM unscrambled flash ID + u64 cardserialno = Card_SerialNo(MEM_CARD); sramex = __SYS_LockSramEx(); __SYS_UnlockSramEx(0); @@ -742,6 +751,10 @@ void showCardInfo(int sel){ DrawText(x,y,txt); y+=20; + sprintf(txt, "Serial N.: %016llX", cardserialno); + DrawText(x,y,txt); + y+=20; + sprintf(txt, "Size: %d blocks", (memsize*16)-5); DrawText(x,y,txt); //END real card info END diff --git a/source/raw.c b/source/raw.c index c1c26f0..197bb9d 100644 --- a/source/raw.c +++ b/source/raw.c @@ -62,7 +62,8 @@ void getserial(u8 *serial) } } - + + void ClearFlashID(s32 chn){ int i; @@ -86,6 +87,75 @@ void _erase_callback(s32 chn,s32 result) erase_data =1; } + +u64 Card_SerialNo(s32 slot) +{ + int err; + u32 SectorSize = 0; + + CARD_Init(NULL,NULL); + EXI_ProbeReset(); + + err = MountCard(slot); + if (err < 0) + { + WaitCardError("SerialNo", err); + return -1; /*** Unable to mount the card ***/ + } + + usleep(10*1000); + + err = CARD_GetSectorSize(slot,&SectorSize); + if(err < 0 ) + { + WaitCardError("SerialNo Sectsize", err); + return -1; + } + + CardBuffer = (u8*)memalign(32,SectorSize); + if(CardBuffer == NULL) + { + WaitPrompt("SerialNo: Failed to malloc memory."); + return -1; + } + s32 current_block = 0; + int read = 0; + + while( 1 ) + { + read_data = 0; + + if( (err != 0) || current_block >= 1) + break; + err = __card_read(slot,0,SectorSize,CardBuffer+SectorSize*current_block,_read_callback); + if(err == 0) + { + while(read_data == 0) + usleep(1*1000); //sleep untill the read is done + read = read + SectorSize; + current_block++; + + } + else + { + mem_free(CardBuffer); + WaitCardError("BakRaw __read", err); + return -1; + } + } + + //get the true serial + u64 serial1[4]; + int i; + for (i=0;i<4;i++){ + memcpy(&serial1[i], CardBuffer+(8*i), sizeof(u64)); + } + u64 serialA = serial1[0]^serial1[1]^serial1[2]^serial1[3]; + + mem_free(CardBuffer); + return serialA; +} + //output is 29 char long void time2name(char *name) { diff --git a/source/raw.h b/source/raw.h index 1006e53..cd9b7c5 100644 --- a/source/raw.h +++ b/source/raw.h @@ -19,5 +19,6 @@ typedef struct { void freecardbuf(); void getserial(u8 *serial); +u64 Card_SerialNo(s32 slot); s8 BackupRawImage(s32 slot, s32 *bytes_writen); s8 RestoreRawImage(s32 slot, char *sdfilename, s32 *bytes_writen);