summaryrefslogtreecommitdiffstats
path: root/testsuites/samples
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2011-07-04 00:34:00 +0000
committerChris Johns <chrisj@rtems.org>2011-07-04 00:34:00 +0000
commit7032a45830795f1764cc9282cb7642a79e7eb5ac (patch)
tree726d325edbf7c2173b2b39142ae8350c0e828511 /testsuites/samples
parentacb92e332ba7a5c978fe5f73e357c8235cc7d37c (diff)
downloadrtems-7032a45830795f1764cc9282cb7642a79e7eb5ac.tar.bz2
2011-07-04 Chris Johns <chrisj@rtems.org>
* fileio/init.c, fileio/system.h: Add commands to create ram disks from the shell prompt. Helps testing.
Diffstat (limited to 'testsuites/samples')
-rw-r--r--testsuites/samples/ChangeLog5
-rw-r--r--testsuites/samples/fileio/init.c529
-rw-r--r--testsuites/samples/fileio/system.h8
3 files changed, 540 insertions, 2 deletions
diff --git a/testsuites/samples/ChangeLog b/testsuites/samples/ChangeLog
index 09a87997ca..e5a32397d9 100644
--- a/testsuites/samples/ChangeLog
+++ b/testsuites/samples/ChangeLog
@@ -1,3 +1,8 @@
+2011-07-04 Chris Johns <chrisj@rtems.org>
+
+ * fileio/init.c, fileio/system.h: Add commands to
+ create ram disks from the shell prompt. Helps testing.
+
2011-06-20 Ralf Cors├ępius <ralf.corsepius@rtems.org>
* pppd/Makefile.am: Add ppp.conf, pppd.options to EXTRA_DIST.
diff --git a/testsuites/samples/fileio/init.c b/testsuites/samples/fileio/init.c
index f277953efe..b0ebc69629 100644
--- a/testsuites/samples/fileio/init.c
+++ b/testsuites/samples/fileio/init.c
@@ -33,14 +33,138 @@
#include <errno.h>
#include <rtems.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <rtems/error.h>
#include <rtems/dosfs.h>
#include <ctype.h>
#include <rtems/bdpart.h>
#include <rtems/libcsupport.h>
#include <rtems/fsmount.h>
+#include <rtems/ramdisk.h>
+#include <rtems/nvdisk.h>
+#include <rtems/nvdisk-sram.h>
#if FILEIO_BUILD
+
+/**
+ * Let the IO system allocation the next available major number.
+ */
+#define RTEMS_DRIVER_AUTO_MAJOR (0)
+
+/*
+ * RAM disk driver so you can create a RAM disk from the shell prompt.
+ */
+/**
+ * The RAM Disk configuration.
+ */
+rtems_ramdisk_config rtems_ramdisk_configuration[] =
+{
+ {
+ block_size: 512,
+ block_num: 1024,
+ location: NULL
+ }
+};
+
+/**
+ * The number of RAM Disk configurations.
+ */
+size_t rtems_ramdisk_configuration_size = 1;
+
+/**
+ * Create the RAM Disk Driver entry.
+ */
+rtems_driver_address_table rtems_ramdisk_io_ops = {
+ initialization_entry: ramdisk_initialize,
+ open_entry: rtems_blkdev_generic_open,
+ close_entry: rtems_blkdev_generic_close,
+ read_entry: rtems_blkdev_generic_read,
+ write_entry: rtems_blkdev_generic_write,
+ control_entry: rtems_blkdev_generic_ioctl
+};
+
+/**
+ * The NV Device descriptor. For this test it is just DRAM.
+ */
+rtems_nvdisk_device_desc rtems_nv_heap_device_descriptor[] =
+{
+ {
+ flags: 0,
+ base: 0,
+ size: 1 * 1024 * 1024,
+ nv_ops: &rtems_nvdisk_sram_handlers
+ }
+};
+
+/**
+ * The NV Disk configuration.
+ */
+const rtems_nvdisk_config rtems_nvdisk_configuration[] =
+{
+ {
+ block_size: 512,
+ device_count: 1,
+ devices: &rtems_nv_heap_device_descriptor[0],
+ flags: 0,
+ info_level: 0
+ }
+};
+
+/**
+ * The number of NV Disk configurations.
+ */
+uint32_t rtems_nvdisk_configuration_size = 1;
+
+/**
+ * Create the NV Disk Driver entry.
+ */
+rtems_driver_address_table rtems_nvdisk_io_ops = {
+ initialization_entry: rtems_nvdisk_initialize,
+ open_entry: rtems_blkdev_generic_open,
+ close_entry: rtems_blkdev_generic_close,
+ read_entry: rtems_blkdev_generic_read,
+ write_entry: rtems_blkdev_generic_write,
+ control_entry: rtems_blkdev_generic_ioctl
+};
+
+int
+setup_nvdisk (const char* mntpath)
+{
+ rtems_device_major_number major;
+ rtems_status_code sc;
+
+ /*
+ * For our test we do not have any static RAM or EEPROM devices so
+ * we allocate the memory from the heap.
+ */
+ rtems_nv_heap_device_descriptor[0].base =
+ malloc (rtems_nv_heap_device_descriptor[0].size);
+
+ if (!rtems_nv_heap_device_descriptor[0].base)
+ {
+ printf ("error: no memory for NV disk\n");
+ return 1;
+ }
+
+ /*
+ * Register the NV Disk driver.
+ */
+ printf ("Register NV Disk Driver: ");
+ sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
+ &rtems_nvdisk_io_ops,
+ &major);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ printf ("error: nvdisk driver not initialised: %s\n",
+ rtems_status_text (sc));
+ return 1;
+ }
+
+ printf ("successful\n");
+
+ return 0;
+}
+
/*
* Table of FAT file systems that will be mounted
* with the "fsmount" function.
@@ -104,6 +228,384 @@ fstab_t fs_table[] = {
#ifdef USE_SHELL
#include <rtems/shell.h>
+int
+shell_nvdisk_trace (int argc, char* argv[])
+{
+ const char* driver;
+ int level;
+
+ if (argc != 3)
+ {
+ printf ("error: invalid number of options\n");
+ return 1;
+ }
+
+ driver = argv[1];
+ level = strtoul (argv[2], 0, 0);
+
+ int fd = open (driver, O_WRONLY, 0);
+ if (fd < 0)
+ {
+ printf ("error: driver open failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ if (ioctl (fd, RTEMS_NVDISK_IOCTL_INFO_LEVEL, level) < 0)
+ {
+ printf ("error: driver set level failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ close (fd);
+
+ return 0;
+}
+
+int
+shell_nvdisk_erase (int argc, char* argv[])
+{
+ const char* driver = NULL;
+ int arg;
+ int fd;
+
+ for (arg = 1; arg < argc; arg++)
+ {
+ if (argv[arg][0] == '-')
+ {
+ printf ("error: invalid option: %s\n", argv[arg]);
+ return 1;
+ }
+ else
+ {
+ if (!driver)
+ driver = argv[arg];
+ else
+ {
+ printf ("error: only one driver name allowed: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+ }
+
+ printf ("erase nv disk: %s\n", driver);
+
+ fd = open (driver, O_WRONLY, 0);
+ if (fd < 0)
+ {
+ printf ("error: nvdisk driver open failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ if (ioctl (fd, RTEMS_NVDISK_IOCTL_ERASE_DISK) < 0)
+ {
+ printf ("error: nvdisk driver erase failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ close (fd);
+
+ printf ("nvdisk erased successful\n");
+
+ return 0;
+}
+
+int
+shell_bdbuf_trace (int argc, char* argv[])
+{
+#if RTEMS_BDBUF_TRACE
+ extern bool rtems_bdbuf_tracer;
+ rtems_bdbuf_tracer = !rtems_bdbuf_tracer;
+ printf ("bdbuf trace: %d\n", rtems_bdbuf_tracer);
+#else
+ printf ("bdbuf trace disabled. Rebuild with enabled.\n");
+#endif
+ return 0;
+}
+
+int
+disk_test_set_block_size (dev_t dev, size_t size)
+{
+ rtems_disk_device* dd;
+ int rc;
+
+ dd = rtems_disk_obtain (dev);
+ if (!dd)
+ {
+ printf ("error: cannot obtain disk\n");
+ return 1;
+ }
+
+ rc = dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size);
+
+ rtems_disk_release (dd);
+
+ return rc;
+}
+
+int
+disk_test_write_blocks (dev_t dev, int start, int count, size_t size)
+{
+ int block;
+ uint32_t* ip;
+ uint32_t value = 0;
+ int i;
+ rtems_bdbuf_buffer* bd;
+ rtems_status_code sc;
+
+ if (disk_test_set_block_size (dev, size) < 0)
+ {
+ printf ("error: set block size failed: %s\n", strerror (errno));
+ return 1;
+ }
+
+ for (block = start; block < (start + count); block++)
+ {
+ sc = rtems_bdbuf_read (dev, block, &bd);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ printf ("error: get block %d bd failed: %s\n",
+ block, rtems_status_text (sc));
+ return 1;
+ }
+
+ ip = (uint32_t*) bd->buffer;
+ for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++)
+ *ip = (size << 16) | value;
+
+ sc = rtems_bdbuf_release_modified (bd);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ printf ("error: release block %d bd failed: %s\n",
+ block, rtems_status_text (sc));
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int
+disk_test_block_sizes (int argc, char *argv[])
+{
+ struct stat st;
+ char* name;
+ int start;
+ int count;
+ int size;
+
+ if (argc != (4 + 1))
+ {
+ printf ("error: need to supply a device path, start, block and size\n");
+ return 1;
+ }
+
+ name = argv[1];
+
+ if (stat (name, &st) < 0)
+ {
+ printf ("error: stat '%s' failed: %s\n", name, strerror (errno));
+ return 1;
+ }
+
+ start = strtoul (argv[2], 0, 0);
+ count = strtoul (argv[3], 0, 0);
+ size = strtoul (argv[4], 0, 0);
+
+ return disk_test_write_blocks (st.st_rdev, start, count, size);
+}
+
+size_t
+parse_size_arg (const char* arg)
+{
+ size_t size;
+ size_t scalar = 1;
+
+ size = strtoul (arg, 0, 0);
+ switch (arg[strlen (arg) - 1])
+ {
+ case 'M':
+ scalar = 1000 * 1024;
+ break;
+ case 'm':
+ scalar = 1000000;
+ break;
+ case 'K':
+ scalar = 1024;
+ break;
+ case 'k':
+ scalar = 1000;
+ break;
+ default:
+ printf ("error: invalid scalar (M/m/K/k): %c\n", arg[strlen (arg) - 1]);
+ return 0;
+ }
+ return size * scalar;
+ }
+
+int
+create_ramdisk (int argc, char *argv[])
+{
+ rtems_device_major_number major;
+ rtems_status_code sc;
+ int arg;
+ size_t size = 0;
+ size_t block_size = 0;
+
+ for (arg = 0; arg < argc; ++arg)
+ {
+ if (argv[arg][0] == '-')
+ {
+ switch (argv[arg][0])
+ {
+ case 's':
+ ++arg;
+ if (arg == argc)
+ {
+ printf ("error: -s needs a size\n");
+ return 1;
+ }
+ size = parse_size_arg (argv[arg]);
+ if (size == 0)
+ return 1;
+ break;
+ case 'b':
+ ++arg;
+ if (arg == argc)
+ {
+ printf ("error: -b needs a size\n");
+ return 1;
+ }
+ block_size = parse_size_arg (argv[arg]);
+ if (size == 0)
+ return 1;
+ break;
+ default:
+ printf ("error: invalid option: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+ }
+
+ if (block_size)
+ rtems_ramdisk_configuration[0].block_size = block_size;
+ if (size)
+ rtems_ramdisk_configuration[0].block_num =
+ size / rtems_ramdisk_configuration[0].block_size;
+
+ /*
+ * Register the RAM Disk driver.
+ */
+ printf ("Register RAM Disk Driver [blocks=%" PRIu32 \
+ " block-size=%" PRIu32"]:",
+ rtems_ramdisk_configuration[0].block_num,
+ rtems_ramdisk_configuration[0].block_size);
+
+ sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
+ &rtems_ramdisk_io_ops,
+ &major);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ printf ("error: ramdisk driver not initialised: %s\n",
+ rtems_status_text (sc));
+ return 1;
+ }
+
+ printf ("successful\n");
+
+ return 0;
+}
+
+int
+create_nvdisk (int argc, char *argv[])
+{
+ rtems_device_major_number major;
+ rtems_status_code sc;
+ int arg;
+ size_t size = 0;
+#if ADD_WHEN_NVDISK_HAS_CHANGED
+ size_t block_size = 0;
+#endif
+
+ for (arg = 0; arg < argc; ++arg)
+ {
+ if (argv[arg][0] == '-')
+ {
+ switch (argv[arg][0])
+ {
+ case 's':
+ ++arg;
+ if (arg == argc)
+ {
+ printf ("error: -s needs a size\n");
+ return 1;
+ }
+ size = parse_size_arg (argv[arg]);
+ if (size == 0)
+ return 1;
+ break;
+#if ADD_WHEN_NVDISK_HAS_CHANGED
+ case 'b':
+ ++arg;
+ if (arg == argc)
+ {
+ printf ("error: -b needs a size\n");
+ return 1;
+ }
+ block_size = parse_size_arg (argv[arg]);
+ if (size == 0)
+ return 1;
+ break;
+#endif
+ default:
+ printf ("error: invalid option: %s\n", argv[arg]);
+ return 1;
+ }
+ }
+ }
+
+#if ADD_WHEN_NVDISK_HAS_CHANGED
+ if (block_size)
+ rtems_nvdisk_configuration[0].block_size = block_size;
+#endif
+ if (size)
+ rtems_nv_heap_device_descriptor[0].size = size;
+
+ /*
+ * For our test we do not have any static RAM or EEPROM devices so
+ * we allocate the memory from the heap.
+ */
+ rtems_nv_heap_device_descriptor[0].base =
+ malloc (rtems_nv_heap_device_descriptor[0].size);
+
+ if (!rtems_nv_heap_device_descriptor[0].base)
+ {
+ printf ("error: no memory for NV disk\n");
+ return 1;
+ }
+
+ /*
+ * Register the RAM Disk driver.
+ */
+ printf ("Register NV Disk Driver [size=%" PRIu32 \
+ " block-size=%" PRIu32"]:",
+ rtems_nv_heap_device_descriptor[0].size,
+ rtems_nvdisk_configuration[0].block_size);
+
+ sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
+ &rtems_nvdisk_io_ops,
+ &major);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ printf ("error: nvdisk driver not initialised: %s\n",
+ rtems_status_text (sc));
+ return 1;
+ }
+
+ printf ("successful\n");
+
+ return 0;
+}
+
static void writeFile(
const char *name,
mode_t mode,
@@ -186,7 +688,30 @@ static void fileio_start_shell(void)
"echo j2 DOES NOT have the magic first line\n"
);
- printf(" =========================\n");
+ rtems_shell_add_cmd ("mkrd", "files",
+ "Create a RAM disk driver", create_ramdisk);
+ rtems_shell_add_cmd ("mknvd", "files",
+ "Create a NV disk driver", create_nvdisk);
+ rtems_shell_add_cmd ("nverase", "misc",
+ "nverase driver", shell_nvdisk_erase);
+ rtems_shell_add_cmd ("nvtrace", "misc",
+ "nvtrace driver level", shell_nvdisk_trace);
+ rtems_shell_add_cmd ("bdbuftrace", "files",
+ "bdbuf trace toggle", shell_bdbuf_trace);
+ rtems_shell_add_cmd ("td", "files",
+ "Test disk", disk_test_block_sizes);
+#if RTEMS_RFS_TRACE
+ rtems_shell_add_cmd ("rfs", "files",
+ "RFS trace",
+ rtems_rfs_trace_shell_command);
+#endif
+#if RTEMS_RFS_RTEMS_TRACE
+ rtems_shell_add_cmd ("rrfs", "files",
+ "RTEMS RFS trace",
+ rtems_rfs_rtems_trace_shell_command);
+#endif
+
+ printf("\n =========================\n");
printf(" starting shell\n");
printf(" =========================\n");
rtems_shell_init(
@@ -196,7 +721,7 @@ static void fileio_start_shell(void)
"/dev/console", /* devname */
false, /* forever */
true, /* wait */
- rtems_shell_login_check /* login */
+ NULL /* login */
);
}
#endif /* USE_SHELL */
diff --git a/testsuites/samples/fileio/system.h b/testsuites/samples/fileio/system.h
index 07044238a3..5bc8c30b47 100644
--- a/testsuites/samples/fileio/system.h
+++ b/testsuites/samples/fileio/system.h
@@ -39,13 +39,21 @@ rtems_task Init(
#include <libchip/ide_ctrl.h> /* for general ide driver prototype */
#endif
+#define CONFIGURE_MAXIMUM_DRIVERS 4
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#ifdef RTEMS_BSP_HAS_IDE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER
+#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 14
#endif
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 2
+#define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS 8
+#define CONFIGURE_SWAPOUT_TASK_PRIORITY 15
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+#define CONFIGURE_FILESYSTEM_RFS
+#define CONFIGURE_FILESYSTEM_DOSFS
/*
* XXX: these values are higher than needed...