summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-06-25 00:05:11 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-06-25 00:05:11 +0000
commitdfab3df14acb516e4a7e127b4ced4d1d755fcb59 (patch)
tree7ad2779537de1ab2f84552c6c1580a203c1f80da
parentf183944854afe2bd8ccb56ad20f79e3aa371dc02 (diff)
downloadnuttx-dfab3df14acb516e4a7e127b4ced4d1d755fcb59.tar.gz
nuttx-dfab3df14acb516e4a7e127b4ced4d1d755fcb59.tar.bz2
nuttx-dfab3df14acb516e4a7e127b4ced4d1d755fcb59.zip
Initial NXFLAT debug fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1943 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/binfmt/binfmt_loadmodule.c9
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_bind.c8
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_init.c2
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_load.c46
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_read.c33
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_verify.c2
-rw-r--r--nuttx/binfmt/nxflat.c2
-rw-r--r--nuttx/examples/nxflat/nxflat_main.c42
8 files changed, 101 insertions, 43 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
diff --git a/nuttx/examples/nxflat/nxflat_main.c b/nuttx/examples/nxflat/nxflat_main.c
index f31c21973..7c03b789d 100644
--- a/nuttx/examples/nxflat/nxflat_main.c
+++ b/nuttx/examples/nxflat/nxflat_main.c
@@ -51,6 +51,7 @@
#include <nuttx/ramdisk.h>
#include <nuttx/binfmt.h>
+#include <nuttx/nxflat.h>
#include "tests/romfs.h"
#include "tests/dirlist.h"
@@ -91,6 +92,18 @@
#define ROMFSDEV "/dev/ram0"
#define MOUNTPT "/mnt/romfs"
+/* If CONFIG_DEBUG is enabled, use dbg instead of printf so that the the
+ * output will be synchronous with the debug output.
+ */
+
+#ifdef CONFIG_DEBUG
+# define message dbg
+# define err dbg
+#else
+# define message printf
+# define err fprintf(stderr,
+#endif
+
/****************************************************************************
* Private Types
****************************************************************************/
@@ -114,7 +127,7 @@ static char path[128];
static inline void testheader(FAR const char *progname)
{
- printf("\n%s\n* Executing %s\n%s\n\n", delimiter, progname, delimiter);
+ message("\n%s\n* Executing %s\n%s\n\n", delimiter, progname, delimiter);
}
/****************************************************************************
@@ -139,26 +152,38 @@ int user_start(int argc, char *argv[])
int ret;
int i;
+ /* Initialize the NXFLAT binary loader */
+
+ message("Initializing the NXFLAT binary loader\n");
+ ret = nxflat_initialize();
+ if (ret < 0)
+ {
+ err("ERROR: Initialization of the NXFLAT loader failed: %d\n", ret);
+ exit(1);
+ }
+
/* Create a ROM disk for the ROMFS filesystem */
- printf("Registering romdisk\n");
+ message("Registering romdisk\n");
ret = romdisk_register(0, romfs_img, NSECTORS(romfs_img_len), SECTORSIZE);
if (ret < 0)
{
- fprintf(stderr, "ERROR: romdisk_register failed: %d\n", ret);
+ err("ERROR: romdisk_register failed: %d\n", ret);
+ nxflat_uninitialize();
exit(1);
}
/* Mount the file system */
- printf("Mounting ROMFS filesystem at target=%s with source=%s\n",
+ message("Mounting ROMFS filesystem at target=%s with source=%s\n",
MOUNTPT, ROMFSDEV);
ret = mount(ROMFSDEV, MOUNTPT, "romfs", MS_RDONLY, NULL);
if (ret < 0)
{
- fprintf(stderr, "ERROR: mount(%s,%s,romfs) failed: %s\n",
+ err("ERROR: mount(%s,%s,romfs) failed: %s\n",
ROMFSDEV, MOUNTPT, errno);
+ nxflat_uninitialize();
}
/* Now excercise every progrm in the ROMFS file system */
@@ -177,16 +202,19 @@ int user_start(int argc, char *argv[])
ret = load_module(&bin);
if (ret < 0)
{
- fprintf(stderr, "ERROR: Failed to load program '%s'\n", dirlist[i]);
+ err("ERROR: Failed to load program '%s'\n", dirlist[i]);
exit(1);
}
ret = exec_module(&bin, 50);
if (ret < 0)
{
- fprintf(stderr, "ERROR: Failed to execute program '%s'\n", dirlist[i]);
+ err("ERROR: Failed to execute program '%s'\n", dirlist[i]);
unload_module(&bin);
}
+
+ message("Wait a bit for test completion\n");
+ sleep(2);
}
return 0;
}