Skip to content

Commit

Permalink
Merge pull request nasa#1156 from jphickey/fix-981-better-filename-pa…
Browse files Browse the repository at this point in the history
…rser

Fix nasa#981, implement better filename parser
  • Loading branch information
astrogeco authored Mar 2, 2021
2 parents b50ae63 + 361eb65 commit f55cc82
Show file tree
Hide file tree
Showing 11 changed files with 893 additions and 57 deletions.
13 changes: 8 additions & 5 deletions cmake/sample_defs/cpu1_cfe_es_startup.scr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CFE_LIB, /cf/sample_lib.so, SAMPLE_LIB_Init, SAMPLE_LIB, 0, 0, 0x0, 0;
CFE_APP, /cf/sample_app.so, SAMPLE_APP_Main, SAMPLE_APP, 50, 16384, 0x0, 0;
CFE_APP, /cf/ci_lab.so, CI_Lab_AppMain, CI_LAB_APP, 60, 16384, 0x0, 0;
CFE_APP, /cf/to_lab.so, TO_Lab_AppMain, TO_LAB_APP, 70, 16384, 0x0, 0;
CFE_APP, /cf/sch_lab.so, SCH_Lab_AppMain, SCH_LAB_APP, 80, 16384, 0x0, 0;
CFE_LIB, sample_lib, SAMPLE_LIB_Init, SAMPLE_LIB, 0, 0, 0x0, 0;
CFE_APP, sample_app, SAMPLE_APP_Main, SAMPLE_APP, 50, 16384, 0x0, 0;
CFE_APP, ci_lab, CI_Lab_AppMain, CI_LAB_APP, 60, 16384, 0x0, 0;
CFE_APP, to_lab, TO_Lab_AppMain, TO_LAB_APP, 70, 16384, 0x0, 0;
CFE_APP, sch_lab, SCH_Lab_AppMain, SCH_LAB_APP, 80, 16384, 0x0, 0;
!
! Startup script fields:
! 1. Object Type -- CFE_APP for an Application, or CFE_LIB for a library.
Expand All @@ -27,4 +27,7 @@ CFE_APP, /cf/sch_lab.so, SCH_Lab_AppMain, SCH_LAB_APP, 80, 16384, 0x0, 0;
! vxWorks = .o ( ci.o )
! RTEMS with S-record Loader = .s3r ( ci.s3r )
! RTEMS with CEXP Loader = .o ( ci.o )
! 3. The filename field (2) no longer requires a fully-qualified filename; the path and extension
! may be omitted. If omitted, the standard virtual path (/cf) and a platform-specific default
! extension will be used, which is derived from the build system.

46 changes: 29 additions & 17 deletions cmake/sample_defs/cpu1_platform_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@
#ifndef _cfe_platform_cfg_
#define _cfe_platform_cfg_


/**
** \cfeescfg Default virtual path for persistent storage
**
** \par Description:
** This configures the default location in the virtual file system
** for persistent/non-volatile storage. Files such as the startup
** script, app/library dynamic modules, and configuration tables are
** expected to be stored in this directory.
**
*/
#define CFE_PLATFORM_ES_NONVOL_DISK_MOUNT_STRING "/cf"

/**
** \cfeescfg Default virtual path for volatile storage
**
** \par Description:
** The #CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING parameter is used to set the cFE mount path
** for the CFE RAM disk. This is a parameter for missions that do not want to
** use the default value of "/ram", or for missions that need to have a different
** value for different CPUs or Spacecraft.
** Note that the vxWorks OSAL cannot currently handle names that have more than one
** path separator in it. The names "/ram", "/ramdisk", "/disk123" will all work, but
** "/disks/ram" will not.
** Multiple separators can be used with the posix or RTEMS ports.
**
*/
#define CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING "/ram"

/**
** \cfesbcfg Maximum Number of Unique Message IDs SB Routing Table can hold
**
Expand Down Expand Up @@ -682,23 +711,6 @@
#define CFE_PLATFORM_ES_RAM_DISK_PERCENT_RESERVED 30


/**
** \cfeescfg RAM Disk Mount string
**
** \par Description:
** The #CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING parameter is used to set the cFE mount path
** for the CFE RAM disk. This is a parameter for missions that do not want to
** use the default value of "/ram", or for missions that need to have a different
** value for different CPUs or Spacecraft.
** Note that the vxWorks OSAL cannot currently handle names that have more than one
** path separator in it. The names "/ram", "/ramdisk", "/disk123" will all work, but
** "/disks/ram" will not.
** Multiple separators can be used with the posix or RTEMS ports.
**
*/
#define CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING "/ram"


/**
** \cfeescfg Define Critical Data Store Size
**
Expand Down
12 changes: 11 additions & 1 deletion cmake/target/inc/target_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,17 @@ typedef const struct
uint32 RamDiskTotalSectors; /***< RAM disk number of sectors */

/**
* Default value for start up file
* Default value for nonvolatile file system mount point
*/
const char *NonvolMountPoint;

/**
* Default value for volatile file system mount point
*/
const char *RamdiskMountPoint;

/**
* File name of startup script
*/
const char *NonvolStartupFile;

Expand Down
5 changes: 3 additions & 2 deletions cmake/target/src/target_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ Target_CfeConfigData GLOBAL_CFE_CONFIGDATA =
.SystemNotify = CFE_ES_ProcessAsyncEvent,

