Help in setting up a RAM Disk
Chris Johns
chrisj at rtems.org
Sat Mar 5 04:26:45 UTC 2011
On 5/03/11 7:52 AM, Robert S. Grimes wrote:
> I have many megabytes of RAM, and want to set aside a large portion for
> use as a RAM disk. I've looked about a bit on the message list, and
> couldn't find the answers I need, and some info I did found seemed
> contradictory - that, and I suspect things have changed a bit in the
> last 4 years anyway!
>
> From what I've read, it seems I don't really want to use just the IMFS,
> as it uses the C heap; I'd like to keep the disk ram usage separate from
> my app's heap, out of concern for fragmentation. Looking at
> http://www.rtems.org/wiki/index.php/File_Systems, I think I have figured
> out the basics, but then come my questions:
>
> 1. It seems I want to use RFS, is that correct? How do I configure it?
> (I could not find the configuration documentation).
The RFS is just one file system. There is also DOSFS. The RFS does not
suffer from the issues DOSFS does.
>
> 2. RFS then needs a block device, specifically the RAM Disk, right? How
> do I configure that?
>
The RFS test code here:
http://www.rtems.org/ftp/pub/rtems/people/chrisj/file-system/rfs-20100603.tar.gz
is a complete working example with a RAM and flash disk. The disk set up
is in main.c.
The RAM can be configured with:
#include <rtems.h>
#include <rtems/bdbuf.h>
#include <rtems/blkdev.h>
#include <rtems/diskdevs.h>
#include <rtems/error.h>
#include <rtems/fsmount.h>
#include <rtems/ramdisk.h>
#include <rtems/shell.h>
/**
* The RAM Disk configuration.
*/
rtems_ramdisk_config rtems_ramdisk_configuration[] =
{
{
block_size: 512,
block_num: 1984 * 2,
location: NULL
}
};
/**
* The number of RAM Disk configurations.
*/
size_t rtems_ramdisk_configuration_size = 1;
/**
* Create the RAM Disk Driver entry.
*/
rtems_driver_address_table rtems_ramdisk_io_ops = {
initialization_entry: ramdisk_initialize,
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
};
int
setup_ramdisk (void)
{
rtems_device_major_number major;
rtems_status_code sc;
/*
* Register the RAM Disk driver.
*/
printf ("Register RAM Disk Driver: ");
sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
&rtems_ramdisk_io_ops,
&major);
if (sc != RTEMS_SUCCESSFUL)
{
printf ("error: ramdisk driver not initialised: %s\n",
rtems_status_text (sc));
return 1;
}
printf ("successful\n");
return 0;
}
In the test application in the link above I handle the formatting and
mounting using an RTEMS shell script. Look in shell-init. There is a
mount call which is simple to use. Check the main_mount.c file in the
shell for an example.
> 3. Is the Block Device Cache required in this setup, and if so, how is
> that configured?
>
Yes the block device cache is needed. You do not need to create a big
cache if you have a RAM disk operating.
> 4. Is there a way to pre-populate the filesystem with a set of files? In
> other words, is there a reasonable way to bind a "disk image" into the
> final output of my build process, such that when my app is loaded and
> begins execution, it can mount this filesystem and use the files it
> finds there?
I am not sure if this relates to the RAM or if this is a separate disk.
I think there is a TARFS but I have not used it. There is also the flash
disk driver that is a block driver. You can use this with the same flash
device as you boot with. The RFS test application has a configuration
for the mcf5235 board.
> What I'm looking for is a nice "how-to". Given that our project team
> will have several RTEMS-based systems in it, and I'm the first one out
> the gate, I'll become a local resource for the others. Therefore, I'll
> be putting together one for our use here, and will post it to the RTEMS
> wiki for others to use too.
Great.
Chris
More information about the users
mailing list