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

Integration Candidate: 2020-06-24 #47

Merged
merged 10 commits into from
Jul 25, 2020
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

This repository contains NASA's ELF to cFE Table Converter Tool (elf2cfetbl), which is a framework component of the Core Flight System.

This lab application is a ground utility to convert ELF to cFE binary tables for cFS. It is intended to be located in the `tools/elf2cfetbl` subdirectory of a cFS Mission Tree. The Core Flight System is bundled at <https://github.com/nasa/cFS> (which includes this tool as a submodule), which includes build and execution instructions.
This lab application is a ground utility to convert ELF to cFE binary tables for cFS. It is intended to be located in the `tools/elf2cfetbl` subdirectory of a cFS Mission Tree. The Core Flight System is bundled at <https://github.com/nasa/cFS>, which includes this tool as a submodule, and includes build and execution instructions.

See README.txt for more information.

## Version History

### Development Build: v3.1.0+dev39

- Adds a null to the end of SrcFilename and DstFilename when using strncpy.
- Support ELF files that have all strings, including ELF section names, in one single ".strtab" section in the ELF file.
- Version reporting now uses the version numbers defined in elf_version.h and reports build number.
- See <https://github.com/nasa/elf2cfetbl/pull/47>

### Development Build: 3.1.5

- Apply code style
Expand Down
32 changes: 27 additions & 5 deletions elf2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <limits.h>
#include "ELF_Structures.h"
#include "cfe_tbl_filedef.h"
#include "elf2cfetbl_version.h"

#define MAX_SECTION_HDR_NAME_LEN (128)
#define TBL_DEF_SYMBOL_NAME "CFE_TBL_FileDef"
Expand Down Expand Up @@ -664,6 +665,12 @@ int main(int argc, char *argv[])
}
}

if (StringTableDataOffset == 0)
{
printf("Error! Unable to locate ELF string table for symbol names\n");
return EXIT_FAILURE;
}

/* Allocate memory for all of the symbol table entries */
Status = AllocateSymbols();
if (Status != SUCCESS)
Expand All @@ -687,7 +694,7 @@ int main(int argc, char *argv[])
{
printf("Error! Unable to locate '%s' object in '%s'.\n", TBL_DEF_SYMBOL_NAME, SrcFilename);
FreeMemoryAllocations();
return Status;
return EXIT_FAILURE;
}

/* Read in the definition of the table file */
Expand Down Expand Up @@ -1227,11 +1234,13 @@ int32 ProcessCmdLineOptions(int ArgumentCount, char *Arguments[])
else if (!InputFileSpecified)
{
strncpy(SrcFilename, Arguments[i], PATH_MAX - 1);
SrcFilename[PATH_MAX - 1] = '\0';
InputFileSpecified = true;
}
else if (!OutputFileSpecified)
{
strncpy(DstFilename, Arguments[i], PATH_MAX - 1);
DstFilename[PATH_MAX - 1] = '\0';
OutputFileSpecified = true;
}
else
Expand Down Expand Up @@ -1272,9 +1281,7 @@ int32 ProcessCmdLineOptions(int ArgumentCount, char *Arguments[])

void OutputVersionInfo(void)
{
printf("\nElf Object File to cFE Table Image File Conversion Tool\n");
printf(" Version v3.1.5\n");
printf(" Built - %s %s\n\n", __DATE__, __TIME__);
printf("\n%s\n", ELF2CFETBL_VERSION_STRING);
}

