I'm trying to compare two memory locations using the u-boot (CMP) command. I've u-boot-swap.bin which is flashed at the MTD partition (/dev/mtd2). There is the same u-boot-swap.bin file present at MMC. I want to see if the u-boot flashed at the MTD location (/dev/mtd2) & one present at MMC partition is the same or not.
I tried following commands,
Read u-boot-swap.bin from /dev/mtd2 to memory address 0x81000000
=> sf read 0x81000000 0x40000 0xc0000
device 0 offset 0x40000, size 0xc0000
SF: 786432 bytes @ 0x40000 Read: OK
Read u-boot-swap.bin from MMC to memory address 0x82000000
=> ext4load mmc 0:2 0x82000000 /boot/u-boot-swap.bin
445512 bytes read in 144 ms (2.9 MiB/s)
Then I tried to compare two memory locations using cmp command, But I'm getting mismatch
=> 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
What I'm doing wrong here? How to compare two memory location?
First of all, some u-boot commands assume arguments are hexadecimal values, you should try replacing
cmp 0x81000000 0x82000000 445512bycmp 0x81000000 0x82000000 0x0006cc48(0x0006cc48= 445512d) or use the $filesize variable which is populated after loading a file.This being said, if you have the original u-boot-swap.bin available, a convenient way to understand what exactly is going on would be to compare the content of your file with the content of the two memory area you loaded using
sfandext4load. This can be done by computing an MD5 hash on the file and the two memory areas (I created one for the purpose of my answer):On my PC:
On the system running u-boot, loading u-boot-swap.bin and verifying the MD5 hash computed on the memory area that received u-boot-swap.bin has the same MD5 hash:
The two computed MD5 hashes are the same.
If you don't have the original file available, you wil just be able to compute the MD5 hashes on the two memory areas, but you will not be able to know which one (if any) matches the content of your original file. On my system:
If your u-boot does not have the hash command available, you may use
crc32instead - on my PC:On my system running u-boot:
In the case you would not have any of the
hashandcrc32commands available, I would strongly suggest to rebuild your u-boot with thehashcommand and update it on your target system.