# OpenWrt 學習筆記 一名新鮮人與一名過來人的對話交流實錄。 採主題式回合交流編集。 ## 章節 - EP1. 刷機 - EP2. /etc/config 與 UCI - EP3. Web UI -- LuCI - EP4. 橋接、延伸、中繼 ## EP1. 刷機 ## EP2. /etc/config 與 UCI ### 參考連結 - [[OpenWrt Wiki] The UCI system](https://openwrt.org/docs/guide-user/base-system/uci) ## EP3. Web UI -- LuCI ### What is LuCI? * A web user interface * A free, clean, extensible * Uses the Lua programming language * A MVC-Webframework Ref: [LuCI – Technical Reference](https://openwrt.org/docs/techref/luci) ### 參考連結 - [OpenWrt LuCI Wiki](https://github.com/openwrt/luci/wiki) - [openwrt开发使用-增加luci - 良知犹存 - 博客园](https://www.cnblogs.com/conscience-remain/p/16989818.html) ## EP4. 橋接、延伸、中繼 - Bridge, Extender, Repeater - https://openwrt.org/docs/guide-user/network/wifi/wifiextenders/start ## EP5. Porting Morse Micro Module driver to Raspberry Pi 3 ### Prepare #### Hardware - Raspberry Pi 3 Model B+(TODO: 3B+ ?, 型號資訊可參考[這裡](https://en.wikipedia.org/wiki/Raspberry_Pi#Model_comparison)) - Morse Micro Module AHM26108D(TODO: 型號資訊?) - Host PC Ubuntu 20.04 LTS(Build System) #### Software - Raspberry Pi OS - MM6108 Linux Driver Release Package 1.12.4 (TODO: 有 public URL?)沒有 - Pre-install package on the Host PC ##### Pre-install package on the Host PC ``` $ sudo apt-get update $ sudo apt-get install unzip git make g++ gcc flex bison libc6-dev libncurses5-dev libssl-dev bc ``` ### Install Raspberry Pi 3 OS Download Raspberry Pi Imager to install Raspberry Pi OS https://www.raspberrypi.com/software/ 請安裝Raspberry Pi OS (64Bits) ### Building Linux Kernel 6.6 version #### Download Linux Kernel ``` $ git clone --depth=1 --branch rpi-6.6.y https://github.com/raspberrypi/linux.git ``` P.S. `--depth=1` 表示 `git log` 只拉最新一層 commit,不會下載整條 History ,以節省下載時間與容量。 #### Patching Linux Kernel ``` $ unzip "MM6108 Linux Driver Release Package 1.12.4.zip" $ cd "MM6108 Linux Driver Release Package 1.12.4/" $ unzip morsemicro_kernel_patches_rel_1_12_4_2024_Jun_11.zip $ cat morsemicro_kernel_patches_rel_1_12_4_2024_Jun_11/6.6.x/*.patch | patch -g0 -p1 -E -d ~/linux/ ``` NOTE: `patch` 的選項說明: <https://www.gnu.org/software/diffutils/manual/html_node/patch-Options.html> #### Modify Kernel Driver Option ``` $ cd ~/linux/ $ KERNEL=kernel8 $ make ARCH=arm64 bcm2711_defconfig ``` #### Cross-compile the Linux Kernel ##### Install toolchain ``` $ sudo apt install crossbuild-essential-arm64 ``` ##### Building Linux Kernel ``` $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs ``` #### Compiler Morse Micro Driver ``` $ cd ~/MM6108\ Linux\ Driver\ Release\ Package\ 1.12.4/ $ unzip morsemicro_driver_rel_1_12_4_2024_Jun_11.zip $ cd morsemicro_driver_rel_1_12_4_2024_Jun_11/ $ ... ``` # Queue, TODO (待後置的資料,先暫放此處) ## 2024-10-28 ``` Q: OpenWrt 是不是就是四大主軸,一編譯與刷機,二改硬體資訊如DTS, porting driver,三 OpenWrt 的網路設定(UCI setting),四改Web UI,只要這些都搞懂,是不是也就差不多了? A: 是啊 ``` OpenWrt 四大主軸: - 編譯與刷機 - 硬體參數修改, DTS, Driver Porting - OpenWrt 網路設定, UCI - Web UI ``` 理解一個事物有多個方式。一是從作者本人口述,一是從上而下的閱讀架構說明文件,另一是由下而上的探索式的自適應組織。 大多數的我們,從小接受學校教育,已經習慣以線性教材式的訓練課程來學習。 但面對陌生事物,且還沒有理想指引的環境下,採取探索式會更有效一些。 ``` - 對照 Upstream 的 LuCI source code 作 Trace code 前, 注意要先定位版本對應關係。若版本對應錯置,容易發生"刻舟求劍"、"用明朝的劍斬清朝的官"的窘境。 ## 2024-10-29 ``` 自己是採取 backtrace code 的方式,反向探索 LuCI 的架構。 訣竅門,針對要改的地方,在那裡觸發一次 backtrace 。 就會得到一份 function 樹狀關係圖切片。 從那個切片,就能反解出整個架構的部分情報,而且是直接跟目標相關的情報。 用這個方式,多改幾個地方,多了幾個角度切片,最終能一步步反解拼湊而掌握整體架構。 因此,上述找 button 的特徵,就是對 LuCI 的一次取樣切片。 過程中,可以找到對應的 module 跟檔案位置。 先讀 LuCI 的架構文件,有助於你框出問題的範圍。 但,初入手的人再怎麼縮框,也無法到很精確。 因此,我慣以針對性切片法下手。 ``` - [luci/luci.mk](https://github.com/openwrt/luci/blob/master/luci.mk) - [luci/themes/luci-theme-openwrt-2020/Makefile](https://github.com/openwrt/luci/blob/master/themes/luci-theme-openwrt-2020/Makefile) - [[OpenWrt Wiki] LuCI essentials](https://openwrt.org/docs/guide-user/luci/luci.essentials) - [ath79: add support for ALFA Network WiFi CampPro Nano Duo · openwrt/openwrt@861a9da](https://github.com/openwrt/openwrt/commit/861a9dac68b9427758ed1771dfb533db2a5bb88e)