Re: [PATCH v2 1/3] cpukit/flash: Add API for Flash devices

2023-04-19 Thread Chris Johns
On 20/4/2023 7:42 am, Gedare Bloom wrote:
> On Mon, Apr 17, 2023 at 9:55 PM Chris Johns  wrote:
>>
>> On 18/4/2023 1:48 pm, Gedare Bloom wrote:
>>> On Sun, Apr 16, 2023 at 6:48 PM Aaron Nyholm
>>>  wrote:
 As for the RTEMS_FLASHDEV_MAX_REGIONS being set at 32 I chose the value as 
 it seamed a good balance between memory usage and function. I wanted to 
 avoid using malloc as your previous feedback suggested. If configurable 
 size is necessary what’s the best way to approach it without using malloc?

>>> A configure-time option may be viable, e.g., spec/build/cpukit/opt*
>>> You should probably elevate that question to its own email thread to
>>> get other opinions.
>>
>> Is there an option that shows how to control a defined in an API header?
>>
> This has mostly been done in the past at a BSP level, so there are
> plenty of examples within BSP drivers and frameworks. Whether it is
> suitable to a cpukit driver framework is something I don't really
> know.
> 
> A quick example could be:
> BSP_CONSOLE_BAUD
> used in bsps/powerpc/shared/console
> define in spec/build/bsps/optconsolebaud.yml
> 
> I'm not saying this is for sure the right way to do this, but I think
> it is worth thinking through.

It is something Aaron and I discuss early on and it has just sat and not moved.
I think it is good to have it raised as part of the review.

> I think you would have to avoid using the define in the header itself
> to make it portable. The way it's defined in this code can be done
> with a RTEMS_ZERO_LENGTH_ARRAY. Then the driver that instantiates the
> structure can determine for itself the size of how many regions to
> support. Even that would be an improvement to the current hard-coded
> method. The size itself could be made a field of the rtems_flashdev
> that the driver would setup at init time. Whether it is made
> configurable in the spec/build approach, or determined by the driver
> itself, is less concerning to me than the fact it is currently not
> configurable at all and is assumed to be sufficient for all flash
> drivers to be 32.

We have just discussed this and he is looking at making the table a pointer and
adding a size for the table and the flash device instance can add a table that
suites the device. This means extra checks for the pointer being a NULL but not
much more (I hope). I think this change will make a better driver.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2 1/3] cpukit/flash: Add API for Flash devices

2023-04-19 Thread Gedare Bloom
On Mon, Apr 17, 2023 at 9:55 PM Chris Johns  wrote:
>
> On 18/4/2023 1:48 pm, Gedare Bloom wrote:
> > On Sun, Apr 16, 2023 at 6:48 PM Aaron Nyholm
> >  wrote:
> >> As for the RTEMS_FLASHDEV_MAX_REGIONS being set at 32 I chose the value as 
> >> it seamed a good balance between memory usage and function. I wanted to 
> >> avoid using malloc as your previous feedback suggested. If configurable 
> >> size is necessary what’s the best way to approach it without using malloc?
> >>
> > A configure-time option may be viable, e.g., spec/build/cpukit/opt*
> > You should probably elevate that question to its own email thread to
> > get other opinions.
>
> Is there an option that shows how to control a defined in an API header?
>
This has mostly been done in the past at a BSP level, so there are
plenty of examples within BSP drivers and frameworks. Whether it is
suitable to a cpukit driver framework is something I don't really
know.

A quick example could be:
BSP_CONSOLE_BAUD
used in bsps/powerpc/shared/console
define in spec/build/bsps/optconsolebaud.yml

I'm not saying this is for sure the right way to do this, but I think
it is worth thinking through.

