Now shows image and inserted card serial number in raw restore mode.

This commit is contained in:
sulokutdcmago
2012-09-11 17:41:30 +00:00
parent efdbcc6f5e
commit b9af1e0967
3 changed files with 92 additions and 8 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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);