Initial NXFLAT debug fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1943 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-06-25 00:05:11 +00:00
parent ca79f124d4
commit fdecac3ce3
8 changed files with 101 additions and 43 deletions

View file

@ -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;
}

View file

@ -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. */

View file

@ -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);

View file

@ -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.
*/
/* 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.
*/
relocsize = loadinfo->reloccount * sizeof(uint32);
extrasize = MAX(loadinfo->bsssize, relocsize);
/* 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.
*/
/* Use this additional amount to adjust the total size of the dspace
* region.
*/
extrasize = MAX(loadinfo->bsssize, relocsize);
loadinfo->dsize = loadinfo->datasize + extrasize;
/* Use this addtional amount to adjust the total size of the dspace
* region.
*/
/* 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.
*/
loadinfo->dsize = loadinfo->datasize + extrasize;
dreadsize = loadinfo->datasize + relocsize;
/* 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;
}
/* We'll need this a few times as well. */
/* We'll need this a few times. */
doffset = loadinfo->isize;

View file

@ -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
****************************************************************************/
@ -61,6 +65,31 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* 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;
}

View file

@ -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;

View file

@ -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

View file

@ -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;
}