How to synch disk cache to SD card? RE: a question about SD card rtems_blkdev_generic functions

André Marques andre.lousa.marques at gmail.com
Thu Aug 20 08:37:23 UTC 2015


On 20-08-2015 05:53, Chan Kim wrote:
> Sorry to flood the list.
> unmount starts writing to SD card but wish there's another way.

Have you tried fsync? Although if you are using IMFS generic nodes I 
think they do not have a handler for it.

>
> Chan
>
>
>
>
> 보낸 사람 : "Chan Kim" <ckim at etri.re.kr>
> 보낸 날짜 : 2015-08-20 13:39:51 ( +09:00 )
> 받는 사람 : users at rtems.org <users at rtems.org>
> 참조 :
> 제목 : How to synch disk cache to SD card? RE: a question about SD card rtems_blkdev_generic functions
>
> Hi, list,
>
> I found that my file writig was done only on disk cache. (I tried reading the file back, and found it has been written)
> Now the problem is I don't know how to flush (write back) the file in the disk cache to the SD card.
>
> In linux, after 3 seconds, it automatically syncs disk cache to actual disk (SD card) but I don't know how this is done in RTEMS.
> The SD card was mounted to a point at IMFS. and I'm doing this on RTEMS 4.10.99 with no libbsd.
>
> Please help.
> Chan
>
>
>>> My real problem is , when I open a file for writing, it reads 32
>>> consecutive 512-byte blocks and another block some space apart and
>>> then does nothing when it is supposed to do some block writing action.
>>> It used to switch to block writing couple of days earlier but somehow
>>> it doesn't now. I'm looking at what went wrong.
>>> Can anyone give me a clue as to what might have gone wrong?
>> I found fopen leads to open() and fprintf leads to write().
>> During fopen() sd_card_disk_ioctl is called many times for block reads and
>> fopen() returns normal.
>> The write() calls handler msdos_file_write() which seems to do
>> fat_file_write() but inside fat_file_write, sd_card_disk_ioctl is called once for
>> "READ" operation. (not "WRITE"). I don't know what's wrong and need to
>> look into it.
>> Does anybody have any guess?
>> Thanks!
>>
>> Chan
>
>
>
> 보낸 사람 : "Chan Kim"
> 보낸 날짜 : 2015-08-20 10:35:56 ( +09:00 )
> 받는 사람 : André Marques
> 참조 : users at rtems.org
> 제목 : RE: a question about SD card rtems_blkdev_generic functions
>
>
>
>> My real problem is , when I open a file for writing, it reads 32 consecutive
>> 512-byte blocks and another block some space apart and then does nothing
>> when it is supposed to do some block writing action. It used to switch to
>> block writing couple of days earlier but somehow it doesn't now. I'm looking
>> at what went wrong.
>> Can anyone give me a clue as to what might have gone wrong?
> I found fopen leads to open() and fprintf leads to write().
> During fopen() sd_card_disk_ioctl is called many times for block reads and fopen() returns normal.
> The write() calls handler msdos_file_write() which seems to do fat_file_write() but inside fat_file_write, sd_card_disk_ioctl is called once for "READ" operation. (not "WRITE"). I don't know what's wrong and need to look into it.
> Does anybody have any guess?
> Thanks!
>
> Chan
>
>
>
>
>
> 보낸 사람 : "Chan Kim"
> 보낸 날짜 : 2015-08-20 09:52:07 ( +09:00 )
> 받는 사람 : André Marques
> 참조 : users at rtems.org
> 제목 : RE: a question about SD card rtems_blkdev_generic functions
>
> Hi André and all,
>
>> sd_card_disk_init should be creating the disk in the system through
>> rtems_disk_create_phys, which takes an IO control handler for the block
>> operations. This controller is the one that should be doing your reads and
>> writes.
> yes, I forgot. Block read and write is through sd_card_disk_ioctl function that I connected to create_phys function.
> and there was a print mistake during the debug which made me miss the rtems_blkdev_generic_ioctl calls.
>
> My real problem is , when I open a file for writing, it reads 32 consecutive 512-byte blocks and another block some space apart and then does nothing when it is supposed to do some block writing action. It used to switch to block writing couple of days earlier but somehow it doesn't now. I'm looking at what went wrong.
> Can anyone give me a clue as to what might have gone wrong?
>
> Chan
>
>
>
>
> 보낸 사람 : "André Marques"
> 보낸 날짜 : 2015-08-19 23:23:03 ( +09:00 )
> 받는 사람 : 김찬
> 참조 : users at rtems.org
> 제목 : Re: a question about SD card rtems_blkdev_generic functions
>
> Hello Chan,
>
> On 19-08-2015 13:46, Chan Kim wrote:
>> Hello, rtems folks,
>> I managed to write an SD card driver on our platform (it was a month ago but I was doing other things lately) and am
>> tryng to test file read and write. File read is done anyway and I can print the file contents.
>> Couple of days ago I saw block write starting initiated by file write operation, but somehow I don't know how to make block write start.
>>
>> somewhere in the driver, there are lines below.
>>
>> static const rtems_driver_address_table sd_card_disk_ops = {
>> .initialization_entry = sd_card_disk_init,
>> .open_entry = rtems_blkdev_generic_open,
>> .close_entry = rtems_blkdev_generic_close,
>> .read_entry = rtems_blkdev_generic_read,
>> .write_entry = rtems_blkdev_generic_write,
>> .control_entry = rtems_blkdev_generic_ioctl
>> };
>>
>> sc = rtems_io_register_driver( 0, &sd_card_disk_ops, &major);
>>
>> but strangely, even when I read a file successfully(using fopen, fgets) and print it, only rtems_blkdev_generic_open and rtems_blkdev_generic_close function are called and rtems_blkdev_generic_read/write.functions are not called.
>> Is this normal? Can someone direct me to a good document on how this works or explain it to me?
>> Thanks!
>> Chan
> sd_card_disk_init should be creating the disk in the system through
> rtems_disk_create_phys, which takes an IO control handler for the block
> operations. This controller is the one that should be doing your reads
> and writes.
>
>  From [1] :
>
> These primitives (except initialize) can be implemented in a generic
> fashion based upon the supplied block device driver IO control handler.
> *Every block device driver should provide an initialize entry point,
> which registers the appropriate IO control handler.*
>
> [1] -
> https://docs.rtems.org/doxygen/cpukit/html/group__rtems__blkdev__generic.html#gab2d9149dc532657053697e5010fffa82
>
> --André Marques
>
>> _______________________________________________
>> users mailing list
>> users at rtems.org
>> http://lists.rtems.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users




More information about the users mailing list