/*
* Default values for Startup file.
* This is a suggested value, but the PSP may provide a different file
* Default values for various file paths
*/
.NonvolMountPoint = CFE_PLATFORM_ES_NONVOL_DISK_MOUNT_STRING,
.RamdiskMountPoint = CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING,
.NonvolStartupFile = CFE_PLATFORM_ES_NONVOL_STARTUP_FILE,

/*
Expand Down
45 changes: 33 additions & 12 deletions fsw/cfe-core/src/es/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
*/
void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
{
char ES_AppLoadBuffer[ES_START_BUFF_SIZE]; /* A buffer of for a line in a file */
char ES_AppLoadBuffer[ES_START_BUFF_SIZE]; /* A buffer of for a line in a file */
char ScriptFileName[OS_MAX_PATH_LEN];
const char *TokenList[CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE];
uint32 NumTokens;
uint32 BuffLen; /* Length of the current buffer */
Expand All @@ -93,14 +94,20 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
if ( ResetType == CFE_PSP_RST_TYPE_PROCESSOR )
{
/*
** Open the file in the volatile disk.
** First Attempt to parse as file in the volatile disk (temp area).
*/
Status = OS_OpenCreate(&AppFile, CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE, OS_FILE_FLAG_NONE, OS_READ_ONLY);
Status = CFE_FS_ParseInputFileName(ScriptFileName, CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE,
sizeof(ScriptFileName), CFE_FS_FileCategory_TEMP);

if (Status == CFE_SUCCESS)
{
Status = OS_OpenCreate(&AppFile, ScriptFileName, OS_FILE_FLAG_NONE, OS_READ_ONLY);
}

if ( Status >= 0 )
{
CFE_ES_WriteToSysLog ("ES Startup: Opened ES App Startup file: %s\n",
CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE);
ScriptFileName);
FileOpened = true;
}
else
Expand All @@ -120,11 +127,17 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
/*
** Try to Open the file passed in to the cFE start.
*/
Status = OS_OpenCreate(&AppFile, StartFilePath, OS_FILE_FLAG_NONE, OS_READ_ONLY);
Status = CFE_FS_ParseInputFileName(ScriptFileName, StartFilePath,
sizeof(ScriptFileName), CFE_FS_FileCategory_SCRIPT);

if (Status == CFE_SUCCESS)
{
Status = OS_OpenCreate(&AppFile, ScriptFileName, OS_FILE_FLAG_NONE, OS_READ_ONLY);
}

if ( Status >= 0 )
{
CFE_ES_WriteToSysLog ("ES Startup: Opened ES App Startup file: %s\n",StartFilePath);
CFE_ES_WriteToSysLog ("ES Startup: Opened ES App Startup file: %s\n",ScriptFileName);
FileOpened = true;
}
else
Expand Down Expand Up @@ -271,7 +284,7 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens)
CFE_ES_AppId_t AppId;
CFE_ES_LibId_t LibId;
} IdBuf;
int32 CreateStatus = CFE_ES_ERR_APP_CREATE;
int32 Status;
CFE_ES_AppStartParams_t ParamBuf;

/*
Expand All @@ -280,7 +293,7 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens)
if (NumTokens < 8)
{
CFE_ES_WriteToSysLog("ES Startup: Invalid ES Startup file entry: %u\n", (unsigned int)NumTokens);
return (CreateStatus);
return CFE_ES_BAD_ARGUMENT;
}

/* Get pointers to specific tokens that are simple strings used as-is */
Expand All @@ -292,7 +305,14 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens)
* Both Libraries and Apps use File Name (1) and Symbol Name (2) fields so copy those now
*/
memset(&ParamBuf, 0, sizeof(ParamBuf));
strncpy(ParamBuf.BasicInfo.FileName, TokenList[1], sizeof(ParamBuf.BasicInfo.FileName) - 1);
Status = CFE_FS_ParseInputFileName(ParamBuf.BasicInfo.FileName, TokenList[1],
sizeof(ParamBuf.BasicInfo.FileName), CFE_FS_FileCategory_DYNAMIC_MODULE);
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("ES Startup: Invalid ES Startup script file name: %s\n", TokenList[1]);
return Status;
}

strncpy(ParamBuf.BasicInfo.InitSymbolName, TokenList[2], sizeof(ParamBuf.BasicInfo.InitSymbolName) - 1);

if (strcmp(EntryType, "CFE_APP") == 0)
Expand Down Expand Up @@ -338,7 +358,7 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens)
/*
** Now create the application
*/
CreateStatus = CFE_ES_AppCreate(&IdBuf.AppId, ModuleName, &ParamBuf);
Status = CFE_ES_AppCreate(&IdBuf.AppId, ModuleName, &ParamBuf);
}
else if (strcmp(EntryType, "CFE_LIB") == 0)
{
Expand All @@ -347,14 +367,15 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens)
/*
** Now load the library
*/
CreateStatus = CFE_ES_LoadLibrary(&IdBuf.LibId, ModuleName, &ParamBuf.BasicInfo);
Status = CFE_ES_LoadLibrary(&IdBuf.LibId, ModuleName, &ParamBuf.BasicInfo);
}
else
{
CFE_ES_WriteToSysLog("ES Startup: Unexpected EntryType %s in startup file.\n", EntryType);
Status = CFE_ES_ERR_APP_CREATE;
}

return (CreateStatus);
return (Status);
}

/*
Expand Down
Loading

0 comments on commit f55cc82

Please sign in to comment.