Xiaomi router stock firmware uses a custom format and verifies an RSA signature during flashing. This makes flashing modified firmware nearly impossible through the normal process.
By analyzing the firmware tool mkxqimage, the firmware packaging and unpacking process can be understood. If you package the firmware with your own RSA private key and replace
/usr/share/xiaoqiang/public.pemwith the corresponding public key, the web interface can accept a self-made firmware image.
I. Unpacking the firmware
The mkxqimage tool unpacks the firmware. Before unpacking, verify the checksum and then use the RSA public key /usr/share/xiaoqiang/public.pem to verify the RSA signature. After both checks pass, use the firmware type at [0x0C] and the four offsets at [0x10], [0x14], [0x18], and [0x1C] to split the firmware. The image may contain files such as:
brcm4709_fac_update_nor.bin
brcm4709_nor.bin
fac_mode.bin
nvram_fac.bin
ramfsz
root.ext4.lzma
root.squashfs
upsetting.sh
upsetting_fac1.sh
upsetting_fac2.sh
upsetting_fac3.sh
vmlinuz.trxII. Packaging the firmware
First, create a pair of RSA private and public keys.
The stable version 0.4.85 is used below as an example of the modification and packaging process.
- Unpack the firmware:
| |
The result contains two files:
| |
- Modify the firmware:
- For an EXT4 image:
mount -o loop -t ext4 root.ext4 /mnt - For SquashFS:
unsquashfs rootfs.squashfs
- For an EXT4 image:
Replace the RSA public key and enable SSH:
| |
Restore disabled web interfaces if needed:
| |
Make any other required modifications, then save the changes back to the firmware image:
| |
- Package the firmware.
Compress the modified filesystem image:
EXT4 image: ./lzma e -a0 root.ext4 root.ext4.lzma
SquashFS: mksquashfs path/to/squashfs_rootfs_folder ... newrootfs.squashfs
| |
III. Preparing for the upgrade
- Replace the public key.
Before upgrading the self-made firmware, replace the RSA public key on the current router:
| |
- Test the customized firmware.
| |
If decompression finishes without errors and two files are listed, the image was packaged correctly:
| |
The brcm4709_nor.bin file must be exactly 16646144 bytes.
Verify the EXT4 image:
| |
You should see information similar to this, although the timestamps will differ:
| |
Back up the customized firmware. In the computer's file manager, open \\192.168.31.1\XiaoMi\xqimage. You should see brcm4709_hdr_00000_0.4.85 and can copy the image to the computer.
IV. Upgrading the customized firmware
Log in to the Xiaomi router management page, select brcm4709_hdr_00000_0.4.85 under Routing Settings → Advanced Features → Manual Router Upgrade, click Upload and Install Firmware, and wait several minutes.
After installation, SSH may not start because the upgrade clears the ssh_en NVRAM value to 0. The first-boot defaults script sets it to 1 only after dropbear starts. Restart the router, then log in through SSH.
- Important note.
Because the router's RSA public key has been replaced, official firmware cannot be upgraded normally. To restore official firmware, replace the customized public key with the original one:
| |
Source
Source: https://www.openwrt.pro/post-415.html


Góp Ý / Bình Luận / Đánh giá