Skip to content

Commit f74dfe2

Browse files
committed
Support enable/disable of eMMC H/W Reset function
(Note: one-time programmable fuse.) $ mmc hwreset enable /dev/mmcblk0 $ mmc hwreset disable /dev/mmcblk0
1 parent bf4ae7d commit f74dfe2

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

mmc.c

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ static struct Command commands[] = {
8080
"Enable the eMMC BKOPS feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.",
8181
NULL
8282
},
83+
{ do_hwreset_en, -1,
84+
"hwreset enable", "<device>\n"
85+
"Permanently enable the eMMC H/W Reset feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.",
86+
NULL
87+
},
88+
{ do_hwreset_dis, -1,
89+
"hwreset disable", "<device>\n"
90+
"Permanently disable the eMMC H/W Reset feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.",
91+
NULL
92+
},
8393
{ 0, 0, 0, 0 }
8494
};
8595

mmc.h

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#define EXT_CSD_BOOT_WP 173
4040
#define EXT_CSD_WR_REL_PARAM 166
4141
#define EXT_CSD_BKOPS_EN 163 /* R/W */
42+
#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */
4243
#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */
4344
#define EXT_CSD_USE_NATIVE_SECTOR 62 /* R/W */
4445
#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */
@@ -70,6 +71,9 @@
7071
#define EXT_CSD_BOOT_CFG_ACK (1<<6)
7172
#define EXT_CSD_BOOT_CFG_EN (0x38)
7273
#define EXT_CSD_BOOT_CFG_ACC (0x03)
74+
#define EXT_CSD_RST_N_EN_MASK (0x03)
75+
#define EXT_CSD_HW_RESET_EN (0x01)
76+
#define EXT_CSD_HW_RESET_DIS (0x02)
7377
#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7)
7478
#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1)
7579
#define EXT_CSD_PART_CONFIG_ACC_BOOT1 (0x2)

mmc_cmds.c

+59
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,65 @@ int do_write_boot_en(int nargs, char **argv)
280280
return ret;
281281
}
282282

283+
int do_hwreset(int value, int nargs, char **argv)
284+
{
285+
__u8 ext_csd[512];
286+
int fd, ret;
287+
char *device;
288+
289+
CHECK(nargs != 2, "Usage: mmc hwreset enable </path/to/mmcblkX>\n",
290+
exit(1));
291+
292+
device = argv[1];
293+
294+
fd = open(device, O_RDWR);
295+
if (fd < 0) {
296+
perror("open");
297+
exit(1);
298+
}
299+
300+
ret = read_extcsd(fd, ext_csd);
301+
if (ret) {
302+
fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
303+
exit(1);
304+
}
305+
306+
if ((ext_csd[EXT_CSD_RST_N_FUNCTION] & EXT_CSD_RST_N_EN_MASK) ==
307+
EXT_CSD_HW_RESET_EN) {
308+
fprintf(stderr,
309+
"H/W Reset is already permanently enabled on %s\n",
310+
device);
311+
exit(1);
312+
}
313+
if ((ext_csd[EXT_CSD_RST_N_FUNCTION] & EXT_CSD_RST_N_EN_MASK) ==
314+
EXT_CSD_HW_RESET_DIS) {
315+
fprintf(stderr,
316+
"H/W Reset is already permanently disabled on %s\n",
317+
device);
318+
exit(1);
319+
}
320+
321+
ret = write_extcsd_value(fd, EXT_CSD_RST_N_FUNCTION, value);
322+
if (ret) {
323+
fprintf(stderr,
324+
"Could not write 0x%02x to EXT_CSD[%d] in %s\n",
325+
value, EXT_CSD_RST_N_FUNCTION, device);
326+
exit(1);
327+
}
328+
329+
return ret;
330+
}
331+
332+
int do_hwreset_en(int nargs, char **argv)
333+
{
334+
return do_hwreset(EXT_CSD_HW_RESET_EN, nargs, argv);
335+
}
336+
337+
int do_hwreset_dis(int nargs, char **argv)
338+
{
339+
return do_hwreset(EXT_CSD_HW_RESET_DIS, nargs, argv);
340+
}
341+
283342
int do_write_bkops_en(int nargs, char **argv)
284343
{
285344
__u8 ext_csd[512], value = 0;

mmc_cmds.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ int do_writeprotect_set(int nargs, char **argv);
2222
int do_disable_512B_emulation(int nargs, char **argv);
2323
int do_write_boot_en(int nargs, char **argv);
2424
int do_write_bkops_en(int nargs, char **argv);
25+
int do_hwreset_en(int nargs, char **argv);
26+
int do_hwreset_dis(int nargs, char **argv);

0 commit comments

Comments
 (0)