EMMC mmc_util 交叉编译

一、获取源码

git clone git@github.com:mhei/mmc-utils.git

二、编译

2.1 Android 环境下编译

/android10/external/mmc-utils

2.1.1、修改编译选项及代码

在这里插入图片描述
由于在编译时会报找不到htobe32 等函数 所以需要在mmc_cmds.c 文件中添加endian.h
在这里插入图片描述

由于在编译时会报结构体未完全初始化所以填充结构体内容

diff --git a/mmc.c b/mmc.c
index bc8f74e..81b5bba 100644
--- a/mmc.c
+++ b/mmc.c
@@ -54,17 +54,23 @@ static struct Command commands[] = {
        { do_read_extcsd, -1,
          "extcsd read", "<device>\n"
                "Print extcsd data from <device>.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_write_extcsd, 3,
          "extcsd write", "<offset> <value> <device>\n"
                  "Write <value> at offset <offset> to <device>'s extcsd.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_writeprotect_boot_get, -1,
          "writeprotect boot get", "<device>\n"
                "Print the boot partitions write protect status for <device>.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_writeprotect_boot_set, -1,
          "writeprotect boot set",
@@ -80,7 +86,9 @@ static struct Command commands[] = {
                "  -p  Protect partition permanently instead.\n"
                "      NOTE! -p is a one-time programmable (unreversible) change.\n"
 #endif /* DANGEROUS_COMMANDS_ENABLED */
-         , NULL
+         , NULL,
+         NULL,
+         0
        },
        { do_writeprotect_user_set, -4,
          "writeprotect user set", "<type>" "<start block>" "<blocks>" "<device>\n"
@@ -89,42 +97,58 @@ static struct Command commands[] = {
 #else
          "Set the write protect configuration for the specified region\nof the user area for <device>.\n<type> must be \"none|temp|pwron\".\n    \"none\"  - Clear temporary write protection.\n    \"temp\"  - Set temporary write protection.\n    \"pwron\" - Set write protection until the next poweron.\n<start block> specifies the first block of the protected area.\n<blocks> specifies the size of the protected area in blocks.\nNOTE! The area must start and end on Write Protect Group\nboundries, Use the \"writeprotect user get\" command to get the\nWrite Protect Group size.",
 #endif /* DANGEROUS_COMMANDS_ENABLED */
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_writeprotect_user_get, -1,
          "writeprotect user get", "<device>\n"
                "Print the user areas write protect configuration for <device>.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_disable_512B_emulation, -1,
          "disable 512B emulation", "<device>\n"
                "Set the eMMC data sector size to 4KB by disabling emulation on\n<device>.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_create_gp_partition, -6,
          "gp create", "<-y|-n|-c> " "<length KiB> " "<partition> " "<enh_attr> " "<ext_attr> " "<device>\n"
                "Create general purpose partition for the <device>.\nDry-run only unless -y or -c is passed.\nUse -c if more partitioning settings are still to come.\nNOTE!  This is a one-time programmable (unreversible) change.\nTo set enhanced attribute to general partition being created set\n <enh_attr> to 1 else set it to 0.\nTo set extended attribute to general partition\n set <ext_attr> to 1,2 else set it to 0",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_enh_area_set, -4,
          "enh_area set", "<-y|-n|-c> " "<start KiB> " "<length KiB> " "<device>\n"
                "Enable the enhanced user area for the <device>.\nDry-run only unless -y or -c is passed.\nUse -c if more partitioning settings are still to come.\nNOTE!  This is a one-time programmable (unreversible) change.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_write_reliability_set, -2,
          "write_reliability set", "<-y|-n|-c> " "<partition> " "<device>\n"
                "Enable write reliability per partition for the <device>.\nDry-run only unless -y or -c is passed.\nUse -c if more partitioning settings are still to come.\nNOTE!  This is a one-time programmable (unreversible) change.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_status_get, -1,
          "status get", "<device>\n"
          "Print the response to STATUS_SEND (CMD13).",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_write_boot_en, -3,
          "bootpart enable", "<boot_partition> " "<send_ack> " "<device>\n"
                "Enable the boot partition for the <device>.\nDisable the boot partition for the <device> if <boot_partition> is set to 0.\nTo receive acknowledgment of boot from the card set <send_ack>\nto 1, else set it to 0.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_boot_bus_conditions_set, -4,
          "bootbus set", "<boot_mode> " "<reset_boot_bus_conditions> " "<boot_bus_width> " "<device>\n"
@@ -132,7 +156,9 @@ static struct Command commands[] = {
          "<boot_mode> must be \"single_backward|single_hs|dual\"\n"
          "<reset_boot_bus_conditions> must be \"x1|retain\"\n"
          "<boot_bus_width> must be \"x1|x4|x8\"",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_write_bkops_en, -2,
          "bkops_en", "<auto|manual> <device>\n"
@@ -140,22 +166,30 @@ static struct Command commands[] = {
                "The auto (AUTO_EN) setting is only supported on eMMC 5.0 or newer.\n"
                "Setting auto won't have any effect if manual is set.\n"
                "NOTE!  Setting manual (MANUAL_EN) is one-time programmable (unreversible) change.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { 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.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_hwreset_dis, -1,
          "hwreset disable", "<device>\n"
                "Permanently disable the eMMC H/W Reset feature on <device>.\nNOTE!  This is a one-time programmable (unreversible) change.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_sanitize, -1,
          "sanitize", "<device> [timeout_ms]\n"
                "Send Sanitize command to the <device>.\nThis will delete the unmapped memory region of the device.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_rpmb_write_key, -1,
          "rpmb write-key", "<rpmb device> <key file>\n"
@@ -166,12 +200,16 @@ static struct Command commands[] = {
                  "Example:\n"
                  "  $ echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH | \\\n"
                  "    mmc rpmb write-key /dev/mmcblk0rpmb -",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_rpmb_read_counter, -1,
          "rpmb read-counter", "<rpmb device>\n"
                  "Counter value for the <rpmb device> will be read to stdout.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_rpmb_read_block, -1,
          "rpmb read-block", "<rpmb device> <address> <blocks count> <output file> [key file]\n"
@@ -184,7 +222,9 @@ static struct Command commands[] = {
                  "    mmc rpmb read-block /dev/mmcblk0rpmb 0x02 2 /tmp/block -\n"
                  "or read two blocks without verification\n"
                  "  $ mmc rpmb read-block /dev/mmcblk0rpmb 0x02 2 /tmp/block",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_rpmb_write_block, -1,
          "rpmb write-block", "<rpmb device> <address> <256 byte data file> <key file>\n"
@@ -195,44 +235,60 @@ static struct Command commands[] = {
                  "  $ (awk 'BEGIN {while (c++<256) printf \"a\"}' | \\\n"
                  "    echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH) | \\\n"
                  "    mmc rpmb write-block /dev/mmcblk0rpmb 0x02 - -",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_cache_en, -1,
          "cache enable", "<device>\n"
                "Enable the eMMC cache feature on <device>.\n"
                "NOTE! The cache is an optional feature on devices >= eMMC4.5.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_cache_dis, -1,
          "cache disable", "<device>\n"
                "Disable the eMMC cache feature on <device>.\n"
                "NOTE! The cache is an optional feature on devices >= eMMC4.5.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_read_csd, -1,
          "csd read", "<device path>\n"
                  "Print CSD data from <device path>.\n"
                  "The device path should specify the csd file directory.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
+       #if 1
        { do_read_cid, -1,
          "cid read", "<device path>\n"
                  "Print CID data from <device path>.\n"
                  "The device path should specify the cid file directory.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_read_scr, -1,
          "scr read", "<device path>\n"
                  "Print SCR data from <device path>.\n"
                  "The device path should specify the scr file directory.",
-         NULL
+         NULL,
+         NULL,
+         0
        },
+       #endif
        { do_ffu, -2,
          "ffu", "<image name> <device> [chunk-bytes]\n"
                "Run Field Firmware Update with <image name> on <device>.\n"
                "[chunk-bytes] is optional and defaults to its max - 512k. "
                "should be in decimal bytes and sector aligned.\n",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_erase, -4,
        "erase", "<type> " "<start address> " "<end address> " "<device>\n"
@@ -240,7 +296,9 @@ static struct Command commands[] = {
                "NOTE!: This will delete all user data in the specified region of the device\n"
                "<type> must be: legacy | discard | secure-erase | "
                "secure-trim1 | secure-trim2 | trim \n",
-       NULL
+       NULL,
+         NULL,
+         0
        },
        { do_general_cmd_read, -1,
        "gen_cmd read", "<device> [arg]\n"
@@ -248,17 +306,23 @@ static struct Command commands[] = {
                "NOTE!: [arg] is optional and defaults to 0x1. If [arg] is specified, then [arg]\n"
                "must be a 32-bit hexadecimal number, prefixed with 0x/0X. And bit0 in [arg] must\n"
                "be 1.",
-       NULL
+       NULL,
+         NULL,
+         0
        },
        { do_softreset, -1,
          "softreset", "<device>\n"
          "Issues a CMD0 softreset, e.g. for testing if hardware reset for UHS works",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_preidle, -1,
          "preidle", "<device>\n"
          "Issues a CMD0 GO_PRE_IDLE",
-         NULL
+         NULL,
+         NULL,
+         0
        },
        { do_alt_boot_op, -1,
          "boot_operation", "<boot_data_file> <device>\n"
@@ -270,9 +334,11 @@ static struct Command commands[] = {
          "2. The MMC must currently be running at the bus mode that is configured for the boot operation (HS200 and HS400 not supported at all).\n"
          "3. Only up to 512K bytes of boot data will be transferred.\n"
          "4. The MMC will perform a soft reset, if your system cannot handle that do not use the boot operation from mmc-utils.\n",
-         NULL
+         NULL,
+         NULL,
+         0
        },
-       { 0, 0, 0, 0 }
+       { 0, 0, 0, 0, NULL, NULL, 0}
 };

2.1.2、编译

在Android目录下执行:
source build/envsetup.sh
lunch ...
然后在android10/external/mmc-utils 目录下执行
mm

在这里插入图片描述

最后将

android10/out/target/product/x9m_ms/data/mmc-utils/mmc_utils

这个文件push到 /system/bin 或其他目录下即可使用

2.2 Android NDK环境下编译

2.2.1 将上述的Android.mk变为修改Makefile其他修改同上

在这里插入图片描述

2.2.2 编译

在这里插入图片描述
这个文件push到 /system/bin 或其他目录下即可使用

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值