diff --git a/cmd/Kconfig b/cmd/Kconfig index e645779f03..31303f2596 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1288,6 +1288,12 @@ config CMD_MMC_REG Enable the commands for reading card registers. This is useful mostly for debugging or extracting details from the card. +config CMD_MAC_FROM_MMC + bool "mac form mmc cid" + depends on CMD_MMC + help + Enable command for forming a MAC address from the CID of a eMMC device. + config CMD_MMC_RPMB bool "Enable support for RPMB in the mmc command" depends on SUPPORT_EMMC_RPMB diff --git a/cmd/Makefile b/cmd/Makefile index 6c37521b4e..acbee5cedf 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -115,6 +115,7 @@ obj-$(CONFIG_CMD_MDIO) += mdio.o obj-$(CONFIG_CMD_PAUSE) += pause.o obj-$(CONFIG_CMD_SLEEP) += sleep.o obj-$(CONFIG_CMD_MMC) += mmc.o +obj-$(CONFIG_CMD_MAC_FROM_MMC) += mac_from_emmc.o obj-$(CONFIG_CMD_OPTEE_RPMB) += optee_rpmb.o obj-$(CONFIG_CMD_MP) += mp.o obj-$(CONFIG_CMD_MTD) += mtd.o diff --git a/cmd/mac_from_emmc.c b/cmd/mac_from_emmc.c new file mode 100644 index 0000000000..855998d24e --- /dev/null +++ b/cmd/mac_from_emmc.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2024 Alchemilla Ventures Private Limited + */ + +#include +#include +#include +#include + +static int do_mac_from_mmc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { + if (argc != 2) { + return CMD_RET_USAGE; + } + + int currentDevice = simple_strtoul(argv[1], NULL, 10); + struct mmc *mmc = find_mmc_device(currentDevice); + + if (!mmc) { + printf("No MMC device at slot %d\n", currentDevice); + return CMD_RET_FAILURE; + } + + if (IS_SD(mmc)) { + printf("SD registers are not supported\n"); + return CMD_RET_FAILURE; + } + + unsigned char mac[6]; + mac[0] = (mmc->cid[0] >> 24) & 0xFE; + mac[1] = (mmc->cid[1] >> 16) & 0xFF; + mac[2] = (mmc->cid[2] >> 8) & 0xFF; + mac[3] = (mmc->cid[3]) & 0xFF; + mac[4] = (mmc->cid[0] >> 8) & 0xFF; + mac[5] = (mmc->cid[1] >> 24) & 0xFF; + + printf("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD( + mac_from_mmc, 2, 0, do_mac_from_mmc, + "Get MAC address from MMC CID", + "mmc" +); \ No newline at end of file