diff options
Diffstat (limited to 'nuttx/binfmt')
-rw-r--r-- | nuttx/binfmt/binfmt_loadmodule.c | 9 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_bind.c | 8 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_init.c | 2 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_load.c | 46 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_read.c | 33 | ||||
-rw-r--r-- | nuttx/binfmt/libnxflat/libnxflat_verify.c | 2 | ||||
-rw-r--r-- | nuttx/binfmt/nxflat.c | 2 |
7 files changed, 66 insertions, 36 deletions
diff --git a/nuttx/binfmt/binfmt_loadmodule.c b/nuttx/binfmt/binfmt_loadmodule.c index bad6ca712..0bed16f3d 100644 --- a/nuttx/binfmt/binfmt_loadmodule.c +++ b/nuttx/binfmt/binfmt_loadmodule.c @@ -87,14 +87,10 @@ int load_module(FAR struct binary_s *bin) { FAR struct binfmt_s *binfmt; - int ret; + int ret = -ENOENT; #ifdef CONFIG_DEBUG - if (!bin || !bin->filename) - { - ret = -EINVAL; - } - else + if (bin && bin->filename) #endif { bdbg("Loading %s\n", bin->filename); @@ -119,6 +115,7 @@ int load_module(FAR struct binary_s *bin) { /* Successfully loaded -- break out with ret == 0 */ + bvdbg("Successfully loaded module %s\n", bin->filename); dump_module(bin); break; } diff --git a/nuttx/binfmt/libnxflat/libnxflat_bind.c b/nuttx/binfmt/libnxflat/libnxflat_bind.c index 86d9f9a20..1d0c8d661 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_bind.c +++ b/nuttx/binfmt/libnxflat/libnxflat_bind.c @@ -215,10 +215,12 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo) hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace; + /* From this, we can get the list of relocation entries. */ + /* From this, we can get the offset to the list of relocation entries */ offset = ntohl(hdr->h_relocstart); - nrelocs = ntohs(hdr->h_reloccount); + nrelocs = ntohl(hdr->h_reloccount); /* The value of the relocation list that we get from the header is a * file offset. We will have to convert this to an offset into the @@ -226,7 +228,9 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo) * list. */ - DEBUGASSERT(offset >= loadinfo->isize && offset < (loadinfo->isize + loadinfo->dsize)); + DEBUGASSERT(offset >= loadinfo->isize); + DEBUGASSERT(offset + nrelocs * sizeof(struct nxflat_reloc_s) <= (loadinfo->isize + loadinfo->dsize)); + relocs = (FAR struct nxflat_reloc_s*)(offset - loadinfo->isize + loadinfo->dspace->region); /* Now, traverse the relocation list of and bind each GOT relocation. */ diff --git a/nuttx/binfmt/libnxflat/libnxflat_init.c b/nuttx/binfmt/libnxflat/libnxflat_init.c index 8be811342..8bc9aef99 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_init.c +++ b/nuttx/binfmt/libnxflat/libnxflat_init.c @@ -105,7 +105,7 @@ int nxflat_init(const char *filename, struct nxflat_hdr_s *header, /* Read the NXFLAT header from offset 0 */ - ret = nxflat_read(loadinfo, (char*)&header, sizeof(struct nxflat_hdr_s), 0); + ret = nxflat_read(loadinfo, (char*)header, sizeof(struct nxflat_hdr_s), 0); if (ret < 0) { bdbg("Failed to read NXFLAT header: %d\n", ret); diff --git a/nuttx/binfmt/libnxflat/libnxflat_load.c b/nuttx/binfmt/libnxflat/libnxflat_load.c index f0488bae1..805b3440d 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_load.c +++ b/nuttx/binfmt/libnxflat/libnxflat_load.c @@ -107,6 +107,8 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo) { off_t doffset; /* Offset to .data in the NXFLAT file */ uint32 dreadsize; /* Total number of bytes of .data to be read */ + uint32 relocsize; /* Memory needed to hold relocations */ + uint32 extrasize; /* MAX(BSS size, relocsize) */ int ret = OK; /* Calculate the extra space we need to allocate. This extra space will be @@ -114,40 +116,34 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo) * temporarily to hold relocation information. So the allocated size of this * region will either be the size of .data + size of.bss section OR, the * size of .data + the relocation entries, whichever is larger + * + * This is the amount of memory that we have to have to hold the + * relocations. */ - { - uint32 relocsize; - uint32 extrasize; + relocsize = loadinfo->reloccount * sizeof(struct nxflat_reloc_s); - /* This is the amount of memory that we have to have to hold the - * relocations. - */ - - relocsize = loadinfo->reloccount * sizeof(uint32); - - /* In the file, the relocations should lie at the same offset as BSS. - * The additional amount that we allocate have to be either (1) the - * BSS size, or (2) the size of the relocation records, whicher is - * larger. - */ + /* In the file, the relocations should lie at the same offset as BSS. + * The additional amount that we allocate have to be either (1) the + * BSS size, or (2) the size of the relocation records, whicher is + * larger. + */ - extrasize = MAX(loadinfo->bsssize, relocsize); + extrasize = MAX(loadinfo->bsssize, relocsize); - /* Use this addtional amount to adjust the total size of the dspace - * region. - */ + /* Use this additional amount to adjust the total size of the dspace + * region. + */ - loadinfo->dsize = loadinfo->datasize + extrasize; + loadinfo->dsize = loadinfo->datasize + extrasize; - /* The number of bytes of data that we have to read from the file is - * the data size plus the size of the relocation table. - */ + /* The number of bytes of data that we have to read from the file is + * the data size plus the size of the relocation table. + */ - dreadsize = loadinfo->datasize + relocsize; - } + dreadsize = loadinfo->datasize + relocsize; - /* We'll need this a few times as well. */ + /* We'll need this a few times. */ doffset = loadinfo->isize; diff --git a/nuttx/binfmt/libnxflat/libnxflat_read.c b/nuttx/binfmt/libnxflat/libnxflat_read.c index cf1ba5b37..f94015060 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_read.c +++ b/nuttx/binfmt/libnxflat/libnxflat_read.c @@ -53,6 +53,10 @@ * Pre-Processor Definitions ****************************************************************************/ +#undef NXFLAT_DUMP_READDATA /* Define to dump all file data read */ +#define DUMPER lib_rawprintf /* If NXFLAT_DUMP_READDATA is defined, this + * is the API used to dump data */ + /**************************************************************************** * Private Constant Data ****************************************************************************/ @@ -62,6 +66,31 @@ ****************************************************************************/ /**************************************************************************** + * Name: nxflat_dumpreaddata + ****************************************************************************/ + +#if defined(NXFLAT_DUMP_READDATA) +static inline void nxflat_dumpreaddata(char *buffer, int buflen) +{ + uint32 *buf32 = (uint32*)buffer; + int i; + int j; + + for (i = 0; i < buflen; i += 32) + { + DUMPER("%04x:", i); + for (j = 0; j < 32; j += sizeof(uint32)) + { + DUMPER(" %08x", *buf32++); + } + DUMPER("\n"); + } +} +#else +# define nxflat_dumpreaddata(b,n) +#endif + +/**************************************************************************** * Public Functions ****************************************************************************/ @@ -85,6 +114,8 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize, int bytesleft; /* Number of bytes of .data left to read */ int bytesread; /* Total number of bytes read */ + bvdbg("Read %d bytes from offset %d\n", readsize, offset); + /* Seek to the position in the object file where the initialized * data is saved. */ @@ -126,6 +157,8 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize, } } while (bytesread < readsize); + + nxflat_dumpreaddata(buffer, readsize); return OK; } diff --git a/nuttx/binfmt/libnxflat/libnxflat_verify.c b/nuttx/binfmt/libnxflat/libnxflat_verify.c index 7e6cc548e..96947dbc8 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_verify.c +++ b/nuttx/binfmt/libnxflat/libnxflat_verify.c @@ -90,7 +90,7 @@ 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\"", + bdbg("Unrecognized magic=\"%c%c%c%c\"\n", header->h_magic[0], header->h_magic[1], header->h_magic[2], header->h_magic[3]); return -ENOEXEC; diff --git a/nuttx/binfmt/nxflat.c b/nuttx/binfmt/nxflat.c index f712422f2..8aee2fdd0 100644 --- a/nuttx/binfmt/nxflat.c +++ b/nuttx/binfmt/nxflat.c @@ -128,7 +128,7 @@ static void nxflat_dumploadinfo(struct nxflat_loadinfo_s *loadinfo) bdbg(" HANDLES:\n"); bdbg(" filfd: %d\n", loadinfo->filfd); - bdbg(" NXFLT HEADER:"); + bdbg(" NXFLT HEADER:\n"); bdbg(" header: %p\n", loadinfo->header); } #else |