OpenWRT 系统增加自定义 machine 型号名称

本文记录在 mtk7688 平台上、修改 machine 名称、配置系统和网卡参数的笔记,在工作中大伙应该经常会碰到产品型号或硬件平台变更的诉求,希望对你有所帮助。
如何在 mtk 平台、通过设备树方式添加 RTC 时钟过程。本篇内容是工作笔记,以做备忘。

首先需要在设备树中,修改 model名称,如MTK7688的设备树文件修改如下:

/include/ "mt7628an.dtsi"

/ {
        compatible = "mediatek,mt7628an-soc";
        model = "ZHANYANG-NEO";   

        chosen {
                bootargs = "console=ttyS0,57600";
        };

        memory@0 {
                device_type = "memory";
                reg = <0x0 0x8000000>;
        };
}

修改model名称、web中显示相关内容即随之改变,还需修改相应内容,系统才能够
正常配置相关内容,主要涉及下面几处内容。

setp 1>. setNetmode file config

openwrt 系统启动时会读取 etc/init.d/setnetmode 脚本,根据脚本配置内容,
配置网络 switch 芯片 phy 接口数量和类型。下面时修改 mtk7688 仅有 wan 接口
的设置方法,内容如下。

@ package/base-files/files/etc/init.d/setnetmode

#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=30

start() {
        ETHMODE=`dd bs=1 skip=1000 count=1 if=/dev/mtdblock1 2>/dev/null`
        if [ $ETHMODE != '1' -a $ETHMODE != '2' -a $ETHMODE != '3' -a $ETHMODE != '4' ] ;
        then
#        echo "use default 1Port LAN" > /dev/console
        echo 2 | dd bs=1 seek=1000 count=1 of=/dev/mtdblock1 2>/dev/null
#        ethmode wllll
        ethmode w
        echo "SetEthmode: = w"
        else
#        echo "ETHMODE" > /dev/console
#        echo $ETHMODE > /dev/console
#        ethmode $ETHMODE
        ethmode w
        echo "Set-Ethmode: = w"
        fi
}

setp 2>. rampis.sh startup

@ target/linux/ramips/base-files/lib/ramips.sh 
ramips_board_detect() {
        local machine
        local name

        machine=$(awk 'BEGIN{FS="[ \t]+:[ \t]"} /machine/ {print $2}' /proc/cpuinfo)

        case "$machine" in
        *"Tenda 3G300M")
                name="3g300m"
                ;;
        *"Huawei D105")
                name="d105"
                ;;
         *"Xiaomi MiWiFi Mini")
                name="xiaomi-miwifi-mini"
                ;;
 	       *"ZHANYANG-NEO")                  # 设备 model 对应
                name="zhanyang-neo"
                ;;
        *"MediaTek LinkIt Smart 7688")
                linkit="$(dd bs=1 skip=1024 count=12 if=/dev/mtd2 2> /dev/null)"
                if [ "${linkit}" = "LINKITS7688D" ]; then
                        name="linkits7688d"
                        RAMIPS_MODEL="${machine} DUO"
                else
                        name="linkits7688"
                fi
                ;;
        *)
                name="generic"
                ;;
	esac

        [ -z "$RAMIPS_BOARD_NAME" ] && RAMIPS_BOARD_NAME="$name"
        [ -z "$RAMIPS_MODEL" ] && RAMIPS_MODEL="$machine"

        [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"

        echo "$RAMIPS_BOARD_NAME" > /tmp/sysinfo/board_name
        echo "$RAMIPS_MODEL" > /tmp/sysinfo/model
}

setp 3>. platform config

@target/linux/ramips/base-files/lib/upgrade/platform.sh

platform_check_image() {
        local board=$(ramips_board_name)
        local magic="$(get_magic_long "$1")"

        [ "$#" -gt 1 ] && return 1

        case "$board" in
        3g-6200n | \
        3g-6200nl | \
	linkits7688 | \
        linkits7688d | \
        zhanyang-neo | \      ## 设备相关平台配置
        esac
        echo "Sysupgrade is not yet supported on $board."
        return 1
}

setp 4>. 02_network config init interface parament

@ target/linux/ramips/base-files/etc/board.d/02_network

