# QCA9563 OpenWRT
U-Boot
```
setenv ipaddr 192.168.2.10
setenv serverip 192.168.2.1
tftpboot 0x80060000 openwrt-ath79-generic-yuncore_xd4200-squashfs-tftp.bin
tftpboot 0x80060000 openwrt-ath79-generic-yuncore_xd4200-squashfs-sysupgrade.bin
erase 0x9f050000 +0xE30000
cp.b 0x80060000 0x9f050000 0x700000
setenv bootm 0x9f050000
setenv bootcmd "bootm 0x9f050000 || bootm 0x9fe80000"
saveenv
```
原始
```
bootcmd=bootm 0x9fe80000
```
安裝luci
```
./scripts/feeds update
./scripts/feeds install -a -p luci
```
設定feeds的資料路徑
feeds.conf.default
改成
feeds.conf

# QSDK
https://github.com/SquareSword/qca95xx-spf503/tree/master
# 啟用wifi設定的方式
系統偵測到wifi網卡呼叫 hotplug
1.package/kernel/mac80211/files/mac80211.hotplug
2.呼叫/sbin/wifi config
(package/base-files/sbin/wifi)
3.將預設值放置於
package/base-files/sbin/wifi內
```
uci set wireless.radio0.disabled=0
uci set wireless.default_radio0.ssid=Antaira-5
uci set wireless.default_radio0.encryption=psk-mixed
uci set wireless.default_radio0.key=12345678
uci commit wireless
```
# luci web
ccu@server:~/openwrt_QCA9563/feeds/luci/modules/luci-base/root/www$ cat index.html
```
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="refresh" content="0; URL=cgi-bin/luci/" />
<style type="text/css">
body { background: white; font-family: arial, helvetica, sans-serif; }
a { color: black; }
@media (prefers-color-scheme: dark) {
body { background: black; }
a { color: white; }
}
</style>
</head>
<body>
<a href="cgi-bin/luci/">LuCI - Lua Configuration Interface</a>
</body>
</html>
```
YunCore XD4200

https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=e5d4c0966736287c7ade29c5ccaf6f1ad841b7db
cat /sys/kernel/debug/gpio
/home/ccu/openwrt_QCA9563/target/linux/ath79/dts/qca9563_yuncore_xd4200.dts

```
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "qca956x.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
/ {
model = "ASUS RP-AC66";
compatible = "asus,rp-ac66", "qca,qca9563";
aliases {
led-boot = &led_orange;
led-failsafe = &led_orange;
led-running = &led_power;
led-upgrade = &led_orange;
label-mac-device = ð0;
};
leds {
compatible = "gpio-leds";
led_power: power {
label = "green:power";
gpios = <&gpio 6 GPIO_ACTIVE_HIGH>;
};
led_orange: wps {
label = "orange:wps";
gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
};
rssilow-wlan0 {
label = "blue:rssilow-wlan0";
gpios = <&gpio 14 GPIO_ACTIVE_HIGH>;
};
rssimedium-wlan0 {
label = "red:rssimedium-wlan0";
gpios = <&gpio 16 GPIO_ACTIVE_HIGH>;
};
rssihigh-wlan0 {
label = "green:rssihigh-wlan0";
gpios = <&gpio 15 GPIO_ACTIVE_HIGH>;
};
rssilow-wlan1 {
label = "blue:rssilow-wlan1";
gpios = <&gpio 7 GPIO_ACTIVE_HIGH>;
};
rssimedium-wlan1 {
label = "red:rssimedium-wlan1";
gpios = <&gpio 9 GPIO_ACTIVE_HIGH>;
};
rssihigh-wlan1 {
label = "green:rssihigh-wlan1";
gpios = <&gpio 8 GPIO_ACTIVE_HIGH>;
};
};
keys {
compatible = "gpio-keys";
wps {
linux,code = <KEY_WPS_BUTTON>;
gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
debounce-interval = <60>;
};
reset {
linux,code = <KEY_RESTART>;
gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
debounce-interval = <60>;
};
};
};
&pcie {
status = "okay";
};
&spi {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x000000 0x40000>;
read-only;
};
partition@40000 {
label = "u-boot-env";
reg = <0x040000 0x10000>;
read-only;
};
art: partition@50000 {
label = "art";
reg = <0x050000 0x10000>;
read-only;
compatible = "nvmem-cells";
#address-cells = <1>;
#size-cells = <1>;
macaddr_art_1002: macaddr@1002 {
reg = <0x1002 0x6>;
};
};
partition@60000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x060000 0xfa0000>;
};
};
};
};
&mdio0 {
status = "okay";
phy0: ethernet-phy@3 {
reg = <0x3>;
phy-mode = "sgmii";
qca,mib-poll-interval = <500>;
};
};
ð0 {
status = "okay";
phy-mode = "sgmii";
nvmem-cells = <&macaddr_art_1002>;
nvmem-cell-names = "mac-address";
phy-handle = <&phy0>;
};
&wmac {
status = "okay";
qca,no-eeprom;
};
```
https://datahunter.org/openwrt
# UCI (Unified Configuration Interface)
uci 是 openwrt 的中央設定工具, 我們可以透過它設定 router 上的一切一切
Default 是有安裝的, 除非人手刪了~
所需的packages:
* uci(/sbin/uci)
* libuci(/lib/libuci.so )
所有設定值保存放在
/etc/config/xxx
常用 config file:
* /etc/config/dhcp
* /etc/config/dropbear
* /etc/config/firewall
* /etc/config/network
* /etc/config/system
* /etc/config/timeserver
* /etc/config/wireless
格式:
```
package 'example'
config 'example' 'test'
option 'string' 'some value'
option 'boolean' '1'
list 'collection' 'first item'
list 'collection' 'second item'
```
Usage: uci <command> [arguments]
### command:
commit 把修改設定值寫入 flash, 並且套用(包括 uci 及 人手修改)
show [<config>[.<section>[.<option>]]] <-- 查看設定 (compressed notation)
get <-- 查看某個設定值 (compressed notation)
changes [config]
set <config>.<section>[.<option>]=<value>
add_list <config>.<section>.<option>=<string>
delete <config>[.<section[.<option>]]
revert <config>[.<section>[.<option>]] <-- 一日未 commit, 一日都可以 revert
export [config] <--- 匯出某"設定" (UCI syntax)
import [config]
### Example:
uci set dhcp.lan.leasetime=4h
uci set dhcp.lan.leasetime=24h
uci get dhcp.lan.leasetime
24h
uci show dhcp
.................
dhcp.lan=dhcp
dhcp.lan.interface=lan
dhcp.lan.start=100
dhcp.lan.limit=150
dhcp.lan.leasetime=24h
.................
uci changes
dhcp.lan.leasetime=1
dhcp.lan.leasetime=24h
uci revert dhcp
uci get dhcp.lan.leasetime
12h
uci commit
### 系統現在的狀態:
uci -P /var/state show network.wan
-P <path> add a search path for config change files and use as default
### 次序
某些設定是有次序之分的, 比如 firewall 的 rule
所以它們有另一種格式
@rule[-1]
[-1] 代表最尾
root@OpenWrt:~# uci add firewall rule
root@OpenWrt:~# uci set firewall.@rule[-1].src=wan
root@OpenWrt:~# uci set firewall.@rule[-1].target=ACCEPT
root@OpenWrt:~# uci set firewall.@rule[-1].proto=tcp
root@OpenWrt:~# uci set firewall.@rule[-1].dest_port=22
root@OpenWrt:~# uci commit firewall
root@OpenWrt:~# /etc/init.d/firewall restart
詳見
http://wiki.openwrt.org/doc/uci
設定檔案

GPIO


target/linux/ath79/dts/qca9563_yuncore_xd4200.dts
# 還原出場
```
fistrboot
reboot
```
# cat /sbin/firstboot
```
#!/bin/sh
/sbin/jffs2reset
```
jffs2reset 是fstools里的工具。做的工作有:
在/proc/mtd里找到名为"rootfs_data"的分区, 假如找到的是mtd5,则/dev/mtd5就是该块设备的节点。
在/proc/mounts里找到/dev/mtd5的挂载点。
如果该设备已挂载(假设挂载在/overlay),则遍历该目录,删除所有的文件和目录。unlink
如果设备没挂载,则擦除该设备。mtd.c: ioctl(p->fd, MEMERASE, &eiu)
http://lirobo.blogspot.com/2019/10/openwrt-start-over.html
# openwrt配置檔案 /etc/conf/system產生方法

https://www.cnblogs.com/tfanalysis/p/3972241.html
https://openwrt.org/docs/guide-developer/uci-defaults

JSON讀取檔案的方法
CFG=/etc/board.json
. /usr/share/libubox/jshn.sh

https://www.cnblogs.com/LiuYanYGZ/p/14212022.html
https://blog.csdn.net/fjlhlonng/article/details/120200364

Luci CBI使用方法
https://blog.51cto.com/u_11866419/4765141
Wifi Client
```
uci set wireless.wifinet2=wifi-iface
uci set wireless.wifinet2.device='radio0'
uci set wireless.wifinet2.mode='sta'
uci set wireless.wifinet2.network='wwan'
uci set wireless.wifinet2.ssid='jqtek'
uci set wireless.wifinet2.encryption='psk2'
uci set wireless.wifinet2.key='0961399930'
```
```
network.wan6=interface
network.wan6.device='eth0.2'
network.wan6.proto='dhcpv6'
```
```
uci set network.wwan=interface
uci set network.wwan.proto='dhcp'
```
```
uci add_list firewall.@zone[1].network='wwan'
```
更改主機名稱
```
uci set system.@system[0].hostname='electroSome'
uci commit system
/etc/init.d/system reload
```
# Luci
這個一定要看:
https://blog.csdn.net/qq_28812525/article/details/103870169
https://github.com/seamustuohy/luci_tutorials
https://blog.51cto.com/u_11866419/4764932
https://blog.csdn.net/weixin_43883277/article/details/99677581
https://blog.chih.me/chang-openwtr-ppoe-password.html
https://openwrt.org/docs/techref/rpcd
https://blog.csdn.net/pyt1234567890/article/details/109546684
https://blog.csdn.net/relijin/article/details/62229004?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-62229004-blog-109546684.pc_relevant_3mothn_strategy_recovery&spm=1001.2101.3001.4242.1&utm_relevant_index=3
https://openwrt.github.io/luci/jsapi/LuCI.rpc.html
## 檔案說明
進入點
/www/index.html
luci
/www/cgi-bin/luci
靜態網頁 css js gif etc....
/www/luci-static/*/*.css、*.js、*.gif
so等檔案
/usr/lib/lua/nixio.so、uci.so
#MVC腳本
/usr/lib/lua/luci/
#lua文件定義了menu的顯示和html 處理的路徑每個文件對應Menu的選項
/usr/lib/lua/luci/controller/*.lua
note: ./admin/index.lua 這個文件定義了node會顯示在最頂部的選單
模組
/usr/lib/lua/luci/model/*.lua
靜態網頁
/usr/lib/lua/luci/view/*.lua
https://blog.csdn.net/qq_37035946/article/details/93629149
## 更改密碼
ubus call luci setPassword '{ "username": "root", "passwo
rd": "admin" }'
## JS內使用 rpc呼叫 rpcd
```
var callSystemBoard = rpc.declare({
object: "system",
method: "board",
});
```
### 說明使用ubus

```
ubus -v list network.interface.lan
```
```
ubus call system reboot
```
### 查閱network.wireless 內有什麼
```
ubus -v list network.wireless
```
### 取得wifi狀態
```
ubus call network.wireless status
```
# CBI
## 網頁規劃
https://blog.csdn.net/qq_28812525/article/details/103881723
https://blog.csdn.net/qq_28812525/article/details/103881723
# UBUS
https://openwrt.org/docs/techref/ubus
# 必讀
https://f0ghua.github.io/openwrt-luci/