From 0dde32fb433d67c4e1c42023cfc08d146977d31e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 26 Oct 2019 13:47:03 -0600 Subject: [PATCH] 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. --- examples/mount/Kconfig | 3 ++- graphics/traveler/trv_romfs.c | 14 ++++++++-- nshlib/Kconfig | 4 ++- nshlib/nsh.h | 2 +- nshlib/nsh_romfsetc.c | 49 +++++++++++++++++++---------------- 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/examples/mount/Kconfig b/examples/mount/Kconfig index e2f685826..81e80eaa5 100644 --- a/examples/mount/Kconfig +++ b/examples/mount/Kconfig @@ -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 diff --git a/graphics/traveler/trv_romfs.c b/graphics/traveler/trv_romfs.c index 155eefaa1..d27a68183 100644 --- a/graphics/traveler/trv_romfs.c +++ b/graphics/traveler/trv_romfs.c @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -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; diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 21b09919c..dc3dfa14a 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -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). diff --git a/nshlib/nsh.h b/nshlib/nsh.h index a2580f002..b2cf53587 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -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 diff --git a/nshlib/nsh_romfsetc.c b/nshlib/nsh_romfsetc.c index 245d5a916..4499f72af 100644 --- a/nshlib/nsh_romfsetc.c +++ b/nshlib/nsh_romfsetc.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -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; }