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 data=$(dd if=/dev/mem bs=4 count=1 skip=$(($addr/4)) 2>/dev/null | hexdump -e '/4 "%08x\n"') #percent=$(echo "scale=2; ($addr - $start_addr) * 100 / ($end_addr - $start_addr)" | bc) # echo -ne "Writing: $percent%\r" done # echo $data 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_write" == "$data_read" ]; then match_count=$((match_count+1)) fi count=$((count+1)) # percent=$(echo "scale=2; $count * 100 / (($end_addr - $start_addr) / 4)" | bc) # echo -ne "Reading: $percent%\r" done #echo $data echo $data_read echo $data_write 如果data_read=55aa55aa,data_write=0x55AA55AA,那么该如何修改程序才能让程序输出PASS
时间: 2024-02-28 09:53:26 浏览: 70
为了让程序输出PASS,我们需要在读取数据的循环中加入判断,当读取到的数据与写入的数据相同时,match_count 加 1。然后在循环结束后,判断 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
#percent=$(echo "scale=2; ($addr - $start_addr) * 100 / ($end_addr - $start_addr)" | bc)
#echo -ne "Writing: $percent%\r"
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_write" == "$data" ]; then
match_count=$((match_count+1))
fi
count=$((count+1))
#percent=$(echo "scale=2; $count * 100 / (($end_addr - $start_addr) / 4)" | bc)
#echo -ne "Reading: $percent%\r"
done
if [ $match_count -eq $count ]; then
echo "PASS"
else
echo "FAIL"
fi
#echo $data
echo $data_read
echo $data_write
```
这样,当数据写入并读取成功时,程序就会输出 PASS。
阅读全文