Index: embios/trunk/target/ipodnano2g/nand.c |
— | — | @@ -94,7 +94,6 @@ |
95 | 95 | static struct mutex ecc_mtx;
|
96 | 96 | static struct wakeup ecc_wakeup;
|
97 | 97 |
|
98 | | -static uint8_t nand_data[0x800] CACHEALIGN_ATTR;
|
99 | 98 | static uint8_t nand_ctrl[0x200] CACHEALIGN_ATTR;
|
100 | 99 | static uint8_t nand_spare[0x40] CACHEALIGN_ATTR;
|
101 | 100 | static uint8_t nand_ecc[0x30] CACHEALIGN_ATTR;
|
— | — | @@ -375,12 +374,17 @@ |
376 | 375 | void* sparebuffer, uint32_t doecc,
|
377 | 376 | uint32_t checkempty)
|
378 | 377 | {
|
379 | | - uint8_t* data = nand_data;
|
| 378 | + uint8_t* data = (uint8_t*)databuffer;
|
380 | 379 | 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);
|
385 | 389 | mutex_lock(&nand_mtx, TIMEOUT_BLOCK);
|
386 | 390 | nand_last_activity_value = USEC_TIMER;
|
387 | 391 | if (!nand_powered) nand_power_up();
|
— | — | @@ -387,22 +391,21 @@ |
388 | 392 | uint32_t rc, eccresult;
|
389 | 393 | nand_set_fmctrl0(bank, FMCTRL0_ENABLEDMA);
|
390 | 394 | 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))
|
392 | 396 | return nand_unlock(1);
|
393 | 397 | if (nand_send_cmd(NAND_CMD_READ2)) return nand_unlock(1);
|
394 | 398 | if (nand_wait_status_ready(bank)) return nand_unlock(1);
|
395 | | - if (databuffer)
|
| 399 | + if (data)
|
396 | 400 | if (nand_transfer_data(bank, 0, data, 0x800))
|
397 | 401 | return nand_unlock(1);
|
398 | 402 | rc = 0;
|
399 | 403 | if (!doecc)
|
400 | 404 | {
|
401 | | - if (databuffer && data != databuffer) memcpy(databuffer, data, 0x800);
|
402 | 405 | if (sparebuffer)
|
403 | 406 | {
|
404 | 407 | if (nand_transfer_data(bank, 0, spare, 0x40))
|
405 | 408 | return nand_unlock(1);
|
406 | | - if (sparebuffer && spare != sparebuffer)
|
| 409 | + if (sparebuffer)
|
407 | 410 | memcpy(sparebuffer, spare, 0x800);
|
408 | 411 | if (checkempty)
|
409 | 412 | rc = nand_check_empty((uint8_t*)sparebuffer) << 1;
|
— | — | @@ -414,7 +417,6 @@ |
415 | 418 | {
|
416 | 419 | memcpy(nand_ecc, &spare[0xC], 0x28);
|
417 | 420 | rc |= (ecc_decode(3, data, nand_ecc) & 0xF) << 4;
|
418 | | - if (data != databuffer) memcpy(databuffer, data, 0x800);
|
419 | 421 | }
|
420 | 422 | memset(nand_ctrl, 0xFF, 0x200);
|
421 | 423 | memcpy(nand_ctrl, spare, 0xC);
|
— | — | @@ -423,7 +425,6 @@ |
424 | 426 | rc |= (eccresult & 0xF) << 8;
|
425 | 427 | if (sparebuffer)
|
426 | 428 | {
|
427 | | - if (spare != sparebuffer) memcpy(sparebuffer, spare, 0x40);
|
428 | 429 | if (eccresult & 1) memset(sparebuffer, 0xFF, 0xC);
|
429 | 430 | else memcpy(sparebuffer, nand_ctrl, 0xC);
|
430 | 431 | }
|
— | — | @@ -436,26 +437,26 @@ |
437 | 438 | void* databuffer, void* sparebuffer,
|
438 | 439 | uint32_t doecc, uint32_t wait)
|
439 | 440 | {
|
440 | | - uint8_t* data = nand_data;
|
| 441 | + uint8_t* data = (uint8_t*)databuffer;
|
441 | 442 | 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);
|
446 | 452 | mutex_lock(&nand_mtx, TIMEOUT_BLOCK);
|
447 | 453 | nand_last_activity_value = USEC_TIMER;
|
448 | 454 | 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);
|
454 | 456 | nand_set_fmctrl0(bank, FMCTRL0_ENABLEDMA);
|
455 | 457 | 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))
|
457 | 459 | 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);
|
460 | 461 | if (doecc)
|
461 | 462 | {
|
462 | 463 | if (ecc_encode(3, data, nand_ecc)) return nand_unlock(1);
|
— | — | @@ -465,7 +466,7 @@ |
466 | 467 | if (ecc_encode(0, nand_ctrl, nand_ecc)) return nand_unlock(1);
|
467 | 468 | memcpy(&spare[0x34], nand_ecc, 0xC);
|
468 | 469 | }
|
469 | | - if (databuffer)
|
| 470 | + if (data)
|
470 | 471 | if (nand_transfer_data_collect(1))
|
471 | 472 | return nand_unlock(1);
|
472 | 473 | if (sparebuffer || doecc)
|
Index: embios/trunk/target/ipodnano2g/ftl.c |
— | — | @@ -1287,6 +1287,11 @@ |
1288 | 1288 | DEBUGF("FTL: Reading %d sectors starting at %d", count, sector);
|
1289 | 1289 | #endif
|
1290 | 1290 |
|
| 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 | +
|
1291 | 1296 | if (sector + count > ftl_nand_type->userblocks * ppb)
|
1292 | 1297 | {
|
1293 | 1298 | DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);
|
— | — | @@ -1942,6 +1947,11 @@ |
1943 | 1948 | DEBUGF("FTL: Writing %d sectors starting at %d", count, sector);
|
1944 | 1949 | #endif
|
1945 | 1950 |
|
| 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 | +
|
1946 | 1956 | if (sector + count > ftl_nand_type->userblocks * ppb)
|
1947 | 1957 | {
|
1948 | 1958 | DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);
|