parent
066688dcac
commit
64e4a8207f
|
@ -7,15 +7,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <drivers/device_manager.h>
|
#include <drivers/device_manager.h>
|
||||||
#include <drivers/KernelExport.h>
|
#include <drivers/KernelExport.h>
|
||||||
#include <drivers/Drivers.h>
|
#include <drivers/Drivers.h>
|
||||||
#include <kernel/OS.h>
|
#include <kernel/OS.h>
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
//#define TRACE_NORFLASH
|
//#define TRACE_NORFLASH
|
||||||
#ifdef TRACE_NORFLASH
|
#ifdef TRACE_NORFLASH
|
||||||
|
@ -24,11 +25,14 @@
|
||||||
#define TRACE(x...)
|
#define TRACE(x...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define NORFLASH_DEVICE_MODULE_NAME "drivers/disk/norflash/device_v1"
|
#define NORFLASH_DEVICE_MODULE_NAME "drivers/disk/norflash/device_v1"
|
||||||
#define NORFLASH_DRIVER_MODULE_NAME "drivers/disk/norflash/driver_v1"
|
#define NORFLASH_DRIVER_MODULE_NAME "drivers/disk/norflash/driver_v1"
|
||||||
|
|
||||||
|
|
||||||
#define NORFLASH_ADDR 0x00000000
|
#define NORFLASH_ADDR 0x00000000
|
||||||
|
|
||||||
|
|
||||||
struct nor_driver_info {
|
struct nor_driver_info {
|
||||||
device_node *node;
|
device_node *node;
|
||||||
size_t blocksize;
|
size_t blocksize;
|
||||||
|
@ -38,42 +42,15 @@ struct nor_driver_info {
|
||||||
void *mapped;
|
void *mapped;
|
||||||
};
|
};
|
||||||
|
|
||||||
static device_manager_info* sDeviceManager;
|
|
||||||
|
|
||||||
static const char *sTabTab = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
static device_manager_info *sDeviceManager;
|
||||||
#define DS "%.*s"
|
|
||||||
#define DA depth - 1, sTabTab
|
|
||||||
|
|
||||||
static void
|
|
||||||
dump_hex(const char *data, int32 len, int depth = 1)
|
|
||||||
{
|
|
||||||
char str[128];
|
|
||||||
char astr[32];
|
|
||||||
char *p;
|
|
||||||
int l;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < len; ) {
|
|
||||||
p = str;
|
|
||||||
l = sizeof(str);
|
|
||||||
for (; i < len && (p == str || (i % 16 != 0)); i++) {
|
|
||||||
snprintf(p, l - 1, "%02x ", data[i]);
|
|
||||||
l -= strlen(p);
|
|
||||||
p += strlen(p);
|
|
||||||
astr[i % 16] = isprint(data[i]) ? data[i] : '.';
|
|
||||||
astr[i % 16] = isprint(data[i]) ? data[i] : '.';
|
|
||||||
astr[(i % 16) + 1] = '\0';
|
|
||||||
}
|
|
||||||
dprintf(DS" %-48.48s %s\n", DA, str, astr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
nor_init_device(void* _info, void** _cookie)
|
nor_init_device(void *_info, void **_cookie)
|
||||||
{
|
{
|
||||||
TRACE("init_device\n");
|
TRACE("init_device\n");
|
||||||
nor_driver_info* info = (nor_driver_info*)_info;
|
nor_driver_info *info = (nor_driver_info*)_info;
|
||||||
|
|
||||||
info->mapped = NULL;
|
info->mapped = NULL;
|
||||||
info->blocksize = 128 * 1024;
|
info->blocksize = 128 * 1024;
|
||||||
|
@ -89,10 +66,10 @@ nor_init_device(void* _info, void** _cookie)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nor_uninit_device(void* _cookie)
|
nor_uninit_device(void *_cookie)
|
||||||
{
|
{
|
||||||
TRACE("uninit_device\n");
|
TRACE("uninit_device\n");
|
||||||
nor_driver_info* info = (nor_driver_info*)_cookie;
|
nor_driver_info *info = (nor_driver_info*)_cookie;
|
||||||
if (info)
|
if (info)
|
||||||
delete_area(info->id);
|
delete_area(info->id);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +77,7 @@ nor_uninit_device(void* _cookie)
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
nor_open(void *deviceCookie, const char *path, int openMode,
|
nor_open(void *deviceCookie, const char *path, int openMode,
|
||||||
void **_cookie)
|
void **_cookie)
|
||||||
{
|
{
|
||||||
TRACE("open(%s)\n", path);
|
TRACE("open(%s)\n", path);
|
||||||
*_cookie = deviceCookie;
|
*_cookie = deviceCookie;
|
||||||
|
@ -127,11 +104,11 @@ nor_free(void *_cookie)
|
||||||
static status_t
|
static status_t
|
||||||
nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||||
{
|
{
|
||||||
nor_driver_info* info = (nor_driver_info*)cookie;
|
nor_driver_info *info = (nor_driver_info*)cookie;
|
||||||
TRACE("ioctl(%ld,%lu)\n", op, length);
|
TRACE("ioctl(%ld,%lu)\n", op, length);
|
||||||
|
|
||||||
switch(op) {
|
switch (op) {
|
||||||
case B_GET_GEOMETRY:
|
case B_GET_GEOMETRY:
|
||||||
{
|
{
|
||||||
device_geometry *deviceGeometry = (device_geometry*)buffer;
|
device_geometry *deviceGeometry = (device_geometry*)buffer;
|
||||||
deviceGeometry->removable = false;
|
deviceGeometry->removable = false;
|
||||||
|
@ -146,9 +123,10 @@ nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case B_GET_DEVICE_NAME:
|
|
||||||
strlcpy((char*)buffer, "NORFlash", length);
|
case B_GET_DEVICE_NAME:
|
||||||
break;
|
strlcpy((char*)buffer, "NORFlash", length);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
@ -158,7 +136,7 @@ nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||||
static status_t
|
static status_t
|
||||||
nor_read(void *_cookie, off_t position, void *data, size_t *numbytes)
|
nor_read(void *_cookie, off_t position, void *data, size_t *numbytes)
|
||||||
{
|
{
|
||||||
nor_driver_info* info = (nor_driver_info*)_cookie;
|
nor_driver_info *info = (nor_driver_info*)_cookie;
|
||||||
TRACE("read(%Ld,%lu)\n", position, *numbytes);
|
TRACE("read(%Ld,%lu)\n", position, *numbytes);
|
||||||
|
|
||||||
if (position + *numbytes > info->totalsize)
|
if (position + *numbytes > info->totalsize)
|
||||||
|
@ -166,10 +144,6 @@ nor_read(void *_cookie, off_t position, void *data, size_t *numbytes)
|
||||||
|
|
||||||
memcpy(data, info->mapped + position, *numbytes);
|
memcpy(data, info->mapped + position, *numbytes);
|
||||||
|
|
||||||
#ifdef TRACE_NORFLASH
|
|
||||||
dump_hex((const char*)(info->mapped + position), *numbytes, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +184,7 @@ nor_init_driver(device_node *node, void **cookie)
|
||||||
{
|
{
|
||||||
TRACE("init_driver\n");
|
TRACE("init_driver\n");
|
||||||
|
|
||||||
nor_driver_info* info = (nor_driver_info*)malloc(sizeof(nor_driver_info));
|
nor_driver_info *info = (nor_driver_info*)malloc(sizeof(nor_driver_info));
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
@ -227,16 +201,16 @@ static void
|
||||||
nor_uninit_driver(void *_cookie)
|
nor_uninit_driver(void *_cookie)
|
||||||
{
|
{
|
||||||
TRACE("uninit_driver\n");
|
TRACE("uninit_driver\n");
|
||||||
nor_driver_info* info = (nor_driver_info*)_cookie;
|
nor_driver_info *info = (nor_driver_info*)_cookie;
|
||||||
free(info);
|
free(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
nor_register_child_devices(void* _cookie)
|
nor_register_child_devices(void *_cookie)
|
||||||
{
|
{
|
||||||
TRACE("register_child_devices\n");
|
TRACE("register_child_devices\n");
|
||||||
nor_driver_info* info = (nor_driver_info*)_cookie;
|
nor_driver_info *info = (nor_driver_info*)_cookie;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
status = sDeviceManager->publish_device(info->node, "disk/nor/0/raw",
|
status = sDeviceManager->publish_device(info->node, "disk/nor/0/raw",
|
||||||
|
@ -245,6 +219,7 @@ nor_register_child_devices(void* _cookie)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct device_module_info sNORFlashDiskDevice = {
|
struct device_module_info sNORFlashDiskDevice = {
|
||||||
{
|
{
|
||||||
NORFLASH_DEVICE_MODULE_NAME,
|
NORFLASH_DEVICE_MODULE_NAME,
|
||||||
|
@ -286,12 +261,14 @@ struct driver_module_info sNORFlashDiskDriver = {
|
||||||
NULL, // removed
|
NULL, // removed
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module_dependency module_dependencies[] = {
|
module_dependency module_dependencies[] = {
|
||||||
{ B_DEVICE_MANAGER_MODULE_NAME, (module_info**)&sDeviceManager },
|
{ B_DEVICE_MANAGER_MODULE_NAME, (module_info**)&sDeviceManager },
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
module_info* modules[] = {
|
|
||||||
|
module_info *modules[] = {
|
||||||
(module_info*)&sNORFlashDiskDriver,
|
(module_info*)&sNORFlashDiskDriver,
|
||||||
(module_info*)&sNORFlashDiskDevice,
|
(module_info*)&sNORFlashDiskDevice,
|
||||||
NULL
|
NULL
|
||||||
|
|
Loading…
Reference in New Issue