Adding new device - D-Link X530

Hi,
I recently got interested in OpenWrt and I'm trying to port a new device to be supported. It is a long way up for me of reading OpenWrt developer documentation and trying.

I have an pre-production sample of D-Link X530 with heavilly modified OpenWrt version.
This is the same main platform, as M30 (filogic, MT7981b).

By using serial console and initramfs firmware for M30 (it boots), I was able to get image of kernel partition and with some ChatGPT help :wink: extract the DTS file from it.

Then, I followed OpenWrt documentation to add it to the OpenWrt source tree in places when I saw M30, adjusting it a bit for flash layout and so on.:

Diff file
diff --git a/package/boot/uboot-envtools/files/mediatek_filogic b/package/boot/uboot-envtools/files/mediatek_filogic
index 1bf63d3061..fe2055b62b 100644
--- a/package/boot/uboot-envtools/files/mediatek_filogic
+++ b/package/boot/uboot-envtools/files/mediatek_filogic
@@ -104,6 +104,9 @@ dlink,aquila-pro-ai-m30-a1|\
 dlink,aquila-pro-ai-m60-a1)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000"
 	;;
+dlink,x530-a1)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x80000"
+	;;
 gatonetworks,gdsp)
 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
 	;;
diff --git a/target/linux/mediatek/filogic/base-files/etc/board.d/02_network b/target/linux/mediatek/filogic/base-files/etc/board.d/02_network
index f9bf2b1faf..57fccbebaa 100644
--- a/target/linux/mediatek/filogic/base-files/etc/board.d/02_network
+++ b/target/linux/mediatek/filogic/base-files/etc/board.d/02_network
@@ -110,6 +110,9 @@ mediatek_setup_interfaces()
 	dlink,aquila-pro-ai-m60-a1)
 		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" internet
 		;;
+	dlink,x530-a1)
+		ucidef_set_interfaces_lan_wan lan internet
+		;;
 	keenetic,kn-3911|\
 	smartrg,sdg-8622|\
 	smartrg,sdg-8632|\
diff --git a/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac b/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac
index b0b301559b..4a107940ec 100644
--- a/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac
+++ b/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac
@@ -97,6 +97,10 @@ case "$board" in
 		addr=$(mtd_get_mac_binary "Odm" 0x81)
 		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
 		;;
+	dlink,x530-a1)
+		addr=$(mtd_get_mac_binary "Odm" 0x95)
+		[ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
+		;;
 	glinet,gl-mt6000|\
 	glinet,gl-x3000|\
 	glinet,gl-xe3000)
diff --git a/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh
index 3cc8b91b74..ef5a6f5d3e 100755
--- a/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh
+++ b/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh
@@ -139,7 +139,8 @@ platform_do_upgrade() {
 		default_do_upgrade "$1"
 		;;
 	dlink,aquila-pro-ai-m30-a1|\
-	dlink,aquila-pro-ai-m60-a1)
+	dlink,aquila-pro-ai-m60-a1|\
+	dlink,x530-a1)
 		fw_setenv sw_tryactive 0
 		nand_do_upgrade "$1"
 		;;
diff --git a/target/linux/mediatek/image/filogic.mk b/target/linux/mediatek/image/filogic.mk
index 78e77ea28d..010fece3df 100644
--- a/target/linux/mediatek/image/filogic.mk
+++ b/target/linux/mediatek/image/filogic.mk
@@ -912,6 +912,26 @@ endif
 endef
 TARGET_DEVICES += dlink_aquila-pro-ai-m60-a1
 
+define Device/dlink_x530-a1
+  DEVICE_VENDOR := D-Link
+  DEVICE_MODEL := X530
+  DEVICE_VARIANT := A1
+  DEVICE_DTS := mt7981b-dlink-x530-a1
+  DEVICE_DTS_DIR := ../dts
+  DEVICE_PACKAGES := kmod-leds-gca230718 kmod-mt7915e kmod-mt7981-firmware mt7981-wo-firmware
+  KERNEL_IN_UBI := 1
+  IMAGE_SIZE := 51200k
+  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
+ifeq ($(IB),)
+ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
+  IMAGES += recovery.bin
+  IMAGE/recovery.bin := append-image-stage initramfs-kernel.bin | sysupgrade-tar kernel=$$$$@ |\
+    pad-to $$(IMAGE_SIZE) | dlink-ai-recovery-header DLK6E6110001 \x6A\x28\xEE\x0B \x00\x00\x2C\x00 \x00\x00\x20\x03 \x61\x6E
+endif
+endif
+endef
+TARGET_DEVICES += dlink_x530-a1
+
 define Device/edgecore_eap111
   DEVICE_VENDOR := Edgecore
   DEVICE_MODEL := EAP111

and also added an extracted DTS file to:

openwrt > target > linux > mediatek > dts > mt7981b-dlink-x530-a1.dts

https://pastebin.com/vWVkGNfj

The kernel compiled, but when it is booting, it freezes after "disabling unused clocks":
https://pastebin.com/FrcWXGvC

The kernel boots if I use

openwrt-24.10.4-mediatek-filogic-dlink_aquila-pro-ai-m30-a1-initramfs-kernel

https://pastebin.com/KCE91kt1

so obviously there is something that is wrong :wink:

From the last boot message I assume that the kernel disables the clock on which the CPU is running but this is only my guess, and I don't really know how to approach it further.
At the beginning I assumed that - because the hardware platform is different - lots of differences, including GPIO should be covered by the "right" DTS file, but obviously it was not enough.

How to go further from here?

You could've just used m30's DTS as base instead of that ChatGPT thing

Why?
The hardware design of x530 is different than m30. When the M30 firmware is booted, there's a lot of error from i2c bus, so the M30 DTS file is faulty by definition.
The one extracted from the original partition should be correct (or much closer) as it was purposely put there.

That DTS will not work on the spot, the include files for kernel DTS changed a lot since OEM firmware was made.
BUT
You can use that file as a reference to edit M30 DTS with correct GPIO-s , smbus, partition offsets etc.

Got your point. I just thought that these definitions embedded in DTS file were sort of kernel agnostic, as they describe the hardware itself, but apparently I was mistaken and some important updates to its specification were made over time.
I'll look into it closer.

1 Like