15
#include <linux/kernel.h>
18
#include <drivers/block_dev.h>
19
#include <drivers/flash/flash.h>
20
#include <drivers/block_dev.h>
21
#include <fs/super_block.h>
22
#include <mem/sysmalloc.h>
24
bool jffs2_flash_read(struct jffs2_sb_info * c,
25
uint32_t read_buffer_offset, const size_t size,
26
size_t * return_size, unsigned char *write_buffer) {
28
struct jffs2_super_block *sb;
29
sb = member_cast_out(c, struct jffs2_super_block, jffs2_sb);
31
err = block_dev_read_buffered(sb->bdev,
32
(char *) write_buffer, size, read_buffer_offset);
35
*return_size = (size_t) err;
42
bool jffs2_flash_write(struct jffs2_sb_info * c,
43
uint32_t write_buffer_offset, const size_t size,
44
size_t * return_size, unsigned char *read_buffer) {
46
struct jffs2_super_block *sb;
48
sb = member_cast_out(c, struct jffs2_super_block, jffs2_sb);
49
err = block_dev_write_buffered(sb->bdev,
50
(char *) read_buffer, size, write_buffer_offset);
53
*return_size = (size_t) err;
60
int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
61
unsigned long count, loff_t to, size_t * retlen) {
63
size_t totlen = 0, thislen;
66
for (i = 0; i < count; i++) {
73
if (((vecs[i].iov_len & (sizeof (int) - 1))) ||
74
(((unsigned long) vecs[i].
75
iov_base & (sizeof (unsigned long) - 1)))) {
79
if ((i + 1) < count || vecs[i].iov_len > 256) {
82
ssize_t sizetomalloc = 0, totvecsize = 0;
85
for (j = i; j < count; j++) {
86
totvecsize += vecs[j].iov_len;
90
sizetomalloc = totvecsize + sizeof (int) - 1;
91
sizetomalloc &= ~(sizeof (int) - 1);
92
cbuf = (char *) sysmalloc(sizetomalloc);
99
for (j = i; j < count; j++) {
100
memcpy(cbufptr, vecs[j].iov_base,
102
cbufptr += vecs[j].iov_len;
105
jffs2_flash_write(c, to, sizetomalloc,
106
&thislen, (unsigned char *) cbuf);
107
if (thislen > totvecsize) {
108
thislen = totvecsize;
115
int buf[256 / sizeof (int)];
118
lentowrite = vecs[i].iov_len;
120
lentowrite += sizeof (int) - 1;
121
lentowrite &= ~(sizeof (int) - 1);
122
memcpy(buf, vecs[i].iov_base, lentowrite);
125
jffs2_flash_write(c, to, lentowrite,
126
&thislen, (unsigned char *) &buf);
127
if (thislen > vecs[i].iov_len) {
128
thislen = vecs[i].iov_len;
133
jffs2_flash_write(c, to, vecs[i].iov_len, &thislen,
137
if (ret || thislen != vecs[i].iov_len) {
140
to += vecs[i].iov_len;
150
bool jffs2_flash_erase(struct jffs2_sb_info * c,
151
struct jffs2_eraseblock * jeb) {
152
struct flash_ioctl_erase e;
155
uint32_t len = sizeof (e);
156
struct jffs2_super_block *sb;
157
sb = member_cast_out(c, struct jffs2_super_block, jffs2_sb);
159
e.offset = jeb->offset;
160
e.len = c->sector_size;
161
e.err_address = (uint32_t) &err_addr;
163
err = block_dev_ioctl(sb->bdev, FLASH_IOCTL_ERASE, &e, len);
165
return (err != ENOERR || e.flasherr != 0);