5

使用systemd修正CroeELEC的MAC地址

 3 years ago
source link: https://blog.ihipop.info/2021/05/5315.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

跳至内容

使用systemd修正CroeELEC的MAC地址

  • Android版本的固件,可以通过uboot上keyman维护mac/mac_wifi等信息,参考

  • s905_autoscript 可以通过uboot-tools里面的mkimage制作,可以免拆机执行keyman的命令

  • 但是CoreELEC不读取keyman里面的任何配置,所以一般都是直接加在s905_autoscript启动参数里面

  • 但是由于CoreELEC内核处理的原因,wifi的MAC不从这里面读取,而内置的CYW43455芯片没有nvram,他们的做法是上传一个txt模拟nvram到内核,N1使用的是/usr/lib/firmware/brcm/nvram_ap6255.txt 写死了是00:90:4c:c5:12:38 这个dummy mac,所以改s905_autoscript的mac_wifi没有用

  • 同样,蓝牙的MAC也是类似的问题

修改内核个,适配keyman或者动态修改nvram.txt内容,固件间不通用

  • 用户态在网络启动之前读取自己uboot预设的环境变量设置设备MAC,把自己预设的变量保存到uboot也能让刷机后地址不变。

  • 传统的服务管理器无法在网络开启之前正确设置mac地址

使用systemd+fw_setenv/fw_printenv

GIST

vim /storage/.config/system.d/[email protected]

# /storage/.config/system.d/[email protected]
[Unit]
Description=MAC address loader for %I From bootloader env
ConditionFileIsExecutable=/usr/sbin/fw_printenv
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
ExecStartPre=/bin/bash -c '[ -z $(/usr/sbin/fw_printenv mac_%i -n 2>/dev/null) ] && { echo "Error: No Mac Address detect for %i from bootloader env";exit 1; } || exit 0'
ExecStart=/bin/bash -c 'MAC_%i=$(/usr/sbin/fw_printenv mac_%i -n 2>/dev/null);/sbin/ip link set dev %i address $MAC_%i'
#ExecStart=/sbin/ip link set dev %i up
[Install]
WantedBy=multi-user.target

确保fw_printenv能正常读取uboot的内容

cat /etc/fw_env.config  |grep -v '#'
/dev/nand_env           0x000000        0x10000         0x10000
/dev/env                0x000000        0x10000         0x10000
fw_printenv
# .... 确保有正确输出,否则说明此固件的fw_printenv无法支持此型号的uboot

然后我们把需要持久保存的的mac写入uboot的env

fw_setenv mac_eth0 cc:cc:cc:cc:cc:cc
fw_setenv mac_wlan0 cc:cc:cc:cc:cc:cb

然后启用此服务即可

systemctl enable [email protected]
systemctl enable [email protected]
Author Info : From:使用systemd修正CroeELEC的MAC地址 URL:https://blog.ihipop.info/2021/05/5315.html Please Reserve This Link,Thanks!

发布于 2021年05月24日2021年05月24日作者 ihipop分类 Fix ProblemsMyOriginal

《使用systemd修正CroeELEC的MAC地址》上有2条评论

发表评论 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论

显示名称 *

电子邮箱地址 *

网站地址


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK