一、基本概况
经过过个版本的折腾,支持luat 4g模块最好的是hi-wooya基于openwrt 15.05故选用此版本。
https://github.com/hi-wooya/openwrt-hiwooya-stable
1、开发板配置
芯片 mt7628系列
flash(rom)=32mb
ram=256mb
相关接口如上图。
2、openwrt 版本
https://github.com/hi-wooya/openwrt-hiwooya-stable
openwrt 15.05版本
3、安装目标
支持luat air720系列4g模块;
支持python2.7运行环境;
二、编译openwrt
1、虚拟机环境
准备虚拟机已安装Ubuntu16.04
2、编译环境
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip zip unrar p7zip p7zip-rar p7zip-full sharutils subversion libncurses5-dev ncurses-term zlib1g-dev gawk git-core libssl-dev xz-utils -y
安装必备的库和软件;
3、下载openwrt
在Ubuntu16.04虚拟机中下载源码
git clone https://github.com/hi-wooya/openwrt-hiwooya-stable
root@ubuntu:/home# git clone https://github.com/hi-wooya/openwrt-hiwooya-stable
Cloning into 'openwrt-hiwooya-stable'...
remote: Enumerating objects: 8770, done.
remote: Total 8770 (delta 0), reused 0 (delta 0), pack-reused 8770
Receiving objects: 100% (8770/8770), 11.91 MiB | 3.16 MiB/s, done.
Resolving deltas: 100% (967/967), done.
Checking connectivity... done.
root@ubuntu:/home#
4、配置编译
到openwrt目录;
./scripts/feeds update -a && ./scripts/feeds install -a
root@ubuntu:/home/openwrt-hiwooya-stable# ./scripts/feeds update -a && ./scripts/feeds install -a
Updating feed 'packages' from 'https://github.com/openwrt/packages.git;for-15.05' ...
Cloning into './feeds/packages'...
remote: Enumerating objects: 2716, done.
remote: Counting objects: 100% (2716/2716), done.
remote: Compressing objects: 100% (2288/2288), done.
remote: Total 2716 (delta 106), reused 2225 (delta 69), pack-reused 0
Receiving objects: 100% (2716/2716), 1.72 MiB | 702.00 KiB/s, done.
Resolving deltas: 100% (106/106), done.
Checking connectivity... done.
Create index file './feeds/packages.index'
5、配置模块
root@ubuntu:/home/openwrt-hiwooya-stable# make menuconfig
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'proper-umask'... ok.
Checking 'gcc'... ok.
Checking 'working-gcc'... ok.
Checking 'g++'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'perl-thread-queue'... ok.
Checking 'tar'... ok.
Checking 'find'... ok.
Checking 'bash'... ok.
Checking 'patch'... ok.
Checking 'diff'... ok.
Checking 'cp'... ok.
Checking 'seq'... ok.
Checking 'awk'... ok.
Checking 'grep'... ok.
Checking 'getopt'... ok.
Checking 'stat'... ok.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'wget'... ok.
Checking 'perl'... ok.
Checking 'python'... ok.
Checking 'git'... ok.
Checking 'file'... ok.
Checking 'ldconfig-stub'... ok.
出现配置页面
选择mt7628相关内容,初次配置红框选项即可。
6、编译固件
root@ubuntu:/home/openwrt-hiwooya-stable# make V=99
make[1]: Entering directory '/home/openwrt-hiwooya-stable'
make[2]: Entering directory '/home/openwrt-hiwooya-stable'
make[3]: Entering directory '/home/openwrt-hiwooya-stable/target/linux'
make[4]: Entering directory '/home/openwrt-hiwooya-stable/target/linux/ramips'
/home/openwrt-hiwooya-stable/scripts/kconfig.pl + /home/openwrt-hiwooya-stable/target/linux/generic/config-3.18 /home/openwrt-hiwooya-stable/target/linux/ramips/mt7628/config-3.18 > /home/openwrt-hiwooya-stable/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.45/.config.target
awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' /home/openwrt-hiwooya-stable/.config >> /home/openwrt-hiwooya-stable/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.45/.config.target
echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> /home/openwrt-hiwooya-stable/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.45/.config.target
echo "# CONFIG_KALLSYMS_ALL is not set" >> /home/openwrt-h
此过程中会下载相关的的软件,下载速度比较慢。可以自己上传下载好的dl目录到文件夹根目录加快编译速度。
百度云盘分享可以下载直接上传即可。
链接:https://pan.baidu.com/s/1EGCEuBMKEuPn9rpMz4606Q
提取码:ysd3
复制这段内容后打开百度网盘手机App,操作更方便哦
完全下载完成要几百mb。
Generating index for package ./python-setuptools_7.0-1_ramips_24kec.ipk
Generating index for package ./python-sqlite3_2.7.12-1_ramips_24kec.ipk
Generating index for package ./python-unittest_2.7.12-1_ramips_24kec.ipk
Generating index for package ./python-xml_2.7.12-1_ramips_24kec.ipk
Generating index for package ./python_2.7.12-1_ramips_24kec.ipk
Signing package index...
make[2]: Leaving directory '/home/openwrt-hiwooya-stable'
make[1]: Leaving directory '/home/openwrt-hiwooya-stable'
编译完成。
7、刷入固件
编译完成的固件目录在
/home/openwrt-hiwooya-stable/bin/ramips
最基本版本不加功能直接编译的固件只有2.7mb,还是比较小的。
找到开发板的调试串口,然后接入usb ttl连接。
开发板加电根据按键提示操作,一般uboot启动有两种方式进行刷固件操作。
breed方式或者tftp方式操作。
我们采用breed方式,开发板接网线,访问指定地址如192.168.1.1即可。
选择相应固件根据操作上传即可。
root@OpenWrt:/# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 2.0M 2.0M 0 100% /rom
tmpfs 13.6M 60.0K 13.5M 0% /tmp
/dev/mtdblock6 4.3M 280.0K 4.0M 6% /overlay
overlayfs:/overlay 4.3M 280.0K 4.0M 6% /
tmpfs 512.0K 0 512.0K 0% /dev
root@OpenWrt:/# free
total used free shared buffers cached
Mem: 27808 18312 9496 60 1792 5008
-/+ buffers/cache: 11512 16296
Swap: 0 0 0
刷默认编译的固件,rom空间和ram都对不上。
我们再后续环节逐一解决。
三、配置4g模块
1、让openwrt识别到luat 4g模块
openwrt 目录下
make menuconfig
make menuconfig->Kenrel modules -> USB Support
kmod-usb-net, kmod-usb-net-rndis
退出;
重新编译固件,方法参考前面内容。
make V=99
刷入测试下是否识别到;
root@OpenWrt:/# [ 153.803126] usb 1-1: new high-speed USB device number 4 using ehci-platform
[ 159.065006] rndis_host 1-1:1.0 eth1: register 'rndis_host' at usb-101c0000.ehci-1, RNDIS device, ac:52:58:30:db:a5
插入usb luat720能提示网卡插入;
root@hi-wooya:/# ifconfig
br-lan Link encap:Ethernet HWaddr 0C:EF:AF:CF:E1:B2
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::eef:afff:fecf:e1b2/64 Scope:Link
inet6 addr: fdd8:c0ec:8d29::1/60 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:2042 (1.9 KiB)
eth0 Link encap:Ethernet HWaddr B0:A3:51:2F:47:1D
inet6 addr: fe80::b2a3:51ff:fe2f:471d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:44 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:6562 (6.4 KiB)
Interrupt:5
eth0.1 Link encap:Ethernet HWaddr B0:A3:51:2F:47:1D
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:3131 (3.0 KiB)
eth0.2 Link encap:Ethernet HWaddr 0C:EF:AF:CF:E1:B3
inet6 addr: fe80::eef:afff:fecf:e1b3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:1729 (1.6 KiB)
eth1 Link encap:Ethernet HWaddr AC:08:C0:CB:1B:F7
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::ae08:c0ff:fecb:1bf7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1901 (1.8 KiB) TX bytes:3756 (3.6 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
已经可以看到eth1就是luat 4g模块启动的网卡;
root@hi-wooya:/# ping www.baidu.com
PING www.baidu.com (112.34.112.41): 56 data bytes
64 bytes from 112.34.112.41: seq=0 ttl=56 time=81.607 ms
64 bytes from 112.34.112.41: seq=1 ttl=56 time=85.780 ms
^C
--- www.baidu.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 81.607/83.693/85.780 ms
ping baidu可以直接ping通了,上网没问题。
因为需要通过串口给luat 4g模块at指令,需要openwrt识别到ttyusb设备。
目前系统尚且认不到。
root@hi-wooya:/# ls /dev
bus mtd2 mtdblock2 random
console mtd2ro mtdblock3 shm
cpu_dma_latency mtd3 mtdblock4 snd
full mtd3ro mtdblock5 tty
kmsg mtd4 mtdblock6 ttyS0
log mtd4ro network_latency ttyS1
mem mtd5 network_throughput urandom
memory_bandwidth mtd5ro null watchdog
mtd0 mtd6 port watchdog0
mtd0ro mtd6ro ppp zero
mtd1 mtdblock0 ptmx
mtd1ro mtdblock1 pts
root@hi-wooya:/#
2、增加串口识别luat 4g模块ttyusb
/home/openwrt-hiwooya-stable/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.45/drivers/usb/serial/option.c
找到文件编辑。
第一个位置:
static const struct usb_device_id option_ids[] = {
//+add by airm2m for Air72x
{ USB_DEVICE(0x1286, 0x4e3d) },
//-add by airm2m for Air72x
#if 1 //Added by Quectel
{ USB_DEVICE(0x05C6, 0x9090) }, /* Quectel UC15 */
{ USB_DEVICE(0x05C6, 0x9003) }, /* Quectel UC20 */
{ USB_DEVICE(0x05C6, 0x9215) }, /* Quectel EC20 */
{ USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC25 */
{ USB_DEVICE(0x2C7C, 0x0121) }, /* Quectel EC21 */
#endif
第二个位置:
#ifdef CONFIG_PM
.suspend = usb_wwan_suspend,
.resume = usb_wwan_resume,
//+add by airm2m for Air726
.reset_resume = usb_wwan_resume,
//-add by airm2m for Air726
#if 1 //Added by Quectel
.reset_resume = usb_wwan_resume,
#endif
#endif
第三个位置,避免当成usb存储设备;
static int option_probe(struct usb_serial *serial,
const struct usb_device_id *id)
{
struct usb_interface_descriptor *iface_desc =
&serial->interface->cur_altsetting->desc;
struct usb_device_descriptor *dev_desc = &serial->dev->descriptor;
/* Never bind to the CD-Rom emulation interface */
if (iface_desc->bInterfaceClass == 0x08)
return -ENODEV;
/*
* Don't bind reserved interfaces (like network ones) which often have
* the same class/subclass/protocol as the serial interfaces. Look at
* the Windows driver .INF files for reserved interface numbers.
*/
if (is_blacklisted(
iface_desc->bInterfaceNumber,
OPTION_BLACKLIST_RESERVED_IF,
(const struct option_blacklist_info *) id->driver_info))
return -ENODEV;
//+add by airm2m for Air72x
if(dev_desc->idVendor == cpu_to_le16(0x1286) &&
dev_desc->idProduct == cpu_to_le16(0x4e3d) &&
iface_desc->bInterfaceNumber <= 1)
return -ENODEV;
//-add by airm2m for Air72x
/*
* Don't bind network interface on Samsung GT-B3730, it is handled by
* a separate module.
保存文件;
找到同目录的usb_wwan.c编辑;
static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
int endpoint,
int dir, void *ctx, char *buf, int len,
void (*callback) (struct urb *))
{
struct usb_serial *serial = port->serial;
struct urb *urb;
urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
if (!urb)
return NULL;
usb_fill_bulk_urb(urb, serial->dev,
usb_sndbulkpipe(serial->dev, endpoint) | dir,
buf, len, callback, ctx);
//+add by airm2m for Air72x
if(dir == USB_DIR_OUT){
struct usb_device_descriptor *desc = &serial->dev->descriptor;
if(desc->idVendor == cpu_to_le16(0x1286) && desc->idProduct == cpu_to_le16(0x4e3d))
{
urb->transfer_flags |= URB_ZERO_PACKET;
}
}
//-add by airm2m for Air72x
#if 1 //Added by Quectel for Zero Packet
配置内核
root@ubuntu:/home/openwrt-hiwooya-stable# make kernel_menuconfig
[] Device Drivers →
[] USB Support →
[] USB Serial Converter support →
[] USB driver for GSM and CDMA modems
选中。
选中配置项,重新编译再写入固件;
root@hi-wooya:/# ls /dev
bus mtd2ro mtdblock4 tty
console mtd3 mtdblock5 ttyS0
cpu_dma_latency mtd3ro mtdblock6 ttyS1
full mtd4 network_latency ttyUSB0
kmsg mtd4ro network_throughput ttyUSB1
log mtd5 null ttyUSB2
mem mtd5ro port urandom
memory_bandwidth mtd6 ppp watchdog
mtd0 mtd6ro ptmx watchdog0
mtd0ro mtdblock0 pts zero
mtd1 mtdblock1 random
mtd1ro mtdblock2 shm
mtd2 mtdblock3 snd
root@hi-wooya:/# ping www.baidu.com
PING www.baidu.com (112.34.112.40): 56 data bytes
64 bytes from 112.34.112.40: seq=0 ttl=56 time=81.694 ms
64 bytes from 112.34.112.40: seq=1 ttl=56 time=86.527 ms
^C
--- www.baidu.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 81.694/84.110/86.527 ms
显示三个ttyusb,上午也正常。
四、配置python环境
1、配置python2标准环境
标星的全部选中即可。
2、配置python-crypto库(阿里云oss需要用到)
从github上下载了python2的crypto编译库
让后放到根目录/package下即可,4.1的选项crypto就会出现了。
makefile
#
# Copyright (c) 2015 Quatanium Co., Ltd.
#
# Based on copyright (C) 2009-2010 openwrt
#
# This is free software, licensed under the GNU General Public License v2.
# License: http://www.gnu.org/licenses/gpl.html GPL version v2.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=pycrypto
PKG_VERSION:=2.6.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/
PKG_MD5SUM:=55a61a054aa66812daf5161a0d5d7eda
include $(INCLUDE_DIR)/package.mk
$(call include_mk, python-package.mk)
define Package/python-crypto
SECTION:=language-python
CATEGORY:=Languages
SUBMENU:=Python
TITLE:=python-crypto
URL:=http://www.pycrypto.org/
DEPENDS:=+python +libgmp
endef
define Package/python-crypto/description
A collection of both secure hash functions (such as MD5 and SHA),
and various encryption algorithms (AES, DES, IDEA, RSA, ElGamal, etc.).
endef
define Build/Compile
$(call Build/Compile/PyMod,,install --prefix=/usr --root=$(PKG_INSTALL_DIR))
endef
define Package/python-crypto/install
$(INSTALL_DIR) $(1)$(PYTHON_PKG_DIR)/
$(CP) \
$(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR)/* \
$(1)$(PYTHON_PKG_DIR)/
endef
$(eval $(call BuildPackage,python-crypto))
001-no-host-paths.patch
--- a/setup.py
+++ b/setup.py
@@ -370,7 +370,7 @@ kw = {'name':"pycrypto",
'ext_modules': plat_ext + [
# _fastmath (uses GNU mp library)
Extension("Crypto.PublicKey._fastmath",
- include_dirs=['src/','/usr/include/'],
+ include_dirs=['src/'],
libraries=['gmp'],
sources=["src/_fastmath.c"]),
验证一下
root@hi-wooya:/# python
Python 2.7.12 (default, Mar 13 2019, 16:36:18)
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Crypto.Cipher import AES
>>>
加载成功。
五、个性定制固件
0、定制固件ram和rom大小
1、设置默认IP地址
采用方法2有效。
方法1:
第一步
/home/openwrt-hiwooya-stable/package/base-files/files/lib/functions/uci-defaults.sh
ucidef_set_interface_lan() {
local ifname=$1
uci batch <
第二步
/package/base-files/files/bin/config_generate
lan) uci -q batch <
/home/openwrt-hiwooya-stable/package/base-files/files/etc/config/network
# Copyright (C) 2006 OpenWrt.org
config interface loopback
option ifname lo
option proto static
option ipaddr 127.0.0.1
option netmask 255.0.0.0
config interface lan
option ifname eth0
option type bridge
option proto static
option ipaddr 192.168.1.182
option netmask 255.255.255.0
option ip6assign 60
config globals globals
option ula_prefix auto
方法2:
目前的源码方法2有效;
/home/openwrt-hiwooya-stable/files/etc/config/network
config interface 'lan'
option ifname 'eth0.1'
option force_link '1'
option macaddr '0c:ef:af:cf:e1:b2'
option type 'bridge'
option proto 'static'
option ipaddr '192.168.1.182'
option netmask '255.255.255.0'
option ip6assign '60'
config interface 'wan'
option ifname 'eth0.2'
option force_link '1'
option macaddr '0c:ef:af:cf:e1:b3'
option proto 'dhcp'
2、设置时区和主机名
/home/openwrt-hiwooya-stable/package/base-files/files/etc/config/system
config system
option hostname adog_mtboard
option timezone CST-8
option zonename Asia/Shanghai
配置成为所需即可.
3、设置开启ssh和启用默认管理员密码
第一步配置开启ssh
选择标星的选项即可。
第二步设置ssh允许远程root访问
/home/openwrt-hiwooya-stable/files/etc/ssh/sshd_config
此文件可从板子复制再上传固件目录;
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
设置root可以登录;
第三步设置默认开机root密码
openwrt的机制如果没有设置root密码是不能开启ssh服务。
现在板子上设置一遍密码,假设是123456
root@hi-wooya:/# passwd
Changing password for root
New password:
Bad password: too weak
Retype password:
Password for root changed by root
然后获取密码加密信息
root@hi-wooya:/# cat /etc/shadow
root:$1$NMGE.QDF$w97egHfx1mWjorn/VL9zM.:17971:0:99999:7:::
daemon:*:0:0:99999:7:::
ftp:*:0:0:99999:7:::
network:*:0:0:99999:7:::
nobody:*:0:0:99999:7:::
sshd:x:0:0:99999:7:::
root@hi-wooya:/#
找到package/base-files/files/etc/shadow
root:$1$NMGE.QDF$w97egHfx1mWjorn/VL9zM.:17971:0:99999:7:::
daemon:*:0:0:99999:7:::
ftp:*:0:0:99999:7:::
network:*:0:0:99999:7:::
nobody:*:0:0:99999:7:::
sshd:x:0:0:99999:7:::
修改启动脚本/package/base-files/files/etc/inittab
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
::askconsole:/bin/login
配置选项
Base system —>
<> busybox ……
[] Customize busybox option
Login/Password Management Utilities —>
[*] login (NEW)
4、设置开机启动
第一步找到以下文件夹
/openwrt/openwrt-hiwooya-stable/package/base-files/files/etc/init.d
自行添加个文件,授权0777;
比如要启动supervisor开机
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=99
STOP=15
start() {
echo start
supervisord -c /home/script/supervisord.conf
#commands to launch application, such as above
}
stop() {
echo stop
supervisorctl shutdown
#commands to kill application
}
第二步
/openwrt/openwrt-hiwooya-stable/package/base-files/files/etc/rc.d
建立supervisor的软链接
5、设置个性wifi
第一步启用wifi
修改wifi名称
/home/openwrt-hiwooya-stable/package/hiwooya-wifi/ralink-wifi-mt7628/files/lib/wifi/ralink.sh
选择隐藏ssid
/home/openwrt-hiwooya-stable/package/hiwooya-wifi/ralink-wifi-mt7628/files/lib/wifi/ralink.sh
option hidden '1'
6、定制python包
现在板子上用pip安装,然后把usr/lib/python2.7/site-package下相关的在复制到固件即可。
7、启用ffmpeg
选中ffmpeg即可,只不过版本比较低。
8、个性启动提示
9、添加文件到固件
添加任意想要的文件。相关要执行权限的记得授权。
10、调试串口密码保护
11、出现can't load library 'libstdc++.so.6'
会导致各种程序运行不了。
12、开启串口2
ls /dev
ttys0作为调试串口,ttyS1可用。
root@adog_mtboard:/# ls /dev/ttyS*
/dev/ttyS0 /dev/ttyS1
修改启用串口数字2改成3
/home/openwrt-hiwooya-stable/target/linux/ramips/dts/mt7628an.dtsi
删掉红色标注内容
/home/openwrt-hiwooya-stable/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/linux-3.18.45/arch/mips/ralink/mt7620.c
修改内容:在prom_soc_init函数末尾添加如下内容,这段修改主要是将复用IO的电平状态由模拟改为数字:
u32 cfg;
cfg = __raw_readl(sysc+0x3c);
cfg|=0x0f;
cfg|=0x10;
cfg|=0x0f<<17;
__raw_writel(cfg,sysc+0x3c);
编译固件刷入看看效果。
root@adog_mtboard:/# ls /dev
bus mtd2ro mtdblock4 tty
console mtd3 mtdblock5 ttyS0
cpu_dma_latency mtd3ro mtdblock6 ttyS1
full mtd4 network_latency ttyS2
kmsg mtd4ro network_throughput ttyUSB0
log mtd5 null ttyUSB1
mem mtd5ro port ttyUSB2
memory_bandwidth mtd6 ppp urandom
mtd0 mtd6ro ptmx watchdog
mtd0ro mtdblock0 pts watchdog0
mtd1 mtdblock1 random zero
mtd1ro mtdblock2 shm
mtd2 mtdblock3 snd
杜邦线接串口2可正常接收数据;
此处有大问题?(一旦启用串口2,原lan口全部不可用。只有wan口插网线才会亮)
变通解决办法需要把lan和wan置换下。(之前的lan口弃用。)
红框内容交换下;
root@adog_mtboard:/# ping 192.168.1.200
PING 192.168.1.200 (192.168.1.200): 56 data bytes
64 bytes from 192.168.1.200: seq=0 ttl=64 time=0.689 ms
64 bytes from 192.168.1.200: seq=1 ttl=64 time=0.543 ms
64 bytes from 192.168.1.200: seq=2 ttl=64 time=0.491 ms
^C
--- 192.168.1.200 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.491/0.574/0.689 ms
ping局域网主机正常;
13、串口0改成通讯串口
使用串口接收数据需要做冗余数据处理;
/home/openwrt-hiwooya-stable/target/linux/ramips/base-files/etc/inittab
关闭串口控制台
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
#::askconsole:/bin/ash --login
关闭内核打印;
/home/openwrt-hiwooya-stable/package/base-files/files/etc/config/system
config system
option 'conloglevel' '1'
option 'kconloglevel' '1'
option hostname adog_mtboard
option timezone CST-8
option zonename Asia/Shanghai
config timeserver ntp
list server 0.openwrt.pool.ntp.org
list server 1.openwrt.pool.ntp.org
list server 2.openwrt.pool.ntp.org
list server 3.openwrt.pool.ntp.org
option enabled 1
option enable_server 0
编译刷固件看下;
原串口0默认波特率是57600,串口1和2默认是9600,都可以自定义修改;
14、修改串口默认波特率
可在启动时采用ser2net修改波特率;
类似代码,可自行更改所需;
新建或编辑文件:
#vi /etc/init.d/usart1
文件内容:
#!/bin/sh /etc/rc.common
#/etc/init.d/usart1
START=80
start() {
/usr/bin/stty -F /dev/ttyS1 raw speed 115200
}
stop(){
killall usart1
}
修改文件属性:
#chmod 777 /etc/init.d/usart1
启用开机启动服务
#/etc/init.d/usart1 enable
关闭服务
此节2019.4.10完成;
15、测试openwrt gpio控制继电器(解决此问题有点难度)
mtk76X8针脚图;
板子针脚位置图;
用gpio3就是i2s_clk测试;其他针脚类似用法;
复用针脚,i2s相关针脚;
/home/openwrt-hiwooya-stable/target/linux/ramips/dts/ 7628.dts
pinctrl {
state_default: pinctrl0 {
gpio {
ralink,group = "gpio","i2s";
ralink,function = "gpio";
};
查看已经定义的gpio
root@adog_mtboard:~# ls /sys/class/gpio
export gpiochip0 gpiochip32 gpiochip64 unexport
root@adog_mtboard:~#
设置需要的gpio,用linux设置方式,其他用法linux通用;
root@adog_mtboard:~# echo 3 > /sys/class/gpio/export
root@adog_mtboard:~# ls /sys/class/gpio
export gpio3 gpiochip0 gpiochip32 gpiochip64 unexport
给予高低电平
root@adog_mtboard:~# echo out > /sys/class/gpio/gpio3/direction
root@adog_mtboard:~# echo 0 > /sys/class/gpio/gpio3/value
root@adog_mtboard:~# echo 1 > /sys/class/gpio/gpio3/value
查看高低电平状态,可以看到继电器磁吸声音;
root@adog_mtboard:~# cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/10000600.gpio, 10000600.gpio:
gpio-3 (sysfs ) out lo
GPIOs 32-63, platform/10000600.gpio, 10000600.gpio:
gpio-38 (reset ) in hi
gpio-39 (sysfs ) out lo
GPIOs 64-95, platform/10000600.gpio, 10000600.gpio:
此节2019.14.11完成;