Skip to content

Commit

Permalink
Update OpenWRT upstream version and fix OOB size (mikeeq#2)
Browse files Browse the repository at this point in the history
* Fix OOB size

* Fix OOB size v2

* Fix OOB size v3

* bump openwrt version

* bump openwrt version v2

* bump openwrt version v3

* bump openwrt version v4

* bump openwrt version v5

* bump openwrt version v6

* bump openwrt version v7

* bump openwrt version v8

* update readme

* Fix patch

* Fix patch v2

* Fix patch v3

* Fix patch v4

* Fix patch v5

* Fix patch v6

* Fix patch v7

* Update readme

* Update readme v2

* Update readme v3

* Update readme v4

* Update readme v5

* Update readme v6

* Update to 5.16.12 v5 - skip 1003

* Update openwrt image

* Update openwrt image v2

* Update openwrt image v3

* Update openwrt image v4

* Update openwrt image v5

* Update openwrt image v6

* Update openwrt image v7

* Update openwrt image v8

* Update openwrt image v10

* Update openwrt image v11

* Update openwrt image v12
  • Loading branch information
mikeeq authored Mar 7, 2022
1 parent 83980b0 commit 66929cd
Show file tree
Hide file tree
Showing 15 changed files with 2,026 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ steps:
- name: build-artifacts
path: /tmp/artifacts
commands:
- build_image/build_image_in_docker.sh | tee /tmp/artifacts/build.log
- /bin/bash -c "set -o pipefail; build_image/build_image_in_docker.sh 2>&1 | tee /tmp/artifacts/build.log"

- name: publish-github
image: plugins/github-release
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ artifacts
openwrt
build.log
.config
config.buildinfo
61 changes: 36 additions & 25 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Password:

- 160Hz wide 5GHz channels don't work on some clients [source](https://forum.openwrt.org/t/adding-openwrt-support-for-xiaomi-redmi-router-ax6s-xiaomi-router-ax3200/111085/131?u=mikeeq)
- Smaller coverage area/WiFi speeds comparing to stock firmware
- I wasn't able to flash OpenWRT on recovered via TFTP AX3200 to 1.0.50 FW, I needed to flash my factory firmware 1.0.71, restore default settings (as they were saved from 1.0.50) and then I was able to flash OpenWRT

## Tutorial: How to install OpenWRT

Expand Down Expand Up @@ -63,7 +62,9 @@ Password:
```

> If `telnet_en=0` or `"telnet": false`, then telnet is not enabled on your device by default and you need to wait for the [exploit](https://forum.openwrt.org/t/adding-openwrt-support-for-xiaomi-redmi-router-ax6s-xiaomi-router-ax3200/111085/74?u=mikeeq) or use [CH341A programmer](https://forum.openwrt.org/t/adding-openwrt-support-for-xiaomi-redmi-router-ax6s-xiaomi-router-ax3200/111085/151?u=mikeeq)
>> If you're using `RB03` there could be a chance to downgrade your FW to development version and maybe that process will enable the telnet on your device - [info](https://github.com/YangWang92/AX6S-unlock)
>> If you're using `RB03` there could be a chance to downgrade your FW to development version and maybe that process will enable the telnet on your device - <https://github.com/YangWang92/AX6S-unlock>
- RB03 1.2.7 dev FW (with telnet enabled) has `MD5: 5eedf1632ac97bb5a6bb072c08603ed7`, `SHA256: 9c80425987fb8d2f8c5f59a7234b795c0990db9147b42f6ad69dc2f76e6a2c11`

4. Start SSHd on router using telnet

Expand Down Expand Up @@ -99,7 +100,7 @@ Password:
mkdir -p xiaomi_openwrt_images

# Download images from Internet
curl -L https://github.com/mikeeq/xiaomi_ax3200_openwrt/releases/download/v20220303/openwrt-mediatek-mt7622-xiaomi_redmi-router-ax6s-squashfs-sysupgrade.bin -o xiaomi_openwrt_images/sysupgrade.bin
curl -L https://github.com/mikeeq/xiaomi_ax3200_openwrt/releases/download/v20220306/openwrt-mediatek-mt7622-xiaomi_redmi-router-ax6s-squashfs-factory.bin -o xiaomi_openwrt_images/factory.bin

# Copy images over SSH to router
scp -r xiaomi_openwrt_images [email protected]:/tmp/
Expand All @@ -114,14 +115,19 @@ Password:

# Validate those checksums against checksums found in github releases file sha256sums_artifacts_only
sha256sum *.bin
curl -Ls https://github.com/mikeeq/xiaomi_ax3200_openwrt/releases/download/v20220306/sha256sums_artifacts_only | grep -i factory

# Set NVRAM flags
## Run also first commented two lines if after flashing sysupgrade.bin image router restarts to stock firmware instead of OpenWRT
# nvram set flag_boot_rootfs=0
# nvram set "boot_fw1=run boot_rd_img;bootm"
nvram set flag_boot_success=1
nvram set flag_try_sys1_failed=0
nvram set flag_try_sys2_failed=0
nvram commit

# Flash image
mtd -r write sysupgrade.bin firmware
mtd -r write factory.bin firmware
```

7. After running last command `mtd write -r` router should automatically reboot and after it gets up you can open <http://192.168.1.1> in the browser and try to login (default password is blank/empty) and set root password here: <http://192.168.1.1/cgi-bin/luci/admin/system/admin>
Expand All @@ -132,13 +138,14 @@ Password:

## Router debricking

1. Change your NIC IP address to 192.168.4.100 or 192.168.4.50 (that one worked for me and i've only tested the process out on Windows using Xiaomi Recovery Tool)
1. Change your NIC IP address to 192.168.31.100 or 192.168.31.50 (that one worked for me and i've only tested the process out on Windows using Xiaomi Recovery Tool)
2. Remember about disabling any firewall on your PC which can block TFTP traffic
3. Create tftp server or use [Xiaomi Recovery Tool](https://forum.openwrt.org/t/xiaomi-mi-router-4a-gigabit-edition-r4ag-r4a-gigabit-fully-supported-and-flashable-with-openwrtinvasion/36685/747?u=mikeeq)

```bash
mkdir -p /tmp/tftp
curl -Ls http://cdn.awsde0-fusion.fds.api.mi-img.com/xiaoqiang/rom/rb01/miwifi_rb01_firmware_36352_1.0.50_INT.bin -o C0A81F02.img
# Stock image should be renamed to TFTP server IP address in hex (Eg. C0A81F64.img), 192.168.31.2 - C0A81F02.img, 192.168.31.50 - C0A81F32.img, 192.168.31.100 - C0A81F64.img
curl -Ls http://cdn.awsde0-fusion.fds.api.mi-img.com/xiaoqiang/rom/rb01/miwifi_rb01_firmware_36352_1.0.50_INT.bin -o C0A81F64.img
# http://cdn.awsde0-fusion.fds.api.mi-img.com/xiaoqiang/rom/rb01/miwifi_rb01_firmware_bbc77_1.0.71_INT.bin
# To grab URL for stock firmware check http://192.168.31.1/cgi-bin/luci/;stok=<stok>/api/xqsystem/check_rom_update

Expand Down Expand Up @@ -180,17 +187,21 @@ mkdir -p /tmp/xiaomi_fw
cd /tmp/xiaomi_fw

# Download image
curl -L https://github.com/mikeeq/xiaomi_ax3200_openwrt/releases/download/v20220303/openwrt-mediatek-mt7622-xiaomi_redmi-router-ax6s-squashfs-sysupgrade.bin -o ./sysupgrade.bin
curl -L https://github.com/mikeeq/xiaomi_ax3200_openwrt/releases/download/v20220306/openwrt-mediatek-mt7622-xiaomi_redmi-router-ax6s-squashfs-sysupgrade.bin -o ./sysupgrade.bin

# Validate checksums against checksums found in github releases file sha256sums_artifacts_only
sha256sum *.bin
curl -Ls https://github.com/mikeeq/xiaomi_ax3200_openwrt/releases/download/v20220306/sha256sums_artifacts_only | grep -i sysupgrade

# Flash image
mtd -r write sysupgrade.bin firmware
```
## If you are coming from other partition layout (check changelog) use mtd flash command instead of sysupgrade from tutorial above (and you will also need to download another image (factory.bin in this case))

1. SYSUPGRADE from Luci or via `sysupgrade` CLI command was not tested yet - <https://openwrt.org/docs/guide-user/installation/sysupgrade.cli#command-line_instructions>
2. Restoring default settings was also not tested yet: <https://openwrt.org/docs/guide-user/troubleshooting/failsafe_and_factory_reset#soft_factory_reset>
## If you want to keep configuration
sysupgrade -u sysupgrade.bin
## If you want to restore default settings
sysupgrade -u -n sysupgrade.bin
## You can also use sysupgrade feature in Luci if you're not upgrading from an image with different partition layout
```

## Stock /proc/mtd

Expand All @@ -217,7 +228,7 @@ mtd14: 00500000 00020000 "obr"
## OpenWRT /proc/mtd

```bash
root@OpenWrt:/# cat /proc/mtd
root@OpenWrt:~# cat /proc/mtd
dev: size erasesize name
mtd0: 00080000 00020000 "Preloader"
mtd1: 00040000 00020000 "ATF"
Expand All @@ -227,10 +238,8 @@ mtd4: 00040000 00020000 "bdata"
mtd5: 00080000 00020000 "factory"
mtd6: 00040000 00020000 "crash"
mtd7: 00040000 00020000 "crash_log"
mtd8: 07300000 00020000 "firmware"
mtd9: 003a0000 00020000 "kernel"
mtd10: 06f60000 00020000 "rootfs"
mtd11: 06a80000 00020000 "rootfs_data"
mtd8: 00400000 00020000 "kernel"
mtd9: 06f00000 00020000 "ubi"
```

## Luci Overview
Expand All @@ -241,26 +250,27 @@ mtd11: 06a80000 00020000 "rootfs_data"

```bash
❯ ssh [email protected]
BusyBox v1.35.0 (2022-03-01 22:57:40 UTC) built-in shell (ash)
BusyBox v1.35.0 (2022-03-05 20:06:35 UTC) built-in shell (ash)

_______ ________ __
| | .-----.-----.-----. | | | | .----. | | _ |
| --- || _ | -__| || | | || _|| _|
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt SNAPSHOT, r19039-8235723c78
OpenWrt SNAPSHOT, r19053-921392e216
-----------------------------------------------------
root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 5.0M 5.0M 0 100% /rom
tmpfs 113.9M 236.0K 113.7M 0% /tmp
tmpfs 113.9M 72.0K 113.9M 0% /tmp/root
/dev/root 5.8M 5.8M 0 100% /rom
tmpfs 113.9M 244.0K 113.7M 0% /tmp
/dev/ubi0_1 89.7M 44.0K 85.0M 0% /overlay
overlayfs:/overlay 89.7M 44.0K 85.0M 0% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/mtdblock11 106.5M 2.5M 104.0M 2% /overlay
overlayfs:/overlay 106.5M 2.5M 104.0M 2% /
root@OpenWrt:~# dmesg | grep -i xia
[ 0.000000] Machine model: Xiaomi Redmi Router AX6S
root@OpenWrt:~# dmesg | grep -i mikeeq
[ 0.000000] Linux version 5.10.103 (mikeeq@08bd2e1-droneci) (aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r19053-921392e216) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP Sat Mar 5 20:06:35 2022
```

## Docs
Expand All @@ -274,6 +284,7 @@ Main:
- <https://github.com/robimarko/openwrt/blob/IPQ807x-5.10-backports/.github/workflows/ipq807x.yaml>
- <https://github.com/YangWang92/AX6S-unlock>
- <https://github.com/geekman/xqrepack/>
- <https://forum.openwrt.org/t/xiaomi-ax3600-install-guide/68273>

Additional:

Expand Down
2 changes: 2 additions & 0 deletions build_image/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
artifacts
openwrt
21 changes: 13 additions & 8 deletions build_image/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,52 @@ set -eu -o pipefail
# set -x

RUN_PATH=$PWD
SCRIPT_PATH=${SCRIPT_PATH:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
SCRIPT_NAME=$(basename "$0")
REPO_PATH=$(cd "${SCRIPT_PATH}/.." && pwd)

cd "$SCRIPT_PATH" || exit
# shellcheck disable=SC1091
source helpers/functions.sh

inf
inf "SCRIPT_NAME=$SCRIPT_NAME"
inf "RUN_PATH=$RUN_PATH"
inf "SCRIPT_PATH=$SCRIPT_PATH"
inf "REPO_PATH=$REPO_PATH"

OPENWRT_PATH=${OPENWRT_PATH:-/tmp/openwrt}

OPENWRT_GIT_URL=https://github.com/openwrt/openwrt.git
OPENWRT_GIT_BRANCH_NAME=master
OPENWRT_GIT_COMMIT_HASH=8235723c78b535635ef47951ec8fa61d6a4f3593
OPENWRT_GIT_COMMIT_HASH=759149977ea9794bcb928500680fa9462ad74394
OPENWRT_GIT_PATH=${OPENWRT_PATH}/upstream

# OPENWRT_NAMIDAIRO_GIT_URL=https://github.com/namidairo/openwrt.git
# OPENWRT_NAMIDAIRO_GIT_BRANCH_NAME=ax6s
# # OPENWRT_NAMIDAIRO_GIT_COMMIT_HASH=78a9bee50bc116f443a56d2c094f5c3d3be5c868
# # OPENWRT_NAMIDAIRO_GIT_COMMIT_HASH=1ce3e53de75b3c1c91a5c5969abfaab9e25d973f
# OPENWRT_NAMIDAIRO_GIT_PATH=${OPENWRT_PATH}/namidairo

if [[ ${SKIP_PULL:-false} == false || ! -d ${OPENWRT_GIT_PATH} ]]; then
inf "Pull official openwrt repo"

git clone --single-branch --branch ${OPENWRT_GIT_BRANCH_NAME} ${OPENWRT_GIT_URL} "${OPENWRT_GIT_PATH}"

cd "${OPENWRT_GIT_PATH}"
git checkout ${OPENWRT_GIT_COMMIT_HASH}

# inf "Pull namidairo openwrt repo with xiaomi support"

# git clone ${OPENWRT_NAMIDAIRO_GIT_URL} "${OPENWRT_NAMIDAIRO_GIT_PATH}"

# cd "${OPENWRT_NAMIDAIRO_GIT_PATH}"
# git checkout ${OPENWRT_NAMIDAIRO_GIT_BRANCH_NAME}
# git pull origin master
# git diff master ${OPENWRT_NAMIDAIRO_GIT_BRANCH_NAME} > "${OPENWRT_PATH}"/patchfile

inf "Apply namidairo patches to upstream repo"
cd "${OPENWRT_GIT_PATH}"
# inf "Apply namidairo patches to upstream repo"
# cd "${OPENWRT_GIT_PATH}"
# git apply "${OPENWRT_PATH}"/patchfile
git apply "${SCRIPT_PATH}"/files/ax3200_78a9bee.patch

git apply "${PATCH_PATH}"
fi

inf "Add build scripts"
Expand Down
27 changes: 23 additions & 4 deletions build_image/build_image_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ set -eu -o pipefail
# set -x

RUN_PATH=$PWD
SCRIPT_PATH=${SCRIPT_PATH:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
SCRIPT_NAME=$(basename "$0")
REPO_PATH=$(cd "${SCRIPT_PATH}/.." && pwd)

cd "$SCRIPT_PATH" || exit
# shellcheck disable=SC1091
source helpers/functions.sh

PATCH_PATH="$SCRIPT_PATH/files/ax3200_1ce3e53.patch"

inf
inf "SCRIPT_NAME=$SCRIPT_NAME"
inf "RUN_PATH=$RUN_PATH"
inf "SCRIPT_PATH=$SCRIPT_PATH"
inf "REPO_PATH=$REPO_PATH"

[ -x "$(command -v apt-get)" ] || err "Run on Debian!"

Expand Down Expand Up @@ -87,9 +94,19 @@ if [[ ${IMAGE_BUILD_ONLY:-false} == false ]]; then
chown -R "$USER_ID":"$GROUP_ID" "$SCRIPT_PATH"
chown -R "$USER_ID":"$GROUP_ID" "$OPENWRT_PATH"

inf "Change build version"
if git describe --exact-match --tags HEAD; then
OPENWRT_BUILD_VERSION=$(git describe --exact-match --tags HEAD)
else
OPENWRT_BUILD_VERSION=$(git log --pretty=format:'%h' -n 1)
fi
inf "OPENWRT_BUILD_VERSION=$OPENWRT_BUILD_VERSION"
cp -rfv "$SCRIPT_PATH/files/config.build" "$SCRIPT_PATH/files/config.buildinfo"
sed -i "s/CONFIG_KERNEL_BUILD_DOMAIN=\"droneci\"/CONFIG_KERNEL_BUILD_DOMAIN=\"${OPENWRT_BUILD_VERSION}-droneci\"/" "$SCRIPT_PATH/files/config.buildinfo"

inf "Run ./build_image.sh"
# IN_DOCKER=true ./build_image.sh
su -c "OPENWRT_PATH=$OPENWRT_PATH IN_DOCKER=true ./build_image.sh" buser
su -c "PATCH_PATH=$PATCH_PATH OPENWRT_PATH=$OPENWRT_PATH IN_DOCKER=true ./build_image.sh" buser
build_exitcode=$?

inf "Copy artifacts to ARTIFACTS_PATH"
Expand All @@ -101,9 +118,11 @@ if [[ ${IMAGE_BUILD_ONLY:-false} == false ]]; then
cp -rfv $(find . | grep bin/targets | grep -i profiles.json) "$ARTIFACTS_PATH/"
# shellcheck disable=SC2046
cp -rfv $(find . | grep bin/targets | grep -i sha256sum) "$ARTIFACTS_PATH/"
# shellcheck disable=SC2046
cp -rfv $(find . | grep bin/targets | grep -i config.buildinfo) "$ARTIFACTS_PATH/"
cp -rfv "$OPENWRT_PATH"/upstream/.config "$ARTIFACTS_PATH/config.build"
cp -rfv "$SCRIPT_PATH"/files/ax3200_78a9bee.patch "$ARTIFACTS_PATH/"
cp -rfv "$SCRIPT_PATH"/files/config.buildinfo "$ARTIFACTS_PATH/config.buildinfo"
cp -rfv "$PATCH_PATH" "$ARTIFACTS_PATH/"
cp -rfv "$SCRIPT_PATH"/files/config.build "$ARTIFACTS_PATH/config.buildrepo"

sha256sum "$ARTIFACTS_PATH"/* > "$ARTIFACTS_PATH/sha256sums_artifacts_only"
exit $build_exitcode
Expand Down
Loading

0 comments on commit 66929cd

Please sign in to comment.