From 72e20b303ac759796460977ced104a2f76f227b2 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 6 Sep 2008 13:29:14 +0000 Subject: [PATCH] Add NSH command to create RAMDISK git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@884 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog | 2 + Documentation/NuttShell.html | 112 ++++++++++++++++----- Documentation/NuttX.html | 4 +- arch/arm/src/common/up_exit.c | 26 ++--- arch/arm/src/common/up_initialize.c | 4 +- arch/arm/src/common/up_releasepending.c | 6 +- arch/arm/src/common/up_reprioritizertr.c | 6 +- arch/arm/src/common/up_schedulesigaction.c | 4 +- arch/arm/src/common/up_sigdeliver.c | 6 +- examples/README.txt | 2 +- examples/nsh/README.txt | 42 +++++++- examples/nsh/nsh.h | 1 + examples/nsh/nsh_fscmds.c | 96 +++++++++++++++++- examples/nsh/nsh_main.c | 1 + 14 files changed, 257 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index a3ebf96e797..0fb5348d7eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -451,4 +451,6 @@ * NSH: Created an HTML document and a more detailed README file describing NSH. * Added basic TFTP client logic (netutils/tftpc). Untested as of initial check-in. * NSH: Add get and put commands to support TFTP get and put operations. + * NSH: Added a mkrd command that will create a RAMDISK that can be formatted + and mounted. diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index 2c8d8e2fb19..fa8003a17c0 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -179,73 +179,79 @@
- 2.18 Mount a File System (mount) + 2.18 Create a RAMDISK (mkrd)
- 2.19 Check Network Peer (ping) + 2.19 Mount a File System (mount)
- 2.20 Send File Via TFTP (put) + 2.20 Check Network Peer (ping)
- 2.21 Show Current Working Directory (pwd) + 2.21 Send File Via TFTP (put)
- 2.22 Remove a File (rm) + 2.22 Show Current Working Directory (pwd)
- 2.23 Remove a Directory (rmdir) + 2.23 Remove a File (rm)
- 2.24 Set an Environment Variable (set) + 2.24 Remove a Directory (rmdir)
- 2.25 Execute an NSH Script (sh) + 2.25 Set an Environment Variable (set)
- 2.26 Wait for Seconds (sleep) + 2.26 Execute an NSH Script (sh)
- 2.27 Unmount a File System (umount) + 2.27 Wait for Seconds (sleep)
- 2.28 Unset an Environment Variable (unset) + 2.28 Unmount a File System (umount)
- 2.29 Wait for Microseconds (usleep) + 2.29 Unset an Environment Variable (unset) + + + +
+ + 2.30 Wait for Microseconds (usleep) @@ -989,7 +995,58 @@ nsh> + +
-

2.18 Mount a File System (mount)

+

2.18 Create a RAMDISK (mkrd)

+
+ +

Command Syntax:

+ +

