From d195751a90789dedbc25464b0c4a47fc38cf6030 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Jan 2017 15:10:12 -0600 Subject: [PATCH] Update NSH and examples/modules for changes in kernel module interface. --- examples/module/drivers/chardev/Makefile | 3 ++- examples/module/drivers/chardev/chardev.c | 10 +++++---- examples/module/module_main.c | 23 +++++++++++++------ nshlib/nsh_modcmds.c | 27 +++++++++++++++++------ 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/examples/module/drivers/chardev/Makefile b/examples/module/drivers/chardev/Makefile index 67ae38255..416f718ac 100644 --- a/examples/module/drivers/chardev/Makefile +++ b/examples/module/drivers/chardev/Makefile @@ -34,6 +34,7 @@ ############################################################################ -include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs OBJEXT ?= .o DELIM ?= / @@ -45,7 +46,7 @@ NUTTXLIB = "$(TOPDIR)$(DELIM)lib" endif KDEFINE = ${shell $(TOPDIR)/tools/define.sh "$(CC)" __KERNEL__} -CFLAGS += $(KDEFINE) +CMODULEFLAGS += $(KDEFINE) ifeq ($(CONFIG_EXAMPLES_MODULE_LIBGCC),y) LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name 2>/dev/null}" diff --git a/examples/module/drivers/chardev/chardev.c b/examples/module/drivers/chardev/chardev.c index 2bab2de88..77e4318ef 100644 --- a/examples/module/drivers/chardev/chardev.c +++ b/examples/module/drivers/chardev/chardev.c @@ -145,16 +145,18 @@ static int module_uninitialize(FAR void *arg) * Name: module_initialize * * Description: - * Register /dev/zero + * Register /dev/chardev * ****************************************************************************/ -int module_initialize(mod_uninitializer_t *uninitializer, FAR void **arg) +int module_initialize(FAR struct mod_info_s *modinfo) { syslog(LOG_INFO, "module_initialize:\n"); - *uninitializer = module_uninitialize; - *arg = NULL; + modinfo->uninitializer = module_uninitialize; + modinfo->arg = NULL; + modinfo->exports = NULL; + modinfo->nexports = 0; return register_driver("/dev/chardev", &chardev_fops, 0666, NULL); } diff --git a/examples/module/module_main.c b/examples/module/module_main.c index 7c919dc46..4e7b6d8f8 100644 --- a/examples/module/module_main.c +++ b/examples/module/module_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/module/module_main.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -124,6 +124,7 @@ int module_main(int argc, char *argv[]) #endif { struct boardioc_symtab_s symdesc; + FAR void *handle; char buffer[128]; ssize_t nbytes; int ret; @@ -149,8 +150,15 @@ int module_main(int argc, char *argv[]) NSECTORS(romfs_img_len), SECTORSIZE); if (ret < 0) { - fprintf(stderr, "ERROR: romdisk_register failed: %d\n", ret); - exit(EXIT_FAILURE); + /* This will happen naturally if we registered the ROM disk previously. */ + + if (ret != -EEXIST) + { + fprintf(stderr, "ERROR: romdisk_register failed: %d\n", ret); + exit(EXIT_FAILURE); + } + + printf("main: ROM disk already registered\n"); } /* Mount the file system */ @@ -168,10 +176,11 @@ int module_main(int argc, char *argv[]) /* Install the character driver */ - ret = insmod(MOUNTPT "/chardev", "chardev"); - if (ret < 0) + handle = insmod(MOUNTPT "/chardev", "chardev"); + if (handle == NULL) { - fprintf(stderr, "ERROR: insmod failed: %d\n", ret); + int errcode = errno; + fprintf(stderr, "ERROR: insmod failed: %d\n", errcode); exit(EXIT_FAILURE); } @@ -214,7 +223,7 @@ int module_main(int argc, char *argv[]) lib_dumpbuffer("main: Bytes written", (FAR const uint8_t *)g_write_string, nbytes); close(fd); - ret = rmmod("chardev"); + ret = rmmod(handle); if (ret < 0) { fprintf(stderr, "ERROR: rmmod failed: %d\n", ret); diff --git a/nshlib/nsh_modcmds.c b/nshlib/nsh_modcmds.c index 5bd5a0ab5..3b1d9e727 100644 --- a/nshlib/nsh_modcmds.c +++ b/nshlib/nsh_modcmds.c @@ -59,13 +59,13 @@ int cmd_insmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { - int ret; + FAR void *handle; /* Usage: insmod */ /* Install the module */ - ret = insmod(argv[1], argv[2]); - if (ret < 0) + handle = insmod(argv[1], argv[2]); + if (handle == NULL) { nsh_output(vtbl, g_fmtcmdfailed, argv[0], "insmod", NSH_ERRNO); return ERROR; @@ -80,12 +80,22 @@ int cmd_insmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) int cmd_rmmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { + FAR void *handle; int ret; /* Usage: rmmod */ + /* Get the module handle associated with the name */ + + handle = modhandle(argv[1]); + if (handle == NULL) + { + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "modhandle", NSH_ERRNO); + return ERROR; + } + /* Remove the module */ - ret = rmmod(argv[1]); + ret = rmmod(handle); if (ret < 0) { nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rmmod", NSH_ERRNO); @@ -116,8 +126,8 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /* Output a Header */ - nsh_output(vtbl, "%-16s %8s %8s %8s %8s %8s %8s %8s\n", - "NAME", "INIT", "UNINIT", "ARG", "TEXT", "SIZE", + nsh_output(vtbl, "%-16s %8s %8s %8s %8s %8s %8s %8s %8s\n", + "NAME", "INIT", "UNINIT", "ARG", "NEXPORTS", "TEXT", "SIZE", "DATA", "SIZE"); /* Read each line from the procfs "file" */ @@ -128,6 +138,7 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) FAR char *initializer; FAR char *uninitializer; FAR char *arg; + FAR char *nexports; FAR char *text; FAR char *textsize; FAR char *data; @@ -152,16 +163,18 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) initializer = strtok_r(NULL, ",\n", &lasts); uninitializer = strtok_r(NULL, ",\n", &lasts); arg = strtok_r(NULL, ",\n", &lasts); + nexports = strtok_r(NULL, ",\n", &lasts); text = strtok_r(NULL, ",\n", &lasts); textsize = strtok_r(NULL, ",\n", &lasts); data = strtok_r(NULL, ",\n", &lasts); datasize = strtok_r(NULL, ",\n", &lasts); - nsh_output(vtbl, "%-16s %8s %8s %8s %8s %8s %8s %8s\n", + nsh_output(vtbl, "%-16s %8s %8s %8s %8s %8s %8s %8s %8s\n", modulename, initializer ? initializer : "", uninitializer ? uninitializer : "", arg ? arg : "", + nexports ? nexports : "", text ? text : "", textsize ? textsize : "", data ? data : "",