1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright (C) 2014 John Crispin <blogic@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _VOLUME_H__
#define _VOLUME_H__
#include <asm/byteorder.h>
struct volume;
typedef int (*volume_probe_t)(void);
typedef int (*volume_init_t)(struct volume *v);
typedef void (*volume_stop_t)(struct volume *v);
typedef struct volume *(*volume_find_t)(char *name);
typedef int (*volume_identify_t)(struct volume *v);
typedef int (*volume_read_t)(struct volume *v, void *buf, int offset, int length);
typedef int (*volume_write_t)(struct volume *v, void *buf, int offset, int length);
typedef int (*volume_erase_t)(struct volume *v, int start, int len);
typedef int (*volume_erase_all_t)(struct volume *v);
struct driver {
struct list_head list;
char *name;
volume_probe_t probe;
volume_init_t init;
volume_stop_t stop;
volume_find_t find;
volume_identify_t identify;
volume_read_t read;
volume_write_t write;
volume_erase_t erase;
volume_erase_all_t erase_all;
};
enum {
UNKNOWN_TYPE,
NANDFLASH,
NORFLASH,
UBIVOLUME,
BLOCKDEV,
};
struct volume {
struct driver *drv;
char *name;
char *blk;
__u64 size;
__u32 block_size;
int type;
};
extern struct volume* volume_find(char *name);
extern void volume_register_driver(struct driver *drv);
static inline int volume_init(struct volume *v)
{
if (v && v->drv->init)
return v->drv->init(v);
return -1;
}
static inline int volume_identify(struct volume *v)
{
if (v && v->drv->identify)
return v->drv->identify(v);
return -1;
}
static inline int volume_erase(struct volume *v, int offset, int len)
{
if (v && v->drv->erase)
return v->drv->erase(v, offset, len);
return -1;
}
static inline int volume_erase_all(struct volume *v)
{
if (v && v->drv->erase_all)
return v->drv->erase_all(v);
return -1;
}
static inline int volume_read(struct volume *v, void *buf, int offset, int length)
{
if (v && v->drv->read)
return v->drv->read(v, buf, offset, length);
return -1;
}
static inline int volume_write(struct volume *v, void *buf, int offset, int length)
{
if (v && v->drv->write)
return v->drv->write(v, buf, offset, length);
return -1;
}
#define DRIVER(x) \
static void __attribute__((constructor)) \
drv_register_##x(void) { \
volume_register_driver(&x); \
}
#endif
|