OpenWRT on CM4 === 前陣子使用Raspberry pi 4b製作了WIFI router,但因為沒有達到理想的網路速度,所以想研究看看。在過程中,看到了有PCIE interface的Raspberry pi cm4,有了PCIE就可以使用一些高速的PCIE網卡,於是買來試試看。 --- ## Environment: * Host: Ubuntu 21.04 x64 * Raspberry pi CM4 4GB RAM, 32GB MMC * Compute Module 4 IO Board * EDUP Wi-Fi 6 PCIe Wireless LAN Card (Intel AX200) [Amazon website](https://www.amazon.co.jp/gp/product/B096XBXL2C/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1) * ASUS AC51 USB Wireless LAN Card (MTK MT7602u) * Micro USB cable (Burn OpenWRT to CM4 mmc) * TTL to USB cable (Debug only) * OpenWRT [Github](https://github.com/openwrt/openwrt) * Usbboot [Github](https://github.com/raspberrypi/usbboot) :::info * Intel AX200 並不支援AP on 5G Mode。於是透過ASUS AC51來當作AP Mode,Intel AX200當作STA Mode。 * Raspberry Pi 內建的網卡AP mode只有提供到802.11ac 40MHZ。 * 雖然使用AC51當作AP,會使速度變慢,但AC51也支援到802.11ac 80MHZ,速度並不差。 ::: [參考Compute_Module_4_IoT_Router_Board_Mini_SKU_DFR0767](https://wiki.dfrobot.com/Compute_Module_4_IoT_Router_Board_Mini_SKU_DFR0767) --- ## Get OpenWRT * 將OpenWRT下載到自己的Host裡 ```bash= git clone https://github.com/openwrt/openwrt --depth=1 ``` --- ## OpenWRT Patch 我在實作過程中,發現有兩個issue待解決。 1. Intel AX200 FW 並不包含在OpenWRT之中。 2. Raspberry pi CM4的 FW 設定檔案 -- brcmfmac43455-sdio.raspberrypi,4-compute-module.txt,沒有包括在OpenWRT之中。[參考解決方式](https://forum.openwrt.org/t/raspberry-pi-cm4-wifi-not-working/90280/3) 解決方式必須手動將這兩個commit加入OpenWRT Source Code: [PATCH 1](https://github.com/openwrt/openwrt/pull/4689/commits/48fcd65c7bf0c3bc94f11f68c7708fa55131486e) [PATCH 2](https://github.com/openwrt/openwrt/pull/4689/commits/e3c994f8d30803e92552f205c0777b9472d62a39) :::info 可以檢查OpenWRT Commit,如果已經有merge進去,就不用手動加入。 ::: --- ## Build OpenWRT 1. 編譯環境安裝: ```bash= sudo apt update sudo apt install build-essential ccache ecj fastjar file g++ gawk \ gettext git java-propose-classpath libelf-dev libncurses5-dev \ libncursesw5-dev libssl-dev python python2.7-dev python3 unzip wget \ python3-distutils python3-setuptools rsync subversion swig time \ xsltproc zlib1g-dev cmake ``` 2. 下載需要的package ```bash= ./scripts/feeds update -a ./scripts/feeds install -a ``` 3. 設定 ```bash= make menuconfig ```  :::info * 基本設定: 1. Target System = Broadcom BCM27xx 2. Subtarget = BCM2711 boards 64bit 3. Target Profile = Raspberry Pi 4b 4. Target Images = squashfs 5. Kernel modules-> Wireless Drivers:   6. Firmware:  7. LUCI - – Collections - = luci = luci-ssl-openssl ::: :::info 因為我本身還有設定其他功能,可以直接下載我的設定檔案,就不用自己設定了。將檔案移到OpenWRT跟目錄底下,並重新命名.config,就可以直接使用了。[Config檔案](https://drive.google.com/file/d/1irBeuz9xNeAg8e_SAU0NdO-rkyu6R44d/view?usp=sharing) ::: 4. 編譯: ```bash= make -j6 V=s ``` :::info 第一次編譯,會需要編譯Toolchain,所以需要幾個小時的時間 ::: --- ## 將OpenWRT燒錄到CM4 ### 安裝,編譯和執行usbboot工具 1. 下載官方模擬usb device工具(可以將CM4的MMC模擬成Disk裝置): ```bash= git clone --depth=1 https://github.com/raspberrypi/usbboot ``` 2. 安裝依賴並編譯工具: ```bash= cd usbboot sudo apt install libusb-1.0-0-dev make ``` 3. 執行工具: ```bash= sudo ./rpiboot ``` ### 連接CM4到Host上 1. 在斷電的情況下,將IO Board J2,"Fit: jumper to disable eMMC boot",用杜邦線或是使用跳線連接起來。  2. 在斷電的情況下,將J11 (Micro USB 孔連接電腦) 3. 插上電源,剛剛開起來的rpiboot會出現:  ```bash= Waiting for BCM2835/6/7/2711... Loading embedded: bootcode4.bin Sending bootcode.bin Successful read 4 bytes Waiting for BCM2835/6/7/2711... Loading embedded: bootcode4.bin Second stage boot server Loading embedded: start4.elf File read: start4.elf Second stage boot server done ``` Host 會出現新磁碟機,就這是我們的目標裝置。 :::info 可以使用以下指令,查看目前系統的磁碟機 ```bash= sudo fdisk -l ``` ::: ### 燒錄IMG到CM4 1. 解壓縮剛剛編譯出來的映像檔案 ```bash= gunzip -d bin/targets/bcm27xx/bcm2711/openwrt-bcm27xx-bcm2711-rpi-4-squashfs-sysupgrade.img.gz ``` 2. 燒錄到CM4 ```bash= sudo dd if=bin/targets/bcm27xx/bcm2711/openwrt-bcm27xx-bcm2711-rpi-4-squashfs-factory.img of={目標裝置} bs=1M sync ``` ### 正式開機 1. 將IO Board的UART透過TTL to USB cable連接Host :::info 與Raspberry pi 4b pinout一樣,可參考Raspberry pi 4b pinout。 ::: 2. 開啟終端程式 這裡透過screen操作console ```bash= sudo screen /dev/ttyUSB0 115200 ``` 範例(這一步還沒上電應該是不會出現東西):  3. 移除IO Board J2的跳線和Micro USB,並重新插入電源 4. 等到IO Board的LED燈號停止閃爍,就可以按下Enter按鍵,進入互動式介面了  ### 設定USB HOST 預設CM4是不開啟USB Host,所以IO Board板載的USB Port是沒有作用的。因此我們手動寫入設定開啟USB Host。 1. 寫入設定到/boot/config.txt 將以下文字添加到最後一行 ```text= dtoverlay=dwc2,dr_mode=host ``` 2. 重新啟動 ```bash= reboot ``` --- ## 到這裡已經完成燒錄OpenWRT到CM4之中了 ### 半完成品:  --- ## OpenWRT 網路設定 OpenWRT 網路設定可以參考官方網站,或是參考我之前的文章。 ### 我之前的文章 [OpenWRT on Raspberry pi 4](https://hackmd.io/MctEFOFISZSSKkez7pbY8A) ### 官方文件 [Network config](https://openwrt.org/docs/guide-user/base-system/basic-networking) [Wireless config](https://openwrt.org/docs/guide-user/network/wifi/basic) --- * 可以看到有三張無線網路卡(Wlan X)  * Raspberry CM4 內建網卡  * Intel AX200  * ASUS AC51  --- ## 網速測試資料: ### Iphone 12 pro -> 802.11ax Router(asus ax3000)  ### Iphone 12 pro -> CM4 -> 802.11ax Router(asus ax3000) 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up