diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-10-24 16:46:12 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-10-24 16:46:12 +0000 |
commit | 1bd66e95f8b9817da320c85fc77ca6466bbdaed7 (patch) | |
tree | 199c1ac47d5ce30532f7b23121bc7df2c580a8c6 /nuttx/binfmt/libnxflat | |
parent | d30053952442a0dfefbea23de238a8077ad3463e (diff) | |
download | px4-firmware-1bd66e95f8b9817da320c85fc77ca6466bbdaed7.tar.gz px4-firmware-1bd66e95f8b9817da320c85fc77ca6466bbdaed7.tar.bz2 px4-firmware-1bd66e95f8b9817da320c85fc77ca6466bbdaed7.zip |
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
Diffstat (limited to 'nuttx/binfmt/libnxflat')
-rw-r--r-- | nuttx/binfmt/libnxflat/Kconfig | 5 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/Make.defs | 24 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_bind.c | 46 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_uninit.c | 4 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_verify.c | 6 |
5 files changed, 51 insertions, 34 deletions
diff --git a/nuttx/binfmt/libnxflat/Kconfig b/nuttx/binfmt/libnxflat/Kconfig index ae2bf3130..fdb270cfb 100644 --- a/nuttx/binfmt/libnxflat/Kconfig +++ b/nuttx/binfmt/libnxflat/Kconfig @@ -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 diff --git a/nuttx/binfmt/libnxflat/Make.defs b/nuttx/binfmt/libnxflat/Make.defs index f979741e5..59c3ce334 100644 --- a/nuttx/binfmt/libnxflat/Make.defs +++ b/nuttx/binfmt/libnxflat/Make.defs @@ -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 diff --git a/nuttx/binfmt/libnxflat/libnxflat_bind.c b/nuttx/binfmt/libnxflat/libnxflat_bind.c index ca348178d..c18a16cd8 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_bind.c +++ b/nuttx/binfmt/libnxflat/libnxflat_bind.c @@ -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; } diff --git a/nuttx/binfmt/libnxflat/libnxflat_uninit.c b/nuttx/binfmt/libnxflat/libnxflat_uninit.c index 5d06296c7..c507fdc14 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_uninit.c +++ b/nuttx/binfmt/libnxflat/libnxflat_uninit.c @@ -57,10 +57,6 @@ ****************************************************************************/ /**************************************************************************** - * Name: nxflat_swap32 - ****************************************************************************/ - -/**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/nuttx/binfmt/libnxflat/libnxflat_verify.c b/nuttx/binfmt/libnxflat/libnxflat_verify.c index f799aca4f..da25d21c7 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_verify.c +++ b/nuttx/binfmt/libnxflat/libnxflat_verify.c @@ -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; } - |