mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
This commit corrects a problem with NSH: NSH was calling the OS internal function ramdisk_register() in violation of the portable POSIX interface. This commit solves the problem by introducing a new boardctl() function BOARDIOC_MKRD which moves the RAM disk creation into the OS.
Squashed commit of the following:
drivers/: Run tools/nxstyle against all drivers/*.c.
boards/boardctl.c: Add new boardctl() command, BOARDIOC_MKRD, that can be used to create a RAM disk. This will replace the illegal call to ramdisk_register() currently used by NSH.
drivers/mkrd.c: Add wrapper around ramdisk_register() for creating a proper ramdisk.
This commit is contained in:
@@ -49,6 +49,10 @@
|
|||||||
#include <nuttx/lib/modlib.h>
|
#include <nuttx/lib/modlib.h>
|
||||||
#include <nuttx/binfmt/symtab.h>
|
#include <nuttx/binfmt/symtab.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_FS_WRITABLE
|
||||||
|
# include <nuttx/drivers/ramdisk.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NX
|
#ifdef CONFIG_NX
|
||||||
# include <nuttx/nx/nxmu.h>
|
# include <nuttx/nx/nxmu.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -354,6 +358,32 @@ int boardctl(unsigned int cmd, uintptr_t arg)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_FS_WRITABLE
|
||||||
|
/* CMD: BOARDIOC_MKRD
|
||||||
|
* DESCRIPTION: Create a RAM disk
|
||||||
|
* ARG: Pointer to read-only instance of struct boardioc_mkrd_s.
|
||||||
|
* CONFIGURATION: CONFIG_FS_WRITABLE
|
||||||
|
* DEPENDENCIES: None
|
||||||
|
*/
|
||||||
|
|
||||||
|
case BOARDIOC_MKRD:
|
||||||
|
{
|
||||||
|
FAR const struct boardioc_mkrd_s *desc =
|
||||||
|
(FAR const struct boardioc_mkrd_s *)arg;
|
||||||
|
|
||||||
|
if (desc == NULL)
|
||||||
|
{
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = mkrd((int)desc->minor, desc->nsectors, desc->sectsize,
|
||||||
|
desc->rdflags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_BOARDCTL_APP_SYMTAB
|
#ifdef CONFIG_BOARDCTL_APP_SYMTAB
|
||||||
/* CMD: BOARDIOC_APP_SYMTAB
|
/* CMD: BOARDIOC_APP_SYMTAB
|
||||||
* DESCRIPTION: Select the application symbol table. This symbol table
|
* DESCRIPTION: Select the application symbol table. This symbol table
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ endif
|
|||||||
CSRCS += dev_null.c dev_zero.c
|
CSRCS += dev_null.c dev_zero.c
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
|
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
|
||||||
CSRCS += ramdisk.c
|
CSRCS += ramdisk.c mkrd.c
|
||||||
ifeq ($(CONFIG_DRVR_WRITEBUFFER),y)
|
ifeq ($(CONFIG_DRVR_WRITEBUFFER),y)
|
||||||
CSRCS += rwbuffer.c
|
CSRCS += rwbuffer.c
|
||||||
else
|
else
|
||||||
|
|||||||
+4
-2
@@ -86,7 +86,8 @@ static const struct file_operations devnull_fops =
|
|||||||
* Name: devnull_read
|
* Name: devnull_read
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
return 0; /* Return EOF */
|
return 0; /* Return EOF */
|
||||||
}
|
}
|
||||||
@@ -95,7 +96,8 @@ static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer, size_t len
|
|||||||
* Name: devnull_write
|
* Name: devnull_write
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static ssize_t devnull_write(FAR struct file *filep, FAR const char *buffer, size_t len)
|
static ssize_t devnull_write(FAR struct file *filep, FAR const char *buffer,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
return len; /* Say that everything was written */
|
return len; /* Say that everything was written */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||||||
nxsem_post(fds->sem);
|
nxsem_post(fds->sem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -185,7 +185,6 @@ static void rwb_wrflush(struct rwbuffer_s *rwb)
|
|||||||
|
|
||||||
rwb_resetwrbuffer(rwb);
|
rwb_resetwrbuffer(rwb);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -933,12 +932,13 @@ ssize_t rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock,
|
|||||||
|
|
||||||
ret = rwb_read_(rwb, startblock, nblocks, rdbuffer);
|
ret = rwb_read_(rwb, startblock, nblocks, rdbuffer);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return readblocks + ret;
|
return readblocks + ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: rwb_write
|
* Name: rwb_write
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Values for rdflags */
|
/* Values for rdflags */
|
||||||
|
|
||||||
#define RDFLAG_WRENABLED (1 << 0) /* Bit 0: 1=Can write to RAM disk */
|
#define RDFLAG_WRENABLED (1 << 0) /* Bit 0: 1=Can write to RAM disk */
|
||||||
@@ -93,11 +94,36 @@ extern "C"
|
|||||||
|
|
||||||
#ifdef CONFIG_FS_WRITABLE
|
#ifdef CONFIG_FS_WRITABLE
|
||||||
int ramdisk_register(int minor, FAR uint8_t *buffer, uint32_t nsectors,
|
int ramdisk_register(int minor, FAR uint8_t *buffer, uint32_t nsectors,
|
||||||
uint16_t sectize, uint8_t rdflags);
|
uint16_t sectsize, uint8_t rdflags);
|
||||||
#define romdisk_register(m,b,n,s) ramdisk_register(m,(FAR uint8_t *)b,n,s,0)
|
#define romdisk_register(m,b,n,s) ramdisk_register(m,(FAR uint8_t *)b,n,s,0)
|
||||||
#else
|
#else
|
||||||
int romdisk_register(int minor, FAR const uint8_t *buffer, uint32_t nsectors,
|
int romdisk_register(int minor, FAR const uint8_t *buffer, uint32_t nsectors,
|
||||||
uint16_t sectize);
|
uint16_t sectsize);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mkrd
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This is a wrapper function around ramdisk_register. It combines the
|
||||||
|
* necessary operations to create a RAM disk into a single callable
|
||||||
|
* function. Memory for the RAM disk is allocated, appropriated, from
|
||||||
|
* the kernel heap (in build modes where there is a distinct kernel heap).
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* minor: Selects suffix of device named /dev/ramN, N={1,2,3...}
|
||||||
|
* nsectors: Number of sectors on device
|
||||||
|
* sectize: The size of one sector
|
||||||
|
* rdflags: See RDFLAG_* definitions. Typically
|
||||||
|
* RDFLAG_WRENABLED | RDFLAG_FUNLINK
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_FS_WRITABLE
|
||||||
|
int mkrd(int minor, uint32_t nsectors, uint16_t sectsize, uint8_t rdflags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
|
|||||||
+29
-10
@@ -96,6 +96,12 @@
|
|||||||
* which to receive the board unique ID.
|
* which to receive the board unique ID.
|
||||||
* DEPENDENCIES: Board logic must provide the board_uniqueid() interface.
|
* DEPENDENCIES: Board logic must provide the board_uniqueid() interface.
|
||||||
*
|
*
|
||||||
|
* CMD: BOARDIOC_MKRD
|
||||||
|
* DESCRIPTION: Create a RAM disk
|
||||||
|
* ARG: Pointer to read-only instance of struct boardioc_mkrd_s.
|
||||||
|
* CONFIGURATION: CONFIG_FS_WRITABLE
|
||||||
|
* DEPENDENCIES: None
|
||||||
|
*
|
||||||
* CMD: BOARDIOC_APP_SYMTAB
|
* CMD: BOARDIOC_APP_SYMTAB
|
||||||
* DESCRIPTION: Select the application symbol table. This symbol table
|
* DESCRIPTION: Select the application symbol table. This symbol table
|
||||||
* provides the symbol definitions exported to application
|
* provides the symbol definitions exported to application
|
||||||
@@ -181,15 +187,16 @@
|
|||||||
#define BOARDIOC_POWEROFF _BOARDIOC(0x0003)
|
#define BOARDIOC_POWEROFF _BOARDIOC(0x0003)
|
||||||
#define BOARDIOC_RESET _BOARDIOC(0x0004)
|
#define BOARDIOC_RESET _BOARDIOC(0x0004)
|
||||||
#define BOARDIOC_UNIQUEID _BOARDIOC(0x0005)
|
#define BOARDIOC_UNIQUEID _BOARDIOC(0x0005)
|
||||||
#define BOARDIOC_APP_SYMTAB _BOARDIOC(0x0006)
|
#define BOARDIOC_MKRD _BOARDIOC(0x0006)
|
||||||
#define BOARDIOC_OS_SYMTAB _BOARDIOC(0x0007)
|
#define BOARDIOC_APP_SYMTAB _BOARDIOC(0x0007)
|
||||||
#define BOARDIOC_BUILTINS _BOARDIOC(0x0008)
|
#define BOARDIOC_OS_SYMTAB _BOARDIOC(0x0008)
|
||||||
#define BOARDIOC_USBDEV_CONTROL _BOARDIOC(0x0009)
|
#define BOARDIOC_BUILTINS _BOARDIOC(0x0009)
|
||||||
#define BOARDIOC_NX_START _BOARDIOC(0x000a)
|
#define BOARDIOC_USBDEV_CONTROL _BOARDIOC(0x000a)
|
||||||
#define BOARDIOC_VNC_START _BOARDIOC(0x000b)
|
#define BOARDIOC_NX_START _BOARDIOC(0x000b)
|
||||||
#define BOARDIOC_NXTERM _BOARDIOC(0x000c)
|
#define BOARDIOC_VNC_START _BOARDIOC(0x000c)
|
||||||
#define BOARDIOC_NXTERM_IOCTL _BOARDIOC(0x000d)
|
#define BOARDIOC_NXTERM _BOARDIOC(0x000d)
|
||||||
#define BOARDIOC_TESTSET _BOARDIOC(0x000e)
|
#define BOARDIOC_NXTERM_IOCTL _BOARDIOC(0x000e)
|
||||||
|
#define BOARDIOC_TESTSET _BOARDIOC(0x000f)
|
||||||
|
|
||||||
/* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support.
|
/* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support.
|
||||||
* In this case, all commands not recognized by boardctl() will be forwarded
|
* In this case, all commands not recognized by boardctl() will be forwarded
|
||||||
@@ -198,7 +205,7 @@
|
|||||||
* User defined board commands may begin with this value:
|
* User defined board commands may begin with this value:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BOARDIOC_USER _BOARDIOC(0x000f)
|
#define BOARDIOC_USER _BOARDIOC(0x0010)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Type Definitions
|
* Public Type Definitions
|
||||||
@@ -206,6 +213,18 @@
|
|||||||
|
|
||||||
/* Structures used with IOCTL commands */
|
/* Structures used with IOCTL commands */
|
||||||
|
|
||||||
|
#ifdef CONFIG_FS_WRITABLE
|
||||||
|
/* Describes the RAM disk to be created */
|
||||||
|
|
||||||
|
struct boardioc_mkrd_s
|
||||||
|
{
|
||||||
|
uint8_t minor; /* Minor device number of the RAM disk. */
|
||||||
|
uint32_t nsectors; /* The number of sectors in the RAM disk */
|
||||||
|
uint16_t sectsize; /* The size of one sector in bytes */
|
||||||
|
uint8_t rdflags; /* See RD_FLAGS_* definitions in include/nuttx/ramdisk.h */
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/* In order to full describe a symbol table, a vector containing the address
|
/* In order to full describe a symbol table, a vector containing the address
|
||||||
* of the symbol table and the number of elements in the symbol table is
|
* of the symbol table and the number of elements in the symbol table is
|
||||||
* required.
|
* required.
|
||||||
|
|||||||
Reference in New Issue
Block a user