I think you would have to avoid using the define in the header itself
to make it portable. The way it's defined in this code can be done
with a RTEMS_ZERO_LENGTH_ARRAY. Then the driver that instantiates the
structure can determine for itself the size of how many regions to
support. Even that would be an improvement to the current hard-coded
method. The size itself could be made a field of the rtems_flashdev
that the driver would setup at init time. Whether it is made
configurable in the spec/build approach, or determined by the driver
itself, is less concerning to me than the fact it is currently not
configurable at all and is assumed to be sufficient for all flash
drivers to be 32.

> I have a quick look and could not see anything.
>
> Thanks
> Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2 1/3] cpukit/flash: Add API for Flash devices

2023-04-17 Thread Chris Johns
On 18/4/2023 1:48 pm, Gedare Bloom wrote:
> On Sun, Apr 16, 2023 at 6:48 PM Aaron Nyholm
>  wrote:
>> As for the RTEMS_FLASHDEV_MAX_REGIONS being set at 32 I chose the value as 
>> it seamed a good balance between memory usage and function. I wanted to 
>> avoid using malloc as your previous feedback suggested. If configurable size 
>> is necessary what’s the best way to approach it without using malloc?
>>
> A configure-time option may be viable, e.g., spec/build/cpukit/opt*
> You should probably elevate that question to its own email thread to
> get other opinions.

Is there an option that shows how to control a defined in an API header?

I have a quick look and could not see anything.

Thanks
Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v2 1/3] cpukit/flash: Add API for Flash devices

2023-04-17 Thread Gedare Bloom
On Sun, Apr 16, 2023 at 6:48 PM Aaron Nyholm
 wrote:
>
> Hi Gedare,
>
> Thanks for the feedback you’ve provided. I have a couple questions.
>
> You suggest refactoring the callouts into another sturct, I’m happy to do so. 
> I originally chose not to as I was was basing the high level structure off 
> the i2c API already in RTEMS. Just clarifying it’s worth doing.
>
I'm not sure there's much advantage one way or the other. You can
leave it as is for now.

> > You might consider refactoring the callouts to another struct that is
> > included here (either by value or by reference), just to separate the
> > function pointers from the data storage. Not strictly necessary, but
> > it would simplify this struct greatly, and should make implementation
> > of different drivers easier by consolidating the definitions of these
> > callouts.
>
> As for the RTEMS_FLASHDEV_MAX_REGIONS being set at 32 I chose the value as it 
> seamed a good balance between memory usage and function. I wanted to avoid 
> using malloc as your previous feedback suggested. If configurable size is 
> necessary what’s the best way to approach it without using malloc?
>
A configure-time option may be viable, e.g., spec/build/cpukit/opt*
You should probably elevate that question to its own email thread to
get other opinions.

