找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 2358|回复: 11

openwrt官方源码增加新机型的实操记录

[复制链接]
发表于 2022-9-17 13:03 | 显示全部楼层 |阅读模式
本帖最后由 99010 于 2022-12-6 21:47 编辑

搭建环境
参考https://openwrt.org/docs/guide-d ... install-buildsystem

下载源码并指定版本
  1. git clone https://github.com/openwrt/openwrt.git
  2. cd openwrt
  3. git checkout v21.02.3
复制代码

获取组件
  1. ./scripts/feeds update -a
  2. ./scripts/feeds install -a
复制代码

找份硬件相似机型的dts修修改改,生成一份target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts文件,大概内容如下:
  1. // SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  2. /dts-v1/;

  3. #include "mt7621.dtsi"

  4. #include <dt-bindings/gpio/gpio.h>
  5. #include <dt-bindings/input/input.h>

  6. / {
  7.         compatible = "jdcloud,re-sp-01b", "mediatek,mt7621-soc";
  8.         model = "JDCloud RE-SP-01B";

  9.         aliases {
  10.                 led-boot = &led_red;
  11.                 led-failsafe = &led_red;
  12.                 led-running = &led_green;
  13.                 led-upgrade = &led_blue;
  14.                 label-mac-device = &gmac0;
  15.                 };

  16.         chosen {
  17.                 bootargs = "console=ttyS0,115200";
  18.                                 };

  19.         keys {
  20.                 compatible = "gpio-keys";

  21.                 reset {
  22.                         label = "reset";
  23.                         gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
  24.                         linux,code = <KEY_RESTART>;
  25.                         };
  26.                 };

  27.         leds {
  28.                 compatible = "gpio-leds";

  29.                 led_red: red {
  30.                         label = "red:sys";
  31.                         gpios = <&gpio 6 GPIO_ACTIVE_LOW>;
  32.                         panic-indicator;
  33.                         };

  34.                 led_green: green {
  35.                         label = "green:sys";
  36.                         gpios = <&gpio 8 GPIO_ACTIVE_LOW>;
  37.                         };

  38.                 led_blue: blue {
  39.                         label = "blue:sys";
  40.                         gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
  41.                         };
  42.         };
  43. };

  44. &sdhci {
  45.         status = "okay";
  46. };

  47. &spi0 {
  48.         status = "okay";

  49.         flash@0 {
  50.                 compatible = "jedec,spi-nor";
  51.                 reg = <0>;
  52.                 spi-max-frequency = <45000000>;
  53.                 broken-flash-reset;

  54.                 partitions {
  55.                         compatible = "fixed-partitions";
  56.                         #address-cells = <1>;
  57.                         #size-cells = <1>;

  58.                         partition@0 {
  59.                                 label = "u-boot";
  60.                                 reg = <0x0 0x30000>;
  61.                                 read-only;
  62.                         };

  63.                         partition@30000 {
  64.                                 label = "u-boot-env";
  65.                                 reg = <0x30000 0x10000>;
  66.                                 read-only;
  67.                         };

  68.                         factory: partition@40000 {
  69.                                 label = "factory";
  70.                                 reg = <0x40000 0x10000>;
  71.                                 read-only;
  72.                         };

  73.                         partition@50000 {
  74.                                 compatible = "denx,uimage";
  75.                                 label = "firmware";
  76.                                 reg = <0x50000 0x1fb0000>;
  77.                         };
  78.                 };
  79.         };
  80. };

  81. &gmac0 {
  82.         mtd-mac-address = <&factory 0xe000>;
  83. };

  84. &switch0 {
  85.         ports {
  86.                 port@0 {
  87.                         status = "okay";
  88.                         label = "wan";
  89.                         mtd-mac-address = <&factory 0xe000>;
  90.                         mtd-mac-address-increment = <1>;
  91.                 };

  92.                 port@1 {
  93.                         status = "okay";
  94.                         label = "lan1";
  95.                 };

  96.                 port@2 {
  97.                         status = "okay";
  98.                         label = "lan2";
  99.                 };
  100.         };
  101. };

  102. &pcie {
  103.         status = "okay";
  104. };

  105. &pcie0 {
  106.         wifi@0,0 {
  107.                 compatible = "mediatek,mt76";
  108.                 reg = <0x0000 0 0 0 0>;
  109.                 mtd-mac-address = <&factory 0xe000>;
  110.                 mtd-mac-address-increment = <2>;
  111.                 mediatek,mtd-eeprom = <&factory 0x0000>;
  112.                 ieee80211-freq-limit = <2400000 2500000>;
  113.         };
  114. };

  115. &pcie1 {
  116.         wifi@0,0 {
  117.                 compatible = "mediatek,mt76";
  118.                 reg = <0x0000 0 0 0 0>;
  119.                 mtd-mac-address = <&factory 0xe000>;
  120.                 mtd-mac-address-increment = <3>;
  121.                 mediatek,mtd-eeprom = <&factory 0x8000>;
  122.                 ieee80211-freq-limit = <5000000 6000000>;
  123.         };
  124. };

  125. &state_default {
  126.         gpio {
  127.                 groups = "uart2", "uart3", "wdt";
  128.                 function = "gpio";
  129.         };
  130. };
