[0282e83] | 1 | /* |
---|
| 2 | * Copyright (c) 2013 embedded brains GmbH. All rights reserved. |
---|
| 3 | * |
---|
| 4 | * embedded brains GmbH |
---|
| 5 | * Dornierstr. 4 |
---|
| 6 | * 82178 Puchheim |
---|
| 7 | * Germany |
---|
| 8 | * <info@embedded-brains.de> |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
| 12 | * http://www.rtems.com/license/LICENSE. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | #include "pmacros.h" |
---|
| 19 | |
---|
| 20 | #include <sys/stat.h> |
---|
| 21 | #include <sys/types.h> |
---|
| 22 | #include <string.h> |
---|
| 23 | |
---|
| 24 | #include <rtems/jffs2.h> |
---|
| 25 | #include <rtems/libio.h> |
---|
| 26 | #include <rtems/libcsupport.h> |
---|
| 27 | |
---|
| 28 | #include "fstest.h" |
---|
| 29 | #include "fstest_support.h" |
---|
| 30 | |
---|
| 31 | #define BLOCK_SIZE (16UL * 1024UL) |
---|
| 32 | |
---|
| 33 | #define FLASH_SIZE (8UL * BLOCK_SIZE) |
---|
| 34 | |
---|
| 35 | typedef struct { |
---|
| 36 | rtems_jffs2_flash_control super; |
---|
| 37 | unsigned char area[FLASH_SIZE]; |
---|
| 38 | } flash_control; |
---|
| 39 | |
---|
| 40 | static flash_control *get_flash_control(rtems_jffs2_flash_control *super) |
---|
| 41 | { |
---|
| 42 | return (flash_control *) super; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | static int flash_read( |
---|
| 46 | rtems_jffs2_flash_control *super, |
---|
| 47 | uint32_t offset, |
---|
| 48 | unsigned char *buffer, |
---|
| 49 | size_t size_of_buffer |
---|
| 50 | ) |
---|
| 51 | { |
---|
| 52 | flash_control *self = get_flash_control(super); |
---|
| 53 | unsigned char *chunk = &self->area[offset]; |
---|
| 54 | |
---|
| 55 | memcpy(buffer, chunk, size_of_buffer); |
---|
| 56 | |
---|
| 57 | return 0; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | static int flash_write( |
---|
| 61 | rtems_jffs2_flash_control *super, |
---|
| 62 | uint32_t offset, |
---|
| 63 | const unsigned char *buffer, |
---|
| 64 | size_t size_of_buffer |
---|
| 65 | ) |
---|
| 66 | { |
---|
| 67 | flash_control *self = get_flash_control(super); |
---|
| 68 | unsigned char *chunk = &self->area[offset]; |
---|
| 69 | size_t i; |
---|
| 70 | |
---|
| 71 | for (i = 0; i < size_of_buffer; ++i) { |
---|
| 72 | chunk[i] &= buffer[i]; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | return 0; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | static int flash_erase( |
---|
| 79 | rtems_jffs2_flash_control *super, |
---|
| 80 | uint32_t offset |
---|
| 81 | ) |
---|
| 82 | { |
---|
| 83 | flash_control *self = get_flash_control(super); |
---|
| 84 | unsigned char *chunk = &self->area[offset]; |
---|
| 85 | |
---|
| 86 | memset(chunk, 0xff, BLOCK_SIZE); |
---|
| 87 | |
---|
| 88 | return 0; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | static flash_control flash_instance = { |
---|
| 92 | .super = { |
---|
| 93 | .block_size = BLOCK_SIZE, |
---|
| 94 | .flash_size = FLASH_SIZE, |
---|
| 95 | .read = flash_read, |
---|
| 96 | .write = flash_write, |
---|
| 97 | .erase = flash_erase |
---|
| 98 | } |
---|
| 99 | }; |
---|
| 100 | |
---|
| 101 | static rtems_jffs2_compressor_control compressor_instance = { |
---|
| 102 | .compress = rtems_jffs2_compressor_rtime_compress, |
---|
| 103 | .decompress = rtems_jffs2_compressor_rtime_decompress |
---|
| 104 | }; |
---|
| 105 | |
---|
| 106 | static const rtems_jffs2_mount_data mount_data = { |
---|
| 107 | .flash_control = &flash_instance.super, |
---|
| 108 | .compressor_control = &compressor_instance |
---|
| 109 | }; |
---|
| 110 | |
---|
| 111 | static void erase_all(void) |
---|
| 112 | { |
---|
| 113 | memset(&flash_instance.area[0], 0xff, FLASH_SIZE); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | static rtems_resource_snapshot before_mount; |
---|
| 117 | |
---|
| 118 | void test_initialize_filesystem(void) |
---|
| 119 | { |
---|
| 120 | int rv; |
---|
| 121 | |
---|
| 122 | erase_all(); |
---|
| 123 | |
---|
| 124 | rv = mkdir(BASE_FOR_TEST, S_IRWXU | S_IRWXG | S_IRWXO); |
---|
| 125 | rtems_test_assert(rv == 0); |
---|
| 126 | |
---|
| 127 | rtems_resource_snapshot_take(&before_mount); |
---|
| 128 | |
---|
| 129 | rv = mount( |
---|
| 130 | NULL, |
---|
| 131 | BASE_FOR_TEST, |
---|
| 132 | RTEMS_FILESYSTEM_TYPE_JFFS2, |
---|
| 133 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
| 134 | &mount_data |
---|
| 135 | ); |
---|
| 136 | rtems_test_assert(rv == 0); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | void test_shutdown_filesystem(void) |
---|
| 140 | { |
---|
| 141 | int rv = unmount(BASE_FOR_TEST); |
---|
| 142 | rtems_test_assert(rv == 0); |
---|
| 143 | rtems_test_assert(rtems_resource_snapshot_check(&before_mount)); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 147 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 148 | |
---|
| 149 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
| 150 | #define CONFIGURE_FILESYSTEM_JFFS2 |
---|
| 151 | |
---|
| 152 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40 |
---|
| 153 | |
---|
| 154 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 155 | |
---|
| 156 | #define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024) |
---|
| 157 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 158 | |
---|
| 159 | #define CONFIGURE_INIT |
---|
| 160 | #include <rtems/confdefs.h> |
---|