On eMMC 5.0+ print eMMC health info similar to `mmc health` from mmc-utils.
Signed-off-by: Marek Behún <[email protected]> --- CI tests passed on github PR https://github.com/u-boot/u-boot/pull/1049 --- cmd/mmc.c | 35 +++++++++++++++++++++++++++++++++++ include/mmc.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/cmd/mmc.c b/cmd/mmc.c index 81b1ca4ad84..6f0a054ce43 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -21,6 +21,20 @@ static int curr_device = -1; +static void print_life_time_typ(char type, u8 life_typ) +{ + printf("Life time type %c: ", type); + + if (!life_typ) + printf("Not defined\n"); + else if (life_typ <= 10) + printf("%d%%-%d%% of device life time used\n", (life_typ - 1) * 10, life_typ * 10); + else if (life_typ == 11) + printf("Exceeded the maximum estimated device life time\n"); + else + printf("Reserved\n"); +} + static void print_mmcinfo(struct mmc *mmc) { int i; @@ -131,6 +145,27 @@ static void print_mmcinfo(struct mmc *mmc) } wp >>= 2; } + + if (mmc->version >= MMC_VERSION_5_0) { + static const char *pre_eol_str[4] = { + "Not defined", + "Normal", + "Warning: Consumed 80% of reserved block", + "Urgent", + }; + u8 pre_eol, life_typ_a, life_typ_b; + + pre_eol = ext_csd[EXT_CSD_PRE_EOL_INFO]; + life_typ_a = ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]; + life_typ_b = ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]; + + printf("Pre EOL info: %s\n", + pre_eol < ARRAY_SIZE(pre_eol_str) ? + pre_eol_str[pre_eol] : "Reserved"); + + print_life_time_typ('A', life_typ_a); + print_life_time_typ('B', life_typ_b); + } } } diff --git a/include/mmc.h b/include/mmc.h index 9509c9e9543..e2eeec97df1 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -240,6 +240,9 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx) #define EXT_CSD_BOOT_MULT 226 /* RO */ #define EXT_CSD_SEC_FEATURE 231 /* RO */ #define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ +#define EXT_CSD_PRE_EOL_INFO 267 /* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A 268 /* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B 269 /* RO */ #define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ /* -- 2.55.0
