为什么RNDIS的MAC地址每次插拔USB都会变?
Posted: 2024-11-21 13:51
我的PC用的是Ubuntu系统,这样每次OS都会认为这是一个新的设备,之前设置的静态IP的参数每次都要重新来过。能不能固定RNDIS的MAC?
A short text to describe your forum
http://forums.luckfox.com/
Code: Select all
ifconfig usb0 down
ifconfig usb0 hw ether <Your MAC addr>#更正 原本为 ifconfig usb0 hw ethertg <Your MAC addr>
ifconfig usb0 up
Code: Select all
/oem/usr/bin/RkLunch.sh
Code: Select all
network_init()
{
ethaddr1=`ifconfig -a | grep "eth.*HWaddr" | awk '{print $5}'`
if [ -f /data/ethaddr.txt ]; then
ethaddr2=`cat /data/ethaddr.txt`
if [ $ethaddr1 == $ethaddr2 ]; then
echo "eth HWaddr cfg ok"
else
ifconfig eth0 down
ifconfig eth0 hw ether $ethaddr2
fi
else
echo $ethaddr1 > /data/ethaddr.txt
fi
ifconfig eth0 up && udhcpc -i eth0
ifconfig usb0 down
ifconfig usb0 hw ethertg BA:B1:44:37:D7:AA
ifconfig usb0 up
}
我在那里设置SET_BOOTARGS呢?There is maybe an easier way to do this.
If you set the kernel params something like g_ether.host_addr=00:11:22:33:44:55 g_ether.dev_addr=55:44:33:22:11:00, the ethernet-over-usb driver (CONFIG_USB_ETH) will not generate random MACs for the host and the device.
For the buildroot image, this would need to be set in SET_BOOTARGS in various places.
Code: Select all
ifconfig usb0 hw ether <Your MAC Address>
Code: Select all
usb0_config() {
if [ "$(cat /proc/device-tree/usbdrd/usb@ffb00000/dr_mode)" == "peripheral" ]; then
################################################
################# Add Here ####################
################################################
ifconfig usb0 down
ifconfig usb0 hw ether 2A:EE:82:4A:7C:0C
ifconfig usb0 up
sleep 0.5
################################################
##################### END ######################
################################################
current_ip=$(ifconfig usb0 | grep -o 'inet addr:[^ ]*' | awk -F ':' '{print $2}')
echo "current_ip = $current_ip"
echo "TARGET_IP = $TARGET_IP"
while [[ "$current_ip" != "$TARGET_IP" && $retries -lt $MAX_RETRIES ]]; do
sleep .5
echo "luckfox : set usb0 ip"
ifconfig usb0 "$TARGET_IP"
current_ip=$(ifconfig usb0 | grep -o 'inet addr:[^ ]*' | awk -F ':' '{print $2}')
echo $current_ip
retries=$((retries + 1))
done
if [[ "$current_ip" != "$TARGET_IP" ]]; then
echo "usb0 config error"
else
echo "usb0 config success"
fi
else
echo "usb0 is using host mode"
fi
}
Code: Select all
g_ether.dev_addr=12:34:56:78:9a:bc g_ether.host_addr=12:34:56:78:9a:bd
Code: Select all
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2022 Rockchip Electronics Co., Ltd.
*/
#include "rv1106-amp.dtsi"
/ {
chosen {
bootargs = "earlycon=uart8250,mmio32,0xff4c0000 console=ttyFIQ0 root=/dev/mmcblk1p7 rootwait snd_soc_core.prealloc_buffer_size_kbytes=16 coherent_pool=0 g_ether.dev_addr=12:34:56:78:9a:bc g_ether.host_addr=12:34:56:78:9a:bd";
};
Crocodile wrote: ↑2024-11-25 6:01 很抱歉,前面提供的参考有误,设置MAC地址的命令应该为usb的初始化在执行RkLunch.sh之后,所以要添加脚本的位置应该在 /etc/init.d/S99usb0config 的 usb0_config 函数下Code: Select all
ifconfig usb0 hw ether <Your MAC Address>
如果需要修改BOOTARG的话直接修改设备树中/choose节点的bootargs,放在luckfox-pico的dts对应的dtsi中Code: Select all
usb0_config() { if [ "$(cat /proc/device-tree/usbdrd/usb@ffb00000/dr_mode)" == "peripheral" ]; then ################################################ ################# Add Here #################### ################################################ ifconfig usb0 down ifconfig usb0 hw ether 2A:EE:82:4A:7C:0C ifconfig usb0 up sleep 0.5 ################################################ ##################### END ###################### ################################################ current_ip=$(ifconfig usb0 | grep -o 'inet addr:[^ ]*' | awk -F ':' '{print $2}') echo "current_ip = $current_ip" echo "TARGET_IP = $TARGET_IP" while [[ "$current_ip" != "$TARGET_IP" && $retries -lt $MAX_RETRIES ]]; do sleep .5 echo "luckfox : set usb0 ip" ifconfig usb0 "$TARGET_IP" current_ip=$(ifconfig usb0 | grep -o 'inet addr:[^ ]*' | awk -F ':' '{print $2}') echo $current_ip retries=$((retries + 1)) done if [[ "$current_ip" != "$TARGET_IP" ]]; then echo "usb0 config error" else echo "usb0 config success" fi else echo "usb0 is using host mode" fi }