-
Notifications
You must be signed in to change notification settings - Fork 1
/
mmc_sh.c
104 lines (91 loc) · 1.99 KB
/
mmc_sh.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
#include "mmc_sh.h"
#include "mmc_cmds.h"
#include "android.h"
#include <string.h>
struct sh_gen_cmd_p {
const char *model;
const __u8 *param;
};
#ifdef HAVE_306SH
static const __u8 gc_306sh[0x28] = {
0x01, 0x0D, 0x34, 0x44, 0x0D, 0x49, 0x1C, 0xF0, 0xD4, 0xE2, 0x4D, 0x36, 0x5E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81,
};
#endif
static const struct sh_gen_cmd_p s_known_gcs[] = {
#ifdef HAVE_306SH
{
.model = "306SH",
.param = gc_306sh,
},
#endif
{
.model = NULL,
},
};
static int get_gen_cmd(__u8 *data) {
char val[PROPERTY_VALUE_MAX];
const struct sh_gen_cmd_p *p;
const __u8 *src;
__u8 *dst;
memset(val, 0, sizeof(val));
property_get("ro.product.model", val, "");
for (p = &s_known_gcs[0]; p->model != NULL; p++) {
if (!strcmp(p->model, val))
break;
}
if (p->model == NULL)
return -1;
src = p->param;
dst = data;
memset(dst, 0, 0x28);
while (*src) {
__u8 i, off, cnt;
off = *src >> 4;
cnt = *src & 0x0F;
src++;
dst += off;
for (i = 0; i < cnt; i++) {
*dst++ = *src++;
}
}
return 0;
}
int mmc_sh_pre_clr_wp(int fd) {
int rc;
__u8 data[512];
__u8 op;
rc = get_gen_cmd(data);
if (rc < 0)
return -1;
op = 2;
data[0x20] = op;
// write
rc = mmc_gen_cmd(fd, 0, data);
if (rc) {
// printf("gen cmd 1\n");
return -1;
}
// read
rc = mmc_gen_cmd(fd, 1, data);
if (rc) {
// printf("gen cmd 2\n");
return -1;
}
rc = get_gen_cmd(data);
if (rc < 0)
return -1;
op = 1;
data[0x20] = op;
// write
rc = mmc_gen_cmd(fd, 0, data);
if (rc)
return -1;
// read
rc = mmc_gen_cmd(fd, 1, data);
if (rc)
return -1;
// dump("mmc_gen_cmd:", data, sizeof(data));
return 0;
}