ramips_setup_interfaces()
{
        local board="$1"

        ucidef_set_interface_loopback

        case $board in
        a5-v11)
                ucidef_set_interface_lan "eth0.1"
                ucidef_add_switch "switch0" "1" "1"
                ucidef_add_switch_vlan "switch0" "1" "0 6t"
                ;;
        zhanyang-neo)           ## 设置 switch 芯片接口配置参数
                ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
                ucidef_add_switch "switch0" "1" "1"
                ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t"
                ucidef_add_switch_vlan "switch0" "2" "0 6t"
                ;;
        e1700 | \
        mt7620a_mt7530)
                ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
                ucidef_add_switch "switch1" "1" "1"
                ucidef_add_switch_vlan "switch1" "1" "0 1 2 3 6t"
                ucidef_add_switch_vlan "switch1" "2" "4 6t"
                ;;

        wzr-agl300nh)
                ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
                ucidef_add_switch "switch0" "1" "1"
                ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
                ucidef_add_switch_vlan "switch0" "2" "0 5t"
                ;;
        *)
                RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
                if [ -n "${RT3X5X}" ]; then
                        ramips_setup_rt3x5x_vlans
                else
                        ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
                fi
                ;;
        esac
}

## set mac address
ramips_setup_macs()
{
        local board="$1"
        local lan_mac=""
        local wan_mac=""

        case $board in
        br-6475nd)
                lan_mac=$(cat /sys/class/net/eth0/address)
                wan_mac=$(mtd_get_mac_binary devdata 7)
                ;;
        linkits7688 | \
        zhanyang-neo)
                wan_mac=$(mtd_get_mac_binary factory 4)
                lan_mac=$(mtd_get_mac_binary factory 46)
                ;;
esac
}

setp 5>. system config

系统时区配置和 ntp server 配置

@ package/base-files/files/etc/config/system
config system
        option hostname ZhanYang
        option conloglevel '8'
        option cronloglevel '8'
        option zonename 'Asia/Shanghai'   # note
        option timezone CST-8

config timeserver ntp
        list server     0.ntp.ntsc.ac.cn
        list server     1.cn.ntp.org.cn
        list server     2.cn.pool.ntp.org
        list server     3.time.pool.aliyun.com
        option enabled 1
        option enable_server 0

以上配置过程就是增加 machine 名称和型号内容。

附录, 在 mtk 平台通过设备数方式,添加 rtc 过程记录。

setp 6>. config kernel RTC suport

$ make kernel_menuconfig

option list:

    Symbol: I2C_MT7621 [=y]                                                                 │  
  │ Type  : tristate                                                                        │  
  │ Prompt: MT7621/MT7628 I2C Controller                                                    │  
  │   Location:                                                                             │  
  │     -> Device Drivers                                                                   │  
  │       -> I2C support                                                                    │  
  │         -> I2C support (I2C [=y])                                                       │  
  │           -> I2C Hardware Bus support      


            --- Real Time Clock                                                           │ │  
  │ │       [*]   Set system time from RTC on startup and resume                          │ │  
  │ │       [*]   Set the RTC time based on NTP synchronization                           │ │  
  │ │       (rtc0)  RTC used to set the system time                                       │ │  
  │ │       [ ]   RTC debug support                                                       │ │  
  │ │             *** RTC interfaces ***                                                  │ │  
  │ │       [*]   /sys/class/rtc/rtcN (sysfs)                                             │ │  
  │ │       [*]   /proc/driver/rtc (procfs for rtcN)                                      │ │  
  │ │       [*]   /dev/rtcN (character devices)              

    Symbol: RTC_DRV_DS1307 [=y]                                                             │  
  │ Type  : tristate                                                                        │  
  │ Prompt: Dallas/Maxim DS1307/37/38/39/40, ST M41T00, EPSON RX-8025                       │  
  │   Location:                                                                             │  
  │     -> Device Drivers                                                                   │  
  │       -> Real Time Clock (RTC_CLASS [=y])    

配置 luci web 内容过程记录:

setp 7>. luci-theme-bootstrap config
@package/feeds/luci/luci-theme-bootstrap/luasrc/view/themes/bootstrap/

setp 8>. luci-mod-admin-full config
@ package/feeds/luci/luci-mod-admin-full/luasrc/

配置 wifi SSID 名称记录

setp 9>. wifi ssid config
@ package/mtk-wifi/files/lib/wifi/ralink.sh

write_ralink() {
        local dir=$1
        local devtype=$2
        local dev=$3
        local mode=$4
        local sta=apcli0

        [ -d /sys/module/$dir ] || return
        [ -d "/sys/class/net/$dev" ] || return

        cat <<EOF
config wifi-device      radio0
        option type     ralink
        option variant  $devtype
        option country  CN
        option hwmode   $mode
        option htmode   HT40
        option channel  auto
        option disabled 0

config wifi-iface ap
        option device   radio0
        option mode     ap
        option network  lan
        option ifname   $dev
        option ssid     ZhanYang-AP-$(cat /sys/class/net/eth0/address|awk -F ":" '{print $5""$6}'| tr a-z A-Z)
        option encryption none 
        option hidden    0

config wifi-iface sta
        option device   radio0
        option disabled 1
        option mode     sta
        option network  wwan
        option ifname   $sta
        option ssid     ZhanYang
        option key      SecretKey
        option hidden   0
EOF
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值