+ Synopsis. + Create a ramdisk consisting of <nsectors>, each of size + <sector-size> (or 512 bytes if <sector-size> is not specified. + The ramdisk will be registered as /dev/ram<n> (if <n> is not + specified, mkrd will attempt to register the ramdisk as /dev/ram0. +

+

Example

+ +

+ Once the ramdisk has been created, it may be formatted using + the mkfatfs command and mounted using the mount command. +

+

Example

+ + + + +
+

2.19 Mount a File System (mount)

@@ -1056,7 +1113,7 @@ nsh>
-

2.19 Check Network Peer (ping)

+

2.20 Check Network Peer (ping)

@@ -1089,7 +1146,7 @@ nsh>
-

2.20 Send File Via TFTP (put)

+

2.21 Send File Via TFTP (put)

@@ -1124,7 +1181,7 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path>
-

2.21 Show Current Working Directory (pwd)

+

2.22 Show Current Working Directory (pwd)

@@ -1154,7 +1211,7 @@ nsh>
-

2.22 Remove a File (rm)

+

2.23 Remove a File (rm)

@@ -1188,7 +1245,7 @@ nsh>
-

2.23 Remove a Directory (rmdir)

+

2.24 Remove a Directory (rmdir)

@@ -1223,7 +1280,7 @@ nsh>
-

2.24 Set an Environment Variable (set)

+

2.25 Set an Environment Variable (set)

@@ -1249,7 +1306,7 @@ nsh>
-

2.25 Execute an NSH Script (sh)

+

2.26 Execute an NSH Script (sh)

@@ -1267,7 +1324,7 @@ sh <script-path>
-

2.26 Wait for Seconds (sleep)

+

2.27 Wait for Seconds (sleep)

@@ -1284,7 +1341,7 @@ sleep <sec>
-

2.27 Unmount a File System (umount)

+

2.28 Unmount a File System (umount)

@@ -1314,7 +1371,7 @@ nsh>
-

2.28 Unset an Environment Variable (unset)

+

2.29 Unset an Environment Variable (unset)

@@ -1340,7 +1397,7 @@ nsh>
-

2.29 Wait for Microseconds (usleep)

+

2.30 Wait for Microseconds (usleep)

@@ -1448,7 +1505,11 @@ usleep <usec> mkfifo - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + CONFIG_NFILE_DESCRIPTORS > 0 + + + mkrd + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT mount @@ -1711,6 +1772,7 @@ usleep <usec>
  • mkdir
  • mkfatfs
  • mkfifo
  • +
  • mkrd
  • mount
  • nice
  • OLDPWD
  • diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index 2e936dee9e2..59f2afdf97b 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -8,7 +8,7 @@

    NuttX RTOS

    -

    Last Updated: September 5, 2008

    +

    Last Updated: September 6, 2008

    @@ -1078,6 +1078,8 @@ nuttx-0.3.14 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * NSH: Created an HTML document and a more detailed README file describing NSH. * Added basic TFTP client logic (netutils/tftpc). Untested as of initial check-in. * NSH: Add get and put commands to support TFTP get and put operations. + * NSH: Added a mkrd command that will create a RAMDISK that can be formatted + and mounted. pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/arch/arm/src/common/up_exit.c b/arch/arm/src/common/up_exit.c index 2660ed80bbb..79ff2121838 100644 --- a/arch/arm/src/common/up_exit.c +++ b/arch/arm/src/common/up_exit.c @@ -78,21 +78,21 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) int i; #endif - dbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); + sdbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - dbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); + sdbg(" filelist refcount=%d\n", + tcb->filelist->fl_crefs); for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { struct inode *inode = tcb->filelist->fl_files[i].f_inode; if (inode) { - dbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } } @@ -101,8 +101,8 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #if CONFIG_NFILE_STREAMS > 0 if (tcb->streams) { - dbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); + sdbg(" streamlist refcount=%d\n", + tcb->streams->sl_crefs); for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { @@ -110,11 +110,11 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) if (filep->fs_filedes >= 0) { #if CONFIG_STDIO_BUFFER_SIZE > 0 - dbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, filep->fs_bufpos - filep->fs_bufstart); #else - dbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif } } @@ -148,10 +148,10 @@ void _exit(int status) (void)irqsave(); - lldbg("TCB=%p exitting\n", tcb); + slldbg("TCB=%p exitting\n", tcb); #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) - lldbg("Other tasks:\n"); + slldbg("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif @@ -164,7 +164,7 @@ void _exit(int status) */ tcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", tcb); + slldbg("New Active Task TCB=%p\n", tcb); /* Then switch contexts */ diff --git a/arch/arm/src/common/up_initialize.c b/arch/arm/src/common/up_initialize.c index 0f70fcca5cd..583142ec05d 100644 --- a/arch/arm/src/common/up_initialize.c +++ b/arch/arm/src/common/up_initialize.c @@ -75,12 +75,12 @@ static void up_calibratedelay(void) { int i; - lldbg("Beginning 100s delay\n"); + slldbg("Beginning 100s delay\n"); for (i = 0; i < 100; i++) { up_mdelay(1000); } - lldbg("End 100s delay\n"); + slldbg("End 100s delay\n"); } #else # define up_calibratedelay() diff --git a/arch/arm/src/common/up_releasepending.c b/arch/arm/src/common/up_releasepending.c index 7f8016d53a0..44b36590f41 100644 --- a/arch/arm/src/common/up_releasepending.c +++ b/arch/arm/src/common/up_releasepending.c @@ -76,7 +76,7 @@ void up_release_pending(void) { _TCB *rtcb = (_TCB*)g_readytorun.head; - lldbg("From TCB=%p\n", rtcb); + slldbg("From TCB=%p\n", rtcb); /* Merge the g_pendingtasks list into the g_readytorun task list */ @@ -101,7 +101,7 @@ void up_release_pending(void) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ @@ -121,7 +121,7 @@ void up_release_pending(void) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ diff --git a/arch/arm/src/common/up_reprioritizertr.c b/arch/arm/src/common/up_reprioritizertr.c index 1f589b73fa9..13081958220 100644 --- a/arch/arm/src/common/up_reprioritizertr.c +++ b/arch/arm/src/common/up_reprioritizertr.c @@ -97,7 +97,7 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority) _TCB *rtcb = (_TCB*)g_readytorun.head; boolean switch_needed; - lldbg("TCB=%p PRI=%d\n", tcb, priority); + slldbg("TCB=%p PRI=%d\n", tcb, priority); /* Remove the tcb task from the ready-to-run list. * sched_removereadytorun will return TRUE if we just @@ -149,7 +149,7 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ @@ -168,7 +168,7 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ diff --git a/arch/arm/src/common/up_schedulesigaction.c b/arch/arm/src/common/up_schedulesigaction.c index 6b56cc3b67b..1dbecc8e76e 100644 --- a/arch/arm/src/common/up_schedulesigaction.c +++ b/arch/arm/src/common/up_schedulesigaction.c @@ -99,7 +99,7 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) { /* Refuse to handle nested signal actions */ - dbg("tcb=0x%p sigdeliver=0x%p\n", tcb, sigdeliver); + sdbg("tcb=0x%p sigdeliver=0x%p\n", tcb, sigdeliver); if (!tcb->xcp.sigdeliver) { @@ -113,7 +113,7 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) * being delivered to the currently executing task. */ - dbg("rtcb=0x%p current_regs=0x%p\n", g_readytorun.head, current_regs); + sdbg("rtcb=0x%p current_regs=0x%p\n", g_readytorun.head, current_regs); if (tcb == (_TCB*)g_readytorun.head) { diff --git a/arch/arm/src/common/up_sigdeliver.c b/arch/arm/src/common/up_sigdeliver.c index 31d798b9356..4b2f1c27b6c 100644 --- a/arch/arm/src/common/up_sigdeliver.c +++ b/arch/arm/src/common/up_sigdeliver.c @@ -90,8 +90,8 @@ void up_sigdeliver(void) up_ledon(LED_SIGNAL); - dbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", - rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); + sdbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", + rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ @@ -124,7 +124,7 @@ void up_sigdeliver(void) * (it is probably EINTR). */ - dbg("Resuming\n"); + sdbg("Resuming\n"); rtcb->pterrno = saved_errno; /* Then restore the correct state for this thread of diff --git a/examples/README.txt b/examples/README.txt index 13865365347..ba6051e16f5 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -39,7 +39,7 @@ examples/mount ^^^^^^^^^^^^^^ This contains a simple test of filesystem mountpoints. - + * CONFIG_EXAMPLES_MOUNT_DEVNAME The name of the user-provided block device to mount. If CONFIG_EXAMPLES_MOUNT_DEVNAME is not provided, then diff --git a/examples/nsh/README.txt b/examples/nsh/README.txt index 1972b2b1364..0c0bc2eba4e 100644 --- a/examples/nsh/README.txt +++ b/examples/nsh/README.txt @@ -325,6 +325,45 @@ o mkfifo brw-rw-rw- 0 ram0 nsh> +o mkrd [-m ] [-s ] + + Create a ramdisk consisting of , each of size + (or 512 bytes if is not specified. + The ramdisk will be registered as /dev/ram (if is not + specified, mkrd will attempt to register the ramdisk as + /dev/ram0. + + Example: + ^^^^^^^^ + + nsh> ls /dev + /dev: + console + null + ttyS0 + ttyS1 + nsh> mkrd 1024 + nsh> ls /dev + /dev: + console + null + ram0 + ttyS0 + ttyS1 + nsh> + + Once the ramdisk has been created, it may be formatted using + the mkfatfs command and mounted using the mount command. + + Example: + ^^^^^^^^ + nsh> mkrd 1024 + nsh> mkfatfs /dev/ram0 + nsh> mount -t vfat /dev/ram0 /tmp + nsh> ls /tmp + /tmp: + nsh> + o mount -t The 'mount' command mounts a file system in the NuttX psuedo @@ -543,7 +582,8 @@ Command Dependencies on Configuration Settings mem --- mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT - mkfifo !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + mkfifo CONFIG_NFILE_DESCRIPTORS > 0 + mkrd !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT ping CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING && !CONFIG_DISABLE_CLOCK && !CONFIG_DISABLE_SIGNALS ps -- diff --git a/examples/nsh/nsh.h b/examples/nsh/nsh.h index f468a264a40..c69aa2342d3 100644 --- a/examples/nsh/nsh.h +++ b/examples/nsh/nsh.h @@ -284,6 +284,7 @@ extern int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # ifndef CONFIG_DISABLE_MOUNTPOINT extern int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + extern int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # ifdef CONFIG_FS_FAT diff --git a/examples/nsh/nsh_fscmds.c b/examples/nsh/nsh_fscmds.c index 458f1130e9d..cd02ca576ee 100644 --- a/examples/nsh/nsh_fscmds.c +++ b/examples/nsh/nsh_fscmds.c @@ -48,6 +48,7 @@ # include # include # endif +# include #endif #endif @@ -756,7 +757,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_mkfifo ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *fullpath = nsh_getfullpath(vtbl, argv[1]); @@ -775,6 +776,99 @@ int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: cmd_mkrd + ****************************************************************************/ + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + const char *fmt; + ubyte *buffer; + uint32 nsectors; + int sectsize = 512; + int minor = 0; + int ret; + + /* Get the mount options */ + + int option; + while ((option = getopt(argc, argv, ":m:s:")) != ERROR) + { + switch (option) + { + case 'm': + minor = atoi(optarg); + if (minor < 0 || minor > 255) + { + fmt = g_fmtargrange; + goto errout_with_fmt; + } + break; + + case 's': + sectsize = atoi(optarg); + if (minor < 0 || minor > 16384) + { + fmt = g_fmtargrange; + goto errout_with_fmt; + } + break; + + case ':': + fmt = g_fmtargrequired; + goto errout_with_fmt; + + case '?': + default: + fmt = g_fmtarginvalid; + goto errout_with_fmt; + } + } + + /* There should be exactly on parameter left on the command-line */ + + if (optind == argc-1) + { + nsectors = (uint32)atoi(argv[optind]); + } + else if (optind >= argc) + { + fmt = g_fmttoomanyargs; + goto errout_with_fmt; + } + else + { + fmt = g_fmtargrequired; + goto errout_with_fmt; + } + + /* Allocate the memory backing up the ramdisk */ + + buffer = (ubyte*)malloc(sectsize * nsectors); + if (!buffer) + { + fmt = g_fmtcmdoutofmemory; + goto errout_with_fmt; + } + + /* Then register the ramdisk */ + + ret = rd_register(minor, buffer, nsectors, sectsize, TRUE); + if (ret < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rd_register", NSH_ERRNO_OF(-ret)); + free(buffer); + return ERROR; + } + return ret; + +errout_with_fmt: + nsh_output(vtbl, fmt, argv[0]); + return ERROR; +} +#endif + /**************************************************************************** * Name: cmd_mount ****************************************************************************/ diff --git a/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index f2890159c66..e58836fccee 100644 --- a/examples/nsh/nsh_main.c +++ b/examples/nsh/nsh_main.c @@ -163,6 +163,7 @@ static const struct cmdmap_s g_cmdmap[] = { "mkfatfs", cmd_mkfatfs, 2, 2, "" }, #endif { "mkfifo", cmd_mkfifo, 2, 2, "" }, + { "mkrd", cmd_mkrd, 2, 6, "[-m ] [-s ] " }, #endif { "mh", cmd_mh, 2, 3, "[=][ ]" }, #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0