Skip to content

Commit

Permalink
Completed FTL_Open, but still need to do subroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
planetbeing committed Nov 11, 2008
1 parent 53d3def commit 87b228f
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 17 deletions.
114 changes: 105 additions & 9 deletions openiboot/ftl.c
Expand Up @@ -97,8 +97,8 @@ static uint8_t* StoreCxt;
static int FTL_Init() {
int numPagesToWriteInStoreCxt = 0;

int x = ((Data->userSubBlksTotal + 23) * 2) / Data->bytesPerPage;
if((((Data->userSubBlksTotal + 23) * 2) % Data->bytesPerPage) != 0) {
int x = ((Data->userSubBlksTotal + 23) * sizeof(uint16_t)) / Data->bytesPerPage;
if((((Data->userSubBlksTotal + 23) * sizeof(uint16_t)) % Data->bytesPerPage) != 0) {
x++;
}

Expand Down Expand Up @@ -138,12 +138,12 @@ static int FTL_Init() {
memset(pstFTLCxt->field_3D8, 0, sizeof(pstFTLCxt->field_3D8));
}

pstFTLCxt->field_31C = NULL;
pstFTLCxt->field_31C = 0;

pstFTLCxt->field_198 = malloc(Data->userSubBlksTotal * 2);
pstFTLCxt->field_1A0 = malloc((Data->pagesPerSubBlk * 2) * 18);
pstFTLCxt->field_19C = malloc((Data->userSubBlksTotal + 23) * 2);
pstFTLCxt->field_3B0 = malloc((Data->userSubBlksTotal + 23) * 2);
pstFTLCxt->field_19C = (uint16_t*) malloc((Data->userSubBlksTotal + 23) * sizeof(uint16_t));
pstFTLCxt->field_3B0 = (uint16_t*) malloc((Data->userSubBlksTotal + 23) * sizeof(uint16_t));

FTLData4 = malloc(Data->pagesPerSubBlk * 12);

Expand Down Expand Up @@ -480,6 +480,10 @@ static int FTL_Restore() {
return FALSE;
}

static int sub_18013C5A(uint8_t* pageBuffer) {
return FALSE;
}

static int FTL_Open(int* pagesAvailable, int* bytesPerPage) {
int refreshPage;
int ret;
Expand Down Expand Up @@ -529,6 +533,7 @@ static int FTL_Open(int* pagesAvailable, int* bytesPerPage) {


if(ftlCxtBlock == 0xffff) {
bufferPrintf("ftl: Cannot find context!\r\n");
goto FTL_Open_Error_Release;
}

Expand Down Expand Up @@ -560,12 +565,14 @@ static int FTL_Open(int* pagesAvailable, int* bytesPerPage) {
if(!ftlCxtFound)
goto FTL_Open_Error_Release;

int numData = (Data->userSubBlksTotal * 2) / Data->bytesPerPage;
int pagesToRead;

pagesToRead = (Data->userSubBlksTotal * 2) / Data->bytesPerPage;
if(((Data->userSubBlksTotal * 2) % Data->bytesPerPage) != 0)
numData++;
pagesToRead++;

for(i = 0; i < numData; i++) {
if(VFL_Read(pstFTLCxt->page[i], pageBuffer, spareBuffer, TRUE, &refreshPage) != 0)
for(i = 0; i < pagesToRead; i++) {
if(VFL_Read(pstFTLCxt->pages_for_198[i], pageBuffer, spareBuffer, TRUE, &refreshPage) != 0)
goto FTL_Open_Error_Release;

int toRead = Data->bytesPerPage;
Expand All @@ -576,6 +583,95 @@ static int FTL_Open(int* pagesAvailable, int* bytesPerPage) {
memcpy(((uint8_t*)pstFTLCxt->field_198) + (i * Data->bytesPerPage), pageBuffer, toRead);
}

pagesToRead = (Data->pagesPerSubBlk * 34) / Data->bytesPerPage;
if(((Data->pagesPerSubBlk * 34) % Data->bytesPerPage) != 0)
pagesToRead++;

for(i = 0; i < pagesToRead; i++) {
if(VFL_Read(pstFTLCxt->pages_for_1A0[i], pageBuffer, spareBuffer, TRUE, &refreshPage) != 0)
goto FTL_Open_Error_Release;

int toRead = Data->bytesPerPage;
if(toRead > ((Data->pagesPerSubBlk * 34) - (i * Data->bytesPerPage))) {
toRead = (Data->pagesPerSubBlk * 34) - (i * Data->bytesPerPage);
}

memcpy(((uint8_t*)pstFTLCxt->field_1A0) + (i * Data->bytesPerPage), pageBuffer, toRead);
}

pagesToRead = ((Data->userSubBlksTotal + 23) * sizeof(uint16_t)) / Data->bytesPerPage;
if((((Data->userSubBlksTotal + 23) * sizeof(uint16_t)) % Data->bytesPerPage) != 0)
pagesToRead++;

for(i = 0; i < pagesToRead; i++) {
if(VFL_Read(pstFTLCxt->pages_for_19C[i], pageBuffer, spareBuffer, TRUE, &refreshPage) != 0)
goto FTL_Open_Error_Release;

int toRead = Data->bytesPerPage;
if(toRead > (((Data->pagesPerSubBlk + 23) * sizeof(uint16_t)) - (i * Data->bytesPerPage))) {
toRead = ((Data->pagesPerSubBlk + 23) * sizeof(uint16_t)) - (i * Data->bytesPerPage);
}

memcpy(((uint8_t*)pstFTLCxt->field_19C) + (i * Data->bytesPerPage), pageBuffer, toRead);
}

int success = FALSE;

if(FTLCxtBuffer->versionLower == 0x46560000 && FTLCxtBuffer->versionUpper == 0xB9A9FFFF) {
pagesToRead = ((Data->userSubBlksTotal + 23) * sizeof(uint16_t)) / Data->bytesPerPage;
if((((Data->userSubBlksTotal + 23) * sizeof(uint16_t)) % Data->bytesPerPage) != 0)
pagesToRead++;

success = TRUE;
for(i = 0; i < pagesToRead; i++) {
if(VFL_Read(pstFTLCxt->pages_for_3B0[i], pageBuffer, spareBuffer, TRUE, &refreshPage) != 0) {
success = FALSE;
break;
}

int toRead = Data->bytesPerPage;
if(toRead > (((Data->pagesPerSubBlk + 23) * sizeof(uint16_t)) - (i * Data->bytesPerPage))) {
toRead = ((Data->pagesPerSubBlk + 23) * sizeof(uint16_t)) - (i * Data->bytesPerPage);
}

memcpy(((uint8_t*)pstFTLCxt->field_3B0) + (i * Data->bytesPerPage), pageBuffer, toRead);
}

if((pstFTLCxt->field_3D4 + 1) == 0) {
int x = pstFTLCxt->field_3D0 / Data->pagesPerSubBlk;
if(x == 0 || x <= Data->userSubBlksTotal) {
if(VFL_Read(pstFTLCxt->field_3D0, pageBuffer, spareBuffer, TRUE, &refreshPage) != 0)
goto FTL_Open_Error_Release;

sub_18013C5A(pageBuffer);
}
}
} else {
bufferPrintf("ftl: updating the FTL from seemingly compatible version\r\n");
for(i = 0; i < (Data->userSubBlksTotal + 23); i++) {
pstFTLCxt->field_3B0[i] = 0x1388;
}

for(i = 0; i < 5; i++) {
pstFTLCxt->elements2[i].field_0 = -1;
pstFTLCxt->elements2[i].field_2 = -1;
}

pstFTLCxt->field_3C8 = 0;
pstFTLCxt->field_31C = 0;
FTLCxtBuffer->versionLower = 0x46560000;
FTLCxtBuffer->versionUpper = 0xB9A9FFFF;

success = TRUE;
}

if(success) {
free(pageBuffer);
free(spareBuffer);
*pagesAvailable = Data->userPagesTotal;
*bytesPerPage = Data->bytesPerPage;
return 0;
}

FTL_Open_Error_Release:
free(pageBuffer);
Expand Down
27 changes: 19 additions & 8 deletions openiboot/includes/ftl.h
Expand Up @@ -27,23 +27,34 @@ typedef struct FTLCxtElement {
uint32_t field_10; // 0x10
} FTLCxtElement;

typedef struct FTLCxtElement2 {
uint16_t field_0; // 0x0
uint16_t field_2; // 0x2
} FTLCxtElement2;

typedef struct FTLCxt {
uint8_t unk1[0x38]; // 0x0
uint32_t page[88]; // 0x38
uint32_t pages_for_198[18]; // 0x38
uint32_t pages_for_19C[36]; // 0x80
uint32_t pages_for_1A0[34]; // 0x110
void* field_198; // 0x198
void* field_19C; // 0x19C
uint16_t* field_19C; // 0x19C
void* field_1A0; // 0x1A0
FTLCxtElement elements[18]; // 0x1A4
uint8_t unk2[6]; // 0x30C
uint16_t thing[3]; // 0x312
uint32_t field_318; // 0x318
void* field_31C; // 0x31C
uint8_t unk3[0x90]; // 0x320
void* field_3B0; // 0x3B0
uint8_t unk4[0x24]; // 0x3B4
uint32_t field_31C; // 0x31C
uint32_t pages_for_3B0[36]; // 0x320
uint16_t* field_3B0; // 0x3B0
FTLCxtElement2 elements2[5]; // 0x3B4
uint32_t field_3C8; // 0x3C8
uint32_t field_3CC; // 0x3CC
uint32_t field_3D0; // 0x3D0
uint32_t field_3D4; // 0x3D4
uint8_t field_3D8[0x420]; // 0x3D8
uint32_t field_7F8; // 0x7F8
uint32_t field_7FC; // 0x7FC
uint32_t versionLower; // 0x7F8
uint32_t versionUpper; // 0x7FC
} FTLCxt;

typedef struct VFLData1Type {
Expand Down

0 comments on commit 87b228f

Please sign in to comment.