linux - 如何使用connman设置以太网接口(interface)MAC地址

标签 linux networking embedded ethernet connman

我有一个嵌入式系统,要求我从闪存中提取一个 MAC 地址,并在它启动时将其传递到以太网接口(interface)。传统上,我在初始化脚本中修改了对 ifconfig 的调用,以仅将从闪存中提取的 MAC 作为 hw ether 参数传递。

我正在使用的系统使用 connman 来处理网络连接。嵌入式系统将始终具有单个以太网连接,并在闪存中以自定义格式具有单个匹配的 MAC 地址。 connman 在接口(interface)可用时使用,因此拥有一个动态系统来处理接口(interface)的启动和关闭以及配置它是有帮助的。

是否可以将 MAC 传递给 connman 以类似于我之前使用 ifconfig 所做的方式使用,如果可以,怎么做?

或者,是否可以将 MAC 作为引导参数传递给内核,以便 connman 永远不必知道这一点?我可以在 U-Boot 中将 MAC 从闪存中取出,但以太网设备对 U-Boot 不可用。

最佳答案

Alternatively is it possible to pass the MAC as a boot parameter to the kernel so that connman never has to know about this?

是的,您可以使用 U-Boot 的 ethaddr 环境变量来做到这一点。

查看 U-Boot Environment Variables有关变量的文档。

相关文档片段:

ethaddr: Ethernet MAC address for first/only ethernet interface (= eth0 in Linux). This variable can be set only once (usually during manufacturing of the board). U-Boot refuses to delete or overwrite this variable once it has been set.

设置环境变量并保存(当然是替换你的 MAC 地址)可能就像运行以下命令一样简单:

setenv ethaddr 11:22:33:44:55:66
saveenv

如果 ethaddr 尚未在您的 U-Boot 引导行中使用,那么您需要做的不仅仅是上述操作。有关如何在系统上配置它的示例,请查看 How to set a fixed MAC address in a LeopardBoard DM36x .

这是使用 ethaddr 的引导命令,上面的站点以以下结尾:

setenv bootcmd 'setenv bootargs \${bootargs} davinci_emac.ethaddr=\${ethaddr}; nboot 0x82000000 0 \${kerneloffset}'

关于linux - 如何使用connman设置以太网接口(interface)MAC地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35890942/

相关文章:

linux - poll()函数检查GPIO中断返回错误如何解决

Swift - 测试与网站的连接和可用端口

c++ - sprintf 缓冲区全局数据溢出 - 如何检测它,Windows

android - Android 是否推荐用于 Atom 处理器平台?

linux - docker-compose up 导致 "client and server don' t 版本相同(客户端 : 1. 14,服务器 : 1. 12)“错误但客户端和服务器版本相同

linux - Linux字符驱动中多次读取一次写入导致死锁?

linux - docker attach vs lxc-attach

java - 完整的 native 应用程序仍然需要 root 访问权限吗?

android - 安卓中的iptables

android - 从 HDMI IN 端口捕获音频帧