mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-25 01:46:30 +08:00
2008-05-01 Chris Johns <chrisj@rtems.org>
* libblock/include/rtems/nvdisk-sram.h, libblock/include/rtems/nvdisk.h, libblock/src/nvdisk-sram.c, libblock/src/nvdisk.c: New. A Non-volatile memory disk drive. * Makefile.am, preinstall.am, libblock/Makefile.am: Updated for the NV disk driver.
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
2008-05-01 Chris Johns <chrisj@rtems.org>
|
||||
|
||||
* libblock/include/rtems/nvdisk-sram.h,
|
||||
libblock/include/rtems/nvdisk.h,
|
||||
libblock/src/nvdisk-sram.c,
|
||||
libblock/src/nvdisk.c: New. A Non-volatile memory disk drive.
|
||||
* Makefile.am, preinstall.am, libblock/Makefile.am: Updated for
|
||||
the NV disk driver.
|
||||
|
||||
2008-05-01 Maarten Van Es <maarten@mind.be>
|
||||
* libnetworking/rtems/rtems_dhcp.c: Removed panic()s. Added
|
||||
interface for rtems_dhcp_failsafe.
|
||||
|
||||
@@ -85,6 +85,7 @@ if !UNIX
|
||||
include_rtems_HEADERS += libblock/include/rtems/bdbuf.h \
|
||||
libblock/include/rtems/blkdev.h libblock/include/rtems/diskdevs.h \
|
||||
libblock/include/rtems/flashdisk.h libblock/include/rtems/ramdisk.h \
|
||||
libblock/include/rtems/nvdisk.h libblock/include/rtems/nvdisk-sram.h \
|
||||
libblock/include/rtems/ide_part_table.h
|
||||
endif
|
||||
|
||||
|
||||
@@ -8,10 +8,12 @@ include $(top_srcdir)/automake/compile.am
|
||||
if !UNIX
|
||||
noinst_LIBRARIES = libblock.a
|
||||
libblock_a_SOURCES = src/bdbuf.c src/blkdev.c src/diskdevs.c src/flashdisk.c \
|
||||
src/ramdisk.c src/ide_part_table.c src/show_bdbuf.c \
|
||||
src/ramdisk.c src/ide_part_table.c src/show_bdbuf.c src/nvdisk.c \
|
||||
src/nvdisk-sram.c \
|
||||
include/rtems/bdbuf.h include/rtems/blkdev.h \
|
||||
include/rtems/diskdevs.h include/rtems/flashdisk.h \
|
||||
include/rtems/ramdisk.h include/rtems/ide_part_table.h
|
||||
include/rtems/ramdisk.h include/rtems/nvdisk.h include/rtems/nvdisk-sram.h \
|
||||
include/rtems/ide_part_table.h
|
||||
endif
|
||||
|
||||
include $(top_srcdir)/automake/local.am
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* RTEMS Project (http://www.rtems.org/)
|
||||
*
|
||||
* Copyright 2007 Chris Johns (chrisj@rtems.org)
|
||||
*/
|
||||
|
||||
/**
|
||||
* NV Disk Static RAM Device Driver.
|
||||
*
|
||||
* This driver maps an NV disk to static RAM. You can use this
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_NVDISK_SRAM_H_)
|
||||
#define _RTEMS_NVDISK_SRAM_H_
|
||||
|
||||
#include <rtems/nvdisk.h>
|
||||
|
||||
/**
|
||||
* The handlers for the NV Disk SRAM driver.
|
||||
*/
|
||||
extern const rtems_nvdisk_driver_handlers rtems_nvdisk_sram_handlers;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* nvdisk.h -- Non-volatile disk block device implementation
|
||||
*
|
||||
* Copyright (C) 2007 Chris Johns
|
||||
*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
/**
|
||||
* The Non-volatile disk provides a simple directly mapped disk
|
||||
* driver with checksums for each. It is designed to provied a
|
||||
* disk that can survive a restart. Examples are EEPROM devices
|
||||
* which have byte writeable locations, or a battery backed up
|
||||
* RAM disk.
|
||||
*
|
||||
* The low level driver provides the physical access to the
|
||||
* hardware.
|
||||
*/
|
||||
#if !defined (_RTEMS_NVDISK_H_)
|
||||
#define _RTEMS_NVDISK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <rtems.h>
|
||||
|
||||
/**
|
||||
* The base name of the nv disks.
|
||||
*/
|
||||
#define RTEMS_NVDISK_DEVICE_BASE_NAME "/dev/nvdisk"
|
||||
|
||||
/**
|
||||
* NV disk specific ioctl request types. To use open the
|
||||
* device and issue the ioctl call.
|
||||
*
|
||||
* @code
|
||||
* int fd = open ("/dev/nvdisk0", O_WRONLY, 0);
|
||||
* if (fd < 0)
|
||||
* {
|
||||
* printf ("driver open failed: %s\n", strerror (errno));
|
||||
* exit (1);
|
||||
* }
|
||||
* if (ioctl (fd, RTEMS_NVDISK_IOCTL_ERASE_DISK) < 0)
|
||||
* {
|
||||
* printf ("driver erase failed: %s\n", strerror (errno));
|
||||
* exit (1);
|
||||
* }
|
||||
* close (fd);
|
||||
* @endcode
|
||||
*/
|
||||
#define RTEMS_NVDISK_IOCTL_ERASE_DISK _IO('B', 128)
|
||||
#define RTEMS_NVDISK_IOCTL_MONITORING _IO('B', 129)
|
||||
#define RTEMS_NVDISK_IOCTL_INFO_LEVEL _IO('B', 130)
|
||||
#define RTEMS_NVDISK_IOCTL_PRINT_STATUS _IO('B', 131)
|
||||
|
||||
/**
|
||||
* NV Disk Monitoring Data allows a user to obtain
|
||||
* the current status of the disk.
|
||||
*/
|
||||
typedef struct rtems_nvdisk_monitor_data
|
||||
{
|
||||
uint32_t block_size;
|
||||
uint32_t block_count;
|
||||
uint32_t page_count;
|
||||
uint32_t pages_available;
|
||||
uint32_t pages_used;
|
||||
uint32_t info_level;
|
||||
} rtems_nvdisk_monitor_data;
|
||||
|
||||
/**
|
||||
* Return the number of kilo-bytes.
|
||||
*/
|
||||
#define RTEMS_NVDISK_KBYTES(_k) ((_k) * 1024)
|
||||
|
||||
/**
|
||||
* NV Low Level driver handlers.
|
||||
|
||||
* Typically this structure is part of a table of handlers in the
|
||||
* device which is referenced in the nvdisk configuration table.
|
||||
* The reference is kept in the driver and used all the time to
|
||||
* manage the nv device, therefore it must always exist.
|
||||
*/
|
||||
typedef struct rtems_nvdisk_driver_handlers
|
||||
{
|
||||
/**
|
||||
* Read data from the device into the buffer. Return an errno
|
||||
* error number if the data cannot be read.
|
||||
*
|
||||
* @param device The device to read data from.
|
||||
* @param flags Device specific flags for the driver.
|
||||
* @param base The base address of the device.
|
||||
* @param offset The offset in the segment to read.
|
||||
* @param buffer The buffer to read the data into.
|
||||
* @param size The amount of data to read.
|
||||
* @retval 0 No error.
|
||||
* @retval EIO The read did not complete.
|
||||
*/
|
||||
int (*read) (uint32_t device, uint32_t flags, uint32_t base,
|
||||
uint32_t offset, void* buffer, uint32_t size);
|
||||
|
||||
/**
|
||||
* Write data from the buffer to the device. Return an errno
|
||||
* error number if the device cannot be written to.
|
||||
*
|
||||
* @param device The device to write data to.
|
||||
* @param flags Device specific flags for the driver.
|
||||
* @param base The base address of the device.
|
||||
* @param offset The offset in the device to write to.
|
||||
* @param buffer The buffer to write the data from.
|
||||
* @param size The amount of data to write.
|
||||
* @retval 0 No error.
|
||||
* @retval EIO The write did not complete or verify.
|
||||
*/
|
||||
int (*write) (uint32_t device, uint32_t flags, uint32_t base,
|
||||
uint32_t offset, const void* buffer, uint32_t size);
|
||||
|
||||
/**
|
||||
* Verify data in the buffer to the data in the device. Return an
|
||||
* errno error number if the device cannot be read or the data verified.
|
||||
*
|
||||
* @param device The device to verify the data with.
|
||||
* @param flags Device specific flags for the driver.
|
||||
* @param base The base address of the device.
|
||||
* @param offset The offset in the device to verify.
|
||||
* @param buffer The buffer to verify the data in the device with.
|
||||
* @param size The amount of data to verify.
|
||||
* @retval 0 No error.
|
||||
* @retval EIO The data did not verify.
|
||||
*/
|
||||
int (*verify) (uint32_t device, uint32_t flags, uint32_t base,
|
||||
uint32_t offset, const void* buffer, uint32_t size);
|
||||
|
||||
} rtems_nvdisk_driver_handlers;
|
||||
|
||||
/**
|
||||
* NV Device Descriptor holds the description of a device that is
|
||||
* part of the NV disk.
|
||||
*
|
||||
* Typically this structure is part of a table of the device which
|
||||
* is referenced in the nvdisk configuration table.
|
||||
* The reference is kept in the driver and used all the time to
|
||||
* manage the nv device, therefore it must always exist.
|
||||
*/
|
||||
typedef struct rtems_nvdisk_device_desc
|
||||
{
|
||||
uint32_t flags; /**< Private user flags. */
|
||||
uint32_t base; /**< Base address of the device. */
|
||||
uint32_t size; /**< Size of the device. */
|
||||
const rtems_nvdisk_driver_handlers* nv_ops; /**< Device handlers. */
|
||||
} rtems_nvdisk_device_desc;
|
||||
|
||||
/**
|
||||
* RTEMS Non-Volatile Disk configuration table used to initialise the
|
||||
* driver.
|
||||
*/
|
||||
typedef struct rtems_nvdisk_config
|
||||
{
|
||||
uint32_t block_size; /**< The block size. */
|
||||
uint32_t device_count; /**< The number of devices. */
|
||||
const rtems_nvdisk_device_desc* devices; /**< The device descriptions. */
|
||||
uint32_t flags; /**< Set of flags to control
|
||||
driver. */
|
||||
uint32_t info_level; /**< Default info level. */
|
||||
} rtems_nvdisk_config;
|
||||
|
||||
/*
|
||||
* Driver flags.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check the pages during initialisation to see which pages are
|
||||
* valid and which are not. This could slow down initialising the
|
||||
* disk driver.
|
||||
*/
|
||||
#define RTEMS_NVDISK_CHECK_PAGES (1 << 0)
|
||||
|
||||
/**
|
||||
* Non-volatile disk device driver initialization. Place in a table as the
|
||||
* initialisation entry and remainder of the entries are the RTEMS block
|
||||
* device generic handlers.
|
||||
*
|
||||
* @param major NV disk major device number.
|
||||
* @param minor Minor device number, not applicable.
|
||||
* @param arg Initialization argument, not applicable.
|
||||
* @return The rtems_device_driver is actually just
|
||||
* rtems_status_code.
|
||||
*/
|
||||
rtems_device_driver
|
||||
rtems_nvdisk_initialize (rtems_device_major_number major,
|
||||
rtems_device_minor_number minor,
|
||||
void* arg);
|
||||
|
||||
/**
|
||||
* External reference to the configuration. Please supply.
|
||||
* Support is present in confdefs.h for providing this variable.
|
||||
*/
|
||||
extern const rtems_nvdisk_config rtems_nvdisk_configuration[];
|
||||
|
||||
/**
|
||||
* External reference to the number of configurations. Please supply.
|
||||
* Support is present in confdefs.h for providing this variable.
|
||||
*/
|
||||
extern uint32_t rtems_nvdisk_configuration_size;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* RTEMS Project (http://www.rtems.org/)
|
||||
*
|
||||
* Copyright 2007 Chris Johns (chrisj@rtems.org)
|
||||
*/
|
||||
/**
|
||||
* Provide SRAM support for the NV Disk.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <rtems.h>
|
||||
|
||||
#include <rtems/nvdisk-sram.h>
|
||||
|
||||
#ifndef NVDISK_SRAM_ERROR_TRACE
|
||||
#define NVDISK_SRAM_ERROR_TRACE (0)
|
||||
#endif
|
||||
|
||||
static int
|
||||
rtems_nvdisk_sram_read (uint32_t device,
|
||||
uint32_t flags,
|
||||
uint32_t base,
|
||||
uint32_t offset,
|
||||
void* buffer,
|
||||
uint32_t size)
|
||||
{
|
||||
memcpy (buffer, (char*) (base + offset), size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rtems_nvdisk_sram_write (uint32_t device,
|
||||
uint32_t flags,
|
||||
uint32_t base,
|
||||
uint32_t offset,
|
||||
const void* buffer,
|
||||
uint32_t size)
|
||||
{
|
||||
memcpy ((char*) (base + offset), buffer, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rtems_nvdisk_sram_verify (uint32_t device,
|
||||
uint32_t flags,
|
||||
uint32_t base,
|
||||
uint32_t offset,
|
||||
const void* buffer,
|
||||
uint32_t size)
|
||||
{
|
||||
return memcmp ((char*) (base + offset), buffer, size) == 0 ? 0 : EIO;
|
||||
}
|
||||
|
||||
|
||||
const rtems_nvdisk_driver_handlers rtems_nvdisk_sram_handlers =
|
||||
{
|
||||
read: rtems_nvdisk_sram_read,
|
||||
write: rtems_nvdisk_sram_write,
|
||||
verify: rtems_nvdisk_sram_verify
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -164,6 +164,14 @@ $(PROJECT_INCLUDE)/rtems/ramdisk.h: libblock/include/rtems/ramdisk.h $(PROJECT_I
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ramdisk.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ramdisk.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/nvdisk.h: libblock/include/rtems/nvdisk.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/nvdisk.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/nvdisk.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/nvdisk-sram.h: libblock/include/rtems/nvdisk-sram.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/nvdisk-sram.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/nvdisk-sram.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/ide_part_table.h: libblock/include/rtems/ide_part_table.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/ide_part_table.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/ide_part_table.h
|
||||
|
||||
Reference in New Issue
Block a user