Skip to content

Commit

Permalink
Merge branches 'fix-367-deprecate-voltab', 'fix-454-statvfs-err-trans…
Browse files Browse the repository at this point in the history
…lation', 'fix-455-devname-length', 'fix-457-bsp-shutdown-handler' and 'fix-459-rtems-ramdisk' into jph-wip-baseline-20200515
  • Loading branch information
jphickey committed May 16, 2020
5 parents 312b7cc + 45c9742 + 72af6d5 + 042db6b + 5f97b9b commit 43819e3
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 99 deletions.
11 changes: 11 additions & 0 deletions src/bsp/mcp750-vxworks/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@

#include "mcp750_bsp_internal.h"

/* ---------------------------------------------------------
OS_BSP_Shutdown_Impl()
Helper function to abort the running task
--------------------------------------------------------- */
void OS_BSP_Shutdown_Impl(void)
{
abort();
}


/******************************************************************************
** Function: OS_BSPMain()
**
Expand Down
11 changes: 11 additions & 0 deletions src/bsp/pc-linux/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ int OS_BSP_GetReturnStatus(void)
return retcode;
}

/* ---------------------------------------------------------
OS_BSP_Shutdown_Impl()
Helper function to abort the running task
--------------------------------------------------------- */
void OS_BSP_Shutdown_Impl(void)
{
abort();
}


/******************************************************************************
** Function: main()
**
Expand Down
64 changes: 28 additions & 36 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 Expand Up @@ -308,6 +285,30 @@ rtems_status_code OS_BSP_GetReturnStatus(void)
return retcode;
}

/* ---------------------------------------------------------
OS_BSP_Shutdown_Impl()
Helper function to abort the running task
--------------------------------------------------------- */
void OS_BSP_Shutdown_Impl(void)
{
/*
* Not calling exit() under RTEMS, this simply shuts down the executive,
* forcing the user to reboot the system.
*
* Calling suspend causes execution to get stuck here, but the RTEMS
* shell thread will still be active so the user can poke around, read results,
* then use a shell command to reboot when ready.
*/
while (!OS_BSP_PcRtemsGlobal.BatchMode)
{
printf("\n\nInit thread idle.\nPress <enter> for shell or reset machine...\n\n");
rtems_task_suspend(rtems_task_self());
}

rtems_shutdown_executive(OS_BSP_GetReturnStatus());
}

/*
** A simple entry point to start from the loader
*/
Expand Down Expand Up @@ -339,20 +340,11 @@ rtems_task Init(rtems_task_argument ignored)
OS_Application_Run();

/*
* Not calling exit() under RTEMS, this simply shuts down the executive,
* forcing the user to reboot the system.
*
* Calling suspend causes execution to get stuck here, but the RTEMS
* shell thread will still be active so the user can poke around, read results,
* then use a shell command to reboot when ready.
* Enter the BSP default shutdown mode
* depending on config, this may reset/reboot or suspend
* so the operator can use the shell.
*/
while (!OS_BSP_PcRtemsGlobal.BatchMode)
{
printf("\n\nInit thread idle.\nPress <enter> for shell or reset machine...\n\n");
rtems_task_suspend(rtems_task_self());
}

rtems_shutdown_executive(OS_BSP_GetReturnStatus());
OS_BSP_Shutdown_Impl();
}

/* configuration information */
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
10 changes: 10 additions & 0 deletions src/bsp/shared/inc/bsp-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen);
------------------------------------------------------------------*/
void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits);

/*----------------------------------------------------------------
Function: OS_BSP_Shutdown_Impl
Purpose: Causes the calling task to abort in a BSP-safe way.
This may map to the abort() system call, but on some systems
that causes a reboot or undesirable side effect. The
BSP may implement this call in a different manner.
------------------------------------------------------------------*/
void OS_BSP_Shutdown_Impl(void);

/*********************
END bsp-impl.h
*********************/
Expand Down
114 changes: 61 additions & 53 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 @@ -70,19 +71,6 @@ const char OS_RTEMS_DEVICEFILE_PREFIX[] = "/dev/";
*/
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 @@ -115,7 +103,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 Down Expand Up @@ -154,48 +142,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 @@ -236,7 +217,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 @@ -283,6 +273,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 Expand Up @@ -406,17 +397,34 @@ int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result)
{
OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id];
struct statvfs stat_buf;
int32 return_code;

if ( statvfs(local->system_mountpt, &stat_buf) != 0 )
{
return OS_ERROR;
/*
* The ENOSYS error means it is not implemented at the system level.
* This should translate to the OS_ERR_NOT_IMPLEMENTED OSAL code.
*/
if (errno == ENOSYS)
{
return_code = OS_ERR_NOT_IMPLEMENTED;
}
else
{
OS_DEBUG("%s: %s\n", local->system_mountpt, strerror(errno));
return_code = OS_ERROR;
}
}
else
{
result->block_size = stat_buf.f_bsize;
result->blocks_free = stat_buf.f_bfree;
result->total_blocks = stat_buf.f_blocks;

result->block_size = stat_buf.f_bsize;
result->blocks_free = stat_buf.f_bfree;
result->total_blocks = stat_buf.f_blocks;
return_code = OS_SUCCESS;
}

return(OS_SUCCESS);
return (return_code);
} /* end OS_FileSysStatVolume_Impl */


Expand Down
2 changes: 1 addition & 1 deletion src/os/shared/inc/os-shared-filesys.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ typedef struct

typedef struct
{
char device_name[OS_MAX_API_NAME]; /**< The name of the underlying block device, if applicable */
char device_name[OS_FS_DEV_NAME_LEN]; /**< The name of the underlying block device, if applicable */
char volume_name[OS_FS_VOL_NAME_LEN];
char system_mountpt[OS_MAX_LOCAL_PATH_LEN]; /**< The name/prefix where the contents are accessible in the host operating system */
char virtual_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix in the OSAL Virtual File system exposed to applications */
Expand Down
4 changes: 2 additions & 2 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ int32 OS_FileSysAddFixedMap(uint32 *filesys_id, const char *phys_path, const cha
return OS_INVALID_POINTER;
}

if (strlen(phys_path) >= OS_MAX_PATH_LEN ||
if (strlen(phys_path) >= OS_MAX_LOCAL_PATH_LEN ||
strlen(virt_path) >= OS_MAX_PATH_LEN)
{
return OS_ERR_NAME_TOO_LONG;
Expand All @@ -474,7 +474,7 @@ int32 OS_FileSysAddFixedMap(uint32 *filesys_id, const char *phys_path, const cha
++dev_name;
}

if (strlen(dev_name) >= OS_MAX_API_NAME)
if (strlen(dev_name) >= OS_FS_DEV_NAME_LEN)
{
return OS_ERR_NAME_TOO_LONG;
}
Expand Down
8 changes: 5 additions & 3 deletions src/unit-test-coverage/shared/src/coveragetest-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ void Test_OS_FileSysAddFixedMap(void)
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, NULL), OS_INVALID_POINTER);

UT_SetForceFail(UT_KEY(OCS_strlen), 2 + OS_MAX_PATH_LEN);
UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 1, 2 + OS_MAX_LOCAL_PATH_LEN);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG);
UT_ClearForceFail(UT_KEY(OCS_strlen));
UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 2, 2 + OS_MAX_PATH_LEN);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG);
UT_ResetState(UT_KEY(OCS_strlen));

UT_SetForceFail(UT_KEY(OCS_strrchr), -1);
UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 3, 2 + OS_MAX_API_NAME);
UT_SetDeferredRetcode(UT_KEY(OCS_strlen), 3, 2 + OS_FS_DEV_NAME_LEN);
OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_ERR_NAME_TOO_LONG);
UT_ResetState(UT_KEY(OCS_strlen));
UT_ResetState(UT_KEY(OCS_strrchr));
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
4 changes: 2 additions & 2 deletions ut_assert/src/utbsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage)

/*
* If any ABORT (major failure) message is thrown,
* then actually call abort() to stop the test and dump a core
* then call a BSP-provided routine to stop the test and possibly dump a core
*/
if (MessageType == UTASSERT_CASETYPE_ABORT)
{
abort();
OS_BSP_Shutdown_Impl();
}
}

Expand Down

0 comments on commit 43819e3

Please sign in to comment.