start_addr=0x05877000 #end_addr=0x3ffff000 end_addr=0x05877002 data_write=0x55AA55AA data_read=$(printf "%08x" $data_write) count=0 match_count=0 for ((addr=$start_addr; addr<$end_addr; addr=addr+4)); do echo $data_write | dd of=/dev/mem bs=4 count=1 seek=$(($addr/8)) conv=notrunc 2>/dev/nul done for ((addr=$start_addr; addr<$end_addr; addr+=4)); do data=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"') if [ "$data_read" == "$data" ]; then match_count=$((match_count+1)) fi count=$((count+1)) done echo $data echo $data_read那么该如何修改程序才能让程序输出PASS
时间: 2024-02-28 14:53:31 浏览: 115
dev_addr_lists.rar_DEV_ADDR
为了让程序输出 PASS,我们需要在循环结束后,判断 match_count 是否等于 count,如果等于,即所有数据都成功读取并且与写入的数据一致,就输出 PASS。
修改后的代码如下:
```
start_addr=0x05877000
end_addr=0x3ffff000
data_write=0x55AA55AA
data_read=$(printf "%08x" $data_write)
count=0
match_count=0
for ((addr=$start_addr; addr<$end_addr; addr=addr+4)); do
echo $data_write | dd of=/dev/mem bs=4 count=1 seek=$(($addr/8)) conv=notrunc 2>/dev/nul
done
for ((addr=$start_addr; addr<$end_addr; addr+=4)); do
data=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"')
if [ "$data_read" == "$data" ]; then
match_count=$((match_count+1))
fi
count=$((count+1))
done
if [ $match_count -eq $count ]; then
echo "PASS"
else
echo "FAIL"
fi
echo $data
echo $data_read
```
这样,当所有数据都成功读取并且与写入的数据一致时,程序就会输出 PASS。
阅读全文