前回、H3C Mqgic NX30 Pro に初めから開いているのを確認したTelnetポートを足掛かりに、現行版 OpenWrt ファームウェア への入れ替えに挑戦します。
お手本にする記事
H3C Mqgic NX30 ProへのOpenWrt謹製ファームウェア書き込み手順について、中華テック界隈で多くの記事が散見される中、書き込み前のバックアップ手順含めて丁寧に解説されていたこちらの記事に沿って、作業を進めます(鳴謝!)。
OpenWrtファームウェアの調達
まず、必要なファームウェアファイル群をOpenWrtの機器別ダウンロードページから調達。本記事執筆時点では23.05.2が安定最新版でした。表示されている4つ全てのファイルを作業用Ubuntu 22.04 PCへ保存します。
|
1 2 3 4 5 |
$ ls -l 1,006,905 byte openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-bl31-uboot.fip # FIP 7,274,496 byte openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-initramfs-recovery.itb # INITRAMFS 226,141 byte openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin # BL2 9,593,142 byte openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-squashfs-sysupgrade.itb # SYSUPGRADE |
Ubuntu 22.04にtftpdの準備
次に、ファームウェア入れ替えの最終工程で必要になるtftpサーバを、作業用Ubuntu PC内に立てます。
まず、パッケージのインストール。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ sudo apt install tftpd-hpa 以下のパッケージが新たにインストールされます: tftpd-hpa アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。 40.7 kB のアーカイブを取得する必要があります。 この操作後に追加で 122 kB のディスク容量が消費されます。 0% [処理中://hk.archive.ubuntu.com/ubuntu jammy/main amd64 tftpd-hpa amd64 5.2+20150808-1.2build2 [40.7 kB] 40.7 kB を 0秒 で取得しました (730 kB/s) パッケージを事前設定しています ... 以前に未選択のパッケージ tftpd-hpa を選択しています。 (データベースを読み込んでいます ... 現在 369227 個のファイルとディレクトリがインストールされています。) .../tftpd-hpa_5.2+20150808-1.2build2_amd64.deb を展開する準備をしています ... tftpd-hpa (5.2+20150808-1.2build2) を展開しています... tftpd-hpa (5.2+20150808-1.2build2) を設定しています ... ureadahead (0.100.0-21) のトリガを処理しています ... man-db (2.10.2-1) のトリガを処理しています ... |
設定ファイルに記述されているtftpルートディレクトリ /srv/tftp/ の確認、オプションを多少変更。
|
1 2 3 4 5 6 7 |
# /etc/default/tftpd-hpa TFTP_USERNAME="tftp" TFTP_DIRECTORY="/srv/tftp" TFTP_ADDRESS=":69" #TFTP_OPTIONS="--secure" TFTP_OPTIONS="-s -c -v" |
tftpルートディレクトリ /srv/tftp/ の所有権を変更します。
|
1 2 3 4 5 6 |
$ ls -l /srv/ drwxr-xr-x 2 root nogroup 4096 2月 6 14:05 tftp $ sudo chown tftp /srv/tftp $ ls -l /srv/ drwxr-xr-x 2 tftp nogroup 4096 2月 6 14:05 tftp |
tftpサーバサービスを再起動。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ sudo systemctl restart tftpd-hpa.service $ systemctl status tftpd-hpa.service ● tftpd-hpa.service - LSB: HPA's tftp server Loaded: loaded (/etc/init.d/tftpd-hpa; generated) Active: active (running) since Tue 2024-02-06 14:09:54 HKT; 2s ago Docs: man:systemd-sysv-generator(8) Process: 105438 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=0/SUCCESS) Tasks: 1 (limit: 9415) Memory: 440.0K CPU: 19ms CGroup: /system.slice/tftpd-hpa.service └─105446 /usr/sbin/in.tftpd --listen --user tftp --address :69 -s -c -v /srv/tftp 2月 06 14:09:54 BionicUSB systemd[1]: tftpd-hpa.service: Deactivated successfully. 2月 06 14:09:54 BionicUSB systemd[1]: Stopped LSB: HPA's tftp server. 2月 06 14:09:54 BionicUSB systemd[1]: Starting LSB: HPA's tftp server... 2月 06 14:09:54 BionicUSB tftpd-hpa[105438]: * Starting HPA's tftpd in.tftpd 2月 06 14:09:54 BionicUSB tftpd-hpa[105438]: ...done. 2月 06 14:09:54 BionicUSB systemd[1]: Started LSB: HPA's tftp server. |
最後に先ほどダウンロードしたファイルのうち、 ...initramfs-recovery.itb と記載のあるファイルをtftpルートディレクトリ /srv/tftp/ へ配置するのですが、その際には次のようにファイル名からバージョン番号の部分を除去しておきます。
|
1 2 |
$ ls -l /srv/tftp -rw-rw-r-- 1 user user 7274496 2月 6 10:48 openwrt-mediatek-filogic-h3c_magic-nx30-pro-initramfs-recovery.itb |
作業PC側のお膳立ては以上です。
telnetで中に入りdropbearの導入
NX30 Proと作業用Ubuntu PCを有線ケーブルで繋いだら、前回確認したtelnetのカスタムポート 99/tcp へ入り、
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
$ telnet 192.168.124.1 99 Trying 192.168.124.1... Connected to 192.168.124.1. Escape character is '^]'. NX30Pro login: H3C Password: BusyBox v1.30.1 () built-in shell (ash) _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -__| || | | || _|| _| |_______|| __|_____|__|__||________||__| |____| |__| W I R E L E S S F R E E D O M ----------------------------------------------------- OpenWrt 21.02-SNAPSHOT, r16802-295c612a4a ----------------------------------------------------- root@NX30Pro:~# uname -a Linux NX30Pro 5.4.225 #0 SMP Wed Dec 7 17:18:33 2022 aarch64 GNU/Linux root@NX30Pro:~# df -h Filesystem Size Used Available Use% Mounted on /dev/root 13.3M 13.3M 0 100% /rom tmpfs 113.2M 1.6M 111.6M 1% /tmp tmpfs 113.2M 1008.0K 112.2M 1% /tmp/root overlayfs:/tmp/root 113.2M 1008.0K 112.2M 1% / /dev/mtdblock6 6.0M 1.4M 4.6M 24% /mnt/config /dev/mtdblock7 6.0M 1.4M 4.5M 24% /mnt/backup tmpfs 512.0K 4.0K 508.0K 1% /dev root@NX30Pro:~# free -h total used free shared buff/cache available Mem: 231848 154048 45980 2648 31820 67152 Swap: 0 0 0 |
パッケージマネージャでdropbearをインストールしようとするも、このプラットフォームのOpenWrt 21.02には、レポジトリにdropbearパッケージはなし。
少し古いOpenWrt 19.07では存在していたので、curlで直接このパッケージファイルをダウンロードし、パッケージマネージャでこのファイルからインストールします。tmpfsの /tmp は容量が限られているので、掃除はこまめに。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
root@NX30Pro:~# curl -o /tmp/dropbear.ipk https://downloads.openwrt.org/releases/packages-19.07/aarch64_cortex-a53/base/dropbear_2019.78-2_aarch64_cortex-a53.ipk % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- root@NX30Pro:~# ls -l /tmp/*.ipk -rw-r--r-- 1 root root 85132 Feb 6 12:00 /tmp/dropbear.ipk root@NX30Pro:~# opkg install /tmp/dropbear.ipk Installing dropbear (2019.78-2) to root... Configuring dropbear. Collected errors: * opkg_conf_parse_file: Duplicate src declaration (openwrt_base https://downloads.openwrt.org/releases/21.02-SNAPSHOT/packages/aarch64_cortex-a53/base). Skipping. root@NX30Pro:~# rm /tmp/dropbear.ipk |
サービス開始とrootのパスワード設定を済ませたら、一旦telnetから抜けてSSHで入り直してみます。
|
1 2 3 4 5 6 7 8 9 10 11 |
root@NX30Pro:~# /etc/init.d/dropbear enable root@NX30Pro:~# /etc/init.d/dropbear start root@NX30Pro:~# /etc/init.d/dropbear status running root@NX30Pro:~# passwd Changing password for root New password: Retype password: passwd: password for root changed by root root@NX30Pro:~# exit Connection closed by foreign host. |
なお、dropbearのレガシーなSSHへは、Ubuntu 18.04からそのまま接続しようとすると怒られてしまうので、 ~/.ssh/config に例外許可を記述しました。
|
1 2 3 4 5 6 7 8 9 10 |
$ ssh root@192.168.124.1 Unable to negotiate with 192.168.124.1 port 22: no matching host key type found. Their offer: ssh-rsa $ cat ~/.ssh/config Host 192.168.124.1 HostName 192.168.124.1 HostKeyAlgorithms=+ssh-rsa $ ssh root@192.168.124.1 root@192.168.124.1's password: |
また、下述でdopbearからのscp転送も同様の理由で怒られてしまうはずなので、 /etc/ssh/sshd_config に次のオプションを追記しておきます。
|
1 |
HostKeyAlgorithms +ssh-rsa |
現在のMTDをバックアップ
ファームウェア書き換えの前に、現在のMTD (Memory Technology Device)をバックアップしておきます。
NX30 ProのMTDは、次のような構成でした。
|
1 2 3 4 5 6 7 8 9 10 11 12 |
root@NX30Pro:~# cat /proc/mtd dev: size erasesize name mtd0: 08000000 00020000 "spi0.0" mtd1: 00100000 00020000 "BL2" mtd2: 00080000 00020000 "u-boot-env" mtd3: 00200000 00020000 "Factory" mtd4: 00200000 00020000 "FIP" mtd5: 04000000 00020000 "ubi" mtd6: 00600000 00020000 "pdt_data" mtd7: 00600000 00020000 "pdt_data_1" mtd8: 00100000 00020000 "exp" mtd9: 02580000 00020000 "plugin" |
今回の作業で入れ替えるのは次の4つ。
- mtd5 : ubi
- mtd1 : BL2
- mtd3 : Factory
- mtd4 : FIP
まずは少しサイズの大きい mtd5 を /tmp へ吸出し、scpでUbuntu PCへ転送します。
|
1 2 3 4 5 6 7 8 9 10 11 |
root@NX30Pro:~# dd if=/dev/mtd5 of=/tmp/mtd5_ubi 131072+0 records in 131072+0 records out 67108864 bytes (64.0MB) copied, 28.834170 seconds, 2.2MB/s root@NX30Pro:~# ls -l /tmp/mtd5_ubi -rw-r--r-- 1 root root 67108864 Feb 6 12:44 mtd5_ubi root@NX30Pro:~#scp /tmp/mtd5_ubi user@192.168.124.2:~/Downloads/ mtd5_ubi 100% 64MB 10.7MB/s 00:06 root@NX30Pro:~# rm /tmp/mtd5_ubi |
残る3つはいずれもサイズが小さいので、それぞれ /tmp へ書き出した後、まとめてscpで転送すればOK。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
root@NX30Pro:~# dd if=/dev/mtd1 of=/tmp/mtd1_BL2 2048+0 records in 2048+0 records out 1048576 bytes (1.0MB) copied, 0.388986 seconds, 2.6MB/s root@NX30Pro:~# dd if=/dev/mtd3 of=/tmp/mtd3_Factory 4096+0 records in 4096+0 records out 2097152 bytes (2.0MB) copied, 0.780508 seconds, 2.6MB/s root@NX30Pro:~# dd if=/dev/mtd4 of=/tmp/mtd4_FIP 4096+0 records in 4096+0 records out 2097152 bytes (2.0MB) copied, 0.780270 seconds, 2.6MB/s root@NX30Pro:~# ls -l /tmp/mtd* -rw-r--r-- 1 root root 1048576 Feb 6 13:46 /tmp/mtd1_BL2 -rw-r--r-- 1 root root 2097152 Feb 6 13:47 /tmp/mtd3_Factory -rw-r--r-- 1 root root 2097152 Feb 6 13:47 /tmp/mtd4_FIP root@NX30Pro:~#scp /tmp/mtd* user@192.168.124.2:~/Downloads/ user@192.168.124.2's password: mtd1_BL2 100% 1024KB 1.0MB/s 00:00 mtd3_Factory 100% 2048KB 2.0MB/s 00:00 mtd4_FIP 100% 2048KB 2.0MB/s 00:00 root@NX30Pro:~# rm /tmp/mtd* |
BL2とFIP(uboot)の書き込み
冒頭でダウンロードした ...preloader.bin (BL2)と、 ...uboot.fip (FIP)をUbuntu PCからNX30 Proへscp転送します。
|
1 2 3 4 5 6 7 |
$ scp openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin root@192.168.124.1:/tmp/ root@192.168.124.1's password: openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin 100% 221KB 6.5MB/s 00:00 $ scp openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-bl31-uboot.fip root@192.168.124.1:/tmp/ root@192.168.124.1's password: openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-bl31-uboot.fip 100% 983KB 7.3MB/s 00:00 |
NX30 Proに入り、BL2から書き込みを試みるも、やはりロックが掛かっていて失敗終了。
|
1 2 3 4 5 6 7 |
root@NX30Pro:~#ll /tmp/openwrt* -rw-r--r-- 1 root root 1006905 Feb 6 13:53 /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-bl31-uboot.fip -rw-r--r-- 1 root root 226141 Feb 6 13:52 /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin root@NX30Pro:~# mtd write /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin BL2 Could not open mtd device: BL2 Can't open device for writing! |
気にせずそのままFIPを書き換えます。こちらは成功。
|
1 2 3 |
root@NX30Pro:~# mtd write /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-bl31-uboot.fip FIP Unlocking FIP ... Writing from /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-bl31-uboot.fip to FIP ... |
initramfsとsysupgradeのインストール
Ubuntu PCを静的IPアドレス 192.168.1.254/24 へ変更したら、NX30 Proの電源を抜き差しして再起動を促します。
再起動後、 192.168.1.1/24 になったNX30 Proからtftpサーバに対して、 initramfs ファイルのリクエストがあるのを確認。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ systemctl status tftpd-hpa ● tftpd-hpa.service - LSB: HPA's tftp server Loaded: loaded (/etc/init.d/tftpd-hpa; generated) Active: active (running) since Tue 2024-02-06 14:09:54 HKT; 14min ago Docs: man:systemd-sysv-generator(8) Process: 105438 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=0/SUCCESS) Tasks: 1 (limit: 9415) Memory: 452.0K CPU: 239ms CGroup: /system.slice/tftpd-hpa.service └─105446 /usr/sbin/in.tftpd --listen --user tftp --address :69 -s -c -v /srv/tftp 2月 06 14:09:54 BionicUSB systemd[1]: tftpd-hpa.service: Deactivated successfully. 2月 06 14:09:54 BionicUSB systemd[1]: Stopped LSB: HPA's tftp server. 2月 06 14:09:54 BionicUSB systemd[1]: Starting LSB: HPA's tftp server... 2月 06 14:09:54 BionicUSB tftpd-hpa[105438]: * Starting HPA's tftpd in.tftpd 2月 06 14:09:54 BionicUSB tftpd-hpa[105438]: ...done. 2月 06 14:09:54 BionicUSB systemd[1]: Started LSB: HPA's tftp server. 2月 06 14:23:19 BionicUSB in.tftpd[115083]: RRQ from 192.168.1.1 filename openwrt-mediatek-filogic-h3c_magic-nx30-pro-initramfs-recovery.itb |
しばらくして、NX30 Proとの疎通に問題ないことを確認の後、残る sysupgrade.itb をscpで転送、
|
1 2 3 |
$ ping 192.168.1.1 $ scp ./openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-squashfs-sysupgrade.itb root@192.168.1.1:/tmp/ openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-squashfs-sysupgrade.itb 100% 9368KB 20.9MB/s 00:00 |
sshで中に入って、 sysupgrade コマンドで適用します。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ ssh root@192.168.1.1 BusyBox v1.36.1 (2023-11-14 13:38:11 UTC) built-in shell (ash) _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -__| || | | || _|| _| |_______|| __|_____|__|__||________||__| |____| |__| W I R E L E S S F R E E D O M ----------------------------------------------------- OpenWrt 23.05.2, r23630-842932a63d ----------------------------------------------------- === WARNING! ===================================== There is no root password defined on this device! Use the "passwd" command to set up a new password in order to prevent unauthorized SSH logins. -------------------------------------------------- root@OpenWrt:~# sysupgrade -F -n /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-squashfs-sysupgrade.itb Tue Feb 6 06:36:33 UTC 2024 upgrade: Commencing upgrade. Closing all shell sessions. Command failed: Connection failed root@OpenWrt:~# Connection to 192.168.1.1 closed by remote host. |
BL2の書き込みに再チャレンジ
OpenWrt 23.05.2ファームウェアへの入れ替えは無事に終わりましたが、BL2のロックを解除して再度書き込みにチャレンジしてみます(BL2は書き換えなくても正常に動作します)。
preloader.bin をもう一度scpで転送、
|
1 2 |
$ scp ./openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin root@192.168.1.1:/tmp/ openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin 100% 221KB 13.7MB/s 00:00 |
sshでNX30 Proの中に入り、パッケージリストの更新の後、MTDのアンロックに必要なパッケージ kmod-mtd-rw をインストール。
|
1 2 3 4 5 6 7 |
root@OpenWrt:~# opkg update root@OpenWrt:~# opkg install kmod-mtd-rw Installing kmod-mtd-rw (5.15.137+git-20160214-2) to root... Downloading https://downloads.openwrt.org/releases/23.05.2/targets/mediatek/filogic/packages/kmod-mtd-rw_5.15.137%2bgit-20160214-2_aarch64_cortex-a53.ipkConfiguring kmod-mtd-rw. root@OpenWrt:~# opkg list kmod-mtd-rw kmod-mtd-rw - 5.15.137+git-20160214-2 - A kernel module that temporarily makes all MTD partitions writeable. |
カーネルモジュールをロードすればロックは解除されるので、BL2を書き換え、デバイスを再起動して作業完了です。
|
1 2 3 4 5 6 7 8 9 |
root@OpenWrt:~# insmod /lib/modules/$(uname -r)/mtd-rw.ko i_want_a_brick=1 root@OpenWrt:~# mtd write /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin BL2 Unlocking BL2 ... Writing from /tmp/openwrt-23.05.2-mediatek-filogic-h3c_magic-nx30-pro-preloader.bin to BL2 ... root@OpenWrt:~# reboot root@OpenWrt:~# Connection to 192.168.1.1 closed by remote host. Connection to 192.168.1.1 closed. |
OpenWrt 23.05.2初期状態の確認
あらためて、コンソールからシステムの状態を確認します。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
BusyBox v1.36.1 (2023-11-14 13:38:11 UTC) built-in shell (ash) _______ ________ __ | |.-----.-----.-----.| | | |.----.| |_ | - || _ | -__| || | | || _|| _| |_______|| __|_____|__|__||________||__| |____| |__| W I R E L E S S F R E E D O M ----------------------------------------------------- OpenWrt 23.05.2, r23630-842932a63d ----------------------------------------------------- root@OpenWrt:~# df -h Filesystem Size Used Available Use% Mounted on /dev/root 4.3M 4.3M 0 100% /rom tmpfs 118.1M 64.0K 118.0M 0% /tmp /dev/ubi0_4 25.8M 160.0K 24.3M 1% /overlay overlayfs:/overlay 25.8M 160.0K 24.3M 1% / tmpfs 512.0K 0 512.0K 0% /dev root@OpenWrt:~#free -h total used free shared buff/cache available Mem: 241772 63364 156440 64 21968 142820 Swap: 0 0 0 root@OpenWrt:~# uname -a Linux OpenWrt 5.15.137 #0 SMP Tue Nov 14 13:38:11 2023 aarch64 GNU/Linux root@OpenWrt:~#cat /proc/cpuinfo processor : 0 BogoMIPS : 26.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 1 BogoMIPS : 26.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 |
LuCIもすでに導入済みの状態です。
MT7981の2.4Gと5Gの各WiFiインターフェイスも、正しく認識されています。
OpenWrt 23.05.2へ無事に入れ替え終わったところで今回はここまで。このデバイスは既存LAN環境のアクセスポイントとして使いたいので、次回はルータのアクセスポイント化(Dumb AP)へと続きます。





