-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathold_diskio.c
140 lines (112 loc) · 2.24 KB
/
old_diskio.c
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
diskio.c -- glue interface to ElmChan FAT FS driver. Part of the
BootMii project.
Copyright (C) 2008, 2009 Haxx Enterprises <bushing@gmail.com>
Copyright (C) 2008, 2009 Sven Peter <svenpeter@gmail.com>
# This code is licensed to you under the terms of the GNU GPL, version 2;
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
#include "powerpc.h"
#include "ipc.h"
#include "mini_ipc.h"
#include "diskio.h"
#include "string.h"
static u8 *buffer[512] __attribute__((aligned(32)));
DSTATUS disk_status (BYTE drv)
{
(void) drv;
int state = sd_get_state();
switch (state) {
case SDMMC_NO_CARD:
return STA_NODISK;
case SDMMC_NEW_CARD:
return STA_NOINIT;
default:
return 0;
}
}
DSTATUS disk_initialize (BYTE drv)
{
(void) drv;
int state = sd_get_state();
switch (state) {
case SDMMC_NO_CARD:
return STA_NODISK;
case SDMMC_NEW_CARD:
if (sd_mount())
return STA_NOINIT;
else
return 0;
default:
return 0;
}
}
DRESULT disk_read (BYTE drv, BYTE *buff, DWORD sector, u32 count)
{
u32 i;
DRESULT res;
(void) drv;
if (count > 1 && ((u32) buff % 64) == 0) {
if (sd_read(sector, count, buff) != 0)
return RES_ERROR;
return RES_OK;
}
res = RES_OK;
for (i = 0; i < count; i++) {
if (sd_read(sector + i, 1, buffer) != 0) {
res = RES_ERROR;
break;
}
memcpy(buff + i * 512, buffer, 512);
}
return res;
}
#if _READONLY == 0
DRESULT disk_write (BYTE drv, const BYTE *buff, DWORD sector, u32 count)
{
u32 i;
DRESULT res;
(void) drv;
res = RES_OK;
if (count > 1 && ((u32) buff % 64) == 0) {
if (sd_write(sector, count, buff) != 0)
return RES_ERROR;
return RES_OK;
}
for (i = 0; i < count; i++) {
memcpy(buffer, buff + i * 512, 512);
if (sd_write(sector + i, 1, buffer) != 0) {
res = RES_ERROR;
break;
}
}
return res;
}
#endif /* _READONLY */
DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff)
{
(void) drv;
u32 *buff_u32 = (u32 *) buff;
DRESULT res = RES_OK;
switch (ctrl) {
case CTRL_SYNC:
break;
case GET_SECTOR_COUNT:
*buff_u32 = sd_getsize();
break;
case GET_SECTOR_SIZE:
*buff_u32 = 512;
break;
case GET_BLOCK_SIZE:
*buff_u32 = 512;
break;
default:
res = RES_PARERR;
break;
}
return res;
}
DWORD get_fattime(void)
{
return 0; // TODO
}