> Thanks,
> Aaron
>
>
> > On 15 Apr 2023, at 01:58, Gedare Bloom  wrote:
> >
> > I focused my review on the API. See below.
> >
> > On Thu, Apr 6, 2023 at 1:08 AM  wrote:
> >>
> >> From: Aaron Nyholm 
> >>
> > [...]
> >> diff --git a/cpukit/include/dev/flash/flashdev.h 
> >> b/cpukit/include/dev/flash/flashdev.h
> >> new file mode 100644
> >> index 00..5d53ea7b97
> >> --- /dev/null
> >> +++ b/cpukit/include/dev/flash/flashdev.h
> >> @@ -0,0 +1,437 @@
> >> +/* SPDX-License-Identifier: BSD-2-Clause */
> >> +
> >> +/**
> >> + * @file
> >> + *
> >> + * @ingroup Flash
> >> + *
> >> + * @brief Generic Flash API
> >> + */
> >> +
> >> +/*
> >> + * Copyright (C) 2023 Aaron Nyholm
> >> + *
> >> + * Redistribution and use in source and binary forms, with or without
> >> + * modification, are permitted provided that the following conditions
> >> + * are met:
> >> + * 1. Redistributions of source code must retain the above copyright
> >> + *notice, this list of conditions and the following disclaimer.
> >> + * 2. Redistributions in binary form must reproduce the above copyright
> >> + *notice, this list of conditions and the following disclaimer in the
> >> + *documentation and/or other materials provided with the distribution.
> >> + *
> >> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
> >> "AS IS"
> >> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
> >> THE
> >> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
> >> PURPOSE
> >> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
> >> BE
> >> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> >> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> >> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
> >> BUSINESS
> >> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> >> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> >> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
> >> THE
> >> + * POSSIBILITY OF SUCH DAMAGE.
> >> + */
> >> +
> >> +#ifndef _DEV_FLASHDEV_H
> >> +#define _DEV_FLASHDEV_H
> >> +
> >> +#include 
> >> +#include 
> >> +
> >> +typedef struct rtems_flashdev rtems_flashdev;
> >> +
> >> +/**
> >> + * @defgroup Generic Flash API
> >> + *
> >> + * @ingroup RTEMSDeviceDrivers
> >> + *
> >> + * @brief Generic Flash API to wrap specific device drivers.
> >> + *
> >> + * @{
> >> + */
> >> +
> >> +/* IOCTL Calls */
> >> +
> >> +/**
> >> + * @brief Obtains the flash device.
> >> + *
> >> + * This command has no argument.
> >> + */
> >> +#define RTEMS_FLASHDEV_IOCTL_OBTAIN 0
> >> +/**
> >> + * @brief Releases the flash device.
> >> + *
> >> + * This command has no argument.
> >> + */
> >> +#define RTEMS_FLASHDEV_IOCTL_RELEASE 1
> >> +/**
> >> + * @brief Returns the JEDEC ID of the flash device.
> >> + *
> >> + * @param[out] jedec_id Pointer to uint32_t in which the JEDEC ID is
> >> + * returned in.
> >> + */
> >> +#define RTEMS_FLASHDEV_IOCTL_JEDEC_ID 2
> >> +/**
> >> + * @brief Erases flash device.
> >> + *
> >> + * @param[in] erase_args Pointer to rtems_flashdev_ioctl_erase_args struct
> >> + * containing offset and size of erase to be performed.
> >> + */
> >> +#define RTEMS_FLASHDEV_IOCTL_ERASE 3
> >> +/**
> >> + * @brief Set a region that limits read, write and erase calls to within 
> >> it.
> >> + * Regions are file descriptor specific and limited to a single region per
> >> + * file descriptor and 32 regions total per flash device. Regions can be
> >> + * changed or updated by calling this IOCTL again.
> >> + 

Re: [PATCH v2 1/3] cpukit/flash: Add API for Flash devices

2023-04-16 Thread Aaron Nyholm
Hi Gedare,

Thanks for the feedback you’ve provided. I have a couple questions.

You suggest refactoring the callouts into another sturct, I’m happy to do so. I 
originally chose not to as I was was basing the high level structure off the 
i2c API already in RTEMS. Just clarifying it’s worth doing.

> You might consider refactoring the callouts to another struct that is
> included here (either by value or by reference), just to separate the
> function pointers from the data storage. Not strictly necessary, but
> it would simplify this struct greatly, and should make implementation
> of different drivers easier by consolidating the definitions of these
> callouts.

As for the RTEMS_FLASHDEV_MAX_REGIONS being set at 32 I chose the value as it 
seamed a good balance between memory usage and function. I wanted to avoid 
using malloc as your previous feedback suggested. If configurable size is 
necessary what’s the best way to approach it without using malloc?

Thanks,
Aaron


> On 15 Apr 2023, at 01:58, Gedare Bloom  wrote:
>
> I focused my review on the API. See below.
>
> On Thu, Apr 6, 2023 at 1:08 AM  wrote:
>>
>> From: Aaron Nyholm 
>>
> [...]
>> diff --git a/cpukit/include/dev/flash/flashdev.h 
>> b/cpukit/include/dev/flash/flashdev.h
>> new file mode 100644
>> index 00..5d53ea7b97
>> --- /dev/null
>> +++ b/cpukit/include/dev/flash/flashdev.h
>> @@ -0,0 +1,437 @@
>> +/* SPDX-License-Identifier: BSD-2-Clause */
>> +
>> +/**
>> + * @file
>> + *
>> + * @ingroup Flash
>> + *
>> + * @brief Generic Flash API
>> + */
>> +
>> +/*
>> + * Copyright (C) 2023 Aaron Nyholm
>> + *
>> + * Redistribution and use in source and binary forms, with or without
>> + * modification, are permitted provided that the following conditions
>> + * are met:
>> + * 1. Redistributions of source code must retain the above copyright
>> + *notice, this list of conditions and the following disclaimer.
>> + * 2. Redistributions in binary form must reproduce the above copyright
>> + *notice, this list of conditions and the following disclaimer in the
>> + *documentation and/or other materials provided with the distribution.
>> + *
>> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
>> IS"
>> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
>> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
>> PURPOSE
>> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
>> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
>> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
>> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
>> THE
>> + * POSSIBILITY OF SUCH DAMAGE.
>> + */
>> +
>> +#ifndef _DEV_FLASHDEV_H
>> +#define _DEV_FLASHDEV_H
>> +
>> +#include 
>> +#include 
>> +
>> +typedef struct rtems_flashdev rtems_flashdev;
>> +
>> +/**
>> + * @defgroup Generic Flash API
>> + *
>> + * @ingroup RTEMSDeviceDrivers
>> + *
>> + * @brief Generic Flash API to wrap specific device drivers.
>> + *
>> + * @{
>> + */
>> +
>> +/* IOCTL Calls */
>> +
>> +/**
>> + * @brief Obtains the flash device.
>> + *
>> + * This command has no argument.
>> + */
>> +#define RTEMS_FLASHDEV_IOCTL_OBTAIN 0
>> +/**
>> + * @brief Releases the flash device.
>> + *
>> + * This command has no argument.
>> + */
>> +#define RTEMS_FLASHDEV_IOCTL_RELEASE 1
>> +/**
>> + * @brief Returns the JEDEC ID of the flash device.
>> + *
>> + * @param[out] jedec_id Pointer to uint32_t in which the JEDEC ID is
>> + * returned in.
>> + */
>> +#define RTEMS_FLASHDEV_IOCTL_JEDEC_ID 2
>> +/**
>> + * @brief Erases flash device.
>> + *
>> + * @param[in] erase_args Pointer to rtems_flashdev_ioctl_erase_args struct
>> + * containing offset and size of erase to be performed.
>> + */
>> +#define RTEMS_FLASHDEV_IOCTL_ERASE 3
>> +/**
>> + * @brief Set a region that limits read, write and erase calls to within it.
>> + * Regions are file descriptor specific and limited to a single region per
>> + * file descriptor and 32 regions total per flash device. Regions can be
>> + * changed or updated by calling this IOCTL again.
>> + *
>> + * @param[in] region Pointer to rtems_flashdev_ioctl_region struct 
>> containing
>> + * base and length of defined region.
>> + */
>> +#define RTEMS_FLASHDEV_IOCTL_REGION_SET 4
>> +/**
>> + * @brief Removes the set region on the file descriptor.
>> + *
>> + * This command has no argument.
>> + */
>> +#define RTEMS_FLASHDEV_IOCTL_REGION_UNSET 5
>> +/**
>> + * @brief Returns the type of flash device (e.g. NOR or NAND).
>> + *
>> + * @param[out] flash_type Pointer to integer which is set to the flash
>> + * type macro value.
>> + */
>> +#define RTEMS_FLASHDEV_IOCTL_TYPE 

