summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8700
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8700')
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c31
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c9
2 files changed, 22 insertions, 18 deletions
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
index 63285dd0ff..0cc7841cd5 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
@@ -113,19 +113,19 @@ struct ftl_cxt_type
113 /* Count of currently free pages in the block pool */ 113 /* Count of currently free pages in the block pool */
114 uint16_t freecount; 114 uint16_t freecount;
115 115
116 /* Index to the first free block in the blockpool ring buffer */ 116 /* Index to the first free hyperblock in the blockpool ring buffer */
117 uint16_t nextfreeidx; 117 uint16_t nextfreeidx;
118 118
119 /* This is a counter that is used to better distribute block 119 /* This is a counter that is used to better distribute block
120 wear. It is incremented on every block erase, and if it 120 wear. It is incremented on every block erase, and if it
121 gets too high (300 on writes, 20 on sync), the most and 121 gets too high (300 on writes, 20 on sync), the most and
122 least worn block will be swapped (inferring an additional 122 least worn hyperblock will be swapped (causing an additional
123 block write) and the counter will be decreased by 20. */ 123 block write) and the counter will be decreased by 20. */
124 uint16_t swapcounter; 124 uint16_t swapcounter;
125 125
126 /* Ring buffer of currently free blocks. nextfreeidx is the 126 /* Ring buffer of currently free hyperblocks. nextfreeidx is the
127 index to freecount free ones, the other ones are currently 127 index to freecount free ones, the other ones are currently
128 allocated for scattered page blocks. */ 128 allocated for scattered page hyperblocks. */
129 uint16_t blockpool[0x14]; 129 uint16_t blockpool[0x14];
130 130
131 /* Alignment to 32 bits */ 131 /* Alignment to 32 bits */
@@ -153,7 +153,7 @@ struct ftl_cxt_type
153 uint32_t ftl_log_ptr; 153 uint32_t ftl_log_ptr;
154 154
155 /* Flag used to indicate that some erase counter pages should be committed 155 /* Flag used to indicate that some erase counter pages should be committed
156 as they were changed more than 100 times since the last commit. */ 156 because they were changed more than 100 times since the last commit. */
157 uint32_t erasedirty; 157 uint32_t erasedirty;
158 158
159 /* Seems to be unused */ 159 /* Seems to be unused */
@@ -203,7 +203,7 @@ typedef struct ftl_vfl_cxt_type
203 into vflcxtblocks. */ 203 into vflcxtblocks. */
204 uint16_t activecxtblock; 204 uint16_t activecxtblock;
205 205
206 /* Number of the first free page in the active FTL context block */ 206 /* Number of the first free page in the active VFL context block */
207 uint16_t nextcxtpage; 207 uint16_t nextcxtpage;
208 208
209 /* Seems to be unused */ 209 /* Seems to be unused */
@@ -270,7 +270,8 @@ union ftl_spare_data_type
270 /* Seems to be unused */ 270 /* Seems to be unused */
271 uint8_t field_8; 271 uint8_t field_8;
272 272
273 /* Type field, 0x40 (data page) or 0x41 (last data page of block) */ 273 /* Type field, 0x40 (data page) or 0x41
274 (last data page of hyperblock) */
274 uint8_t type; 275 uint8_t type;
275 276
276 /* ECC mark, usually 0xFF. If an error occurred while reading the 277 /* ECC mark, usually 0xFF. If an error occurred while reading the
@@ -379,7 +380,7 @@ union ftl_spare_data_type ftl_sparebuffer __attribute__((aligned(16)));
379/* Lowlevel BBT for each bank */ 380/* Lowlevel BBT for each bank */
380uint8_t ftl_bbt[4][0x410]; 381uint8_t ftl_bbt[4][0x410];
381 382
382/* Erase countes for the vBlocks */ 383/* Erase counters for the vBlocks */
383uint16_t ftl_erasectr[0x2000]; 384uint16_t ftl_erasectr[0x2000];
384 385
385/* Used by ftl_log */ 386/* Used by ftl_log */
@@ -462,8 +463,8 @@ uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt)
462 if (memcmp(&ftl_buffer[0x18], "BBT", 4) != 0) return 1; 463 if (memcmp(&ftl_buffer[0x18], "BBT", 4) != 0) return 1;
463 unk1 = ((uint16_t*)ftl_buffer)[0x10]; 464 unk1 = ((uint16_t*)ftl_buffer)[0x10];
464 unk2 = ((uint16_t*)ftl_buffer)[0x11]; 465 unk2 = ((uint16_t*)ftl_buffer)[0x11];
465 unk3 = ((uint16_t*)ftl_buffer)[((uint32_t*)ftl_buffer)[4] * 0xC + 10] 466 unk3 = ((uint16_t*)ftl_buffer)[((uint32_t*)ftl_buffer)[4] * 6 + 10]
466 + ((uint16_t*)ftl_buffer)[((uint32_t*)ftl_buffer)[4] * 0xC + 11]; 467 + ((uint16_t*)ftl_buffer)[((uint32_t*)ftl_buffer)[4] * 6 + 11];
467 for (i = 0; i < unk1; i++) 468 for (i = 0; i < unk1; i++)
468 { 469 {
469 for (j = 0; ; j++) 470 for (j = 0; ; j++)
@@ -976,16 +977,16 @@ uint32_t ftl_open(void)
976 struct ftl_vfl_cxt_type* cxt = ftl_vfl_get_newest_cxt(); 977 struct ftl_vfl_cxt_type* cxt = ftl_vfl_get_newest_cxt();
977 978
978 uint32_t ftlcxtblock = 0xffffffff; 979 uint32_t ftlcxtblock = 0xffffffff;
979 uint32_t minlpn = 0xffffffff; 980 uint32_t minusn = 0xffffffff;
980 for (i = 0; i < 3; i++) 981 for (i = 0; i < 3; i++)
981 { 982 {
982 ret = ftl_vfl_read(ppb * (*cxt).ftlctrlblocks[i], 983 ret = ftl_vfl_read(ppb * (*cxt).ftlctrlblocks[i],
983 ftl_buffer, &ftl_sparebuffer, 1, 0); 984 ftl_buffer, &ftl_sparebuffer, 1, 0);
984 if ((ret &= 0x11F) != 0) continue; 985 if ((ret &= 0x11F) != 0) continue;
985 if (ftl_sparebuffer.user.type - 0x43 > 4) continue; 986 if (ftl_sparebuffer.meta.type - 0x43 > 4) continue;
986 if (ftlcxtblock != 0xffffffff && ftl_sparebuffer.user.lpn >= minlpn) 987 if (ftlcxtblock != 0xffffffff && ftl_sparebuffer.meta.usn >= minusn)
987 continue; 988 continue;
988 minlpn = ftl_sparebuffer.user.lpn; 989 minusn = ftl_sparebuffer.meta.usn;
989 ftlcxtblock = (*cxt).ftlctrlblocks[i]; 990 ftlcxtblock = (*cxt).ftlctrlblocks[i];
990 } 991 }
991 992
@@ -998,7 +999,7 @@ uint32_t ftl_open(void)
998 ret = ftl_vfl_read(ppb * ftlcxtblock + i, 999 ret = ftl_vfl_read(ppb * ftlcxtblock + i,
999 ftl_buffer, &ftl_sparebuffer, 1, 0); 1000 ftl_buffer, &ftl_sparebuffer, 1, 0);
1000 if ((ret & 0x11F) != 0) continue; 1001 if ((ret & 0x11F) != 0) continue;
1001 else if (ftl_sparebuffer.user.type == 0x43) 1002 else if (ftl_sparebuffer.meta.type == 0x43)
1002 { 1003 {
1003 memcpy(&ftl_cxt, ftl_buffer, 0x28C); 1004 memcpy(&ftl_cxt, ftl_buffer, 0x28C);
1004 ftlcxtfound = 1; 1005 ftlcxtfound = 1;
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c
index 7961b94f7f..3b5f88d3c2 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c
@@ -406,9 +406,12 @@ uint32_t nand_read_page(uint32_t bank, uint32_t page, void* databuffer,
406 return nand_unlock(rc); 406 return nand_unlock(rc);
407 } 407 }
408 if (nand_transfer_data(bank, 0, spare, 0x40)) return nand_unlock(1); 408 if (nand_transfer_data(bank, 0, spare, 0x40)) return nand_unlock(1);
409 memcpy(nand_ecc, &spare[0xC], 0x28); 409 if (databuffer)
410 rc |= (ecc_decode(3, data, nand_ecc) & 0xF) << 4; 410 {
411 if (databuffer && data != databuffer) memcpy(databuffer, data, 0x800); 411 memcpy(nand_ecc, &spare[0xC], 0x28);
412 rc |= (ecc_decode(3, data, nand_ecc) & 0xF) << 4;
413 if (data != databuffer) memcpy(databuffer, data, 0x800);
414 }
412 memset(nand_ctrl, 0xFF, 0x200); 415 memset(nand_ctrl, 0xFF, 0x200);
413 memcpy(nand_ctrl, spare, 0xC); 416 memcpy(nand_ctrl, spare, 0xC);
414 memcpy(nand_ecc, &spare[0x34], 0xC); 417 memcpy(nand_ecc, &spare[0x34], 0xC);