When debugging chips in a Linux system, we often need to read the values of registers. Sometimes, manual reading is sufficient, but in scenarios where the reading frequency is high and the data volume is large, scripts are necessary to solve the problem. Scripting languages such as Python and shell can be used, with complex scripts recommended to be implemented in Python. For simpler scripts, it is recommended to use shell, as all Linux systems support shell commands, allowing scripts to be executed directly.When obtaining register values, we typically need to filter and select the information to retain the necessary read data. The command “mem_access nic -d 06:00.0 -r 0xa8110868 1” reads the 06:00.0 (PCIe bdf) network card device at address 0xa8110868 for a 32-bit register. The read data is 0x10.In the command read_value1=$(mem_access nic -d $bdf_num -r 0xa8302f00 1 | grep “Value:” | awk ‘{print $4}’), a read command is first executed, resulting in 3 lines of data. The grep “Value:” filters out the third line, which is “Addr: 0xa8110868, Value: 0x10“.AWK is a powerful text processing tool that uses spaces or tabs as field separators by default, splitting input lines into multiple fields.$4 is a parameter used in the awk command for field extraction. awk ‘{print $4}’ matches the fourth parameter, which is 0x10. Ultimately, read_value1 is 0x10; in fact, in a formal debugging script, obtaining read data is just one of the most basic functions.
[root@asic-lab-asic205 icxiaoge]# mem_access nic -d 06:00.0 -r 0xa8110868 1nic: read register 0xa8110868BDF:0000:06:00.0:Addr: 0xa8110868, Value: 0x10[root@asic-lab-asic205 icxiaoge]# [root@asic-lab-asic205 icxiaoge]# cat ./read.sh #!/bin/bash
bdf_num=06:00.0
read_value1=$(mem_access nic -d $bdf_num -r 0xa8110868 1 | grep "Value:" | awk '{print $4}')
echo "read value is:$read_value1"[root@asic-lab-asic205 icxiaoge]# [root@asic-lab-asic205 icxiaoge]# ./read.sh read value is:0x10