2020-09-16

Linux中常用的外设测试命令

  1. 查看内核和CPU信息
    使用uname 命令,查看内核和CPU信息,如下:
root@xx:~# uname -a
root@xx:~# 
  1. 查看计算机的名字
    使用hostname 命令,查看计算机的名字,如下:
    root@xx:~# hostname
    root@xx:~#

3.查看内存
使用cat 命令,查看内存使用情况,如下:

root@xx:~# cat /proc/meminfo
MemTotal:        1868952 kB
MemFree:         1516576 kB
MemAvailable:    1683992 kB
Buffers:           10908 kB
Cached:           186060 kB
……
VmallocChunk:          0 kB
CmaTotal:         245760 kB
CmaFree:          174568 kB
root@xx:~# 

4.查看环境变量
使用env 命令,查看环境变量,如下:

root@xx:~# env 
SHELL=/bin/sh
TERM=xterm
USER=root
LD_LIBRARY_PATH=:/home/root:/home/root/lib/
……

5.查看CPU 的主频
使用cat命令可以查看CPU 的主频,如下:

root@xx:~# ls /sys/devices/system/cpu      
cpu0        cpufreq     isolated    offline     possible    present
cpu1        cpuidle     kernel_max  online      power       uevent
root@xx:~#       
root@xx:~# cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq 
root@xx:~# cat /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq  
root@xx:~# 
root@xx:~# cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq 
root@xx:~# cat /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq  
root@xx:~# 
  1. 将SD卡插到开发板并启动系统,使用df查看分区信息,如下:
root@xx:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root              3753376   3420628    138752  96% /
devtmpfs                811424         4    811420   0% /dev
tmpfs                   934476         0    934476   0% /dev/shm
……
/dev/mmcblk0p1          157270     17242    140028  11% /run/media/mmcblk0p1
tmpfs                   186896         0    186896   0% /run/user/0
root@xx:~# 

SD卡的boot分区挂载在“/run/media/mmcblk0p1”目录下,使用ls查看,如下:

root@xx:~# ls /run/media/mmcblk0p1
dtb                        u-boot.img                 zImage  ……
root@xx:~# cd /  

7.LED 测试
一般的开发板上有多个LED,用于显示设备的状态等。在/sys/class/leds目录下,有多个LED控制目录,如下:

root@xx:/# cd /sys/class/leds
root@xx:/sys/class/leds# 
root@xx:/sys/class/leds# ls
user-led0               user-led1   ……
root@xx:/sys/class/leds# 

控制LED的亮和灭,执行如下命令:
控制LED1熄灭

root@xx:/sys/class/leds# echo 0 > /sys/class/leds/user-led0/brightness 
root@xx:/sys/class/leds# 

控制LED1亮

root@xx:/sys/class/leds# echo 1 > /sys/class/leds/user-led0/brightness  
root@xx:/sys/class/leds# 

其它的LED控制类似。

8.按键测试
一般开发板的底板上,有多个按键,用于用户对设备的控制。按键后有一串数字打印出来。
分别按下其中的一个按键,打印如下信息:

root@xx:~# od -x /dev/input/event0
0000000     c19a    5aee    39f5    0006    0001    0095    0001    0000
0000020     c19a    5aee    39f5    0006    0000    0000    0000    0000
0000040     c19a    5aee    54b8    0009    0001    0095    0000    0000
0000060     c19a    5aee    54b8    0009    0000    0000    0000    0000
0000100     c19b    5aee    fbf9    0004    0001    0094    0001    0000
0000120     c19b    5aee    fbf9    0004    0000    0000    0000    0000
0000140     c19b    5aee    fa83    0007    0001    0094    0000    0000
0000160     c19b    5aee    fa83    0007    0000    0000    0000    0000

9.时钟测试
linux系统中分系统时钟,即软件时钟和RTC 时钟,即硬件时钟,系统时钟掉电后会消失,RTC 时钟在电池有点的时候运行。系统时钟会在系统重启时与RTC 时钟同步。目前的文件系统会自动同步系统时间与网络时间。
使用date命令查看系统的运行时钟,如下:

root@xx:~# date
Sun May  6 11:31:43 UTC 2018
root@xx:~# 

使用hwclock命令查看RTC 时钟,如下:

root@xx:~# hwclock
Sun May  6 11:32:05 2018  0.000000 seconds
root@xx:~# 

使用date命令设置系统时间,如下:

