Filesystem in RTEMS

Chris Johns chrisj at rtems.org
Sat Oct 21 00:56:21 UTC 2017


On 21/10/2017 11:17, xuelin.tian at qkmtech.com wrote:
> I followed the example (testsuites/fstests/jffs2_support/fs_support.c), and some
> error came up, like 
> "undefined reference to rtems_jffs2_initialize",
> "undefined reference to rtems_jffs2_compressor_zlib_compress", and 
> "undefined reference to rtems_jffs2_compressor_zlib_decompress"
> I have no clue here. Do I have to give my own implementation of these functions
> here? I can exploit the default functions for jffs2 entry table and compress, I
> think. 
> 
> And I have a little confused about the model of device driver in rtems, since I
> get stuck for a few days.
> First, a deivce descriptor (rtems_fdisk_device_desc) should be given, including
> some handlers defined in rtems_fdisk_driver_handlers,  and device configuration
> (rtems_flashdisk_config). 
> Then, I need to register (or initialize) my flash device into rtems dynamically
> or statically, with my own initialize, open, close functions.
> Last, the JFFS2 should be set up based on the registered device driver. The
> block size need to be equal to the page size of flash, and the read, write,
> erase operations should invoke the corresponding functions defined
> in rtems_fdisk_driver_handlers.
> 
> Am I correct in this whoe process?

I have something like the following piece of code in a file in my application:

typedef struct
{
  rtems_jffs2_flash_control super;
  /* private data for my flash driver such as stats */
} ffs_control;

static ffs_control*
flash_get_control(rtems_jffs2_flash_control* super)
{
  return (ffs_control *) super;
}

static int
flash_read(rtems_jffs2_flash_control* super,
           uint32_t                   offset,
           unsigned char*             buffer,
           size_t                     length)
{
  ffs_control* self = flash_get_control(super);
  int          r;
  .
  .
  .
  return r;
}

static int
flash_write(rtems_jffs2_flash_control* super,
            uint32_t                   offset,
            const unsigned char*       buffer,
            size_t                     length)
{
  ffs_control* self = flash_get_control(super);
  int          r;
  .
  .
  .
  return r;
}

static int
flash_erase(rtems_jffs2_flash_control* super,
            uint32_t                   offset)
{
  ffs_control* self = flash_get_control(super);
  int          r;
  .
  .
  .
  return r;
}

static void
flash_destroy(rtems_jffs2_flash_control* super)
{
  ffs_control* self = flash_get_control(super);
  int          r;
  .
  .
  .
  return r;
}

static ffs_control ffs_data = {
    .super = {
        .read = flash_read,
        .write = flash_write,
        .erase = flash_erase,
        .destroy = flash_destroy
    }
};

static rtems_jffs2_compressor_zlib_control compressor_instance = {
    .super = {
        .compress = rtems_jffs2_compressor_zlib_compress,
        .decompress = rtems_jffs2_compressor_zlib_decompress
    }
};

static const rtems_jffs2_mount_data ffs_mount_data = {
    .flash_control = &ffs_data.super,
    .compressor_control = &compressor_instance.super
};

bool
ffs_mount(const char* path)
{
  int r;

  r = flash_open();
  if (r != 0)
  {
    /* print something */
    return false;
  }

 ffs_data.super.block_size = HYDRA_FLASH_BLOCK_SIZE;
 ffs_data.super.flash_size = HYDRA_FLASH_FILESYSTEM_SIZE;

 r = mount_and_make_target_path(NULL,
                                path,
                                RTEMS_FILESYSTEM_TYPE_JFFS2,
                                RTEMS_FILESYSTEM_READ_WRITE,
                                &ffs_mount_data);
 if (r != 0)
 {
    /* print something */
    return false;
 }

 return true;
}

You need to provide the open, close, read, write, erase and destroy code that
accesses your flash device. This can be calls to something that directly
accesses the flash device or you can build a driver registered in the device
tree to handle the flash via ioctls.

Chris


More information about the users mailing list