---
# System prepended metadata

title: OpenWRT with Linkit 7688
tags: [Construction]

---


###### tags: `Construction`

## OpenWRT with Linkit 7688
#### Basic requirement
| OS/Kernel                  | Version                                 |
|:-------------------------- |:----------------------------------------|
| Host operating system      | Linux Ubuntu 18.04 or 20.04 or 22.04    |
| Kernel                     | 4.15.0.142.lowlatency                   |
## OpenWRT Introduction
![](https://hackmd.io/_uploads/HyxKneJ1a.png)

OpenWrt Project is a Linux operating system targeting embedded devices. Instead of trying to create a single, static firmware, OpenWrt provides a fully writable filesystem with package management. This frees you from the application selection and configuration provided by the vendor and allows you to customize the device through the use of packages to suit any application. For developers, OpenWrt is the framework to build an application without having to build a complete firmware around it; for users this means the ability for full customization, to use the device in ways never envisioned.


## OpenWRT Installation
#### Check files
```shell=
$ MTK Linkit 7688 following MVC
$ /usr/lib/lua/luci/controller/*
$ /usr/lib/lua/luci/view/*
$ /usr/lib/lua/luci/model/cbi/*
```
#### Remote settings
![](https://hackmd.io/_uploads/H16CBGJyp.png)
#### Install requestments
```shell=
$ opkg update
$ opkg install luci
$ /etc/init.d/uhttpd restart
```

#### Create myapp
```shell=
$ cd /usr/lib/lua/luci/view/myapp-mymodule
$ vim helloworld.htm

<%+header%>
<h1><%: HelloWorld %></h1>
<%+footer%>

$ cd /usr/lib/lua/luci/controller
$ mkdir myapp
$ cd /usr/lib/lua/luci/controller/myapp
$ touch eric.lua
```

#### eric.lua
```shell=
$ vim eric.lua
module("luci.controller.myapp.eric", package.seeall)
function index()
    --luci.template.render("path_to_your_template")
    entry({"admin", "new_tab", "HelloWorld"}, template("myapp-mymodule/helloworld"), _("Hello World"), 10)
end
$ rm -r /tmp/luci-*
```
![](https://hackmd.io/_uploads/HJ65Ofky6.png)


![](https://hackmd.io/_uploads/B1SEOM1y6.png)


#### cbi file settings
```shell=
root@OpenWrt:/etc/config# vim cbi_file

config gateway_sn 'sn'
        option sn 'testtt'
config gateway_sn1 'SSID'
        option SSID 'testtt'
config gateway_sn2 'PASSWORD'
        option PASSWORD 'mwnlmwnl'
config wifi_switch 'wifi_switch'
        option wifi_switch ''
config wifi_mode 'wifi_mode'
        option wifi_mode ''
config encryption 'encryption'
        option encryption ''
```

#### myapp-mymodule settings
```shell=
$ root@OpenWrt:/usr/lib/lua/luci/model/cbi/myapp-mymodule
$ vim gateway_sn1.lua

m = Map("cbi_file", translate("WiFi Settings")) -- cbi_file is the config file in /etc/config

-- SSID
d = m:section(TypedSection, "gateway_sn1")  -- info is the section called info in cbi_file
a = d:option(Value, "SSID", translate("SSID"));

-- Password
d = m:section(TypedSection, "gateway_sn2")  -- info is the section called info in cbi_file
a = d:option(Value, "PASSWORD", translate("PASSWORD"));

a.optional=false;
a.rmempty = false;  -- name is the option in the cbi_file


-- Enable/Disable WiFi
d = m:section(TypedSection, "wifi_switch")
a = d:option(Flag, "enabled", translate("Enable WiFi"))
a.rmempty = false


-- WiFi Mode
d = m:section(TypedSection, "wifi_mode")
a = d:option(ListValue, "mode", translate("WiFi Mode"))
a:value("ap", translate("Access Point"))
a:value("client", translate("Client Mode"))

-- Encryption Type
d = m:section(TypedSection, "encryption")
a = d:option(ListValue, "type", translate("Encryption Type"))
a:value("none", translate("None"))
a:value("wpa2", translate("WPA2"))
a:value("wpa3", translate("WPA3"))


return m
```
![](https://hackmd.io/_uploads/BJqlDVJ16.png)


## Use OpenWRT source code
```shell=
need to check your firmware, switch the correct branch
$ git clone https://github.com/openwrt/openwrt.git
OpenWrt v21.02.7: revert to branch defaults
```


## Development
To build your own firmware you need a GNU/Linux, BSD or MacOSX system (case sensitive filesystem required). Cygwin is unsupported because of the lack of a case sensitive file system.

## Requirements
You need the following tools to compile OpenWrt, the package names vary between distributions. A complete list with distribution specific packages is found in the Build System Setup documentation.
```shell=
gcc binutils bzip2 flex python3 perl make find grep diff unzip gawk getopt
subversion libz-dev libc-dev rsync which
```

## Quickstart
```shell=
$ ./scripts/feeds update -a 
to obtain all the latest package definitions defined in feeds.conf / feeds.conf.default

$ ./scripts/feeds install -a 
to install symlinks for all obtained packages into package/feeds/

$ make menuconfig 
to select your preferred configuration for the toolchain, target system & firmware packages.

$ make 
to build your firmware. This will download all sources, build the cross-compile toolchain and then cross-compile the GNU/Linux kernel & all chosen applications for your target system.
```
## Related Repositories
The main repository uses multiple sub-repositories to manage packages of different categories. All packages are installed via the OpenWrt package manager called opkg. If you're looking to develop the web interface or port packages to OpenWrt, please find the fitting repository below.

https://github.com/openwrt/luci
LuCI Web Interface: Modern and modular interface to control the device via a web browser.

https://github.com/openwrt/packages
OpenWrt Packages: Community repository of ported packages.

https://github.com/openwrt/routing.git
OpenWrt Routing: Packages specifically focused on (mesh) routing.

## Linkit-smart-feed
This feeds holds the SDK wifi driver and the config/meta package for the LinkIt Smart 7688 (Duo)

Note : LinkIt Smart 7688 uses the MediaTek proprietary Wi-Fi driver. While OpenWrt Chaos Calmer is evolving, only selected Linux kernel versions of it are supported by the Wi-Fi driver (3.18.21 ~ 3.18.44). If you are looking for a non-proprietary Wi-Fi driver, the mt76 project would be a reference of the choice.


## Build the firmware from sources
![](https://hackmd.io/_uploads/HkjpNXgJp.png)

```shell=
Install packages
$ sudo apt-get install git g++ make libncurses5-dev subversion libssl-dev gawk libxml-parser-perl unzip wget python xz-utils
Prepare the default configuration file for feeds:
$ cd openwrt
$ cp feeds.conf.default feeds.conf
Add the LinkIt Smart 7688 feed:
$ echo src-git linkit https://github.com/MediaTek-Labs/linkit-smart-7688-feed.git >> feeds.conf
Update the feed information of all available packages for building the firmware:
$ ./scripts/feeds update
Install all packages:
$ ./scripts/feeds install -a
Prepare the kernel configuration to inform OpenWrt that we want to build an firmware for LinkIt Smart 7688:
$ make menuconfig
Select the options as below:
    Target System:Ralink RT288x/RT3xxx
    Subtarget:MT7688 based boards
    Target Profile:LinkIt7688
Save and exit ( use the deafult config file name without changing it )
```
![](https://hackmd.io/_uploads/HyVVk-l1T.png)
```shell=
Start the compilation process:
$ make or make V=99
After the build process completes, the resulted firmware file will be under bin/ramips/openwrt-ramips-mt7688-LinkIt7688-squashfs-sysupgrade.bin. Depending on the H/W resources of the host environment, the build process may take more than 2 hours .
You can use this file to do the firmware upgrade through the Web UI. Or rename it to lks7688.imgfor upgrading through a USB drive.
$ cd bin/targets/ramips/mt76x8
```
![](https://hackmd.io/_uploads/r1_egbek6.png)

## UCI API
```shell=
$ opkg install libuci uci
```

## Libubox librabry install
```shell=
$ sudo apt-get install cmake
$ cd openwrt/dl
$ git clone https://github.com/yubo/libubox.git
$ tar xvf libubox-2021-05-16-b14c4688.tar
$ cd libubox-2021-05-16-b14c4688
$ cmake -D BUILD_LUA:BOOL=OFF -D BUILD_EXAMPLES:BOLL=OFF .
$ make
$ sudo make install
```

## UCI librabry install
```shell=
$ cd openwrt/dl
$ git clone https://github.com/jkjuopperi/uci.git
$ tar Jxvf uci-2021-04-14-4b3db117.tar.xz
$ cd uci-2021-04-14-4b3db117
$ cmake -D BUILD_LUA:BOOL=OFF .
$ make
$ sudo make install
$ sudo ldconfig
```