root@xx:~# date -s "2020-09-16 10:06:11"
Wed Sep 31 10:06:11 UTC 2020
root@xx:~# 
root@xx:~# date
Wed Sep 31 10:06:16 UTC 2020
root@xx:~# 
root@xx:~# hwclock
Sun May  6 11:33:10 2018  0.000000 seconds
root@xx:~# 

使用hwclock 命令设置RTC 时钟,执行hwclock -w命令后,系统时钟会写入到RTC中

root@xx:~# hwclock -w
root@xx:~# hwclock
Wed Sep 31 10:06:18 UTC 2020  0.000000 seconds
root@xx:~# 

使用hwclock -s 命令同步系统和RTC 时钟,执行该命令后,系统会同步RTC 时钟作为系统时钟。

root@xx:~# hwclock -s
root@xx:~# 
root@xx:~# hwclock
Wed Sep 31 10:06:19 UTC 2020  0.000000 seconds
root@xx:~# 

10.QSPI Flash测试

使用cat命令,在系统下查看QSPI FLASH 分区

root@xx:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00020000 00001000 "QSPI.SPL"
mtd1: 00020000 00001000 "QSPI.SPL.backup1"
……
mtd7: 01620000 00001000 "QSPI.user-data"
root@xx:~# 

测试分区是否正常,拷贝文件到该分区:

root@xx:~# dd if=/run/media/mmcblk0p1/MLO of=/dev/mtdblock0
134+1 records in
134+1 records out
root@xx:~# 

通过time dd命令可以测试写数据所耗的时间,写入20M字节的数据到mtdblock7所耗的时间:

root@xx:~# time dd if=/dev/zero of=/dev/mtdblock7 bs=1024k count=20
20+0 records in
20+0 records out
real    0m 47.93s
user    0m 0.00s
sys     0m 0.12s
root@xx:~# 

通过time dd命令可以测试读数据所耗的时间,读取23M字节的数据所耗的时间:

root@xx:~# time dd if=/dev/mtdblock7 of=/dev/null bs=1024k
22+1 records in
22+1 records out
real    0m 2.11s
user    0m 0.00s
sys     0m 0.04s
root@xx:~# 

QSPI FLASH测试结果:
读写类型 速率 文件系统
读 426.22KB/s 无
写 10.69MB/s 无

11.USB测试
11.1 挂载测试
将FAT32格式的U盘插入到USB3.0接口上,可以看到系统打印如下的信息:

root@xx:~# 
root@xx:~# [ 3772.447238] usb 2-1: new SuperSpeed USB device number 2 using xhci-hcd
[ 3772.485102] usb-storage 2-1:1.0: USB Mass Storage device detected
[ 3772.501605] scsi host1: usb-storage 2-1:1.0
[ 3773.507396] scsi 1:0:0:0: Direct-Access     Kingston DataTraveler 3.0      PQ: 0 ANSI: 6
[ 3773.516231] sd 1:0:0:0: [sda] 30218842 512-byte logical blocks: (15.5 GB/14.4 GiB)
[ 3773.525931] sd 1:0:0:0: [sda] Write Protect is off
[ 3773.532507] sd 1:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 3773.547772]  sda: sda1
[ 3773.552392] sd 1:0:0:0: [sda] Attached SCSI removable disk
[ 3773.702521] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

将FAT32格式的U盘插入到USB2.0接口上,可以看到系统打印如下的信息:

root@xx:~# [ 3790.166864] usb 3-1.4: new high-speed USB device number 3 using xhci-hcd
[ 3790.271618] usb 3-1.4: ep 0x81 - rounding interval to 128 microframes, ep desc says 255 microframes
[ 3790.280844] usb 3-1.4: ep 0x2 - rounding interval to 128 microframes, ep desc says 255 microframes
[ 3790.292381] usb-storage 3-1.4:1.0: USB Mass Storage device detected
[ 3790.299919] scsi host2: usb-storage 3-1.4:1.0
[ 3791.329983] scsi 2:0:0:0: Direct-Access     Kingston DataTraveler 2.0 1.00 PQ: 0 ANSI: 4
[ 3791.339892] sd 2:0:0:0: [sdb] 15131636 512-byte logical blocks: (7.75 GB/7.21 GiB)
[ 3791.349195] sd 2:0:0:0: [sdb] Write Protect is off
[ 3791.356972] sd 2:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 3791.372853]  sdb: sdb1
[ 3791.377436] sd 2:0:0:0: [sdb] Attached SCSI removable disk
[ 3791.683616] FAT-fs (sdb1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

从上面的打印信息,可以知道usb 2-1已经成功挂载了一个15.5G的U盘,usb 3-1成功挂载了一个7.75G的硬盘,
同时还可以知道,挂载名为"sda"和"sdb"
root@xx:~#
执行df命令可以看到系统所有的挂载信息,如下所示:

root@xx:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 3.6G      3.3G    135.5M  96% /
……
/dev/sda1                14.4G      1.9G     12.5G  13% /run/media/sda1
/dev/sdb1                 7.2G      2.4G      4.8G  33% /run/media/sdb1
root@xx:~# 

11.2 读写速率测试
使用U盘插入USB2.0接口,写入200MB测试数据到U盘的test文件,测试所需要的时间,如下:

root@xx:~# time dd if=/dev/zero of=/run/media/sdb1/test bs=1024k count=200
200+0 records in
200+0 records out
real    0m 45.88s
user    0m 0.00s
sys     0m 1.11s

将200MB的test文件读到"/dev/null",测试所需要的时间,如下:

root@xx:~# time dd if=/run/media/sdb1/test of=/dev/null bs=1024k 
200+0 records in
200+0 records out
real    0m 10.53s
user    0m 0.00s
sys     0m 0.36s
root@xx:~# 
root@xx:~# 

使用U盘插入USB3.0接口,写入200MB测试数据到U盘的test文件,测试所需要的时间,如下:

root@xx:~# time dd if=/dev/zero of=/run/media/sda1/test bs=1024k count=200 
200+0 records in
200+0 records out
real    0m 6.50s
user    0m 0.00s
sys     0m 1.03s

将200MB的test文件读到"/dev/null",测试所需要的时间,如下:

root@xx:~# time dd if=/run/media/sda1/test of=/dev/null bs=1024k
200+0 records in
200+0 records out
real    0m 1.82s
user    0m 0.00s
sys     0m 0.38s

USB测试的结果如下:
USB协议 读写类型 速率 文件系统
USB3.0 写 26.56MB/S FAT32
USB3.0 读 90.9MB/S FAT32
USB2.0 写 4.25MB/S FAT32
USB2.0 读 18.38MB/S FAT32

12.RGMII网口测试
高端的开发板上一般都配置有多个RGMII接口的网口,支持GE速率。
通过路由器用网线连接开发板的网络接口,输入ifconfig命令,可以看到网口的IP地址,如下:

root@xx:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 34:03:DE:EE:95:DA  
          inet addr:192.168.1.150  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::3603:deff:feee:95da%131824/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2916 errors:0 dropped:0 overruns:0 frame:0
          TX packets:296 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:194934 (190.3 KiB)  TX bytes:25644 (25.0 KiB)
          Interrupt:100 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%131824/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:924 errors:0 dropped:0 overruns:0 frame:0
          TX packets:924 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:290866 (284.0 KiB)  TX bytes:290866 (284.0 KiB)

root@xx:~# 

ubuntu上设置如下IP:

[root@tl tronlong]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:2f:e1:03  
          inet addr:192.168.1.155  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe2f:e103/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4588 errors:0 dropped:0 overruns:0 frame:0
          TX packets:136 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:283429 (283.4 KB)  TX bytes:25378 (25.3 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:30 errors:0 dropped:0 overruns:0 frame:0
          TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1856 (1.8 KB)  TX bytes:1856 (1.8 KB)

[root@tl tronlong]# 

在开发板上ping ubuntu,看网络通信是否正常,如下:

root@xx:~# ping 192.168.1.155
PING 192.168.1.155 (192.168.0.55): 56 data bytes
64 bytes from 192.168.1.155: seq=0 ttl=64 time=0.491 ms
64 bytes from 192.168.1.155: seq=1 ttl=64 time=0.486 ms
^C
--- 192.168.1.155 ping statistics ---
7 packets transmitted, 7 packets received, 0% packet loss
round-trip min/avg/max = 0.467/0.530/0.674 ms
root@xx:~# 

在ubuntu上,ping开发板,看网络通信是否正常,如下:

[root@tl tronlong]# ping 192.168.1.150
PING 192.168.1.150 (192.168.1.150) 56(84) bytes of data.
64 bytes from 192.168.1.150: icmp_seq=1 ttl=64 time=1.20 ms
64 bytes from 192.168.1.150: icmp_seq=2 ttl=64 time=0.626 ms
^C
--- 192.168.1.150 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.466/0.720/1.201/0.285 ms
[root@tl tronlong]# 

使用ethool命令查看网口的属性,如下:

root@xx:~# ethtool eth0
Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Supported pause frame use: Symmetric
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes
        Link partner advertised link modes:  10baseT/Half 10baseT/Full 
                                             100baseT/Half 100baseT/Full 
                                             1000baseT/Full 
        Link partner advertised pause frame use: Symmetric
        Link partner advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 0
        Transceiver: external
        Auto-negotiation: on
        Supports Wake-on: d
        Wake-on: d
        Current message level: 0x00000000 (0)
                               
        Link detected: yes
root@xx:~# 
root@xx:~# 

使用网络测试软件ipref来测试网口的通信速率,如下:

[root@tl tronlong]# iperf -s
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
[  4] local 192.168.1.155 port 5001 connected with 192.168.1.150 port 57738
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.0 sec  1.09 GBytes   932 Mbits/sec
^C[root@tl tronlong]# 
[root@tl tronlong]# 
[root@tl tronlong]# 

root@xx:~# iperf -c 192.168.1.155 -i 1
Client connecting to 192.168.1.155, TCP port 5001
TCP window size: 43.8 KByte (default)
[  3] local 192.168.1.150 port 57738 connected with 192.168.1.155 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec   111 MBytes   930 Mbits/sec
[  3]  1.0- 2.0 sec   111 MBytes   934 Mbits/sec
[  3]  0.0-10.0 sec  1.09 GBytes   932 Mbits/sec

[root@tl tronlong]# iperf -s -u
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size:  208 KByte (default)
[  3] local 192.168.1.155 port 5001 connected with 192.168.1.150 port 59237
[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
[  3]  0.0-10.2 sec   890 MBytes   728 Mbits/sec  15.381 ms 172920/807705 (21%)
[  3]  0.0-10.2 sec  1 datagrams received out-of-order
^C[root@tl tronlong]# 

root@xx:~# iperf -u -c 192.168.1.155 -b 1000M -i 1 -w 1M -t 10
Client connecting to 192.168.1.155, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  320 KByte (WARNING: requested 1.00 MByte)
[  3] local 192.168.1.150 port 59237 connected with 192.168.1.155 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec   114 MBytes   953 Mbits/sec
[  3]  1.0- 2.0 sec   113 MBytes   951 Mbits/sec
[  3]  0.0-10.0 sec  1.11 GBytes   950 Mbits/sec
[  3] Sent 807815 datagrams
[  3] Server Report:
[  3]  0.0-10.2 sec   890 MBytes   728 Mbits/sec  15.380 ms 172920/807705 (21%)
[  3]  0.0-10.2 sec  1 datagrams received out-of-order
root@xx:~# 
root@xx:~# 

RGMII 测试结果:
测试类型 速率
TCP 932 Mbits/s
UDP 728 Mbits/s

13.SD卡读写测试
使用time dd命令测试SD卡的读写速度,如下:
写入200MB大小的文件到SD卡:

root@xx:~# time dd if=/dev/zero of=/home/root/test bs=1024k count=200
200+0 records in
200+0 records out
real    0m 35.33s
user    0m 0.00s
sys     0m 1.36s
root@xx:~# 

从SD卡读取200M大小的文件,如下:

root@xx:~# time dd if=/home/root/test of=/dev/null bs=1024k
200+0 records in
200+0 records out
real    0m 19.21s
user    0m 0.00s
sys     0m 0.32s
root@xx:~# 

SD卡测试结果:
SD卡读写类型 速率 文件系统
读 10.24MB/s FAT32
写 5.45MB/s FAT32

14.eMMC测试
使用time dd命令测试eMMC卡的读写速度,如下:
写入200MB大小的文件到eMMC卡:

root@xx:~# time dd if=/dev/zero of=/run/media/mmcblk1p2/test bs=1024k count=200
200+0 records in
200+0 records out
real    0m 6.21s
user    0m 0.00s
sys     0m 0.66s
root@xx:~# 

从eMMC卡读取200M大小的文件,如下:

root@xx:~# time dd if=/run/media/mmcblk1p2/test of=/dev/null bs=1024k
200+0 records in
200+0 records out
real    0m 2.97s
user    0m 0.01s
sys     0m 0.28s
root@xx:~# 

eMMC卡测试结果:
eMMC卡读写类型 速率 文件系统
读 61.54MB/s EXT4
写 29.11MB/s EXT4

15.LCD亮度调节测试
执行指令后,屏幕亮度会随着参数而改变,调节范围为0~8,默认为8(最亮):

root@xx:~# echo 0 > /sys/class/backlight/backlight/brightness 
root@xx:~# echo 6 > /sys/class/backlight/backlight/brightness  
root@xx:~# 
root@xx:~# echo 8 > /sys/class/backlight/backlight/brightness  
root@xx:~# 

你可能感兴趣的:(linux驱动,linux,嵌入式)