nshlib/nsh_romfsetc.c and graphics/traveler/trv_romfs.c: Replace direct calls to romdisk_register() with indirect calls via boardioctl(BOARDIOC_ROMDISK). This not only fixes the violation of the portable POSIX OS interface, but also permits use of ROM disks in PROTECTED and KERNEL modes. There are still multiple illegal calls to romdisk_register() from code under apps/examples. These all must also be converted to use boardioctl(BOARDIOC_ROMDISK) someday.

This commit is contained in:
Gregory Nutt 2019-10-26 13:47:03 -06:00
parent 06acc559a1
commit 0dde32fb43
5 changed files with 45 additions and 27 deletions

View File

@ -6,7 +6,8 @@
config EXAMPLES_MOUNT
tristate "File system mount example"
default n
select DRVR_MKRD if !EXAMPLES_MOUNT_BLOCKDEVICE
select LIB_BOARDCTL if !EXAMPLES_MOUNT_BLOCKDEVICE
select BOARDCTL_MKRD if !EXAMPLES_MOUNT_BLOCKDEVICE
---help---
Enable the file system mount example

View File

@ -44,6 +44,7 @@
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/boardctl.h>
#include <stdio.h>
#include <nuttx/drivers/ramdisk.h>
@ -62,6 +63,10 @@
# error You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT
#endif
#ifndef CONFIG_BOARDCTL_ROMDISK
# error You must select CONFIG_BOARDCTL_ROMDISK in your configuration file
#endif
/* Describe the ROMFS file system */
#define SECTORSIZE 512
@ -81,13 +86,18 @@
int trv_mount_world(int minor, FAR const char *mountpoint)
{
struct boardioc_romdisk_s desc;
char devpath[16];
int ret;
/* Create a ROM disk for the ROMFS filesystem */
ret = romdisk_register(minor, (FAR uint8_t *)trv_romfs_img,
NSECTORS(trv_romfs_img_len), SECTORSIZE);
desc.minor = minor; /* Minor device number of the RAM disk. */
desc.nsectors = NSECTORS(trv_romfs_img_len); /* The number of sectors in the RAM disk */
desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */
desc.image = trv_romfs_img; /* File system image */
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
if (ret < 0)
{
return ret;

View File

@ -12,7 +12,9 @@ config NSH_LIBRARY
select NETUTILS_NETLIB if NET
select LIBC_NETDB if NET
select READLINE_HAVE_EXTMATCH
select DRVR_MKRD if !NSH_DISABLE_MKRD && !DISABLE_MOUNTPOINT
select LIB_BOARDCTL if (!NSH_DISABLE_MKRD && !DISABLE_MOUNTPOINT) || NSH_ARCHINIT || NSH_ROMFSETC
select BOARDCTL_MKRD if !NSH_DISABLE_MKRD && !DISABLE_MOUNTPOINT
select BOARDCTL_ROMDISK if NSH_ROMFSETC
---help---
Build the NSH support library. This is used, for example, by
system/nsh in order to implement the full NuttShell (NSH).

View File

@ -874,7 +874,7 @@ int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl);
/* The mkrd command depends on boardctl(BOARDIOC_MKRD) */
#if !defined(CONFIG_LIB_BOARDCTL) || !defined(CONFIG_DRVR_MKRD)
#if !defined(CONFIG_LIB_BOARDCTL) || !defined(CONFIG_BOARDCTL_MKRD)
# undef CONFIG_NSH_DISABLE_MKRD
# define CONFIG_NSH_DISABLE_MKRD 1
#endif

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <sys/mount.h>
#include <sys/boardctl.h>
#include <debug.h>
#include <errno.h>
@ -65,25 +66,22 @@
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
#ifdef CONFIG_DISABLE_MOUNTPOINT
# error You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
#if defined(CONFIG_NSH_CROMFSETC)
# ifndef CONFIG_FS_CROMFS
# error You must select CONFIG_FS_CROMFS in your configuration file
# endif
#else
# ifndef CONFIG_FS_ROMFS
# error You must select CONFIG_FS_ROMFS in your configuration file
# endif
# ifndef CONFIG_BOARDCTL_ROMDISK
# error You must select CONFIG_BOARDCTL_ROMDISK in your configuration file
# endif
#endif
/****************************************************************************
* Public Functions
@ -97,14 +95,20 @@ int nsh_romfsetc(void)
{
int ret;
#if !defined(CONFIG_NSH_CROMFSETC)
#ifndef CONFIG_NSH_CROMFSETC
struct boardioc_romdisk_s desc;
/* Create a ROM disk for the /etc filesystem */
ret = romdisk_register(CONFIG_NSH_ROMFSDEVNO, romfs_img,
NSECTORS(romfs_img_len), CONFIG_NSH_ROMFSSECTSIZE);
desc.minor = CONFIG_NSH_ROMFSDEVNO; /* Minor device number of the RAM disk. */
desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the RAM disk */
desc.sectsize = CONFIG_NSH_ROMFSSECTSIZE; /* The size of one sector in bytes */
desc.image = romfs_img; /* File system image */
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
if (ret < 0)
{
ferr("ERROR: romdisk_register failed: %d\n", -ret);
ferr("ERROR: boardctl(BOARDIOC_ROMDISK) failed: %d\n", -ret);
return ERROR;
}
#endif
@ -125,6 +129,7 @@ int nsh_romfsetc(void)
MOUNT_DEVNAME, CONFIG_NSH_ROMFSMOUNTPT, errno);
return ERROR;
}
return OK;
}