/**
Expand All @@ -1283,6 +1290,7 @@ void OutputVersionInfo(void)

void OutputHelpInfo(void)
{
printf("\nElf Object File to cFE Table Image File Conversion Tool (elf2cfetbl)\n\n");
printf("elf2cfetbl [-tTblName] [-d\"Description\"] [-h] [-v] [-V] [-s#] [-p#] [-n] \n");
printf(" [-T] [-eYYYY:MM:DD:hh:mm:ss] [-fYYYY:MM:DD:hh:mm:ss] SrcFilename [DestDirectory]\n");
printf(" where:\n");
Expand Down Expand Up @@ -1757,7 +1765,15 @@ int32 GetSectionHeader(int32 SectionIndex, union Elf_Shdr *SectionHeader)

case SHT_STRTAB:
sprintf(VerboseStr, "SHT_STRTAB (3)");
if (SectionIndex != get_e_shstrndx(&ElfHeader))
/*
* If the section name is ".strtab" then preferentially use this section for symbol name data
* Otherwise use the first section which is NOT the section header string table (.shstrtab)
*
* Not all compilers generate a separate strtab for section header names; some put everything
* into one string table.
*/
if (strcmp(SectionNamePtrs[SectionIndex],".strtab") == 0 ||
(StringTableDataOffset == 0 && SectionIndex != get_e_shstrndx(&ElfHeader)))
{
StringTableDataOffset = get_sh_offset(SectionHeader);
}
Expand Down Expand Up @@ -2247,6 +2263,12 @@ int32 GetTblDefInfo(void)
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
NumDefsRead = fread(&TblFileDef, sizeof(CFE_TBL_FileDef_t), 1, SrcFileDesc);

/* ensuring all are strings are null-terminated */
TblFileDef.ObjectName[sizeof(TblFileDef.ObjectName) - 1] = '\0';
TblFileDef.TableName[sizeof(TblFileDef.TableName) - 1] = '\0';
TblFileDef.Description[sizeof(TblFileDef.Description) - 1] = '\0';
TblFileDef.TgtFilename[sizeof(TblFileDef.TgtFilename) - 1] = '\0';

if (NumDefsRead != 1)
{
printf("Error! Unable to read data content of '%s' from '%s'.\n", TBL_DEF_SYMBOL_NAME, SrcFilename);
Expand Down
66 changes: 66 additions & 0 deletions elf2cfetbl_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/


/*! @file elf2cfetbl_version.h
* @brief Purpose:
* @details Provide version identifiers for the ELF to cFE Table Converter. @n
* See @ref cfsversions for version and build number and description
*
*/
#ifndef ELF2CFETBL_VERSION_H
#define ELF2CFETBL_VERSION_H

/*
* Development Build Macro Definitions
*/
#define ELF2CFETBL_BUILD_NUMBER 39 /*!< @brief Number of commits since baseline */
#define ELF2CFETBL_BUILD_BASELINE "v3.1.0+dev" /*!< @brief Development Build: git tag that is the base for the current */

/*
* Version Macro Definitions
*/
#define ELF2CFETBL_MAJOR_VERSION 3 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */
#define ELF2CFETBL_MINOR_VERSION 1 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */
#define ELF2CFETBL_REVISION 0 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. */
#define ELF2CFETBL_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */

/*
* Tools to construct version string
*/
#define ELF2CFETBL_STR_HELPER(x) #x /*!< @brief Helper function to concatenate strings from integer macros */
#define ELF2CFETBL_STR(x) ELF2CFETBL_STR_HELPER(x) /*!< @brief Helper function to concatenate strings from integer macros */

/*! @brief Development Build Version Number.
* @details Baseline git tag + Number of commits since baseline. @n
* See @ref cfsversions for format differences between development and release versions.
*/
#define ELF2CFETBL_VERSION ELF2CFETBL_BUILD_BASELINE ELF2CFETBL_STR(ELF2CFETBL_BUILD_NUMBER)

/*! @brief Development Build Version String.
* @details Reports the current development build's baseline, number, and name. Also includes a note about the latest official version. @n
* See @ref cfsversions for format differences between development and release versions.
*/
#define ELF2CFETBL_VERSION_STRING \
" elf2cfetbl Development Build\n" \
" " ELF2CFETBL_VERSION " (Codename: Bootes)\n" /* Codename for current development */ \
" Last Offical Release: elf2cfetbl v3.1.0" /* For full support please use official release version */

#endif /* ELF2CFETBL_VERSION_H */