freemyipod r68 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r67‎ | r68 | r69 >
Date:22:47, 9 August 2010
Author:theseven
Status:new
Tags:
Comment:
Remove unaligned NAND transfer support, the caller is now responsible for aligning buffers properly
Modified paths:
  • /embios/trunk/target/ipodnano2g/ftl.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/nand.c (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano2g/nand.c
@@ -94,7 +94,6 @@
9595 static struct mutex ecc_mtx;
9696 static struct wakeup ecc_wakeup;
9797
98 -static uint8_t nand_data[0x800] CACHEALIGN_ATTR;
9998 static uint8_t nand_ctrl[0x200] CACHEALIGN_ATTR;
10099 static uint8_t nand_spare[0x40] CACHEALIGN_ATTR;
101100 static uint8_t nand_ecc[0x30] CACHEALIGN_ATTR;
@@ -375,12 +374,17 @@
376375 void* sparebuffer, uint32_t doecc,
377376 uint32_t checkempty)
378377 {
379 - uint8_t* data = nand_data;
 378+ uint8_t* data = (uint8_t*)databuffer;
380379 uint8_t* spare = nand_spare;
381 - if (databuffer && !((uint32_t)databuffer & 0xf))
382 - data = (uint8_t*)databuffer;
383 - if (sparebuffer && !((uint32_t)sparebuffer & 0xf))
384 - spare = (uint8_t*)sparebuffer;
 380+ if (sparebuffer) spare = (uint8_t*)sparebuffer;
 381+ if ((uint32_t)databuffer & 0xf)
 382+ panicf(PANIC_KILLUSERTHREADS,
 383+ "nand_read_page: Misaligned data buffer at %08X (bank %lu, page %lu)",
 384+ (unsigned int)databuffer, bank, page);
 385+ if ((uint32_t)sparebuffer & 0xf)
 386+ panicf(PANIC_KILLUSERTHREADS,
 387+ "nand_read_page: Misaligned spare buffer at %08X (bank %lu, page %lu)",
 388+ (unsigned int)sparebuffer, bank, page);
385389 mutex_lock(&nand_mtx, TIMEOUT_BLOCK);
386390 nand_last_activity_value = USEC_TIMER;
387391 if (!nand_powered) nand_power_up();
@@ -387,22 +391,21 @@
388392 uint32_t rc, eccresult;
389393 nand_set_fmctrl0(bank, FMCTRL0_ENABLEDMA);
390394 if (nand_send_cmd(NAND_CMD_READ)) return nand_unlock(1);
391 - if (nand_send_address(page, databuffer ? 0 : 0x800))
 395+ if (nand_send_address(page, data ? 0 : 0x800))
392396 return nand_unlock(1);
393397 if (nand_send_cmd(NAND_CMD_READ2)) return nand_unlock(1);
394398 if (nand_wait_status_ready(bank)) return nand_unlock(1);
395 - if (databuffer)
 399+ if (data)
396400 if (nand_transfer_data(bank, 0, data, 0x800))
397401 return nand_unlock(1);
398402 rc = 0;
399403 if (!doecc)
400404 {
401 - if (databuffer && data != databuffer) memcpy(databuffer, data, 0x800);
402405 if (sparebuffer)
403406 {
404407 if (nand_transfer_data(bank, 0, spare, 0x40))
405408 return nand_unlock(1);
406 - if (sparebuffer && spare != sparebuffer)
 409+ if (sparebuffer)
407410 memcpy(sparebuffer, spare, 0x800);
408411 if (checkempty)
409412 rc = nand_check_empty((uint8_t*)sparebuffer) << 1;
@@ -414,7 +417,6 @@
415418 {
416419 memcpy(nand_ecc, &spare[0xC], 0x28);
417420 rc |= (ecc_decode(3, data, nand_ecc) & 0xF) << 4;
418 - if (data != databuffer) memcpy(databuffer, data, 0x800);
419421 }
420422 memset(nand_ctrl, 0xFF, 0x200);
421423 memcpy(nand_ctrl, spare, 0xC);
@@ -423,7 +425,6 @@
424426 rc |= (eccresult & 0xF) << 8;
425427 if (sparebuffer)
426428 {
427 - if (spare != sparebuffer) memcpy(sparebuffer, spare, 0x40);
428429 if (eccresult & 1) memset(sparebuffer, 0xFF, 0xC);
429430 else memcpy(sparebuffer, nand_ctrl, 0xC);
430431 }
@@ -436,26 +437,26 @@
437438 void* databuffer, void* sparebuffer,
438439 uint32_t doecc, uint32_t wait)
439440 {
440 - uint8_t* data = nand_data;
 441+ uint8_t* data = (uint8_t*)databuffer;
441442 uint8_t* spare = nand_spare;
442 - if (databuffer && !((uint32_t)databuffer & 0xf))
443 - data = (uint8_t*)databuffer;
444 - if (sparebuffer && !((uint32_t)sparebuffer & 0xf))
445 - spare = (uint8_t*)sparebuffer;
 443+ if (sparebuffer) spare = (uint8_t*)sparebuffer;
 444+ if ((uint32_t)databuffer & 0xf)
 445+ panicf(PANIC_KILLUSERTHREADS,
 446+ "nand_write_page: Misaligned data buffer at %08X (bank %lu, page %lu)",
 447+ (unsigned int)databuffer, bank, page);
 448+ if ((uint32_t)sparebuffer & 0xf)
 449+ panicf(PANIC_KILLUSERTHREADS,
 450+ "nand_write_page: Misaligned spare buffer at %08X (bank %lu, page %lu)",
 451+ (unsigned int)sparebuffer, bank, page);
446452 mutex_lock(&nand_mtx, TIMEOUT_BLOCK);
447453 nand_last_activity_value = USEC_TIMER;
448454 if (!nand_powered) nand_power_up();
449 - if (sparebuffer)
450 - {
451 - if (spare != sparebuffer) memcpy(spare, sparebuffer, 0x40);
452 - }
453 - else memset(spare, 0xFF, 0x40);
 455+ if (!sparebuffer) memset(spare, 0xFF, 0x40);
454456 nand_set_fmctrl0(bank, FMCTRL0_ENABLEDMA);
455457 if (nand_send_cmd(NAND_CMD_PROGRAM)) return nand_unlock(1);
456 - if (nand_send_address(page, databuffer ? 0 : 0x800))
 458+ if (nand_send_address(page, data ? 0 : 0x800))
457459 return nand_unlock(1);
458 - if (databuffer && data != databuffer) memcpy(data, databuffer, 0x800);
459 - if (databuffer) nand_transfer_data_start(bank, 1, data, 0x800);
 460+ if (data) nand_transfer_data_start(bank, 1, data, 0x800);
460461 if (doecc)
461462 {
462463 if (ecc_encode(3, data, nand_ecc)) return nand_unlock(1);
@@ -465,7 +466,7 @@
466467 if (ecc_encode(0, nand_ctrl, nand_ecc)) return nand_unlock(1);
467468 memcpy(&spare[0x34], nand_ecc, 0xC);
468469 }
469 - if (databuffer)
 470+ if (data)
470471 if (nand_transfer_data_collect(1))
471472 return nand_unlock(1);
472473 if (sparebuffer || doecc)
Index: embios/trunk/target/ipodnano2g/ftl.c
@@ -1287,6 +1287,11 @@
12881288 DEBUGF("FTL: Reading %d sectors starting at %d", count, sector);
12891289 #endif
12901290
 1291+ if ((uint32_t)buffer & 0xf)
 1292+ panicf(PANIC_KILLTHREAD,
 1293+ "ftl_read: Misaligned data buffer at %08X (sector %lu, count %lu)",
 1294+ (unsigned int)buffer, sector, count);
 1295+
12911296 if (sector + count > ftl_nand_type->userblocks * ppb)
12921297 {
12931298 DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);
@@ -1942,6 +1947,11 @@
19431948 DEBUGF("FTL: Writing %d sectors starting at %d", count, sector);
19441949 #endif
19451950
 1951+ if ((uint32_t)buffer & 0xf)
 1952+ panicf(PANIC_KILLTHREAD,
 1953+ "ftl_write: Misaligned data buffer at %08X (sector %lu, count %lu)",
 1954+ (unsigned int)buffer, sector, count);
 1955+
19461956 if (sector + count > ftl_nand_type->userblocks * ppb)
19471957 {
19481958 DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);