1. 重写网络控制脚本; 2. 添加iputils-ping工具

This commit is contained in:
hehaoyang 2024-05-11 22:52:03 +08:00
parent 18d334c2ea
commit 3dac60d370
13 changed files with 138 additions and 229 deletions

View File

@ -176,10 +176,10 @@ struct xs9922 {
#define NI_40F0_DEVICE_ID_1 (0x40F0)
#define NI_40F1_DEVICE_ID_0 (0x40F1)
#define NI_4345_CDT_STATUS_CH0 (0x0000) //(0x4345)
#define NI_4346_CDT_STATUS_CH1 (0x0001) //(0x4346)
#define NI_4347_CDT_STATUS_CH2 (0x2000)// (0x4347)
#define NI_4348_CDT_STATUS_CH3 (0x3000)// (0x4348)
#define NI_4345_CDT_STATUS_CH0 (0x0000)//(0x4345)
#define NI_4346_CDT_STATUS_CH1 (0x1000)///(0x4346)
#define NI_4347_CDT_STATUS_CH2 (0x2000)//(0x4347)
#define NI_4348_CDT_STATUS_CH3 (0x3000)//(0x4348)
#define to_xs9922(sd) container_of(sd, struct xs9922, subdev)
@ -198,26 +198,6 @@ static const s64 link_freq_items[] = {
static bool xs9922_reg_config;
// detect_status: bit 0~3 means channels plugin status : 0, no pluged in; 1, pluged in
static ssize_t show_hotplug_status(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct xs9922 *xs9922 = to_xs9922(sd);
return sprintf(buf, "%d\n", xs9922->detect_status);
}
static DEVICE_ATTR(hotplug_status, S_IRUSR, show_hotplug_status, NULL);
static struct attribute *dev_attrs[] = {
&dev_attr_hotplug_status.attr,
NULL,
};
static struct attribute_group dev_attr_grp = {
.attrs = dev_attrs,
};
static const struct xs9922_mode supported_modes[] = {
{
.bus_fmt = MEDIA_BUS_FMT_UYVY8_2X8,//MEDIA_BUS_FMT_YVYU8_2X8
@ -630,34 +610,30 @@ static __maybe_unused int xs9922_auto_detect_hotplug(struct xs9922 *xs9922)
{
int ret = 0;
u32 val0, val1, val2, val3;
u32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10;
struct i2c_client *client = xs9922->client;
xs9922_read_reg(client, NI_4345_CDT_STATUS_CH0, XS9922_REG_VALUE_08BIT, &val0);
xs9922_read_reg(client, NI_4346_CDT_STATUS_CH1, XS9922_REG_VALUE_08BIT, &val1);
xs9922_read_reg(client, NI_4347_CDT_STATUS_CH2, XS9922_REG_VALUE_08BIT, &val2);
xs9922_read_reg(client, NI_4348_CDT_STATUS_CH3, XS9922_REG_VALUE_08BIT, &val3);
xs9922_read_reg(client, 0x0803, XS9922_REG_VALUE_08BIT, &tmp0);
xs9922_read_reg(client, 0x1803, XS9922_REG_VALUE_08BIT, &tmp1);
xs9922_read_reg(client, 0x2803, XS9922_REG_VALUE_08BIT, &tmp2);
dev_err(&xs9922->client->dev, "%s:ch0 %x ch1 %x ch2 %x ch3 %x\n", __func__,
val0, val1, val2, val3);
xs9922_read_reg(client, 0x0805, XS9922_REG_VALUE_08BIT, &tmp3);
xs9922_read_reg(client, 0x1805, XS9922_REG_VALUE_08BIT, &tmp4);
xs9922_read_reg(client, 0x2805, XS9922_REG_VALUE_08BIT, &tmp5);
//打开摄像头时通过0×N000(N=0,1,2,3)的bit 1-3判断摄像头是否在位
val0 = ((val0 & 0x0f) == 0x0e)? 0x01 : 0x00;
val1 = ((val1 & 0x0f) == 0x0e)? 0x01 : 0x00;
val2 = ((val2 & 0x0f) == 0x0e)? 0x01 : 0x00;
val3 = ((val3 & 0x0f) == 0x0e)? 0x01 : 0x00;
xs9922_read_reg(client, 0x4200, XS9922_REG_VALUE_08BIT, &tmp6);
xs9922_read_reg(client, 0x4210, XS9922_REG_VALUE_08BIT, &tmp7);
xs9922_read_reg(client, 0x4220, XS9922_REG_VALUE_08BIT, &tmp8);
xs9922_read_reg(client, 0x0e10, XS9922_REG_VALUE_08BIT, &tmp9);
xs9922_read_reg(client, 0x0e08, XS9922_REG_VALUE_08BIT, &tmp10);
dev_dbg(&xs9922->client->dev, "%s: auto detect: %d\n", __func__,
dev_err(&xs9922->client->dev, "%s: auto detect: %d\n", __func__,
(val0 & 0x01) | (val1 & 0x01) << 1 | (val2 & 0x01) << 2 | (val3 & 0x01) << 3);
// /dev_dbg(&xs9922->client->dev, "Ch0 is %s\n", (val0 & 0x01) ? "Online ": "Offline");
// /dev_dbg(&xs9922->client->dev, "Ch1 is %s\n", (val1 & 0x01) ? "Online ": "Offline");
// /dev_dbg(&xs9922->client->dev, "Ch2 is %s\n", (val2 & 0x01) ? "Online ": "Offline");
// /dev_dbg(&xs9922->client->dev, "Ch3 is %s\n", (val3 & 0x01) ? "Online ": "Offline");
dev_err(&xs9922->client->dev, "Ch0 is %s\n", (val0 & 0x01) ? "Online ": "Offline");
dev_err(&xs9922->client->dev, "Ch1 is %s\n", (val1 & 0x01) ? "Online ": "Offline");
dev_err(&xs9922->client->dev, "Ch2 is %s\n", (val2 & 0x01) ? "Online ": "Offline");
dev_err(&xs9922->client->dev, "Ch3 is %s\n", (val3 & 0x01) ? "Online ": "Offline");
xs9922->detect_status = (val0 & 0x01) | (val1 & 0x01) << 1 | (val2 & 0x01) << 2 | (val3 & 0x01) << 3 ;
return ret;
@ -1316,6 +1292,28 @@ static const struct v4l2_ctrl_ops xs9922_ctrl_ops = {
.g_volatile_ctrl = xs9922_g_volatile_ctrl,
.s_ctrl = xs9922_s_ctrl,
};
// detect_status: bit 0~3 means channels plugin status : 0, no pluged in; 1, pluged in
static ssize_t show_hotplug_status(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct xs9922 *xs9922 = to_xs9922(sd);
xs9922_auto_detect_hotplug(xs9922);
return sprintf(buf, "%d\n", xs9922->detect_status);
}
static DEVICE_ATTR(hotplug_status, S_IRUSR, show_hotplug_status, NULL);
static struct attribute *dev_attrs[] = {
&dev_attr_hotplug_status.attr,
NULL,
};
static struct attribute_group dev_attr_grp = {
.attrs = dev_attrs,
};
static int xs9922_initialize_controls(struct xs9922 *xs9922)
{
const struct xs9922_mode *mode;

View File

@ -14,5 +14,4 @@ RDEPENDS:${PN} = "\
fct \
rockchip-test \
qmake-tool \
set-jumbo-frame \
"

View File

@ -1,42 +0,0 @@
# Copyright (c) 2018 The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[Unit]
Description=Set Jumbo Frame Service
SourcePath=/etc/initscripts/set_jumbo_frame.sh
After=pcie1scan.service
[Service]
Restart=no
RemainAfterExit=yes
ExecStartPre=/bin/sleep 10
ExecStart=/etc/initscripts/set_jumbo_frame.sh start
ExecStop=/etc/initscripts/set_jumbo_frame.sh stop
[Install]
WantedBy=multi-user.target

View File

@ -1,110 +0,0 @@
#!/bin/sh
# Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
export IP_ADDRESS_01=192.168.10.12
export SUBNET_NETMASK_01=192.168.10.1
export IP_ADDRESS_02=10.77.35.186
export SUBNET_NETMASK_02=10.77.35.1
HELP="Usage $0 {start | stop | restart}"
DUMP_TO_KMSG=/dev/kmsg
do_set_jumbo_frame () {
case "$1" in
start)
echo "systemctl stop dhcpcd.service..."
systemctl stop dhcpcd.service
while true; do
ip addr show eth0 > /dev/null
echo "ip addr show eth0"
echo "ip addr flush dev eth0"
ip addr flush dev eth0
rc=$?
if [ $? -ne 0 ]; then
break
fi
echo "ifconfig eht0 $IP_ADDRESS_01"
ip addr add $IP_ADDRESS_01/24 dev eth0 > /dev/null 2>&1
rc=$?
if [ $? -ne 0 ]; then
break
fi
echo "route add default gw $SUBNET_NETMASK_01 dev eth0"
route add default gw $SUBNET_NETMASK_01 dev eth0 > /dev/null
rc=$?
if [ $? -ne 0 ]; then
echo "eth0 set jumbo frame failed !!!"
fi
break
done
while true; do
ip addr show enP1p17s0 > /dev/null
echo "ip addr show enP1p17s0"
echo "ip addr flush dev enP1p17s0"
ip addr flush dev enP1p17s0
rc=$?
if [ $? -ne 0 ]; then
break
fi
echo "ifconfig ehtenP1p17s00 $IP_ADDRESS_02"
ip addr add $IP_ADDRESS_02/24 dev enP1p17s0 > /dev/null 2>&1
rc=$?
if [ $? -ne 0 ]; then
break
fi
echo "route add default gw $SUBNET_NETMASK_02 dev enP1p17s0"
route add default gw $SUBNET_NETMASK_02 dev enP1p17s0 > /dev/null
rc=$?
if [ $? -ne 0 ]; then
echo "enP1p17s0 set jumbo frame failed !!!"
fi
break
done
# systemctl start dhcpcd.service
# 设置优先级
ifmetric eth0 2100
ifmetric enP1p17s0 2000
;;
stop)
echo "Nothing to Stop..."
;;
restart)
do_set_jumbo_frame stop
shift
do_set_jumbo_frame start
return $?
;;
*)
return 1
;;
esac
return 0
}
do_set_jumbo_frame $@
if [ $? -ne 0 ]; then
echo $HELP >&2
exit 1
fi
exit 0

View File

@ -1,28 +0,0 @@
#
# This file was derived from the 'Hello World!' example recipe in the
# Yocto Project Development Manual.
#
SUMMARY = "Simple helloworld application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
inherit bin_package
SRC_URI = "file://set_jumbo_frame.sh"
SRC_URI += "file://set-jumbo-frame.service"
S = "${WORKDIR}"
do_install() {
install -d ${D}/etc/initscripts/
install -m 0755 set_jumbo_frame.sh ${D}/etc/initscripts/set_jumbo_frame.sh
install -d ${D}/etc/systemd/system/
install -d ${D}/etc/systemd/system/multi-user.target.wants/
install -m 0644 ${WORKDIR}/set-jumbo-frame.service -D ${D}/etc/systemd/system/set-jumbo-frame.service
ln -sf /etc/systemd/system/set-jumbo-frame.service ${D}/etc/systemd/system/multi-user.target.wants/set-jumbo-frame.service
}
FILES_${PN} += "/etc/*"

View File

@ -17,7 +17,8 @@ static version versions[] = {
{"V1.06 20240407", "添加魔视模型库"},
{"V1.07 20240425", "1.继承SDK1.3版本; 2. rtsp-server 更新; 3. 有线网卡脚本优化;"},
{"V1.08 20240430", "修复485+RTC"},
{"V1.09 20240508", "1. 添加 i2c-tools、can-utils、ifmetric、network-manager等测试工具包; 2. 解决QT界面程序编译报错问题"},
{"V1.09 20240508", "1.添加 i2c-tools、can-utils、ifmetric、network-manager等测试工具包; 2.解决QT界面程序编译报错问题"},
{"V1.10 20240510", "重写网络控制脚本"},
};
/* 获取版本信息说明 */

View File

@ -0,0 +1,13 @@
[Unit]
Description=network-manager-service
SourcePath=/usr/bin/network-manager.sh
After=pcie1scan.service
[Service]
Restart=no
RemainAfterExit=yes
ExecStartPre=/bin/sleep 10
ExecStart=/usr/bin/network-manager.sh
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,41 @@
#!/bin/bash
eth0_dhcp=false
eth0_address="192.168.10.12/24"
eth0_gateway="192.168.10.1"
eth0_dns="192.168.10.1"
enP1p17s0_dhcp=false
enP1p17s0_address="192.168.1.249/24"
enP1p17s0_gateway="192.168.1.1"
enP1p17s0_dns="192.168.1.1"
# 禁用DHCP服务
systemctl stop dhcpcd.service
systemctl disable dhcpcd.service
# 删除默认配置
nmcli connection delete "Wired connection 1"
nmcli connection delete "Wired connection 2"
nmcli connection delete eth0
nmcli connection delete enP1p17s0
if $eth0_dhcp ;then
nmcli connection add type ethernet con-name eth0 ifname eth0
else
nmcli connection add type ethernet con-name eth0 ifname eth0 ipv4.addresses $eth0_address ipv4.gateway $eth0_gateway ipv4.dns $eth0_dns ipv4.method manual
fi
if $enP1p17s0_dhcp ;then
nmcli connection add type ethernet con-name enP1p17s0 ifname enP1p17s0
else
nmcli connection add type ethernet con-name enP1p17s0 ifname enP1p17s0 ipv4.addresses $enP1p17s0_address ipv4.gateway $enP1p17s0_gateway ipv4.dns $enP1p17s0_dns ipv4.method manual
fi
# 启动
nmcli connection up eth0
nmcli connection up enP1p17s0
# 设置优先级
ifmetric eth0 2100
ifmetric enP1p17s0 2000

View File

@ -0,0 +1,26 @@
DESCRIPTION = "Install network manager application"
SECTION = "network-manager"
DEPENDS = ""
LICENSE = "CLOSED"
SRC_URI += "file://network-manager.sh"
SRC_URI += "file://network-manager.service"
S = "${WORKDIR}"
## prebuilt library don't need following steps
do_configure[noexec] = "1"
do_compile[noexec] = "1"
do_package_qa[noexec] = "1"
do_install() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/network-manager.sh ${D}${bindir}
install -d ${D}/etc/systemd/system/
install -d ${D}/etc/systemd/system/multi-user.target.wants/
install -m 0644 ${WORKDIR}/network-manager.service -D ${D}/etc/systemd/system/network-manager.service
ln -sf /etc/systemd/system/network-manager.service ${D}/etc/systemd/system/multi-user.target.wants/network-manager.service
}
FILES_${PN} += "/etc/*"

View File

@ -10,5 +10,6 @@ RDEPENDS:${PN} = "\
motovis-tvis \
netcore-tvis \
opencv-tvis \
network-manager-tvis \
rtsp-server-tvis \
"

View File

@ -199,13 +199,13 @@ humanity_theme_install() {
set -e
}
tvis_application_install() {
ubuntu_application_install() {
set +e
fakechroot fakeroot chroot ${TMP_WKDIR} /bin/bash -c "apt-get install i2c-tools can-utils ifmetric network-manager -y"
exitcode=$?
flag=0
while [[ "$exitcode" != "0" && "${flag}" -le "3" ]]; do
echo "network-manager package install failed"
while [[ "$exitcode" != "0" && "${flag}" -le "10" ]]; do
echo "ubuntu application package install failed"
echo "re-try count: ${flag}"
((flag++));
fakechroot fakeroot chroot ${TMP_WKDIR} /bin/bash -c "apt-get clean"
@ -290,7 +290,7 @@ do_ubuntu_install() {
# There has a low probability that downloaded broken humanity-icon-theme.
# We will clean the cache and take a re-try to fix it
humanity_theme_install
tvis_application_install
ubuntu_application_install
fakechroot fakeroot chroot ${TMP_WKDIR} /bin/bash -c "export DEBIAN_FRONTEND=noninteractive ; apt-get install ${UBUN_ROOTFS_PACKAGE} -y"
rm -rf ${TMP_WKDIR}/sbin/init

View File

@ -354,6 +354,10 @@ do_post_install() {
chmod +x ${IMAGE_ROOTFS}/usr/lib/librknnrt.so
ln -sf /usr/lib/librknnrt.so ${IMAGE_ROOTFS}/usr/lib/librknn_api.so
# ping工具
cp -rf ${THISDIR}/files/iputils-ping/ping ${IMAGE_ROOTFS}/usr/bin/ping
chmod +x ${IMAGE_ROOTFS}/usr/bin/ping
}
do_enable_coredump() {
@ -388,6 +392,7 @@ do_enable_ssh_root_login() {
cp -rf ${THISDIR}/files/toilet/toilet-fonts/* ${IMAGE_ROOTFS}/usr/share/toilet-fonts/
}
# QT系統环境
do_set_qt_env() {
echo "" >> ${IMAGE_ROOTFS}/root/.bashrc
echo "# QT环境配置" >> ${IMAGE_ROOTFS}/root/.bashrc
@ -398,6 +403,11 @@ do_set_qt_env() {
echo "export QT_QPA_FONTDIR=/usr/lib/fonts" >> ${IMAGE_ROOTFS}/root/.bashrc
}
# NMCLI托管eth网络
do_set_nmcli_env() {
sed -i '/unmanaged-devices/s/$/&,except:type:ethernet/' ${IMAGE_ROOTFS}/usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
}
#install debug symbol
IMAGE_FEATURES:append = "\
${@bb.utils.contains('DISTRO', 'qti-distro-ubuntu-fullstack-debug', ' dbg-pkgs', '', d)} \
@ -409,7 +419,7 @@ DEB_POSTPROCESS_COMMANDS = " do_deb_post "
#ROOTFS_PREPROCESS_COMMAND += "do_fs_pre; "
#ROOTFS_POSTPROCESS_COMMAND += "do_fs_post; "
ROOTFS_POSTINSTALL_COMMAND += "do_post_install; do_deb; do_enable_adb_root; "
ROOTFS_POSTINSTALL_COMMAND += "do_enable_hot_plug; do_enable_ssh_root_login; do_set_qt_env; "
ROOTFS_POSTINSTALL_COMMAND += "do_enable_hot_plug; do_enable_ssh_root_login; do_set_qt_env; do_set_nmcli_env;"
ROOTFS_POSTPROCESS_COMMAND += "\
${@bb.utils.contains('DISTRO', 'qti-distro-ubuntu-fullstack-debug', 'do_enable_coredump; ', '', d)} \
"