Re: [PATCH v2 1/3] cpukit/flash: Add API for Flash devices

2023-04-14 Thread Gedare Bloom
I focused my review on the API. See below.

On Thu, Apr 6, 2023 at 1:08 AM  wrote:
>
> From: Aaron Nyholm 
>
[...]
> diff --git a/cpukit/include/dev/flash/flashdev.h 
> b/cpukit/include/dev/flash/flashdev.h
> new file mode 100644
> index 00..5d53ea7b97
> --- /dev/null
> +++ b/cpukit/include/dev/flash/flashdev.h
> @@ -0,0 +1,437 @@
> +/* SPDX-License-Identifier: BSD-2-Clause */
> +
> +/**
> + * @file
> + *
> + * @ingroup Flash
> + *
> + * @brief Generic Flash API
> + */
> +
> +/*
> + * Copyright (C) 2023 Aaron Nyholm
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
> IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef _DEV_FLASHDEV_H
> +#define _DEV_FLASHDEV_H
> +
> +#include 
> +#include 
> +
> +typedef struct rtems_flashdev rtems_flashdev;
> +
> +/**
> + * @defgroup Generic Flash API
> + *
> + * @ingroup RTEMSDeviceDrivers
> + *
> + * @brief Generic Flash API to wrap specific device drivers.
> + *
> + * @{
> + */
> +
> +/* IOCTL Calls */
> +
> +/**
> + * @brief Obtains the flash device.
> + *
> + * This command has no argument.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_OBTAIN 0
> +/**
> + * @brief Releases the flash device.
> + *
> + * This command has no argument.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_RELEASE 1
> +/**
> + * @brief Returns the JEDEC ID of the flash device.
> + *
> + * @param[out] jedec_id Pointer to uint32_t in which the JEDEC ID is
> + * returned in.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_JEDEC_ID 2
> +/**
> + * @brief Erases flash device.
> + *
> + * @param[in] erase_args Pointer to rtems_flashdev_ioctl_erase_args struct
> + * containing offset and size of erase to be performed.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_ERASE 3
> +/**
> + * @brief Set a region that limits read, write and erase calls to within it.
> + * Regions are file descriptor specific and limited to a single region per
> + * file descriptor and 32 regions total per flash device. Regions can be
> + * changed or updated by calling this IOCTL again.
> + *
> + * @param[in] region Pointer to rtems_flashdev_ioctl_region struct containing
> + * base and length of defined region.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_REGION_SET 4
> +/**
> + * @brief Removes the set region on the file descriptor.
> + *
> + * This command has no argument.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_REGION_UNSET 5
> +/**
> + * @brief Returns the type of flash device (e.g. NOR or NAND).
> + *
> + * @param[out] flash_type Pointer to integer which is set to the flash
> + * type macro value.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_TYPE 6
> +
> +/**
> + * @brief Get the size and address of flash page at given offset
> + *
> + * The offset ignores the region limiting. To find page of region
> + * limited offset add the base of the region to the desired offset.
> + *
> + * @param[in,out] rtems_flashdev_ioctl_page_info arg Pointer to struct
> + * with offset and space for return values.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_OFFSET 7
> +
> +/**
> + * @brief Get the size and address of nth flash page where n is index passed 
> in.
> + *
> + * The index ignores the region limiting.
> + *
> + * @param[in,out] rtems_flashdev_ioctl_page_info arg Pointer to struct
> + * with index and space for return values.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_PAGEINFO_BY_INDEX 8
> +
> +/**
> + * @brief Get the number of pages in flash device.
> + *
> + * @param[out] count Integer containing the number of pages.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_PAGE_COUNT 9
> +
> +/**
> + * @brief Get the minimum write size supported by the driver.
> + *
> + * @param[out] count Integer containing the minimum write size.
> + */
> +#define RTEMS_FLASHDEV_IOCTL_WRITE_BLOCK_SIZE 10
> +
> +/* Flash Types */
> 

