Skip to content

Commit

Permalink
Use OEM fs-uboot to boot from 0x40000
Browse files Browse the repository at this point in the history
  • Loading branch information
jwmullally committed Nov 29, 2022
1 parent 9a72440 commit 02e0fcc
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 76 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/build_release_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ on:
push:
tags:
- 'v*'
- 'snapshot*'
workflow_dispatch: {}
jobs:
build-release-images:
name: Build and Release Firmware Images
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -23,9 +22,9 @@ jobs:
[Build logs.](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
prerelease: True
files: |
openwrt-imagebuilder-*/bin/targets/*/*/openwrt-*.bin
openwrt-imagebuilder-*/bin/targets/*/*/openwrt-*.manifest
openwrt-imagebuilder-*/bin/targets/*/*/sha256sums
openwrt-imagebuilder-*/bin/targets/*/*/profiles.json
build/openwrt-imagebuilder-*/bin/targets/*/*/openwrt-*.bin
build/openwrt-imagebuilder-*/bin/targets/*/*/openwrt-*.manifest
build/openwrt-imagebuilder-*/bin/targets/*/*/sha256sums
build/openwrt-imagebuilder-*/bin/targets/*/*/profiles.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
openwrt-imagebuilder-*
linux-include
build/
71 changes: 41 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

ALL_CURL_OPTS := $(CURL_OPTS) -L --fail --create-dirs

VERSION := 21.02.0-rc4
VERSION := 21.02.5
BOARD := ath79
SUBTARGET := generic
SOC := qca9563
Expand All @@ -13,58 +13,69 @@ DEVICE_DTS := $(SOC)_$(PROFILE)
PACKAGES := luci luci-app-commands open-plc-utils-plctool open-plc-utils-plcrate open-plc-utils-hpavkeys
EXTRA_IMAGE_NAME := custom

TOPDIR := $(CURDIR)/$(BUILDER)
BUILD_DIR := build
TOPDIR := $(CURDIR)/$(BUILD_DIR)/$(BUILDER)
KDIR := $(TOPDIR)/build_dir/target-mips_24kc_musl/linux-$(BOARD)_$(SUBTARGET)
PATH := $(TOPDIR)/staging_dir/host/bin:$(PATH)
LINUX_VERSION = $(shell sed -n -e '/Linux-Version: / {s/Linux-Version: //p;q}' $(BUILDER)/.targetinfo)
LINUX_VERSION = $(shell sed -n -e '/Linux-Version: / {s/Linux-Version: //p;q}' $(BUILD_DIR)/$(BUILDER)/.targetinfo)
OUTPUT_DIR := $(BUILD_DIR)/$(BUILDER)/bin/targets/$(BOARD)/$(SUBTARGET)


all: images


$(BUILDER).tar.xz:
curl $(ALL_CURL_OPTS) -O https://downloads.openwrt.org/releases/$(VERSION)/targets/$(BOARD)/$(SUBTARGET)/$(BUILDER).tar.xz
$(BUILD_DIR)/downloads:
mkdir -p $(BUILD_DIR)/downloads.tmp
cd $(BUILD_DIR)/downloads.tmp && curl $(ALL_CURL_OPTS) -O https://downloads.openwrt.org/releases/$(VERSION)/targets/$(BOARD)/$(SUBTARGET)/$(BUILDER).tar.xz
mv $(BUILD_DIR)/downloads.tmp $(BUILD_DIR)/downloads


$(BUILDER): $(BUILDER).tar.xz
tar -xf $(BUILDER).tar.xz
$(BUILD_DIR)/$(BUILDER): $(BUILD_DIR)/downloads
cd $(BUILD_DIR) && tar -xf downloads/$(BUILDER).tar.xz

# Fetch firmware utility sources to apply patches
curl $(ALL_CURL_OPTS) "https://git.openwrt.org/?p=openwrt/openwrt.git;hb=refs/tags/v$(VERSION);a=blob_plain;f=tools/firmware-utils/src/tplink-safeloader.c" -o $(BUILDER)/tools/firmware-utils/src/tplink-safeloader.c
curl $(ALL_CURL_OPTS) "https://git.openwrt.org/?p=openwrt/openwrt.git;hb=refs/tags/v$(VERSION);a=blob_plain;f=tools/firmware-utils/src/md5.h" -o $(BUILDER)/tools/firmware-utils/src/md5.h

cd $(BUILD_DIR)/$(BUILDER) && curl $(ALL_CURL_OPTS) "https://git.openwrt.org/?p=project/firmware-utils.git;hb=0c92b20ad488a4fb5fb290f6d1b893df45761275;a=blob_plain;f=src/tplink-safeloader.c" -o tools/firmware-utils/src/tplink-safeloader.c
cd $(BUILD_DIR)/$(BUILDER) && curl $(ALL_CURL_OPTS) "https://git.openwrt.org/?p=project/firmware-utils.git;hb=0c92b20ad488a4fb5fb290f6d1b893df45761275;a=blob_plain;f=src/md5.h" -o tools/firmware-utils/src/md5.h
# Apply all patches
cd $(BUILDER) && patch -p1 < ../$(PROFILE).patch
gcc -Wall -o $(TOPDIR)/staging_dir/host/bin/tplink-safeloader $(BUILDER)/tools/firmware-utils/src/tplink-safeloader.c -lcrypto -lssl
$(foreach file, $(sort $(wildcard patches/*.patch)), patch -d $(BUILD_DIR)/$(BUILDER) -p1 < $(file);)

# Build tools
cd $(BUILD_DIR)/$(BUILDER) && gcc -Wall -o staging_dir/host/bin/tplink-safeloader tools/firmware-utils/src/tplink-safeloader.c -lcrypto -lssl
cd $(BUILD_DIR)/$(BUILDER) && ln -sf /usr/bin/cpp staging_dir/host/bin/mips-openwrt-linux-musl-cpp

# Regenerate .targetinfo
cd $(BUILDER) && make -f include/toplevel.mk TOPDIR="$(TOPDIR)" prepare-tmpinfo || true
cp -f $(BUILDER)/tmp/.targetinfo $(BUILDER)/.targetinfo
cd $(BUILD_DIR)/$(BUILDER) && make -f include/toplevel.mk TOPDIR="$(TOPDIR)" prepare-tmpinfo || true
cd $(BUILD_DIR)/$(BUILDER) && cp -f tmp/.targetinfo .targetinfo


$(BUILD_DIR)/$(BUILDER)/extra: $(BUILD_DIR)/$(BUILDER)
mkdir -p $(BUILD_DIR)/$(BUILDER)/extra.tmp
cd $(BUILD_DIR)/$(BUILDER)/extra.tmp && ../../../src/get_stock_fs_uboot.sh
cd $(BUILD_DIR)/$(BUILDER)/extra.tmp && ../../../src/gen_default_mac.sh
mv -f $(BUILD_DIR)/$(BUILDER)/extra.tmp $(BUILD_DIR)/$(BUILDER)/extra


linux-include: $(BUILDER)
$(BUILD_DIR)/linux-include: $(BUILD_DIR)/$(BUILDER)
# Fetch DTS include dependencies
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/clock/ath79-clk.h?h=v$(LINUX_VERSION)" -o linux-include.tmp/dt-bindings/clock/ath79-clk.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/gpio/gpio.h?h=v$(LINUX_VERSION)" -o linux-include.tmp/dt-bindings/gpio/gpio.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/input/input.h?h=v$(LINUX_VERSION)" -o linux-include.tmp/dt-bindings/input/input.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/uapi/linux/input-event-codes.h?h=v$(LINUX_VERSION)" -o linux-include.tmp/dt-bindings/input/linux-event-codes.h
mv -T linux-include.tmp linux-include
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/clock/ath79-clk.h?h=v$(LINUX_VERSION)" -o $(KDIR)/linux-$(LINUX_VERSION)/include/dt-bindings/clock/ath79-clk.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/gpio/gpio.h?h=v$(LINUX_VERSION)" -o $(KDIR)/linux-$(LINUX_VERSION)/include/dt-bindings/gpio/gpio.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/dt-bindings/input/input.h?h=v$(LINUX_VERSION)" -o $(KDIR)/linux-$(LINUX_VERSION)/include/dt-bindings/input/input.h
curl $(ALL_CURL_OPTS) "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/include/uapi/linux/input-event-codes.h?h=v$(LINUX_VERSION)" -o $(KDIR)/linux-$(LINUX_VERSION)/include/dt-bindings/input/linux-event-codes.h
touch $(BUILD_DIR)/linux-include


$(KDIR)/$(PROFILE)-kernel.bin: $(BUILDER) linux-include
$(KDIR)/$(PROFILE)-kernel.bin: $(BUILD_DIR)/$(BUILDER) $(BUILD_DIR)/linux-include
# Build this device's DTB and firmware kernel image. Uses the official kernel build as a base.
ln -sf /usr/bin/cpp $(BUILDER)/staging_dir/host/bin/mips-openwrt-linux-musl-cpp
cp -Trf linux-include $(KDIR)/linux-$(LINUX_VERSION)/include
cd $(BUILDER) && env PATH=$(PATH) make --trace -C target/linux/$(BOARD)/image $(KDIR)/$(PROFILE)-kernel.bin TOPDIR="$(TOPDIR)" INCLUDE_DIR="$(TOPDIR)/include" TARGET_BUILD=1 BOARD="$(BOARD)" SUBTARGET="$(SUBTARGET)" PROFILE="$(PROFILE)" DEVICE_DTS="$(DEVICE_DTS)"
cd $(BUILD_DIR)/$(BUILDER) && env PATH=$(PATH) make --trace -C target/linux/$(BOARD)/image $(KDIR)/$(PROFILE)-kernel.bin V=s TOPDIR="$(TOPDIR)" INCLUDE_DIR="$(TOPDIR)/include" TARGET_BUILD=1 BOARD="$(BOARD)" SUBTARGET="$(SUBTARGET)" PROFILE="$(PROFILE)" DEVICE_DTS="$(DEVICE_DTS)"


images: $(BUILDER) $(KDIR)/$(PROFILE)-kernel.bin
images: $(BUILD_DIR)/$(BUILDER) $(KDIR)/$(PROFILE)-kernel.bin $(BUILD_DIR)/$(BUILDER)/extra
# Use ImageBuilder as normal
cd $(BUILDER) && make image PROFILE="$(PROFILE)" EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" PACKAGES="$(PACKAGES)" FILES="$(TOPDIR)/target/linux/$(BOARD)/$(SUBTARGET)/base-files/"
cat $(BUILDER)/bin/targets/$(BOARD)/$(SUBTARGET)/sha256sums
ls -hs $(BUILDER)/bin/targets/$(BOARD)/$(SUBTARGET)/openwrt-*.bin
cd $(BUILD_DIR)/$(BUILDER) && make image PROFILE="$(PROFILE)" EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" PACKAGES="$(PACKAGES)" FILES="$(TOPDIR)/target/linux/$(BOARD)/$(SUBTARGET)/base-files/"
cat $(OUTPUT_DIR)/sha256sums
ls -hs $(OUTPUT_DIR)


clean:
rm -rf openwrt-imagebuilder-*
rm -rf linux-include
rm -rf build
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ After installing, the device flash layout will look like:
| Partition | Base | Size |
| --- | ---: | ---: |
| `factory-uboot` | `0x00000` | `0x20000` |
| `os-image` | `0x20000` | `...` |
| `fs-uboot` | `0x20000` | `0x20000` |
| `os-image` | `0x40000` | `...` |
| `file-system` | `...` | `...` |
| `soft-version` | `0x7e0000` | `0x01000` |
| `partition-table` | `0x7e1000` | `0x02000` |
Expand All @@ -89,7 +90,7 @@ These partitions containing data unique to your device will be irretrievably ove
| `device-id` |
| `product-info` |

**!!! Make sure you have a full memory backup before proceeding !!!**
**!!! If you want to restore this device later, make sure you have a full memory backup using a flash programmer before proceeding !!!**


### Region-specific PLC firmware
Expand All @@ -103,22 +104,19 @@ If the user later wants to upgrade this firmware for whatever reason, it is thei

Unfortunately, your devices original `defaul-mac` partition will need to be overwritten. A replacement one is included with the address `02:BC:DE:39:E8:32`.

To set your own MAC address, do the following:

```bash
echo -en "\x02\xBC\xDE\x39\xE8\x32" | dd of=default-mac oflag=seek_bytes seek=8 conv=notrunc
make
```
To set your own MAC address, edit the file [`gen_default_mac.sh`](src/gen_default_mac.sh) before building, or after installation you can edit the `info` partition.


## Building

If you want to build the firmwares yourself, checkout this repo and do the following:
If you want to build the firmware yourself and change the default packages, checkout this repo and do the following:

```bash
make
```

Be careful when modifying the base image, as [this device can only be unbricked by opening it up and using a flash programmer](https://openwrt.org/toh/tp-link/tl-wpa8630p_v2#debricking). Unless you are willing to do this, you should stick with the safe and tested images in the releases section of this repository, and add/remove packages from LuCI after installation.


## Issues

Expand Down
Binary file removed default-mac
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/tools/firmware-utils/src/tplink-safeloader.c
+++ b/tools/firmware-utils/src/tplink-safeloader.c
@@ -1723,6 +1723,46 @@
@@ -1723,6 +1723,47 @@
.last_sysupgrade_partition = "file-system"
},

Expand All @@ -21,7 +21,7 @@
+ "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:41550000}\n" /* AU */
+ "{product_name:TL-WPA8630P,product_ver:2.1.0,special_id:45550000}\n", /* EU */
+ .part_trail = 0x00,
+ .soft_ver = NULL,
+ .soft_ver = SOFT_VER_DEFAULT,
+
+ /* This erases all stock partitions except for "factory-uboot" and "radio".
+ * Do not use unless you have a full backup of your existing flash to
Expand All @@ -30,7 +30,8 @@
+ * images (tl-wpa8630p-v2-int, tl-wpa8630p-v2.0-eu, etc). */
+ .partitions = {
+ {"factory-uboot", 0x00000, 0x20000},
+ {"firmware", 0x20000, 0x7c0000},
+ {"fs-uboot", 0x20000, 0x20000},
+ {"firmware", 0x40000, 0x7a0000},
+ {"soft-version", 0x7e0000, 0x01000},
+ {"partition-table", 0x7e1000, 0x02000},
+ {"support-list", 0x7e3000, 0x01000},
Expand All @@ -47,56 +48,72 @@
/** Firmware layout for the TL-WR1043 v5 */
{
.id = "TLWR1043NV5",
@@ -2845,6 +2886,8 @@
@@ -2833,7 +2875,7 @@

size_t i;

- struct image_partition_entry parts[7] = {};
+ struct image_partition_entry parts[8] = {};

struct flash_partition_entry *firmware_partition = NULL;
struct flash_partition_entry *os_image_partition = NULL;
@@ -2845,6 +2887,9 @@
const uint8_t extra_para[2] = {0x01, 0x01};
parts[5] = make_extra_para(info, extra_para,
sizeof(extra_para));
+ } else if (strcasecmp(info->id, "TL-WPA8630P-V2-FULLMEM") == 0) {
+ parts[5] = read_file("default-mac", "../../../../../default-mac", false, NULL);
+ parts[5] = read_file("fs-uboot", "../../../../extra/fs-uboot", false, NULL);
+ parts[6] = read_file("default-mac", "../../../../extra/default-mac", false, NULL);
}

size_t len;

--- a/target/linux/ath79/image/generic-tp-link.mk
+++ b/target/linux/ath79/image/generic-tp-link.mk
@@ -617,6 +617,14 @@
@@ -617,6 +617,17 @@
endef
TARGET_DEVICES += tplink_tl-wpa8630p-v2.1-eu
TARGET_DEVICES += tplink_tl-wpa8630-v1

+define Device/tplink_tl-wpa8630p-v2-fullmem
+ $(Device/tplink_tl-wpa8630p-v2)
+ IMAGE_SIZE := 7983k
+ $(Device/tplink-safeloader)
+ SOC := qca9563
+ IMAGE_SIZE := 7808k
+ DEVICE_MODEL := TL-WPA8630P
+ DEVICE_VARIANT := v2 (FULLMEM)
+ DEVICE_PACKAGES := kmod-ath10k-ct ath10k-firmware-qca9888-ct
+ TPLINK_BOARD_ID := TL-WPA8630P-V2-FULLMEM
+endef
+TARGET_DEVICES += tplink_tl-wpa8630p-v2-fullmem
+
define Device/tplink_tl-wr1043nd-v1
$(Device/tplink-8m)
SOC := ar9132
--- a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -230,6 +230,7 @@
tplink,eap225-outdoor-v1|\
tplink,eap225-v3|\
tplink,eap225-wall-v2|\
+ tplink,tl-wpa8630p-v2-fullmem|\
tplink,tl-wpa8630p-v2-int|\
tplink,tl-wpa8630p-v2.0-eu|\
tplink,tl-wpa8630p-v2.1-eu)
--- a/target/linux/ath79/generic/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/generic/base-files/etc/board.d/02_network
@@ -373,6 +373,7 @@
@@ -382,7 +382,8 @@
ucidef_add_switch "switch0" \
"0@eth0" "1:lan:1" "2:lan:3" "3:lan:2"
;;
tplink,tl-wpa8630-v1|\
+ tplink,tl-wpa8630p-v2-fullmem|\
tplink,tl-wpa8630p-v2-int|\
tplink,tl-wpa8630p-v2.0-eu|\
tplink,tl-wpa8630p-v2.1-eu)
- tplink,tl-wpa8630-v1)
+ tplink,tl-wpa8630-v1|\
+ tplink,tl-wpa8630p-v2-fullmem)
# port 5 (internal) is the power-line port
ucidef_add_switch "switch0" \
"0@eth0" "2:lan:3" "3:lan:2" "4:lan:1" "5:lan:4"
--- a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -228,7 +228,8 @@
;;
tplink,eap225-outdoor-v1|\
tplink,eap225-v3|\
- tplink,eap225-wall-v2)
+ tplink,eap225-wall-v2|\
+ tplink,tl-wpa8630p-v2-fullmem)
caldata_extract "art" 0x5000 0x2f20
ath10k_patch_mac $(macaddr_add $(mtd_get_mac_binary info 0x8) +1)
ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
--- /dev/null
+++ b/target/linux/ath79/dts/qca9563_tplink_tl-wpa8630p-v2-fullmem.dts
@@ -0,0 +1,52 @@
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "qca9563_tplink_tl-wpa8630.dtsi"
Expand All @@ -118,9 +135,15 @@
+ };
+
+ partition@20000 {
+ label = "u-boot";
+ reg = <0x020000 0x020000>;
+ read-only;
+ };
+
+ partition@40000 {
+ compatible = "tplink,firmware";
+ label = "firmware";
+ reg = <0x020000 0x7c0000>;
+ reg = <0x040000 0x7a0000>;
+ };
+
+ partition@7e0000 {
Expand All @@ -132,7 +155,6 @@
+ info: partition@7e4000 {
+ label = "info";
+ reg = <0x7e4000 0x000020>;
+ read-only;
+ };
+
+ art: partition@7f0000 {
Expand Down
8 changes: 8 additions & 0 deletions src/gen_default_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -ex

# Generate a "default-mac" partition for TL-WPA8630P v2.0

printf '%b' '\x00\x00\x00\x06\x00\x00\x00\x00' > default-mac
printf '%b' '\x02\xBC\xDE\x39\xE8\x32' | dd of=default-mac oflag=seek_bytes seek=8 conv=notrunc
hexdump -C default-mac
16 changes: 16 additions & 0 deletions src/get_stock_fs_uboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -ex

# Extract "fs-uboot" from an OEM firmware release that loads "os-image" from 0x40000.
# Hardware Model: TP-Link TL-WPA8630P(AU) v2.0
# Firmware Version: 2.0.0 Build 20170608 Rel.64411

curl $CURL_OPTS --fail -LO "https://static.tp-link.com/TL-WPA8630P%20KIT(AU)_V2_170608.zip"
filemd5="$(md5sum 'TL-WPA8630P%20KIT(AU)_V2_170608.zip' | awk '{print $1}')"
if [ "$filemd5" != "1cb80fb680d8189076ecec4011ea9355" ]; then
echo "Error: Invalid md5sum" 1>&2
exit 1
fi
unzip -j "TL-WPA8630P%20KIT(AU)_V2_170608.zip" "*.bin"
dd if="wpa8630pv2_au-up-ver2-0-0-P1-20170608-rel64411-APPLC.bin" of="fs-uboot" iflag=skip_bytes skip=8272 bs=68076 count=1
rm -f "TL-WPA8630P%20KIT(AU)_V2_170608.zip" "wpa8630pv2_au-up-ver2-0-0-P1-20170608-rel64411-APPLC.bin"

0 comments on commit 02e0fcc

Please sign in to comment.