添加blk_detect

This commit is contained in:
HEYAHONG 2024-04-10 23:03:35 +08:00
parent 318b27f536
commit af0e480bb8
No known key found for this signature in database
GPG Key ID: 2D9DCE4738519ABB
4 changed files with 68 additions and 0 deletions

View File

@ -1,3 +1,4 @@
- [usb_detect](usb_detect):通过USB检测ExtBoard-001.
- [serialport_detect](serialport_detect):检测ExtBoard-001的Console串口(由DAPLink提供)。
- [blk_detect](blk_detect):在Linux检测ExtBoard-001的DAPLink的块设备虚拟U盘

11
SOFT/blk_detect/ReadMe.md Normal file
View File

@ -0,0 +1,11 @@
# 说明
本程序主要用于检测ExtBoard-001的DAPLink虚拟的块设备。
采用Linux的sysfs检测。
# 截图
## ubuntu测试Core固件编号001
![blk_detect_001_ubuntu](blk_detect_001_ubuntu.png)

56
SOFT/blk_detect/blk_detect.sh Executable file
View File

@ -0,0 +1,56 @@
#!/bin/bash
function CheckTool
{
[ -n "$1" ] ||
{
echo -e "CheckTool 参数错误!!";
return 255;
};
ToolPath=`which $1`;
[ -e "$ToolPath" ] ||
{
echo -e "$1 不存在,请先安装此工具!!!";
return 255;
};
return 0;
}
CheckTool find
[ $? -eq 0 ] || exit
CheckTool xargs
[ $? -eq 0 ] || exit
CheckTool dirname
[ $? -eq 0 ] || exit
CheckTool cat
[ $? -eq 0 ] || exit
CheckTool readlink
[ $? -eq 0 ] || exit
#判断sysfs
SYSFS_BLOCK="/sys/class/block/"
[ -d "${SYSFS_BLOCK}" ] || SYSFS_BLOCK="/sys/block"
[ -d "${SYSFS_BLOCK}" ] || exit
for i in `find /sys/block/ |xargs realpath`
do
DIR=`dirname "$i"`
DEVNAME=`realpath --relative-to="${DIR}" "${i}"`
if [ -b "/dev/${DEVNAME}" ]
then
while [ "/" != "${DIR}" ]
do
if [ -e "${DIR}/manufacturer" ] && [ -e "${DIR}/product" ]
then
if [ "HYH" == `cat "${DIR}/manufacturer"` ] && [ "ExtBoard-001" == `cat "${DIR}/product"` ]
then
echo "Found ExtBoard-001 DAPLink Block /dev/${DEVNAME}"
fi
DIR="/"
fi
DIR=`dirname ${DIR}`
done
fi
done

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB