【问题标题】:How to compare two memory location using CMP command in u-boot如何在 u-boot 中使用 CMP 命令比较两个内存位置
【发布时间】:2022-11-13 03:52:27
【问题描述】:

我正在尝试使用 u-boot (CMP) 命令比较两个内存位置。我有 u-boot-swap.bin,它在 MTD 分区 (/dev/mtd2) 中闪烁。 MMC 中存在相同的 u-boot-swap.bin 文件。我想看看 u-boot 是否在 MTD 位置 (/dev/mtd2) 闪烁,并且 MMC 分区中的一个是否相同。

我尝试了以下命令,

从/dev/mtd2读取u-boot-swap.bin到内存地址0x81000000

=> sf read 0x81000000 0x40000 0xc0000
device 0 offset 0x40000, size 0xc0000
SF: 786432 bytes @ 0x40000 Read: OK

从MMC读取u-boot-swap.bin到内存地址0x82000000

=> ext4load mmc 0:2 0x82000000 /boot/u-boot-swap.bin
445512 bytes read in 144 ms (2.9 MiB/s)

然后我尝试使用cmp 命令比较两个内存位置,但我得到了不匹配

=> cmp 0x81000000 0x82000000 445512
word at 0x8105c7dc (0x76203033) != word at 0x8205c7dc (0x76203130)
Total of 94711 word(s) were the same
=> cmp 0x81000000 0x82000000 786432
word at 0x8105c7dc (0x76203033) != word at 0x8205c7dc (0x76203130)
Total of 94711 word(s) were the same

我在这里做错了什么?如何比较两个内存位置?

【问题讨论】:

    标签: u-boot cmp


    【解决方案1】:

    首先,一些 u-boot 命令假定参数是十六进制值,您应该尝试将 cmp 0x81000000 0x82000000 445512 替换为 cmp 0x81000000 0x82000000 0x0006cc48 (0x0006cc48= 445512d)

    话虽如此,如果您有原始的 u-boot-swap.bin 可用,了解究竟发生了什么的一种方便方法是将文件的内容与您使用 @987654323 加载的两个内存区域的内容进行比较@ 和 ext4load。这可以通过计算文件和两个内存区域的 MD5 散列来完成(我为回答的目的创建了一个):

    在我的电脑上:

    dd if=/dev/random of=u-boot-swap.bin bs=445512 count=1
    ls -l u-boot-swap.bin
    md5sum -b u-boot-swap.bin
    def7d2bd063bc9d383889a4fc148aff6 *u-boot-swap.bin
    

    在运行 u-boot 的系统上,加载 u-boot-swap.bin 并验证在接收 u-boot-swap.bin 的内存区域上计算的 MD5 哈希具有相同的 MD5 哈希:

    => loadb
    ## Ready for binary (kermit) download to 0x80800000 at 115200 bps...
    CACHE: Misaligned operation at range [80800000, 8086cc48]
    ## Total Size      = 0x0006cc48 = 445512 Bytes
    ## Start Addr      = 0x80800000
    => hash md5 0x80800000 0x0006cc48
    md5 for 80800000 ... 8086cc47 ==> def7d2bd063bc9d383889a4fc148aff6
    

    两个计算的 MD5 哈希值是相同的。

    如果您没有可用的原始文件,您可以在您加载的两个内存区域上计算 MD5 哈希值 - 在我的系统上:

    # Copying file content previously loaded at `0x80800000` to `0x81000000`  and `0x820000001  :
    cp.b 80800000 0x81000000 0x0006cc48
    cp.b 80800000 0x82000000 0x0006cc48
    hash md5 0x81000000 0x0006cc48
    md5 for 81000000 ... 8106cc47 ==> def7d2bd063bc9d383889a4fc148aff6
    hash md5 0x82000000 0x0006cc48
    md5 for 82000000 ... 8206cc47 ==> def7d2bd063bc9d383889a4fc148aff6
    

    如果您的 u-boot 没有可用的 hash 命令,您可以改用 crc32 - 在我的 PC 上:

    sudo apt install libarchive-zip-perl
    crc32 u-boot-swap.bin
    b952fb8d
    

    在我运行 u-boot 的系统上:

    crc32  80800000 0x0006cc48
    crc32 for 80800000 ... 8086cc47 ==> b952fb8d
    crc32  0x81000000 0x0006cc48
    crc32 for 81000000 ... 8106cc47 ==> b952fb8d
    crc32  0x82000000 0x0006cc48
    crc32 for 82000000 ... 8206cc47 ==> b952fb8d
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多