1+ #include <sysclib.h>
12#include <bdm.h>
23#include <stdint.h>
34#include <thevent.h>
@@ -577,6 +578,11 @@ static int spisd_write_multi_end()
577578 * BDM interface:
578579 * - BDM -> "spisd" library
579580 */
581+ /* DMA and reverse_buffer work on words: a buffer that is not word aligned
582+ * (FatFs passes the caller's, at any offset) goes a sector at a time through
583+ * this one */
584+ static uint32_t bounce [SECTOR_SIZE / 4 ];
585+
580586int spisd_read (struct block_device * bd , uint64_t sector , void * buffer , uint16_t count )
581587{
582588 uint16_t sectors_left = count ;
@@ -588,6 +594,16 @@ int spisd_read(struct block_device *bd, uint64_t sector, void *buffer, uint16_t
588594 if (count == 0 )
589595 return 0 ;
590596
597+ if ((uint32_t )buffer & 3 ) {
598+ uint16_t i ;
599+ for (i = 0 ; i < count ; i ++ ) {
600+ if (spisd_read (bd , sector + i , bounce , 1 ) != 1 )
601+ break ;
602+ memcpy ((uint8_t * )buffer + i * SECTOR_SIZE , bounce , SECTOR_SIZE );
603+ }
604+ return i ;
605+ }
606+
591607 M_DEBUG ("%s: sector %i, count: %i \n" , __FUNCTION__ , (u32 )sector , count );
592608
593609 mx_sio2_lock (INTR_RX );
@@ -642,6 +658,16 @@ int spisd_write(struct block_device *bd, uint64_t sector, const void *buffer, ui
642658 if (count == 0 )
643659 return 0 ;
644660
661+ if ((uint32_t )buffer & 3 ) {
662+ uint16_t i ;
663+ for (i = 0 ; i < count ; i ++ ) {
664+ memcpy (bounce , (const uint8_t * )buffer + i * SECTOR_SIZE , SECTOR_SIZE );
665+ if (spisd_write (bd , sector + i , bounce , 1 ) != 1 )
666+ break ;
667+ }
668+ return i ;
669+ }
670+
645671 M_DEBUG ("%s: sector %i, count: %i \n" , __FUNCTION__ , (u32 )sector , count );
646672
647673 /* recast */
0 commit comments