summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2010-05-05 15:06:28 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2010-05-05 15:06:28 +0000
commit9b2361a20d85493471d52545259128bdb3640b29 (patch)
tree8da7596d62bf40340b835910cc37b7fa463c567d /misc
parent2010-04-29 Joel Sherrill <joel.sherrilL@OARcorp.com> (diff)
downloadrtems-examples-9b2361a20d85493471d52545259128bdb3640b29.tar.bz2
2010-05-05 Joel Sherrill <joel.sherrill@oarcorp.com>
* qemu_vfat/.cvsignore, qemu_vfat/Makefile, qemu_vfat/README, qemu_vfat/init.c, qemu_vfat/system.h: New files.
Diffstat (limited to 'misc')
-rw-r--r--misc/ChangeLog5
-rw-r--r--misc/qemu_vfat/.cvsignore1
-rw-r--r--misc/qemu_vfat/Makefile32
-rw-r--r--misc/qemu_vfat/README19
-rw-r--r--misc/qemu_vfat/init.c164
-rw-r--r--misc/qemu_vfat/system.h118
6 files changed, 339 insertions, 0 deletions
diff --git a/misc/ChangeLog b/misc/ChangeLog
index 2acf5fb..46dac60 100644
--- a/misc/ChangeLog
+++ b/misc/ChangeLog
@@ -1,3 +1,8 @@
+2010-05-05 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * qemu_vfat/.cvsignore, qemu_vfat/Makefile, qemu_vfat/README,
+ qemu_vfat/init.c, qemu_vfat/system.h: New files.
+
2010-04-15 Joel Sherrill <joel.sherrill@oarcorp.com>
* x86_display_cpu/Makefile, x86_display_cpu/test.c: Clean up.
diff --git a/misc/qemu_vfat/.cvsignore b/misc/qemu_vfat/.cvsignore
new file mode 100644
index 0000000..fecf58a
--- /dev/null
+++ b/misc/qemu_vfat/.cvsignore
@@ -0,0 +1 @@
+o-optimize
diff --git a/misc/qemu_vfat/Makefile b/misc/qemu_vfat/Makefile
new file mode 100644
index 0000000..3b873d5
--- /dev/null
+++ b/misc/qemu_vfat/Makefile
@@ -0,0 +1,32 @@
+#
+# $Id$
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+PGM=${ARCH}/qemu_vfat.exe
+
+# optional managers required
+MANAGERS=all
+
+# C source names
+CSRCS = init.c
+COBJS = $(CSRCS:%.c=${ARCH}/%.o)
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(PROJECT_ROOT)/make/leaf.cfg
+
+# Define this if you want to run the shell after mounting
+# DEFINES += -DUSE_SHELL
+# Defint this if you want to call start_test() instead
+DEFINES += -DUSE_START_TEST
+
+OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS)
+
+all: ${ARCH} $(PGM)
+
+$(PGM): $(OBJS)
+ $(make-exe)
diff --git a/misc/qemu_vfat/README b/misc/qemu_vfat/README
new file mode 100644
index 0000000..14b1922
--- /dev/null
+++ b/misc/qemu_vfat/README
@@ -0,0 +1,19 @@
+#
+# $Id$
+#
+
+This directory contains an example program which should be of use
+in some situations. It is designed to be used with Qemu's
+virtual FAT file system support. Qemu can make a directory on
+the host computer appear as a FAT file system to the simulated
+system. This capability appears to have limits on the number
+and size of files as well as some limitations about writes
+from the simulated system appearing in the native file system.
+But this should be useful for testing interpreters like Parrot,
+Mono, or the RTEMS Shell.
+
+When testing an interpreter, you often want to have the same
+executable exercised with different arguments or input files.
+With this setup, you can copy those test support files into
+the host directory and the RTEMS "main" will use those in
+support of the testing.
diff --git a/misc/qemu_vfat/init.c b/misc/qemu_vfat/init.c
new file mode 100644
index 0000000..05a2913
--- /dev/null
+++ b/misc/qemu_vfat/init.c
@@ -0,0 +1,164 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <rtems.h>
+#include <fcntl.h>
+#include <rtems/error.h>
+#include <rtems/dosfs.h>
+#include <ctype.h>
+#include <rtems/bdpart.h>
+#include <rtems/libcsupport.h>
+#include <rtems/fsmount.h>
+
+/*
+ * Table of FAT file systems that will be mounted
+ * with the "rtems_fsmount" function.
+ * See cpukit/libmisc/fsmount for definition of fields
+ */
+fstab_t fs_table[] = {
+ {
+ "/dev/hda1", "/mnt/test",
+ &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE,
+ FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
+ 0
+ },
+};
+
+#ifndef USE_SHELL
+void start_test(void);
+#endif
+
+#ifdef USE_SHELL
+#include <rtems/shell.h>
+
+static void writeFile(
+ const char *name,
+ mode_t mode,
+ const char *contents
+)
+{
+ int sc;
+ sc = setuid(0);
+ if ( sc ) {
+ printf( "setuid failed: %s: %s\n", name, strerror(errno) );
+ }
+
+ rtems_shell_write_file( name, contents );
+
+ sc = chmod ( name, mode );
+ if ( sc ) {
+ printf( "chmod %s: %s\n", name, strerror(errno) );
+ }
+}
+
+#define writeScript( _name, _contents ) \
+ writeFile( _name, 0777, _contents )
+
+static void fileio_start_shell(void)
+{
+ int sc;
+
+ sc = mkdir("/scripts", 0777);
+ if ( sc ) {
+ printf( "mkdir /scripts: %s:\n", strerror(errno) );
+ }
+
+ sc = mkdir("/etc", 0777);
+ if ( sc ) {
+ printf( "mkdir /etc: %s:\n", strerror(errno) );
+ }
+
+ fprintf(
+ stderr,
+ "Creating /etc/passwd and group with three useable accounts\n"
+ "root/pwd , test/pwd, rtems/NO PASSWORD"
+ );
+
+ writeFile(
+ "/etc/passwd",
+ 0644,
+ "root:7QR4o148UPtb.:0:0:root::/:/bin/sh\n"
+ "rtems:*:1:1:RTEMS Application::/:/bin/sh\n"
+ "test:8Yy.AaxynxbLI:2:2:test account::/:/bin/sh\n"
+ "tty:!:3:3:tty owner::/:/bin/false\n"
+ );
+ writeFile(
+ "/etc/group",
+ 0644,
+ "root:x:0:root\n"
+ "rtems:x:1:rtems\n"
+ "test:x:2:test\n"
+ "tty:x:3:tty\n"
+ );
+
+ rtems_shell_init(
+ "SHLL", /* task_name */
+ RTEMS_MINIMUM_STACK_SIZE * 4, /* task_stacksize */
+ 100, /* task_priority */
+ "/dev/console", /* devname */
+ false, /* forever */
+ true, /* wait */
+ rtems_shell_login_check /* login */
+ );
+}
+#endif /* USE_SHELL */
+
+/*
+ * RTEMS Startup Task
+ */
+rtems_task
+Init (rtems_task_argument ignored)
+{
+ rtems_status_code rc;
+
+ puts( "\n\n*** QEMU VFAT AND SHELL TEST ***" );
+
+ rc = rtems_bdpart_register_from_disk("/dev/hda");
+ if ( rc != RTEMS_SUCCESSFUL ) {
+ fprintf( stderr, "Unable to initialize partition table from /dev/hda\n" );
+ exit(1);
+ }
+
+ rc = rtems_fsmount(
+ fs_table,
+ sizeof(fs_table)/sizeof(fs_table[0]),
+ NULL
+ );
+ if ( rc != RTEMS_SUCCESSFUL ) {
+ fprintf( stderr, "Unable to mount /dev/hda1\n" );
+ exit(1);
+ }
+
+#if defined(USE_SHELL)
+ fileio_start_shell ();
+#endif
+#if defined(USE_START_TEST)
+ start_test ();
+#endif
+ puts( "*** END OF QEMU VFAT AND SHELL TEST ***" );
+ exit(0);
+}
+
+#if defined(USE_SHELL)
+
+#define CONFIGURE_SHELL_COMMANDS_INIT
+#define CONFIGURE_SHELL_COMMANDS_ALL
+#define CONFIGURE_SHELL_MOUNT_MSDOS
+
+#include <rtems/shellconfig.h>
+#endif
diff --git a/misc/qemu_vfat/system.h b/misc/qemu_vfat/system.h
new file mode 100644
index 0000000..f6663d8
--- /dev/null
+++ b/misc/qemu_vfat/system.h
@@ -0,0 +1,118 @@
+/* system.h
+ *
+ * This include file contains information that is included in every
+ * function in the test set.
+ *
+ * COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * system.h,v 1.13 2000/06/12 15:00:12 joel Exp
+ */
+
+#include <rtems.h>
+
+/* functions */
+
+rtems_task Init(
+ rtems_task_argument argument
+);
+
+/* global variables */
+
+
+/* configuration information */
+
+#include <bsp.h> /* for device driver prototypes */
+
+#define FILEIO_BUILD 1
+#if BSP_SMALL_MEMORY
+#undef FILEIO_BUILD
+#endif
+
+#if defined(RTEMS_BSP_HAS_IDE_DRIVER) && !BSP_SMALL_MEMORY
+#include <libchip/ata.h> /* for ata driver prototype */
+#include <libchip/ide_ctrl.h> /* for general ide driver prototype */
+#endif
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#ifdef RTEMS_BSP_HAS_IDE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
+#endif
+#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+/*
+ * XXX: these values are higher than needed...
+ */
+#define CONFIGURE_MAXIMUM_TASKS 20
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 20
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
+#define CONFIGURE_STACK_CHECKER_ENABLED
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_EXTRA_TASK_STACKS (6 * RTEMS_MINIMUM_STACK_SIZE)
+
+#define CONFIGURE_MALLOC_STATISTICS
+
+#define CONFIGURE_UNIFIED_WORK_AREAS
+#include <rtems/confdefs.h>
+
+/*
+ * Handy macros and static inline functions
+ */
+
+/*
+ * Macro to hide the ugliness of printing the time.
+ */
+
+#define print_time(_s1, _tb, _s2) \
+ do { \
+ printf( "%s%02d:%02d:%02d %02d/%02d/%04d%s", \
+ _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
+ (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
+ fflush(stdout); \
+ } while ( 0 )
+
+/*
+ * Macro to print an task name that is composed of ASCII characters.
+ *
+ */
+
+#define put_name( _name, _crlf ) \
+ do { \
+ uint32_t c0, c1, c2, c3; \
+ \
+ c0 = ((_name) >> 24) & 0xff; \
+ c1 = ((_name) >> 16) & 0xff; \
+ c2 = ((_name) >> 8) & 0xff; \
+ c3 = (_name) & 0xff; \
+ putchar( (char)c0 ); \
+ if ( c1 ) putchar( (char)c1 ); \
+ if ( c2 ) putchar( (char)c2 ); \
+ if ( c3 ) putchar( (char)c3 ); \
+ if ( (_crlf) ) \
+ putchar( '\n' ); \
+ } while (0)
+
+/*
+ * This allows us to view the "Test_task" instantiations as a set
+ * of numbered tasks by eliminating the number of application
+ * tasks created.
+ *
+ * In reality, this is too complex for the purposes of this
+ * example. It would have been easier to pass a task argument. :)
+ * But it shows how rtems_id's can sometimes be used.
+ */
+
+#define task_number( tid ) \
+ ( rtems_object_id_get_index( tid ) - \
+ rtems_configuration_get_rtems_api_configuration()-> \
+ number_of_initialization_tasks )
+
+/* end of include file */