From: Lars Pedersen <lapeddk@xxxxxxxxx> Add bkops start functionality when BKOPS_EN[0](MANUAL_EN) is set. --- mmc.c | 5 +++++ mmc.h | 5 +++++ mmc_cmds.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ mmc_cmds.h | 1 + 4 files changed, 57 insertions(+) diff --git a/mmc.c b/mmc.c index 9e02ba0..4ea1339 100644 --- a/mmc.c +++ b/mmc.c @@ -131,6 +131,11 @@ static struct Command commands[] = { "NOTE! Only supported in eMMC-5.1 and MANUAL_EN(BKOPS_EN[0]) must not be set", NULL }, + { do_write_bkops_start, -1, + "bkops start", "<device>\n" + "Manually start eMMC BKOPS feature on <device>.\nNOTE! BKOPS_EN[0] must be set.", + NULL + }, { do_hwreset_en, -1, "hwreset enable", "<device>\n" "Permanently enable the eMMC H/W Reset feature on <device>.\nNOTE! This is a one-time programmable (unreversible) change.", diff --git a/mmc.h b/mmc.h index 0596d6c..a804067 100644 --- a/mmc.h +++ b/mmc.h @@ -80,6 +80,7 @@ #define EXT_CSD_WR_REL_SET 167 #define EXT_CSD_WR_REL_PARAM 166 #define EXT_CSD_SANITIZE_START 165 +#define EXT_CSD_BKOPS_START 164 #define EXT_CSD_BKOPS_EN 163 /* R/W */ #define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */ @@ -132,6 +133,10 @@ #define BKOPS_ENABLE_AUTO_SET (1<<1) /* AUTO_EN */ #define BKOPS_ENABLE_AUTO_CLR (0) /* AUTO_EN */ +/* + * BKOPS_START field definition + */ +#define BKOPS_START (1<<0) /* * EXT_CSD field definitions diff --git a/mmc_cmds.c b/mmc_cmds.c index 05a63db..db1e98c 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -829,6 +829,52 @@ int do_write_bkops_auto_en(int nargs, char **argv) return ret; } +int do_write_bkops_start(int nargs, char **argv) +{ + __u8 ext_csd[512], value = 0; + int fd, ret; + char *device; + + if (nargs != 2) { + fprintf(stderr, "Usage: mmc bkops start </path/to/mmcblkX>\n"); + exit(1); + } + + device = argv[1]; + + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = read_extcsd(fd, ext_csd); + if (ret) { + fprintf(stderr, "Could not read EXT_CSD from %s\n", device); + exit(1); + } + + if (!(ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1)) { + fprintf(stderr, "%s doesn't support background operations\n", device); + exit(1); + } + + if (!(ext_csd[EXT_CSD_BKOPS_EN] & 0x1)) { + fprintf(stderr, "%s manual starting of background operations isn't enabled\n", device); + exit(1); + } + + ret = write_extcsd_value(fd, EXT_CSD_BKOPS_START, BKOPS_START); + if (ret) { + fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n", + value, EXT_CSD_BKOPS_EN, device); + exit(1); + } + + return ret; +} + + int do_status_get(int nargs, char **argv) { __u32 response; diff --git a/mmc_cmds.h b/mmc_cmds.h index 7f825ae..91b7ec5 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -29,6 +29,7 @@ int do_write_boot_en(int nargs, char **argv); int do_boot_bus_conditions_set(int nargs, char **argv); int do_write_bkops_manual_en(int nargs, char **argv); int do_write_bkops_auto_en(int nargs, char **argv); +int do_write_bkops_start(int nargs, char **argv); int do_hwreset_en(int nargs, char **argv); int do_hwreset_dis(int nargs, char **argv); int do_sanitize(int nargs, char **argv); -- 2.21.0