From a7f0d6768c69434865568bb0175f5ded623fca21 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Tue, 16 Jun 2026 22:55:49 +0300 Subject: [PATCH] sdmmc: add gen cmd support --- bdk/storage/sdmmc.c | 29 +++++++++++++++++++++++++++-- bdk/storage/sdmmc.h | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bdk/storage/sdmmc.c b/bdk/storage/sdmmc.c index 04621d2f..85ab3d6b 100644 --- a/bdk/storage/sdmmc.c +++ b/bdk/storage/sdmmc.c @@ -166,7 +166,7 @@ static int _sdmmc_storage_check_status(sdmmc_storage_t *storage) return _sdmmc_storage_get_status(storage, &tmp, 0); } -int sdmmc_storage_execute_vendor_cmd(sdmmc_storage_t *storage, u32 arg) +int sdmmc_storage_vendor_cmd(sdmmc_storage_t *storage, u32 arg) { sdmmc_cmd_t cmdbuf; sdmmc_init_cmd(&cmdbuf, MMC_VENDOR_CMD_62, arg, SDMMC_RSP_TYPE_1, 1); @@ -196,7 +196,7 @@ int sdmmc_storage_execute_vendor_cmd(sdmmc_storage_t *storage, u32 arg) int sdmmc_storage_vendor_sandisk_report(sdmmc_storage_t *storage, void *buf) { // Request health report. - if (sdmmc_storage_execute_vendor_cmd(storage, MMC_SANDISK_HEALTH_REPORT)) + if (sdmmc_storage_vendor_cmd(storage, MMC_SANDISK_HEALTH_REPORT)) return 2; u32 tmp = 0; @@ -222,6 +222,31 @@ int sdmmc_storage_vendor_sandisk_report(sdmmc_storage_t *storage, void *buf) return _sdmmc_storage_check_cached_card_status(storage->sdmmc); } +int sdmmc_storage_gen_cmd(sdmmc_storage_t *storage, u32 arg, void *buf) +{ + u32 tmp = 0; + sdmmc_cmd_t cmdbuf; + sdmmc_req_t reqbuf; + + sdmmc_init_cmd(&cmdbuf, MMC_GEN_CMD, arg, SDMMC_RSP_TYPE_1, 0); + + reqbuf.buf = buf; + reqbuf.blksize = SDMMC_DAT_BLOCKSIZE; + reqbuf.num_sectors = 1; + reqbuf.is_write = !(arg & 1); + reqbuf.is_multi_block = 0; + reqbuf.is_auto_stop_trn = 0; + + if (sdmmc_execute_cmd(storage->sdmmc, &cmdbuf, &reqbuf, NULL)) + { + _sdmmc_storage_get_status(storage, &tmp, 0); + + return 1; + } + + return _sdmmc_storage_check_cached_card_status(storage->sdmmc); +} + static int _sdmmc_storage_readwrite_ex(sdmmc_storage_t *storage, u32 *blkcnt_out, u32 sector, u32 num_sectors, void *buf, u32 is_write) { u32 tmp = 0; diff --git a/bdk/storage/sdmmc.h b/bdk/storage/sdmmc.h index 2723e06f..dc86529a 100644 --- a/bdk/storage/sdmmc.h +++ b/bdk/storage/sdmmc.h @@ -233,7 +233,8 @@ void sdmmc_storage_init_wait_sd(); int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_width, u32 type); int sdmmc_storage_init_gc(sdmmc_storage_t *storage, sdmmc_t *sdmmc); -int sdmmc_storage_execute_vendor_cmd(sdmmc_storage_t *storage, u32 arg); +int sdmmc_storage_gen_cmd(sdmmc_storage_t *storage, u32 arg, void *buf); +int sdmmc_storage_vendor_cmd(sdmmc_storage_t *storage, u32 arg); int sdmmc_storage_vendor_sandisk_report(sdmmc_storage_t *storage, void *buf); int mmc_storage_get_ext_csd(sdmmc_storage_t *storage);