nicsensor/docs/扩展脚本说明.md

120 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 如何扩展脚本?
## 一、前言
> [!tip]
>
> 脚本扩展一般涉及到两部分内容的扩充,包含对于支持服务器类型的扩充,或者对支持读取的传感器类型的扩充。
不论如何修改脚本,请在完成后主要修改后,修改 `SCRIPT_VERSION` 用于和主线脚本进行版本区分。
例如:
- `SCRIPT_VERSION="1.6.5 for project"` 代表基于脚本1.6.5版本为某个项目做特殊定制
## 二、新增支持服务器
### 修改点1-Support_Server_List
``````sh
# 可以在这里添加对应的服务器型号
Support_Server_List="5280m7, 5468m7, 5688m7, donghu, yichun, qiandaohu"
``````
### 修改点2-添加服务器配置入口
``````sh
# 修改函数 set_configuration
set_configuration(){
# ... 省略部分代码
case ${server_type} in
"5280m7")
set_configuration_5280m7
;;
# [开始修改]在这里针对要添加的服务器添加如下语句,将 {server_name} 替换为对应的服务器型号
# 这里修改的意义在于添加一个设置服务器I2C拓扑的入口后面会专门编写 set_configuration_{server_name} 函数
"{server_name}")
set_configuration_{server_name}
;;
# [结束修改]
esac
# ... 省略部分代码
}
``````
### 修改点3-添加I2C拓扑适配函数
``````sh
# 在脚本中找到函数 set_configuration_5280m7在这个函数上面新建一个函数名为
set_configuration_{server_name}(){
# 可以模仿 5280m7 函数的写法,来编写本函数
# 主体编写的内容就是针对卡的类型和槽位来配置通道上正确的I2C属性
# 需要考虑的内容如下:
# 1.是否支持OCP网卡
# 2.I2C链路上是否存在PCA9641
# 3.每个物理slot和I2C Bus的对应关系
# 4.每个物理slot和I2C PCA9546/9548 channel的对应关系
# 5.PCA9641和PCA9546/9548的slave地址
# 提供一种模板
# 首先判断网卡类型是否为 pcie (ocp形态同理)
if [ ${nic_type} = "pcie" ];then
# 根据 SLOT number 做针对性配置
if [ ${slot_number} -eq 0 ];then
i2c_bus=12
is_have_pca9641=1
pca9641_slave=0x41
pca9548_slave=0x70
pca9548_channel="0x01"
elif [ ${slot_number} -eq 1 ]; then
i2c_bus=12
is_have_pca9641=1
pca9641_slave=0x41
pca9548_slave=0x70
pca9548_channel="0x02"
elif [ ${slot_number} -eq 2 ]; then
i2c_bus=12
is_have_pca9641=1
pca9641_slave=0x41
pca9548_slave=0x70
pca9548_channel="0x04"
else
format_print $WARNING "Unspecified card slot!"
fi
fi
}
``````
### 修改点4-添加I2C扫描函数可选
``````sh
# 类似 修改点2, 在 start_detect_device 函数中添加入口函数
# 形如 detect_on_{server_name}
# 随后新建一个对应的函数
detect_on_{server_name}(){
# 首先给定对应 slot 的 i2c bus号码
i2c_bus=12
# 根据链路上是否存在9641来编写如果没有9641跳过这里
pca9641_slave="0x31"
get_pca9641_control
# 调用 do_i2c_detect 函数来执行一次9548的通道切换并做一次i2cdetect
# 参数表如下 i2cbus 9548_slave 9548_channel(hex) 9548_index slot_number
do_i2c_detect $i2c_bus "0x70" "0x01" 0 1
do_i2c_detect $i2c_bus "0x70" "0x02" 1 2
do_i2c_detect $i2c_bus "0x70" "0x04" 2 3
}
``````
### 修改点5-服务器auto选择配置可选
> [!note]
>
> script v1.8 新增特性:
>
> - server_type 配置为 auto 后可以自行搜索boardid进行匹配服务器类型仅限通用服务器
可以针对已知的boardid对 `try_get_server_type`函数中做针对性修改。