From 1fbf0261fc90ce239638a1cea413688c457d5228 Mon Sep 17 00:00:00 2001 From: hayzamjs Date: Mon, 20 May 2024 16:40:36 +0530 Subject: [PATCH] mmc: cmd: add mmc mac command to generate mac from mmc (ethaddr, eth1addr) --- cmd/Kconfig | 6 ++++++ cmd/mmc.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index e645779f03..13dda1273f 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_MMC_MAC + bool "Enable support for creating a mac from the mmc command" + depends on CMD_MMC + help + Enable the commands for creating a mac from the emmc card. + config CMD_MMC_RPMB bool "Enable support for RPMB in the mmc command" depends on SUPPORT_EMMC_RPMB diff --git a/cmd/mmc.c b/cmd/mmc.c index 56c834a7cf..48d994312b 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -1198,6 +1198,49 @@ static int do_mmc_reg(struct cmd_tbl *cmdtp, int flag, } #endif +#if CONFIG_IS_ENABLED(CMD_MMC_MAC) +static int do_mac_mmc(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + struct mmc *mmc; + u8 mac[6], mac1[6]; + int i; + + mmc = init_mmc_device(curr_device, false); + u64 cid = ((u64)mmc->cid[2] << 32) | mmc->cid[3]; + + mac[0] = (cid >> 40) & 0xfe; + mac[1] = (cid >> 32) & 0xff; + mac[2] = (cid >> 24) & 0xff; + mac[3] = (cid >> 16) & 0xff; + mac[4] = (cid >> 8) & 0xff; + mac[5] = cid & 0xff; + + for (i = 0; i < 6; i++) { + mac1[i] = mac[i]; + } + + for (i = 5; i >= 0; i--) { + if (mac1[i] == 0xFF) { + mac1[i] = 0x00; + } else { + mac1[i] += 1; + break; + } + } + + printf("MAC Address for ethaddr: %02x:%02x:%02x:%02x:%02x:%02x\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + printf("MAC Address for eth1addr: %02x:%02x:%02x:%02x:%02x:%02x\n", + mac1[0], mac1[1], mac1[2], mac1[3], mac1[4], mac1[5]); + + eth_env_set_enetaddr("ethaddr", mac); + eth_env_set_enetaddr("eth1addr", mac1); + + return CMD_RET_SUCCESS; +} +#endif + static struct cmd_tbl cmd_mmc[] = { U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""), U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""), @@ -1233,6 +1276,9 @@ static struct cmd_tbl cmd_mmc[] = { #if CONFIG_IS_ENABLED(CMD_MMC_REG) U_BOOT_CMD_MKENT(reg, 5, 0, do_mmc_reg, "", ""), #endif +#if CONFIG_IS_ENABLED(CMD_MMC_MAC) + U_BOOT_CMD_MKENT(mac, 1, 0, do_mac_mmc, "", ""), +#endif }; static int do_mmcops(struct cmd_tbl *cmdtp, int flag, int argc, @@ -1326,6 +1372,9 @@ U_BOOT_CMD( " (optionally into [env] variable)\n" " - reg: cid/csd/dsr/ocr/rca/extcsd\n" " - offset: for cid/csd [0..3], for extcsd [0..511,all]\n" +#endif +#if CONFIG_IS_ENABLED(CMD_MMC_MAC) + "mmc mac - get the MAC address of the eMMC device\n" #endif );