[PATCH v2 1/3] cpukit/flash: Add API for Flash devices

2023-04-06 Thread aaron . nyholm
From: Aaron Nyholm 

---
 cpukit/dev/flash/flashdev.c | 732 
 cpukit/include/dev/flash/flashdev.h | 437 +
 spec/build/cpukit/librtemscpu.yml   |   4 +
 3 files changed, 1173 insertions(+)
 create mode 100644 cpukit/dev/flash/flashdev.c
 create mode 100644 cpukit/include/dev/flash/flashdev.h

diff --git a/cpukit/dev/flash/flashdev.c b/cpukit/dev/flash/flashdev.c
new file mode 100644
index 00..08e1c16e34
--- /dev/null
+++ b/cpukit/dev/flash/flashdev.c
@@ -0,0 +1,732 @@
+/*
+ * Copyright (C) 2023 Aaron Nyholm
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RTEMS_FLASHDEV_REGION_ALLOC_FULL 0xUL
+#define RTEMS_FLASHDEV_REGION_UNDEFINED 0xUL
+
+static int rtems_flashdev_do_init(
+  rtems_flashdev *flash,
+  void ( *destroy )( rtems_flashdev *flash )
+);
+
+static int rtems_flashdev_ioctl_erase(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  void *arg
+);
+
+static off_t rtems_flashdev_get_region_offset(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop
+);
+
+static size_t rtems_flashdev_get_region_size(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop
+);
+
+static int rtems_flashdev_ioctl_set_region(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  void *arg
+);
+
+static int rtems_flashdev_ioctl_create_region(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  rtems_flashdev_ioctl_region *region_in
+);
+
+static int rtems_flashdev_ioctl_update_region(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  rtems_flashdev_ioctl_region *region_in
+);
+
+static int rtems_flashdev_ioctl_clear_region(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop
+);
+
+static uint32_t rtems_flashdev_ioctl_jedec_id(
+  rtems_flashdev *flash
+);
+
+static uint32_t rtems_flashdev_ioctl_flash_type(
+  rtems_flashdev *flash
+);
+
+static int rtems_flashdev_ioctl_pageinfo_offset(
+  rtems_flashdev *flash,
+  void *arg
+);
+
+static int rtems_flashdev_ioctl_pageinfo_index(
+  rtems_flashdev *flash,
+  void *arg
+);
+
+static int rtems_flashdev_ioctl_page_count(
+  rtems_flashdev *flash,
+  void *arg
+);
+
+static int rtems_flashdev_ioctl_write_block_size(
+  rtems_flashdev *flash,
+  void *arg
+);
+
+static int rtems_flashdev_get_addr(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  size_t count,
+  off_t *addr
+);
+
+static int rtems_flashdev_update_and_return(
+  rtems_libio_t *iop,
+  int status,
+  size_t count,
+  off_t new_offset
+);
+
+static uint32_t rtems_flashdev_get_region_index(
+  rtems_libio_t *iop
+)
+{
+  return (uint32_t)iop->data0;
+}
+
+static int rtems_flashdev_is_region_defined(
+  rtems_libio_t *iop
+)
+{
+  return (rtems_flashdev_get_region_index( iop ) != 
RTEMS_FLASHDEV_REGION_UNDEFINED);
+}
+
+static void rtems_flashdev_set_region_index(
+  rtems_libio_t *iop,
+  uint32_t index
+)
+{
+  iop->data0 = index;
+}
+
+static int rtems_flashdev_check_offset_region(
+  rtems_flashdev *flash,
+  rtems_libio_t *iop,
+  off_t offset
+)
+{
+  if ( ( rtems_flashdev_is_region_defined( iop ) ) &&
+   ( offset > rtems_flashdev_get_region_size( flash, iop ) ) ) {
+rtems_set_errno_and_return_minus_one( EINVAL );
+  }
+  return 0;
+}
+
+static void rtems_flashdev_obtain( rtems_flashdev *flash )
+{
+  rtems_recursive_mutex_lock( >mutex );
+}
+
+static void rtems_flashdev_release( rtems_flashdev *flash )
+{
+  rtems_recursive_mutex_unlock( >mutex );
+}
+
+static ssize_t rtems_flashdev_read(
+  rtems_libio_t *iop,
+  void *buffer,
+  size_t count
+)
+{
+  rtems_flashdev *flash = IMFS_generic_get_context_by_iop( iop );
+  off_t