Skip to content

Commit

Permalink
binfmt/binfmt_execsymtab.c: Fix a recently introduced error: The size…
Browse files Browse the repository at this point in the history
… of the symbol table is now an 'int' variable; but a variable cannot be used as an initializer because it is not constant. Also updates a README file.
  • Loading branch information
gregory-nutt committed Jul 17, 2018
1 parent fddc4bf commit 2553df7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
27 changes: 19 additions & 8 deletions binfmt/binfmt_execsymtab.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
* binfmt/binfmt_execsymtab.c
*
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2013, 2016, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -81,13 +81,8 @@ extern int CONFIG_EXECFUNCS_NSYMBOLS_VAR;
* Private Data
****************************************************************************/

#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
static FAR const struct symtab_s *g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
static int g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
#else
static FAR const struct symtab_s *g_exec_symtab;
static int g_exec_nsymbols;
#endif

/****************************************************************************
* Public Functions
Expand All @@ -112,13 +107,29 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
{
irqstate_t flags;

DEBUGASSERT(symtab && nsymbols);
DEBUGASSERT(symtab != NULL && nsymbols != NULL);

/* Disable interrupts very briefly so that both the symbol table and its
* size are returned as a single atomic operation.
*/

flags = enter_critical_section();

#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
/* If a bring-up symbol table has been provided and if the exec symbol
* table has not yet been initialized, then use the provided start-up
* symbol table.
*/

if (g_exec_symtab == NULL)
{
g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
}
#endif

/* Return the symbol table and its size */

*symtab = g_exec_symtab;
*nsymbols = g_exec_nsymbols;
leave_critical_section(flags);
Expand All @@ -143,7 +154,7 @@ void exec_setsymtab(FAR const struct symtab_s *symtab, int nsymbols)
{
irqstate_t flags;

DEBUGASSERT(symtab);
DEBUGASSERT(symtab != NULL);

/* Disable interrupts very briefly so that both the symbol table and its
* size are set as a single atomic operation.
Expand Down
34 changes: 20 additions & 14 deletions configs/sama5d4-ek/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4158,23 +4158,27 @@ Configurations
6a. General build directions (boot from SD card):

A. Build with no symbol table

$ cd nuttx : Go to the NuttX build directory
$ tools/configure.sh sama5d4-ek/kernel : Establish this configuration
$ export PATH=???:$PATH : Set up the PATH variable
$ make : Build the kerne with a dummy ROMFS image
: This should create the nuttx ELF

B. Create the export package

$ make export : Create the kernel export package
: You should have a file like
: nuttx-export-*.zip

C. Build the file system image at apps/bin

$ cd apps/ : Go to the apps/ directory
$ tools/mkimport.sh -x <zip-file> : Use the full path to nuttx-export-*.zip
$ make import : This will build the file system.

D. Create the symbol table from the apps/bin

$ tools/mksymtab.sh bin import/symtab.c
$ ar rcs ../nuttx/binfmt/libbinfmt.a import/symtab.o

Expand All @@ -4195,39 +4199,48 @@ Configurations
You will then need to copy the files from apps/bin to an SD card or USB
FLASH drive to create the bootable SD card.

But how does the SD card/USB drive get mounted? This must be done in
board-specific logic before the 'init' program is started.
But how does the SD card/USB FLASH drive get mounted? This must be
done in board-specific logic before the 'init' program is started.
That logic is not yet implemented for the case of SD card or USB FLASH
driver

6b. General build directions (boot from ROMFS image):

A. Build with dummy ROMFS file system image and no symbol table

$ tools/configure.sh sama5d4-ek/kernel : Establish this configuration
$ export PATH=???:$PATH : Set up the PATH variable
$ touch configs/sama5d4-ek/include/boot_romfsimg.h
$ make : Build the kernel with a dummy ROMFS image
: This should create the nuttx ELF

B. Create the export package

$ make export : Create the kernel export package
: You should have a file like
: nuttx-export-*.zip

C. Build the file system image at apps/bin

$ cd apps/ : Go to the apps/ directory
$ tools/mkimport.sh -x <zip-file> : Use the full path to nuttx-export-*.zip
$ make import : This will build the file system

D. Create the ROMFS file system image

$ tools/mkromfsimg.sh : Create the real ROMFS image
$ mv boot_romfsimg.h ../nuttx/configs/sama5d4-ek/include/boot_romfsimg.h

E. Create the symbol table from the apps/bin

$ tools/mksymtab.sh bin import/symtab.c
$ make symtab : Compile the symbol table
$ ar rcs ../nuttx/binfmt/libbinfmt.a import/symtab.o

NOTE: There are many ways to create symbol tables. The above will create
the minimal symbol tabled needed.

F. Reconfigure and rebuild NuttX
F. Reconfigure and rebuild NuttX/bin

Enable the following in the configuration:
CONFIG_EXECFUNCS_HAVE_SYMTAB=y
Expand All @@ -4238,8 +4251,8 @@ Configurations
$ cd nuttx/ : Rebuild the system with the correct
$ make clean_context all : ROMFS file system and symbol table

But how does the ROMFS file system get mounted? This must be done in
board-specific logic before the 'init' program is started.
But how does the ROMFS file system get mounted? This is done in board-
specific logic before the 'init' program is started.

STATUS:

Expand Down Expand Up @@ -4272,15 +4285,8 @@ Configurations

2018-07-15: Revisited. It is not clear to me how, back in 2014, the
symbol table was created. I have added logic to created the symbol
table, but I am currently stuck in the 'make import' step. This
currently dies with a mysterious error '/bin/sh: -w: invalid option'

That mysterious error is comming from the COMPILE macro defined in
apps/import/Make.defs. There is something lethal about CFLAGS.
Although I can print all of the components of CFLAGS, the use of
CFLAGS causes the error. In fact, this will generate the same error;

$(warning CFLAGS=$(CFLAGS))
table. After some additional fixes, the full build is again
successful.

nsh:

Expand Down

0 comments on commit 2553df7

Please sign in to comment.