Add framework to support loadable ELF modules (not much logic in place yet)

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5250 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-10-24 16:46:12 +00:00
parent d300539524
commit 1bd66e95f8
35 changed files with 1802 additions and 651 deletions
+5
View File
@@ -2,3 +2,8 @@
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config NXFLAT_DUMPBUFFER
bool "Dump NXFLAT buffers"
default n
depends on DEBUG && DEBUG_VERBOSE
+19 -5
View File
@@ -1,5 +1,5 @@
############################################################################
# nxflat/lib/Make.defs
# binfmt/libnxflat/Make.defs
#
# Copyright (C) 2009 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
@@ -33,7 +33,21 @@
#
############################################################################
LIBNXFLAT_ASRCS =
LIBNXFLAT_CSRCS = libnxflat_init.c libnxflat_uninit.c libnxflat_load.c \
libnxflat_unload.c libnxflat_verify.c libnxflat_read.c \
libnxflat_bind.c
ifeq ($(CONFIG_NXFLAT),y)
# NXFLAT application interfaces
BINFMT_CSRCS += nxflat.c
# NXFLAT library
BINFMT_CSRCS = libnxflat_init.c libnxflat_uninit.c libnxflat_load.c \
libnxflat_unload.c libnxflat_verify.c libnxflat_read.c \
libnxflat_bind.c
# Hook the libnxflat subdirectory into the build
VPATH += libnxflat
SUBDIRS += libnxflat
endif
+24 -22
View File
@@ -263,7 +263,6 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
result = OK;
switch (NXFLAT_RELOC_TYPE(reloc.r_info))
{
/* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
* into I-Space at the offset.
* Fixup: Add mapped I-Space address to the offset.
@@ -329,6 +328,7 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
nxflat_dumpbuffer("GOT", (FAR const uint8_t*)relocs, nrelocs * sizeof(struct nxflat_reloc_s));
}
#endif
return ret;
}
@@ -388,7 +388,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
offset < loadinfo->isize + loadinfo->dsize);
imports = (struct nxflat_import_s*)
(offset - loadinfo->isize + loadinfo->dspace->region);
(offset - loadinfo->isize + loadinfo->dspace->region);
/* Now, traverse the list of imported symbols and attempt to bind
* each symbol to the value exported by from the exported symbol
@@ -396,41 +396,41 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
*/
for (i = 0; i < nimports; i++)
{
bvdbg("Import[%d] (%08p) offset: %08x func: %08x\n",
i, &imports[i], imports[i].i_funcname, imports[i].i_funcaddress);
{
bvdbg("Import[%d] (%08p) offset: %08x func: %08x\n",
i, &imports[i], imports[i].i_funcname, imports[i].i_funcaddress);
/* Get a pointer to the imported symbol name. The name itself
* lies in the TEXT segment. But the reference to the name
* lies in DATA segment. Therefore, the name reference should
* have been relocated when the module was loaded.
*/
/* Get a pointer to the imported symbol name. The name itself
* lies in the TEXT segment. But the reference to the name
* lies in DATA segment. Therefore, the name reference should
* have been relocated when the module was loaded.
*/
offset = imports[i].i_funcname;
DEBUGASSERT(offset < loadinfo->isize);
symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
/* Find the exported symbol value for this this symbol name. */
/* Find the exported symbol value for this this symbol name. */
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
symbol = symtab_findorderedbyname(exports, symname, nexports);
#else
symbol = symtab_findbyname(exports, symname, nexports);
#endif
if (!symbol)
{
bdbg("Exported symbol \"%s\" not found\n", symname);
if (!symbol)
{
bdbg("Exported symbol \"%s\" not found\n", symname);
return -ENOENT;
}
}
/* And put this into the module's import structure. */
/* And put this into the module's import structure. */
imports[i].i_funcaddress = (uint32_t)symbol->sym_value;
imports[i].i_funcaddress = (uint32_t)symbol->sym_value;
bvdbg("Bound import[%d] (%08p) to export '%s' (%08x)\n",
i, &imports[i], symname, imports[i].i_funcaddress);
}
bvdbg("Bound import[%d] (%08p) to export '%s' (%08x)\n",
i, &imports[i], symname, imports[i].i_funcaddress);
}
}
/* Dump the relocation import table */
@@ -441,6 +441,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
nxflat_dumpbuffer("Imports", (FAR const uint8_t*)imports, nimports * sizeof(struct nxflat_import_s));
}
#endif
return OK;
}
@@ -484,9 +485,10 @@ int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo,
*/
memset((void*)(loadinfo->dspace->region + loadinfo->datasize),
0, loadinfo->bsssize);
0, loadinfo->bsssize);
}
}
return ret;
}
@@ -56,10 +56,6 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxflat_swap32
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
+3 -3
View File
@@ -91,10 +91,10 @@ int nxflat_verifyheader(const struct nxflat_hdr_s *header)
if (strncmp(header->h_magic, NXFLAT_MAGIC, 4) != 0)
{
bdbg("Unrecognized magic=\"%c%c%c%c\"\n",
header->h_magic[0], header->h_magic[1],
header->h_magic[2], header->h_magic[3]);
header->h_magic[0], header->h_magic[1],
header->h_magic[2], header->h_magic[3]);
return -ENOEXEC;
}
return OK;
}