Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #459, dynamically create RAM disk devices on RTEMS #466

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/bsp/pc-rtems/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,6 @@
extern rtems_status_code rtems_ide_part_table_initialize(const char *);
extern int rtems_rtl_shell_command (int argc, char* argv[]);

/*
* The RAM Disk configuration.
*/
rtems_ramdisk_config rtems_ramdisk_configuration[RTEMS_NUMBER_OF_RAMDISKS];

/*
* The number of RAM Disk configurations.
*/
size_t rtems_ramdisk_configuration_size = RTEMS_NUMBER_OF_RAMDISKS;

/*
** RAM Disk IO op table.
*/
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
};

/*
* Additional shell commands for the RTL functionality
*/
Expand Down
1 change: 0 additions & 1 deletion src/bsp/pc-rtems/src/pcrtems_bsp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* BSP compile-time tuning
*/
#define RTEMS_MAX_USER_OPTIONS 4
#define RTEMS_NUMBER_OF_RAMDISKS 1
#define RTEMS_MAX_CMDLINE 256

/*
Expand Down
87 changes: 39 additions & 48 deletions src/os/rtems/src/os-impl-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
typedef struct
{
char blockdev_name[OS_MAX_PATH_LEN];
rtems_device_minor_number minor;

struct ramdisk *allocated_disk;

/* other data to pass to "mount" when mounting this disk */
const char *mount_fstype;
Expand All @@ -65,19 +66,6 @@ typedef struct
*/
OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS];


/*
* These external references are for the RTEMS RAM disk device descriptor table
* This is necessary for the RAM disk. These tables can either be here, or
* in a RTEMS kernel startup file. In this case, the tables are in the
* application startup
*
* Currently, it does not appear possible to create multiple arbitrary disks
* The RAM disk driver appears to require these specific variables.
*/
extern rtems_ramdisk_config rtems_ramdisk_configuration[];
extern size_t rtems_ramdisk_configuration_size;

/****************************************************************************************
Filesys API
***************************************************************************************/
Expand Down Expand Up @@ -110,7 +98,7 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id)
{
OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id];
OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id];
uint32 os_idx;
rtems_status_code sc;
int32 return_code;

return_code = OS_ERR_NOT_IMPLEMENTED;
Expand All @@ -136,48 +124,41 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id)
}
case OS_FILESYS_TYPE_VOLATILE_DISK:
{
/*
* This finds the correct driver "minor number"
* to use for the RAM disk (i.e. /dev/rd<X>)
*/
OS_DEBUG("No RAMDISK available at address %p\n", local->address);

/* find a matching entry in the OS ramdisk table,
* (identified by the location address) */
for (os_idx = 0; os_idx < rtems_ramdisk_configuration_size; ++os_idx)
{
if (rtems_ramdisk_configuration[os_idx].location == local->address)
{
impl->minor = os_idx;
break;
}
}
impl->allocated_disk = ramdisk_allocate(
local->address,
local->blocksize,
local->numblocks,
false
);

if (os_idx >= rtems_ramdisk_configuration_size)
if (impl->allocated_disk == NULL)
{
OS_DEBUG("No RAMDISK available at address %p\n", local->address);
OS_DEBUG("ramdisk_allocate() failed\n");
return_code = OS_INVALID_POINTER;
break;
}
if ( local->numblocks > rtems_ramdisk_configuration[os_idx].block_num)
{
OS_DEBUG("OSAL: Error: RAM disk too large, %lu blocks requested, %lu available.\n",
(unsigned long)local->numblocks,
(unsigned long)rtems_ramdisk_configuration[os_idx].block_num);
return_code = OS_ERROR;
break;
}
if ( local->blocksize != rtems_ramdisk_configuration[os_idx].block_size )

impl->mount_fstype = RTEMS_FILESYSTEM_TYPE_RFS;
impl->mount_options = RTEMS_FILESYSTEM_READ_WRITE;
snprintf(impl->blockdev_name, sizeof(impl->blockdev_name), "%s%c", RAMDISK_DEVICE_BASE_NAME, (int)filesys_id + 'a');

sc = rtems_blkdev_create(
impl->blockdev_name,
local->blocksize,
local->numblocks,
ramdisk_ioctl,
impl->allocated_disk
);
if (sc != RTEMS_SUCCESSFUL)
{
OS_DEBUG("OSAL: Error: RAM Disk needs a block size of %lu.\n",
(unsigned long)rtems_ramdisk_configuration[os_idx].block_size);
return_code = OS_ERROR;
break;
OS_DEBUG("rtems_blkdev_create() failed: %s.\n", rtems_status_text(sc));
return_code = OS_ERROR;
}

snprintf(impl->blockdev_name, sizeof(impl->blockdev_name), "%s%c", RAMDISK_DEVICE_BASE_NAME, (int)impl->minor + 'a');
impl->mount_fstype = RTEMS_FILESYSTEM_TYPE_RFS;

OS_DEBUG("OSAL: RAM disk initialized: volume=%s device=%s address=0x%08lX\n",
OS_DEBUG("RAM disk initialized: volume=%s device=%s address=0x%08lX\n",
local->volume_name, impl->blockdev_name, (unsigned long)local->address);

return_code = OS_SUCCESS;
Expand Down Expand Up @@ -218,7 +199,16 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id)
*-----------------------------------------------------------------*/
int32 OS_FileSysStopVolume_Impl (uint32 filesys_id)
{
/* Currently nothing to do here */
OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id];

/*
* If this was a dynamically allocated disk, then unlink it.
*/
if (impl->allocated_disk != NULL)
{
unlink(impl->blockdev_name);
}

return OS_SUCCESS;

} /* end OS_FileSysStopVolume_Impl */
Expand Down Expand Up @@ -265,6 +255,7 @@ int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id)
** Format the RAM disk with the RFS file system
*/
memset (&config, 0, sizeof(config));
config.inode_overhead = 30;
sc = rtems_rfs_format(impl->blockdev_name, &config);
if ( sc < 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/unit-tests/osfile-test/ut_osfile_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int32 UT_os_setup_fs()
{
int32 res;

res = OS_mkfs(g_fsAddrPtr, g_devName, " ", 512, 20);
res = OS_mkfs(g_fsAddrPtr, g_devName, "RAM3", 512, 64);
if (res != OS_SUCCESS)
{
UT_OS_LOG("OS_mkfs() returns %d\n", (int)res);;
Expand Down