start_addr=0x30000000 end_addr=0x30000003 data_write=0x55AA55AA count=0 match_count=0 # 写入数据 for ((addr=$start_addr; addr<$end_addr+1; addr=addr+1)); do echo "addr: $addr" echo -ne "\x55\xAA\x55\xAA" | dd of=/dev/mem bs=4 count=1 seek=$(($addr/8)) conv=notrunc 2>/dev/null data=$(echo -ne "\x55\xAA\x55\xAA" | hexdump -e '/4 "%08x\n"') data_text=$(echo -ne "\x55\xAA\x55\xAA" | hexdump -e '/4 "%08x\n"' | sed 's/../& /g') echo "data_text: $data_text" #echo "data: $data" data_read=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"') data_read_text=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"' | sed 's/../& /g') echo "data_read_text: $data_read_text" # echo "data_read: $data_read" if [ "$data_read" == "$data" ]; then match_count=$((match_count+1)) echo "match_count: $match_count" fi count=$((count+1)) echo "count: $count" done # 输出结果 # 判断结果 if [ $match_count -eq $count ]; then echo "PASS" else echo "FAIL" fi如何能让这段代码输出addr时输出0x30000000、0x30000001、0x30000002和0x30000003而不是805306368、805306369、805306370和805306371
时间: 2024-03-01 16:54:02 浏览: 142
可以使用printf命令来控制输出格式,将addr以16进制的形式输出。修改代码如下:
```
start_addr=0x30000000
end_addr=0x30000003
data_write=0x55AA55AA
count=0
match_count=0
# 写入数据
for ((addr=$start_addr; addr<$end_addr+1; addr=addr+1)); do
printf "addr: 0x%x\n" $addr
echo -ne "\x55\xAA\x55\xAA" | dd of=/dev/mem bs=4 count=1 seek=$(($addr/8)) conv=notrunc 2>/dev/null
data=$(echo -ne "\x55\xAA\x55\xAA" | hexdump -e '/4 "%08x\n"')
data_text=$(echo -ne "\x55\xAA\x55\xAA" | hexdump -e '/4 "%08x\n"' | sed 's/../& /g')
echo "data_text: $data_text"
#echo "data: $data"
data_read=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"')
data_read_text=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"' | sed 's/../& /g')
echo "data_read_text: $data_read_text"
#echo "data_read: $data_read"
if [ "$data_read" == "$data" ]; then
match_count=$((match_count+1))
echo "match_count: $match_count"
fi
count=$((count+1))
echo "count: $count"
done
# 输出结果
# 判断结果
if [ $match_count -eq $count ]; then
echo "PASS"
else
echo "FAIL"
fi
```
这样输出的addr就会以16进制的形式显示。
阅读全文