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 config EXAMPLES_MOUNT
tristate "File system mount example" tristate "File system mount example"
default n default n
select DRVR_MKRD if !EXAMPLES_MOUNT_BLOCKDEVICE select LIB_BOARDCTL if !EXAMPLES_MOUNT_BLOCKDEVICE
select BOARDCTL_MKRD if !EXAMPLES_MOUNT_BLOCKDEVICE
---help--- ---help---
Enable the file system mount example Enable the file system mount example

View File

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

View File

@ -12,7 +12,9 @@ config NSH_LIBRARY
select NETUTILS_NETLIB if NET select NETUTILS_NETLIB if NET
select LIBC_NETDB if NET select LIBC_NETDB if NET
select READLINE_HAVE_EXTMATCH 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--- ---help---
Build the NSH support library. This is used, for example, by Build the NSH support library. This is used, for example, by
system/nsh in order to implement the full NuttShell (NSH). 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) */ /* 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 # undef CONFIG_NSH_DISABLE_MKRD
# define CONFIG_NSH_DISABLE_MKRD 1 # define CONFIG_NSH_DISABLE_MKRD 1
#endif #endif

View File

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