复制代码

修改target/linux/ramips/image/mt7621.mk,在后面添加如下内容:
  1. define Device/jdcloud_re-sp-01b
  2.   $(Device/dsa-migration)
  3.   $(Device/uimage-lzma-loader)
  4.   IMAGE_SIZE := 32448k
  5.   DEVICE_VENDOR := JDCloud
  6.   DEVICE_MODEL := RE-SP-01B
  7.   DEVICE_PACKAGES := kmod-fs-ext4 kmod-mt7603 kmod-mt7615e kmod-mt7615-firmware kmod-sdhci-mt7620 kmod-usb3
  8. endef
  9. TARGET_DEVICES += jdcloud_re-sp-01b
复制代码

修改target/linux/ramips/mt7621/base-files/etc/board.d/02_network文件,大概在58行左右添加如下内容:
  1.         jdcloud,re-sp-01b)
  2.                 ucidef_set_interfaces_lan_wan "lan1 lan2" "wan"
  3.                 ;;
复制代码

进入编译组件包菜单,选择新增加的机型,并选择luci组件(不建议选太多组件,第一次编译有个基本功能即可)
  1. make menuconfig
复制代码
开始编译(网络环境良好的可以-j多线程编译,否则建议单线程编译)
  1. make download V=99 -j4
  2. make V=99 -j4
复制代码
小技巧:如果在添加新机型之前有过编译其他机型,建议在运行make menuconfig之前执行
  1. make clean
  2. rm -rf tmp
  3. mv .config  config.xxxxx
复制代码


手上刚好有个全新的32M 闪存,用编程器刷好breed再焊到机子上。登陆breed界面,先刷入备份的原厂eeprom,mac项填入lan的mac即可,再刷入编译出来的固件,运行正常。


镜像生成器,老规矩,回复后下载
链接:https://share.weiyun.com/44NvaeZL 密码:ev39bm



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2022-9-17 13:07 | 显示全部楼层
本帖最后由 99010 于 2022-9-17 13:24 编辑

进价篇一

既然使用了openwrt官方源码,当然希望编译出来的固件能在后期完美安装openwrt官方源kmod内核组件,所以这里使用了一个笨办法。
  1. make clean
  2. rm -rf tmp
  3. rm -rf .config

  4. wget https://downloads.openwrt.org/releases/21.02.3/targets/ramips/mt7621/config.buildinfo -O .config
复制代码
恢复默认编译设置
  1. make defconfig
复制代码


进入编译组件包菜单,不要做任何修改,直接退出保存
  1. make menuconfig
复制代码


开始编译(网络环境良好的可以-j多线程编译,否则建议单线程编译)
  1. make download V=99 -j4
  2. make V=99 -j4
复制代码



进价篇二
在进价篇一中编译得到的固件没什么组件,所以这里用进价篇一编译出来的imagebuilder镜像生成器去集成组件。

解压imagebuilder镜像生成器,并把进价篇一编译出来的base-files_1442-r16554-1d4dea6d4f_mipsel_24kc.ipk以及需要集成的非openwrt官方组件ipk复制到packages目录里面。
  1. tar xvJf  openwrt-imagebuilder-21.02.3-ramips-mt7621.Linux-x86_64.tar.xz
  2. cd openwrt-imagebuilder-21.02.3-ramips-mt7621.Linux-x86_64
复制代码

国内可以把官方源改成中科大源
  1. sed -i 's#downloads.openwrt.org#mirrors.ustc.edu.cn/openwrt#g' repositories.conf
