diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-03-11 18:37:57 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-03-11 18:37:57 +0000 |
commit | 9a183605116062f42d13c5993f17f6b436a2fc06 (patch) | |
tree | a24bcb07cda58a4603cbdbacb4e4ff9190e0da19 /filesystem | |
parent | 2011-03-11 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-examples-9a183605116062f42d13c5993f17f6b436a2fc06.tar.bz2 |
2011-03-11 Joel Sherrill <joel.sherrill@oarcorp.com>
* fat_ramdisk/.cvsignore, fat_ramdisk/Makefile, fat_ramdisk/README,
fat_ramdisk/init.c, fat_ramdisk/rootfs/shell-init: New files.
Diffstat (limited to 'filesystem')
-rw-r--r-- | filesystem/fat_ramdisk/.cvsignore | 4 | ||||
-rw-r--r-- | filesystem/fat_ramdisk/Makefile | 41 | ||||
-rw-r--r-- | filesystem/fat_ramdisk/README | 9 | ||||
-rw-r--r-- | filesystem/fat_ramdisk/init.c | 163 | ||||
-rwxr-xr-x | filesystem/fat_ramdisk/rootfs/shell-init | 3 |
5 files changed, 220 insertions, 0 deletions
diff --git a/filesystem/fat_ramdisk/.cvsignore b/filesystem/fat_ramdisk/.cvsignore new file mode 100644 index 0000000..e1e4b63 --- /dev/null +++ b/filesystem/fat_ramdisk/.cvsignore @@ -0,0 +1,4 @@ +o-optimize +FilesystemImage +FilesystemImage.c +FilesystemImage.h diff --git a/filesystem/fat_ramdisk/Makefile b/filesystem/fat_ramdisk/Makefile new file mode 100644 index 0000000..58c51b2 --- /dev/null +++ b/filesystem/fat_ramdisk/Makefile @@ -0,0 +1,41 @@ +# +# $Id$ +# + +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/fat_ramdisk.exe + +# optional managers required +MANAGERS=all + +# C source names +CSRCS = init.c FilesystemImage.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +CLEAN_ADDITIONS += stamp-fs-image +CLEAN_ADDITIONS += FilesystemImage FilesystemImage.c FilesystemImage.h + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(OBJS) $(PGM) + +$(ARCH)/init.o: init.c stamp-fs-image + +FilesystemImage: $(ARCH) rootfs/shell-init + cd rootfs ; \ + tar cf ../FilesystemImage --exclude CVS --exclude .cvsignore . + +stamp-fs-image: $(ARCH) FilesystemImage + $(PROJECT_ROOT)/bin/rtems-bin2c FilesystemImage FilesystemImage + ls -l Filesystem* + touch stamp-fs-image + +$(PGM): $(OBJS) + $(make-exe) diff --git a/filesystem/fat_ramdisk/README b/filesystem/fat_ramdisk/README new file mode 100644 index 0000000..e29b5a5 --- /dev/null +++ b/filesystem/fat_ramdisk/README @@ -0,0 +1,9 @@ +# +# $Id$ +# + +This is a simple example which illustrates how to use the +In-Memory File System (IMFS) in conjunction with "untar" to +load the initial contents. + +Thanks to Gedare Bloom for the code this is based upon. diff --git a/filesystem/fat_ramdisk/init.c b/filesystem/fat_ramdisk/init.c new file mode 100644 index 0000000..de01bf6 --- /dev/null +++ b/filesystem/fat_ramdisk/init.c @@ -0,0 +1,163 @@ +/* + * COPYRIGHT (c) 1989-2011. + * 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$ + */ + + +#include <bsp.h> + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <rtems/ramdisk.h> +#include <rtems/error.h> +#include <rtems/untar.h> +#include <rtems/shell.h> + +#include "FilesystemImage.h" + + +/** + * The RAM Disk configuration. + */ +rtems_ramdisk_config rtems_ramdisk_configuration[] = +{ + { + block_size: 256, + 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 +}; + +#define RTEMS_DRIVER_AUTO_MAJOR (0) + +int setup_ramdisk (const char* mntpath) +{ + rtems_device_major_number major; + rtems_status_code sc; + + /* + * Register the RAM Disk driver. + */ + printf ("Register RAM Disk Driver: "); + 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; +} + +/** + * Run the /shell-init script. + */ +void shell_init_script(void) +{ + rtems_status_code sc; + printf("Running /shell-init....\n\n"); + sc = rtems_shell_script("fstst", 60 * 1024, 160, "/shell-init", "stdout", + 0, 1, 1); + if (sc != RTEMS_SUCCESSFUL) + printf("error: running shell script: %s (%d)\n", + rtems_status_text (sc), sc); +} + +/** + * Start the RTEMS Shell. + */ +void shell_start () +{ + rtems_status_code sc; + printf ("Starting shell....\n\n"); + sc = rtems_shell_init ("fstst", 60 * 1024, 150, "/dev/console", 0, 1, NULL); + if (sc != RTEMS_SUCCESSFUL) + printf ("error: starting shell: %s (%d)\n", rtems_status_text (sc), sc); +} + + + +rtems_task Init( + rtems_task_argument ignored +) +{ + int ret; + + puts( "\n\n*** ramdisk/fat example ***" ); + + printf("Unpacking tar filesystem\nThis may take awhile...\n"); + if(Untar_FromMemory(FilesystemImage, FilesystemImage_size) != 0) { + printf("Can't unpack tar filesystem\n"); + exit(1); + } + + ret = setup_ramdisk ("/mnt/ramdisk"); + if (ret) + exit (ret); + + shell_init_script(); + shell_start(); + + printf( "*** end of demonstration ***\n" ); + exit( 0 ); +} + + +/* configuration */ + +#define CONFIGURE_SHELL_COMMANDS_INIT +#define CONFIGURE_SHELL_COMMANDS_ALL +#define CONFIGURE_SHELL_MOUNT_MSDOS + +#include <rtems/shellconfig.h> + +/* drivers */ +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + +/* filesystem */ +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40 +#define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK 512 +#define CONFIGURE_MAXIMUM_DRIVERS 10 + +#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK +#define CONFIGURE_SWAPOUT_TASK_PRIORITY 10 + +#define CONFIGURE_MAXIMUM_TASKS rtems_resource_unlimited (10) +#define CONFIGURE_MAXIMUM_SEMAPHORES rtems_resource_unlimited (10) +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES rtems_resource_unlimited (5) +#define CONFIGURE_MAXIMUM_PARTITIONS rtems_resource_unlimited (2) +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT +#include <rtems/confdefs.h> +/* end of file */ diff --git a/filesystem/fat_ramdisk/rootfs/shell-init b/filesystem/fat_ramdisk/rootfs/shell-init new file mode 100755 index 0000000..4c38d9e --- /dev/null +++ b/filesystem/fat_ramdisk/rootfs/shell-init @@ -0,0 +1,3 @@ +mkdos /dev/ramdisk0 +mkdir /rd +mount -t msdos /dev/ramdisk0 /rd |