mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-19 19:44:35 +08:00
apps/examples/module: Add support for CROMFS and for stripping symbols from ELF module binaries.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* examples/module/module_main.c
|
||||
*
|
||||
* Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2015, 2017-2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -57,9 +57,11 @@
|
||||
#include <nuttx/module.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_MODULE_BUILTINFS
|
||||
#if defined(CONFIG_EXAMPLES_MODULE_ROMFS)
|
||||
# include <nuttx/drivers/ramdisk.h>
|
||||
# include "drivers/romfs.h"
|
||||
#elif defined(CONFIG_EXAMPLES_MODULE_CROMFS)
|
||||
# include "drivers/cromfs.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -79,8 +81,8 @@
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_MODULE_BUILTINFS
|
||||
# ifndef CONFIG_FS_ROMFS
|
||||
# error "You must select CONFIG_FS_ROMFS in your configuration file"
|
||||
# if !defined(CONFIG_FS_ROMFS) || !defined(CONFIG_FS_CROMFS)
|
||||
# error "You must select CONFIG_FS_ROMFS or CONFIG_FS_CROMFS in your configuration file"
|
||||
# endif
|
||||
|
||||
# ifdef CONFIG_DISABLE_MOUNTPOINT
|
||||
@@ -89,19 +91,28 @@
|
||||
|
||||
/* Describe the ROMFS file system */
|
||||
|
||||
# define SECTORSIZE 64
|
||||
# define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
|
||||
# define BINDIR "/mnt/romfs"
|
||||
# if defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
||||
# define SECTORSIZE 64
|
||||
# define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
|
||||
# define MOUNTPT "/mnt/romfs"
|
||||
|
||||
# ifndef CONFIG_EXAMPLES_MODULE_DEVMINOR
|
||||
# define CONFIG_EXAMPLES_MODULE_DEVMINOR 0
|
||||
# ifndef CONFIG_EXAMPLES_MODULE_DEVMINOR
|
||||
# define CONFIG_EXAMPLES_MODULE_DEVMINOR 0
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_EXAMPLES_MODULE_DEVPATH
|
||||
# define CONFIG_EXAMPLES_MODULE_DEVPATH "/dev/ram0"
|
||||
# endif
|
||||
# elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
||||
/* Describe the CROMFS file system */
|
||||
|
||||
# define MOUNTPT "/mnt/cromfs"
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_EXAMPLES_MODULE_DEVPATH
|
||||
# define CONFIG_EXAMPLES_MODULE_DEVPATH "/dev/ram0"
|
||||
# endif
|
||||
# define BINDIR MOUNTPT
|
||||
|
||||
#else
|
||||
# define BINDIR CONFIG_EXAMPLES_MODULE_BINDIR
|
||||
# define BINDIR CONFIG_EXAMPLES_MODULE_BINDIR
|
||||
#endif /* CONFIG_EXAMPLES_MODULE_BUILTINFS */
|
||||
|
||||
/****************************************************************************
|
||||
@@ -150,11 +161,21 @@ int module_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_MODULE_BUILTINFS
|
||||
#if defined(CONFIG_EXAMPLES_ELF_ROMFS)
|
||||
/* Create a ROM disk for the ROMFS filesystem */
|
||||
|
||||
printf("main: Registering romdisk at /dev/ram%d\n",
|
||||
CONFIG_EXAMPLES_MODULE_DEVMINOR);
|
||||
|
||||
#if defined(CONFIG_BUILD_FLAT)
|
||||
/* This example violates the portable POSIX interface by calling the OS
|
||||
* internal function romdisk_register() (aka ramdisk_register()). We can
|
||||
* squeak by in with this violation in the FLAT build mode, but not in
|
||||
* other build modes. In other build modes, the following logic must be
|
||||
* performed in the OS board initialization logic (where it really belongs
|
||||
* anyway).
|
||||
*/
|
||||
|
||||
ret = romdisk_register(CONFIG_EXAMPLES_MODULE_DEVMINOR, (FAR uint8_t *)romfs_img,
|
||||
NSECTORS(romfs_img_len), SECTORSIZE);
|
||||
if (ret < 0)
|
||||
@@ -169,19 +190,34 @@ int module_main(int argc, char *argv[])
|
||||
|
||||
printf("main: ROM disk already registered\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Mount the file system */
|
||||
|
||||
printf("main: Mounting ROMFS filesystem at target=%s with source=%s\n",
|
||||
BINDIR, CONFIG_EXAMPLES_MODULE_DEVPATH);
|
||||
MOUNTPT, CONFIG_EXAMPLES_MODULE_DEVPATH);
|
||||
|
||||
ret = mount(CONFIG_EXAMPLES_MODULE_DEVPATH, BINDIR, "romfs", MS_RDONLY, NULL);
|
||||
ret = mount(CONFIG_EXAMPLES_MODULE_DEVPATH, MOUNTPT, "romfs",
|
||||
MS_RDONLY, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: mount(%s,%s,romfs) failed: %s\n",
|
||||
CONFIG_EXAMPLES_MODULE_DEVPATH, BINDIR, errno);
|
||||
CONFIG_EXAMPLES_MODULE_DEVPATH, MOUNTPT, errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
||||
/* Mount the CROMFS file system */
|
||||
|
||||
printf("Mounting CROMFS filesystem at target=%s\n", MOUNTPT);
|
||||
|
||||
ret = mount(NULL, MOUNTPT, "cromfs", MS_RDONLY, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
errmsg("ERROR: mount(%s, cromfs) failed: %d\n", MOUNTPT, errno);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_EXAMPLES_ELF_ROMFS */
|
||||
#endif /* CONFIG_EXAMPLES_MODULE_BUILTINFS */
|
||||
|
||||
/* Install the character driver */
|
||||
|
Reference in New Issue
Block a user