Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:31

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2013 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 #include <tmacros.h>
0032 
0033 #include <sys/stat.h>
0034 #include <sys/types.h>
0035 #include <string.h>
0036 
0037 #include <rtems/jffs2.h>
0038 #include <rtems/libio.h>
0039 #include <rtems/libcsupport.h>
0040 
0041 #include "fstest.h"
0042 #include "fstest_support.h"
0043 
0044 #define BLOCK_SIZE (16UL * 1024UL)
0045 
0046 #define FLASH_SIZE (8UL * BLOCK_SIZE)
0047 
0048 typedef struct {
0049   rtems_jffs2_flash_control super;
0050   unsigned char area[FLASH_SIZE];
0051 } flash_control;
0052 
0053 static flash_control *get_flash_control(rtems_jffs2_flash_control *super)
0054 {
0055   return (flash_control *) super;
0056 }
0057 
0058 static int flash_read(
0059   rtems_jffs2_flash_control *super,
0060   uint32_t offset,
0061   unsigned char *buffer,
0062   size_t size_of_buffer
0063 )
0064 {
0065   flash_control *self = get_flash_control(super);
0066   unsigned char *chunk = &self->area[offset];
0067 
0068   memcpy(buffer, chunk, size_of_buffer);
0069 
0070   return 0;
0071 }
0072 
0073 static int flash_write(
0074   rtems_jffs2_flash_control *super,
0075   uint32_t offset,
0076   const unsigned char *buffer,
0077   size_t size_of_buffer
0078 )
0079 {
0080   flash_control *self = get_flash_control(super);
0081   unsigned char *chunk = &self->area[offset];
0082   size_t i;
0083 
0084   for (i = 0; i < size_of_buffer; ++i) {
0085     chunk[i] &= buffer[i];
0086   }
0087 
0088   return 0;
0089 }
0090 
0091 static int flash_erase(
0092   rtems_jffs2_flash_control *super,
0093   uint32_t offset
0094 )
0095 {
0096   flash_control *self = get_flash_control(super);
0097   unsigned char *chunk = &self->area[offset];
0098 
0099   memset(chunk, 0xff, BLOCK_SIZE);
0100 
0101   return 0;
0102 }
0103 
0104 static flash_control flash_instance = {
0105   .super = {
0106     .block_size = BLOCK_SIZE,
0107     .flash_size = FLASH_SIZE,
0108     .read = flash_read,
0109     .write = flash_write,
0110     .erase = flash_erase
0111   }
0112 };
0113 
0114 static rtems_jffs2_compressor_control compressor_instance = {
0115   .compress = rtems_jffs2_compressor_rtime_compress,
0116   .decompress = rtems_jffs2_compressor_rtime_decompress
0117 };
0118 
0119 static const rtems_jffs2_mount_data mount_data = {
0120   .flash_control = &flash_instance.super,
0121   .compressor_control = &compressor_instance
0122 };
0123 
0124 static void erase_all(void)
0125 {
0126   memset(&flash_instance.area[0], 0xff, FLASH_SIZE);
0127 }
0128 
0129 static rtems_resource_snapshot before_mount;
0130 
0131 void test_initialize_filesystem(void)
0132 {
0133   int rv;
0134 
0135   erase_all();
0136 
0137   rv = mkdir(BASE_FOR_TEST, S_IRWXU | S_IRWXG | S_IRWXO);
0138   rtems_test_assert(rv == 0);
0139 
0140   rtems_resource_snapshot_take(&before_mount);
0141 
0142   rv = mount(
0143     NULL,
0144     BASE_FOR_TEST,
0145     RTEMS_FILESYSTEM_TYPE_JFFS2,
0146     RTEMS_FILESYSTEM_READ_WRITE,
0147     &mount_data
0148   );
0149   rtems_test_assert(rv == 0);
0150 }
0151 
0152 void test_shutdown_filesystem(void)
0153 {
0154   int rv = unmount(BASE_FOR_TEST);
0155   rtems_test_assert(rv == 0);
0156   rtems_test_assert(rtems_resource_snapshot_check(&before_mount));
0157 }
0158 
0159 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0160 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0161 
0162 #define CONFIGURE_FILESYSTEM_JFFS2
0163 
0164 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 40
0165 
0166 #define CONFIGURE_MAXIMUM_TASKS 2
0167 
0168 #define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
0169 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
0170 
0171 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0172 
0173 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0174 
0175 #define CONFIGURE_INIT
0176 #include <rtems/confdefs.h>