Update NSH and examples/modules for changes in kernel module interface.

This commit is contained in:
Gregory Nutt 2017-01-22 15:10:12 -06:00
parent b17917a39a
commit d195751a90
4 changed files with 44 additions and 19 deletions

View file

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

View file

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

View file

@ -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 <gnutt@nuttx.org>
*
* 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);

View file

@ -59,13 +59,13 @@
int cmd_insmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
int ret;
FAR void *handle;
/* Usage: insmod <filepath> <modulename> */
/* 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 <modulename> */
/* 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 : "",