From a2428db4995a5834c186f4842bd0673334c697de Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 7 Aug 2018 10:50:25 -0600 Subject: [PATCH] configs/olimex-stm32_p407: Add logic to support initialization of the kernel module symbol table installed in the pass2/ directory during the application phase of the build. The kmodule configuration appears to be fully functional. --- configs/olimex-stm32-p407/README.txt | 9 +++------ configs/olimex-stm32-p407/kmodule/defconfig | 19 ++---------------- .../olimex-stm32-p407/src/olimex-stm32-p407.h | 12 +++++++++++ configs/olimex-stm32-p407/src/stm32_bringup.c | 20 +++++++++++++++++++ sched/module/mod_insmod.c | 2 +- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/configs/olimex-stm32-p407/README.txt b/configs/olimex-stm32-p407/README.txt index c509f8f972..dfbc22fb6b 100644 --- a/configs/olimex-stm32-p407/README.txt +++ b/configs/olimex-stm32-p407/README.txt @@ -333,12 +333,9 @@ must be is one of the following. kelf configuration, the logic in apps/example/module will wait on power up until the USB FLASH driver has been inserted and initialized. - STATUS: There is an issue that makes this configuration unusable at the - present time: The symbol table is built by apps/examples/module/drivers/Makefile - in user space. The problem with that is that the kernel module does reference - internal kernel symbols which are not available in the user space build context. - A mechanism is needed in the build system to build the symbol table in the - context of the kernel. There is currently no way to do that. + STATUS: + 2018-08-07: After some struggle, the configuration appears to be + working correctly. knsh: diff --git a/configs/olimex-stm32-p407/kmodule/defconfig b/configs/olimex-stm32-p407/kmodule/defconfig index a2ea0e8882..dafbd47abf 100644 --- a/configs/olimex-stm32-p407/kmodule/defconfig +++ b/configs/olimex-stm32-p407/kmodule/defconfig @@ -9,24 +9,10 @@ CONFIG_ARCH_IRQBUTTONS=y CONFIG_ARCH_STACKDUMP=y CONFIG_ARMV7M_USEBASEPRI=y CONFIG_ARM_MPU=y +CONFIG_BOARD_INITIALIZE=y +CONFIG_BOARD_INITTHREAD=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILD_PROTECTED=y -CONFIG_DEBUG_ASSERTIONS=y -CONFIG_DEBUG_BINFMT=y -CONFIG_DEBUG_BINFMT_ERROR=y -CONFIG_DEBUG_BINFMT_WARN=y -CONFIG_DEBUG_CUSTOMOPT=y -CONFIG_DEBUG_ERROR=y -CONFIG_DEBUG_FEATURES=y -CONFIG_DEBUG_FS=y -CONFIG_DEBUG_FS_ERROR=y -CONFIG_DEBUG_FS_WARN=y -CONFIG_DEBUG_INFO=y -CONFIG_DEBUG_SYMBOLS=y -CONFIG_DEBUG_USB=y -CONFIG_DEBUG_USB_ERROR=y -CONFIG_DEBUG_USB_WARN=y -CONFIG_DEBUG_WARN=y CONFIG_EXAMPLES_MODULE=y CONFIG_EXAMPLES_MODULE_DEVPATH="/dev/sda" CONFIG_EXAMPLES_MODULE_FSREMOVEABLE=y @@ -34,7 +20,6 @@ CONFIG_FAT_LCNAMES=y CONFIG_FAT_LFN=y CONFIG_FS_FAT=y CONFIG_FS_PROCFS=y -CONFIG_HOST_WINDOWS=y CONFIG_INTELHEX_BINARY=y CONFIG_LIB_BOARDCTL=y CONFIG_MAX_TASKS=16 diff --git a/configs/olimex-stm32-p407/src/olimex-stm32-p407.h b/configs/olimex-stm32-p407/src/olimex-stm32-p407.h index 3f33c72d1b..44f6c8ddde 100644 --- a/configs/olimex-stm32-p407/src/olimex-stm32-p407.h +++ b/configs/olimex-stm32-p407/src/olimex-stm32-p407.h @@ -62,6 +62,7 @@ #define HAVE_USBHOST 1 #define HAVE_USBMONITOR 1 #define HAVE_ELF 1 +#define HAVE_MODSYMS 1 /* Can't support MMC/SD features if mountpoints are disabled or if SDIO support * is not enabled. @@ -131,6 +132,17 @@ # undef HAVE_ELF #endif +/* Module symbol table */ + +#if !defined(CONFIG_EXAMPLES_MODULE) || defined(CONFIG_BUILD_FLAT) +# undef HAVE_MODSYMS +#endif + +#ifdef HAVE_MODSYMS +# define MODSYMS_NSYMBOLS_VAR g_mod_nexports +# define MODSYMS_SYMTAB_ARRAY g_mod_exports +#endif + /* Olimex-STM32-P407 GPIOs **************************************************/ /* LEDs */ diff --git a/configs/olimex-stm32-p407/src/stm32_bringup.c b/configs/olimex-stm32-p407/src/stm32_bringup.c index 05ba7aae06..c83ad38a76 100644 --- a/configs/olimex-stm32-p407/src/stm32_bringup.c +++ b/configs/olimex-stm32-p407/src/stm32_bringup.c @@ -54,6 +54,11 @@ # include #endif +#ifdef CONFIG_MODULE +# include "nuttx/symtab.h" +# include "nuttx/lib/modlib.h" +#endif + #ifdef CONFIG_STM32_OTGFS # include "stm32_usbhost.h" #endif @@ -61,6 +66,15 @@ #include "stm32.h" #include "olimex-stm32-p407.h" +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef HAVE_MODSYMS +extern const struct symtab_s MODSYMS_SYMTAB_ARRAY[]; +extern const int MODSYMS_NSYMBOLS_VAR; +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -96,6 +110,12 @@ int stm32_bringup(void) } #endif +#ifdef HAVE_MODSYMS + /* Install the module symbol table */ + + modlib_setsymtab(MODSYMS_SYMTAB_ARRAY, MODSYMS_NSYMBOLS_VAR); +#endif + #ifdef HAVE_ELF /* Initialize the ELF binary loader */ diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index 7337a0ee12..4b4b5dba98 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -70,7 +70,7 @@ * Name: mod_dumploadinfo ****************************************************************************/ -#if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_BINFMT) +#ifdef CONFIG_DEBUG_BINFMT_INFO static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) { int i;