复制代码


列出机型
  1. make info
复制代码


集成固件,参考如下(组件自行增减)。注:files文件夹可以放一些自定义脚本或者文件,打包时会按照对应目录一起集成进去。
  1. make image PROFILE=jdcloud_re-sp-01b PACKAGES="luci luci-compat \
  2. luci-app-upnp luci-app-wol luci-app-ddns  \
  3. luci-i18n-base-zh-cn luci-i18n-opkg-zh-cn luci-i18n-firewall-zh-cn \
  4. luci-i18n-upnp-zh-cn luci-i18n-wol-zh-cn  luci-i18n-ddns-zh-cn   \
  5. luci-app-wireguard luci-i18n-wireguard-zh-cn qrencode \
  6. -dnsmasq dnsmasq-full \
  7. ipset ip-full iptables-mod-nat-extra \
  8. bash htop  nano bind-dig \
  9. wget-ssl curl openssl-util ca-certificates ca-bundle  \
  10. kmod-usb-storage kmod-usb-storage-uas block-mount kmod-fs-ext4 blkid lsblk fdisk e2fsprogs \
  11. kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-utf8  \
  12. kmod-usb3 kmod-usb-ohci  usbutils \
  13. kmod-tcp-bbr kmod-macvlan kmod-tun" FILES=files/
复制代码


附录:
files/etc/uci-defaults/09_wireless.wireless,大概内容如下
  1. #!/bin/sh

  2. ls /sys/class/ieee80211/|while read dev
  3. do
  4. ssid=$(cat /tmp/sysinfo/model|cut -d" " -f2| tr a-z A-Z)_$(cat /sys/class/ieee80211/${dev}/macaddress|awk -F ":" '{print $4""$5""$6 }'| tr a-z A-Z)

  5. uci -q batch <<-EOF >/dev/null
  6.         set wireless.radio${dev##phy}.disabled=0
  7.         set wireless.radio${dev##phy}.country=CN
  8.         set wireless.@wifi-iface[${dev##phy}].ssid='$ssid'
  9.         set wireless.@wifi-iface[${dev##phy}].key='1234567890'
  10.         set wireless.@wifi-iface[${dev##phy}].encryption='psk2'
  11.         commit wireless
  12. EOF
  13. done

  14. exit 0
复制代码



files/etc/uci-defaults/13_password_root,大概内容如下

  1. #!/bin/sh

  2. echo -ne "password\npassword" > /tmp/password.txt
  3. passwd root < /tmp/password.txt
  4. rm -f /tmp/password.txt
  5. uci set luci.main.lang=zh_cn
  6. uci set system.@system[0].hostname=OpenWrt
  7. uci set system.@system[0].timezone=CST-8
  8. uci set system.@system[0].zonename='Asia/Shanghai'
  9. uci set network.lan.ipaddr=192.168.2.1
  10. uci commit
  11. sed -i 's#downloads.openwrt.org#mirrors.ustc.edu.cn/openwrt#g' /etc/opkg/distfeeds.conf
  12. sed -i 's#openwrt.pool.ntp.org#cn.pool.ntp.org#g' /etc/config/system
复制代码


我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2022-9-17 13:07 | 显示全部楼层
占坑二。。。。。。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-9-17 15:53 | 显示全部楼层
改机型就改三个文件就可以了?

点评

openwrt官方21.02.x之后的mt762x系列使用spi闪存路由器基本只需要3个文件  详情 回复 发表于 2022-9-18 09:29
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-9-18 08:53 | 显示全部楼层
这篇文章必须支持一下,恩山很少有这知识贴了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2022-9-18 09:29 | 显示全部楼层
keben 发表于 2022-9-17 15:53
改机型就改三个文件就可以了?

openwrt官方21.02.x之后的mt762x系列使用spi闪存路由器基本只需要3个文件
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-10-10 20:53 | 显示全部楼层
好的收藏了行
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-11-22 19:44 | 显示全部楼层
感谢大佬分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-11-27 13:14 | 显示全部楼层
授之以渔,感谢分享。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-12-30 13:45 | 显示全部楼层
老规矩,回复后下载
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2023-3-2 18:21 | 显示全部楼层
看看。。。。。。。。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2023-11-26 12:00 | 显示全部楼层
收藏 多谢~
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-25 18:25

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表