/dts-v1/; /include/ "vr9.dtsi" / { model = "FRITZ3370 - Fritz!Box WLAN 3370"; chosen { bootargs = "console=ttyLTQ0,115200 ubi.mtd=1,512 root=/dev/mtdblock9"; }; memory@0 { reg = <0x0 0x8000000>; }; fpi@10000000 { localbus@0 { nand-parts@0 { compatible = "gen_nand", "lantiq,nand-xway"; bank-width = <2>; reg = <1 0x0 0x2000000>; #address-cells = <1>; #size-cells = <1>; partition@0 { label = "kernel"; reg = <0x0 0x400000>; }; partition@400000 { label = "rootfs_ubi"; reg = <0x400000 0x3000000>; }; partition@3400000 { label = "vr9_firmware"; reg = <0x3400000 0x400000>; }; partition@3800000 { label = "reserved"; reg = <0x3800000 0x3000000>; }; partition@6800000 { label = "config"; reg = <0x6800000 0x200000>; }; partition@6a00000 { label = "nand-filesystem"; reg = <0x6a00000 0x1600000>; }; }; }; gpio: pinmux@E100B10 { pinctrl-names = "default"; pinctrl-0 = <&state_default>; state_default: pinmux { spi { lantiq,groups = "spi", "spi_cs4"; lantiq,function = "gpio"; }; mdio { lantiq,groups = "mdio"; lantiq,function = "mdio"; }; nand { lantiq,groups = "nand cle", "nand ale", "nand rd", "nand cs1", "nand rdy"; lantiq,function = "ebu"; lantiq,pull = <1>; }; phy-rst { lantiq,pins = "io37", "io44"; lantiq,pull = <0>; lantiq,open-drain = <0>; lantiq,output = <1>; }; pcie-rst { lantiq,pins = "io38"; lantiq,pull = <0>; lantiq,output = <1>; }; }; }; eth@E108000 { #address-cells = <1>; #size-cells = <0>; compatible = "lantiq,xrx200-net"; reg = < 0xE108000 0x3000 /* switch */ 0xE10B100 0x70 /* mdio */ 0xE10B1D8 0x30 /* mii */ 0xE10B308 0x30 /* pmac */ >; interrupt-parent = <&icu0>; interrupts = <73 72>; lan: interface@0 { compatible = "lantiq,xrx200-pdi"; #address-cells = <1>; #size-cells = <0>; reg = <0>; mac-address = [ 00 11 22 33 44 55 ]; lantiq,switch; ethernet@0 { compatible = "lantiq,xrx200-pdi-port"; reg = <0>; phy-mode = "rgmii"; phy-handle = <&phy0>; gpios = <&gpio 37 0>; }; ethernet@1 { compatible = "lantiq,xrx200-pdi-port"; reg = <1>; phy-mode = "rgmii"; phy-handle = <&phy1>; gpios = <&gpio 44 0>; }; ethernet@2 { compatible = "lantiq,xrx200-pdi-port"; reg = <2>; phy-mode = "gmii"; phy-handle = <&phy11>; }; ethernet@3 { compatible = "lantiq,xrx200-pdi-port"; reg = <4>; phy-mode = "gmii"; phy-handle = <&phy13>; }; }; mdio@0 { #address-cells = <1>; #size-cells = <0>; compatible = "lantiq,xrx200-mdio"; phy0: ethernet-phy@0 { reg = <0x0>; compatible = "lantiq,phy11g", "ethernet-phy-ieee802.3-c22"; }; phy1: ethernet-phy@1 { reg = <0x1>; compatible = "lantiq,phy11g", "ethernet-phy-ieee802.3-c22"; }; phy11: ethernet-phy@11 { reg = <0x11>; compatible = "lantiq,phy11g", "ethernet-phy-ieee802.3-c22"; }; phy13: ethernet-phy@13 { reg = <0x13>; compatible = "lantiq,phy11g", "ethernet-phy-ieee802.3-c22"; }; }; }; ifxhcd@E101000 { status = "okay"; gpios = <&gpio 5 0 &gpio 14 0>; lantiq,portmask = <0x3>; }; }; spi { #address-cells = <1>; #size-cells = <1>; compatible = "spi-gpio"; gpio-miso = <&gpio 16 0>; gpio-mosi = <&gpio 17 0>; gpio-sck = <&gpio 18 0>; num-chipselects = <1>; cs-gpios = <&gpio 10 1>; m25p80@0 { #address-cells = <1>; #size-cells = <1>; compatible = "mx25l2005a"; reg = <0 0>; linux,modalias = "m25p80", "mx25l2005a"; spi-max-frequency = <1000000>; ath9k_cal: partition@0 { reg = <0x0 0x20000>; label = "urlader"; read-only; }; partition@20000 { reg = <0x20000 0x10000>; label = "tffs (1)"; read-only; }; partition@30000 { reg = <0x30000 0x10000>; label = "tffs (2)"; read-only; }; }; }; ath9k_eep { compatible = "ath9k,eeprom"; ath,eep-flash = <&ath9k_cal 0x985>; ath,eep-endian; ath,eep-swap; }; gphy-xrx200 { compatible = "lantiq,phy-xrx200"; firmware = "lantiq/vr9_phy11g_a1x.bin"; phys = [ 00 01 ]; }; gpio-keys-polled { compatible = "gpio-keys-polled"; #address-cells = <1>; #size-cells = <0>; poll-interval = <100>; power { label = "power"; gpios = <&gpio 1 0>; linux,code = <0x100>; }; /* wifi { label = "wifi"; gpios = <&gpio 29 0>; linux,code = <0x101>; };*/ }; gpio-leds { compatible = "gpio-leds"; power { label = "power"; gpios = <&gpio 32 1>; }; power2 { label = "power2"; gpios = <&gpio 33 1>; }; info_red { label = "info_red"; gpios = <&gpio 34 1>; }; wifi { label = "wifi"; gpios = <&gpio 35 1>; }; dsl { label = "dsl"; gpios = <&gpio 36 1>; }; lan { label = "lan"; gpios = <&gpio 38 1>; }; info_green { label = "info_green"; gpios = <&gpio 47 1>; }; }; }; ='#n54'>54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
DTS_DIR := $(DTS_DIR)/mediatek

ifdef CONFIG_LINUX_5_4
  KERNEL_LOADADDR := 0x44080000
else
  KERNEL_LOADADDR := 0x44000000
endif

define Image/Prepare
	# For UBI we want only one extra block
	rm -f $(KDIR)/ubi_mark
	echo -ne '\xde\xad\xc0\xde' > $(KDIR)/ubi_mark
endef

define Build/buffalo-kernel-trx
	$(eval magic=$(word 1,$(1)))
	$(eval dummy=$(word 2,$(1)))
	$(eval kern_size=$(if $(KERNEL_SIZE),$(KERNEL_SIZE),0x400000))

	$(if $(dummy),touch $(dummy))
	$(STAGING_DIR_HOST)/bin/otrx create $@.new \
		$(if $(magic),-M $(magic),) \
		-f $@ \
		$(if $(dummy),\
			-a 0x20000 \
			-b $$(( $(subst k, * 1024,$(kern_size)) )) \
			-f $(dummy),)
	mv $@.new $@
endef

define Build/bl2
	cat $(STAGING_DIR_IMAGE)/mt7622-$1-bl2.img >> $@
endef

define Build/bl31-uboot
	cat $(STAGING_DIR_IMAGE)/mt7622_$1-u-boot.fip >> $@
endef

define Build/mt7622-gpt
	cp $@ $@.tmp 2>/dev/null || true
	ptgen -g -o $@.tmp -a 1 -l 1024 \
		$(if $(findstring sdmmc,$1), \
			-H \
			-t 0x83	-N bl2		-r	-p 512k@512k \
		) \
			-t 0xef	-N fip		-r	-p 2M@2M \
			-t 0x83	-N ubootenv	-r	-p 1M@4M \
				-N recovery	-r	-p 32M@6M \
		$(if $(findstring sdmmc,$1), \
				-N install	-r	-p 7M@38M \
			-t 0x2e -N production		-p $(CONFIG_TARGET_ROOTFS_PARTSIZE)M@45M \
		) \
		$(if $(findstring emmc,$1), \
			-t 0x2e -N production		-p $(CONFIG_TARGET_ROOTFS_PARTSIZE)M@40M \
		)
	cat $@.tmp >> $@
	rm $@.tmp
endef

define Build/trx-nand
	# kernel: always use 4 MiB (-28 B or TRX header) to allow upgrades even
	#	  if it grows up between releases
	# root: UBI with one extra block containing UBI mark to trigger erasing
	#	rest of partition
	$(STAGING_DIR_HOST)/bin/otrx create $@.new \
		-M 0x32504844 \
		-f $(IMAGE_KERNEL) -a 0x20000 -b 0x400000 \
		-f $@ \
		-A $(KDIR)/ubi_mark -a 0x20000
	mv $@.new $@
endef

define Device/bananapi_bpi-r64
  DEVICE_VENDOR := Bananapi
  DEVICE_MODEL := BPi-R64
  DEVICE_DTS := mt7622-bananapi-bpi-r64
  DEVICE_DTS_OVERLAY := mt7622-bananapi-bpi-r64-pcie1 mt7622-bananapi-bpi-r64-sata
  DEVICE_PACKAGES := kmod-ata-ahci-mtk kmod-btmtkuart kmod-usb3 e2fsprogs mkf2fs f2fsck
  ARTIFACTS := emmc-preloader.bin emmc-bl31-uboot.fip sdcard.img.gz snand-preloader.bin snand-bl31-uboot.fip
  IMAGES := sysupgrade.itb
  KERNEL_INITRAMFS_SUFFIX := -recovery.itb
  ARTIFACT/emmc-preloader.bin	:= bl2 emmc-2ddr
  ARTIFACT/emmc-bl31-uboot.fip	:= bl31-uboot bananapi_bpi-r64-emmc
  ARTIFACT/snand-preloader.bin	:= bl2 snand-2ddr
  ARTIFACT/snand-bl31-uboot.fip	:= bl31-uboot bananapi_bpi-r64-snand
  ARTIFACT/sdcard.img.gz	:= mt7622-gpt sdmmc |\
				   pad-to 512k | bl2 sdmmc-2ddr |\
				   pad-to 2048k | bl31-uboot bananapi_bpi-r64-sdmmc |\
				$(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),\
				   pad-to 6144k | append-image-stage initramfs-recovery.itb | check-size 38912k |\
				) \
				   pad-to 38912k | mt7622-gpt emmc |\
				   pad-to 39424k | bl2 emmc-2ddr |\
				   pad-to 40960k | bl31-uboot bananapi_bpi-r64-emmc |\
				   pad-to 43008k | bl2 snand-2ddr |\
				   pad-to 43520k | bl31-uboot bananapi_bpi-r64-snand |\
				$(if $(CONFIG_TARGET_ROOTFS_SQUASHFS),\
				   pad-to 46080k | append-image squashfs-sysupgrade.itb | check-size | gzip \
				)
  IMAGE_SIZE := $$(shell expr 45 + $$(CONFIG_TARGET_ROOTFS_PARTSIZE))m
  KERNEL			:= kernel-bin | gzip
  KERNEL_INITRAMFS		:= kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb with-initrd | pad-to 128k
  IMAGE/sysupgrade.itb		:= append-kernel | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb external-static-with-rootfs | append-metadata
endef
TARGET_DEVICES += bananapi_bpi-r64

define Device/buffalo_wsr-2533dhp2
  DEVICE_VENDOR := Buffalo
  DEVICE_MODEL := WSR-2533DHP2
  DEVICE_DTS := mt7622-buffalo-wsr-2533dhp2
  DEVICE_DTS_DIR := ../dts
  IMAGE_SIZE := 59392k
  KERNEL_SIZE := 4096k
  BLOCKSIZE := 128k
  PAGESIZE := 2048
  SUBPAGESIZE := 512
  UBINIZE_OPTS := -E 5
  BUFFALO_TAG_PLATFORM := MTK
  BUFFALO_TAG_VERSION := 9.99
  BUFFALO_TAG_MINOR := 9.99
  IMAGES += factory.bin factory-uboot.bin
  KERNEL_INITRAMFS := kernel-bin | lzma | \
	fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | \
	buffalo-kernel-trx
  IMAGE/factory.bin := append-ubi | trx-nand | \
	buffalo-enc WSR-2533DHP2 $$(BUFFALO_TAG_VERSION) -l | \
	buffalo-tag-dhp WSR-2533DHP2 JP JP | buffalo-enc-tag -l | buffalo-dhp-image
  IMAGE/factory-uboot.bin := append-ubi | trx-nand
  IMAGE/sysupgrade.bin := append-kernel | \
	buffalo-kernel-trx 0x32504844 $(KDIR)/tmp/$$(DEVICE_NAME).null | \
	sysupgrade-tar kernel=$$$$@ | append-metadata
  DEVICE_PACKAGES := swconfig
endef
TARGET_DEVICES += buffalo_wsr-2533dhp2

define Device/elecom_wrc-2533gent
  DEVICE_VENDOR := Elecom
  DEVICE_MODEL := WRC-2533GENT
  DEVICE_DTS := mt7622-elecom-wrc-2533gent
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-btmtkuart kmod-usb3 swconfig
endef
TARGET_DEVICES += elecom_wrc-2533gent

define Device/linksys_e8450
  DEVICE_VENDOR := Linksys
  DEVICE_MODEL := E8450
  DEVICE_ALT0_VENDOR := Belkin
  DEVICE_ALT0_MODEL := RT3200
  DEVICE_DTS := mt7622-linksys-e8450
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-mt7915e kmod-usb3
endef
TARGET_DEVICES += linksys_e8450

define Device/linksys_e8450-ubi
  DEVICE_VENDOR := Linksys
  DEVICE_MODEL := E8450
  DEVICE_VARIANT := UBI
  DEVICE_ALT0_VENDOR := Belkin
  DEVICE_ALT0_MODEL := RT3200
  DEVICE_ALT0_VARIANT := UBI
  DEVICE_DTS := mt7622-linksys-e8450-ubi
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-mt7915e kmod-usb3
  UBINIZE_OPTS := -E 5
  BLOCKSIZE := 128k
  PAGESIZE := 2048
  UBOOTENV_IN_UBI := 1
  KERNEL_IN_UBI := 1
  KERNEL := kernel-bin | gzip
# recovery can also be used with stock firmware web-ui, hence the padding...
  KERNEL_INITRAMFS := kernel-bin | lzma | \
	fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 128k
  KERNEL_INITRAMFS_SUFFIX := -recovery.itb
  IMAGES := sysupgrade.itb
  IMAGE/sysupgrade.itb := append-kernel | fit gzip $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb external-static-with-rootfs | append-metadata
  ARTIFACTS := preloader.bin bl31-uboot.fip
  ARTIFACT/preloader.bin := bl2 snand-1ddr
  ARTIFACT/bl31-uboot.fip := bl31-uboot linksys_e8450
endef
TARGET_DEVICES += linksys_e8450-ubi

define Device/mediatek_mt7622-rfb1
  DEVICE_VENDOR := MediaTek
  DEVICE_MODEL := MTK7622 rfb1 AP
  DEVICE_DTS := mt7622-rfb1
  DEVICE_PACKAGES := kmod-ata-ahci-mtk kmod-btmtkuart kmod-usb3
endef
TARGET_DEVICES += mediatek_mt7622-rfb1

define Device/mediatek_mt7622-rfb1-ubi
  DEVICE_VENDOR := MediaTek
  DEVICE_MODEL := MTK7622 rfb1 AP (UBI)
  DEVICE_DTS := mt7622-rfb1-ubi
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-ata-ahci-mtk kmod-btmtkuart kmod-usb3
  BOARD_NAME := mediatek,mt7622-rfb1-ubi
  UBINIZE_OPTS := -E 5
  BLOCKSIZE := 128k
  PAGESIZE := 2048
  KERNEL_SIZE := 4194304
  IMAGE_SIZE := 32768k
  IMAGES += factory.bin
  IMAGE/factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | \
                check-size $$$$(IMAGE_SIZE)
  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
endef
TARGET_DEVICES += mediatek_mt7622-rfb1-ubi

define Device/ruijie_rg-ew3200gx-pro
  DEVICE_VENDOR := Ruijie
  DEVICE_MODEL := RG-EW3200GX PRO
  DEVICE_DTS := mt7622-ruijie-rg-ew3200gx-pro
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-mt7915e
endef
TARGET_DEVICES += ruijie_rg-ew3200gx-pro

define Device/totolink_a8000ru
  DEVICE_VENDOR := TOTOLINK
  DEVICE_MODEL := A8000RU
  DEVICE_DTS := mt7622-totolink-a8000ru
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := swconfig
  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
endef
TARGET_DEVICES += totolink_a8000ru

define Device/ubnt_unifi-6-lr-v1
  DEVICE_VENDOR := Ubiquiti
  DEVICE_MODEL := UniFi 6 LR
  DEVICE_VARIANT := v1
  DEVICE_DTS_CONFIG := config@1
  DEVICE_DTS := mt7622-ubnt-unifi-6-lr-v1
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-mt7915e kmod-leds-ubnt-ledbar
  SUPPORTED_DEVICES += ubnt,unifi-6-lr
endef
TARGET_DEVICES += ubnt_unifi-6-lr-v1

define Device/ubnt_unifi-6-lr-v1-ubootmod
  DEVICE_VENDOR := Ubiquiti
  DEVICE_MODEL := UniFi 6 LR
  DEVICE_VARIANT := v1 U-Boot mod
  DEVICE_DTS := mt7622-ubnt-unifi-6-lr-v1-ubootmod
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-mt7915e kmod-leds-ubnt-ledbar
  KERNEL := kernel-bin | lzma
  KERNEL_INITRAMFS_SUFFIX := -recovery.itb
  KERNEL_INITRAMFS := kernel-bin | lzma | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 64k
  IMAGES := sysupgrade.itb
  IMAGE/sysupgrade.itb := append-kernel | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb external-static-with-rootfs | pad-rootfs | append-metadata
  ARTIFACTS := preloader.bin bl31-uboot.fip
  ARTIFACT/preloader.bin := bl2 nor-2ddr
  ARTIFACT/bl31-uboot.fip := bl31-uboot ubnt_unifi-6-lr
  SUPPORTED_DEVICES += ubnt,unifi-6-lr-ubootmod
endef
TARGET_DEVICES += ubnt_unifi-6-lr-v1-ubootmod

define Device/ubnt_unifi-6-lr-v2
  DEVICE_VENDOR := Ubiquiti
  DEVICE_MODEL := UniFi 6 LR
  DEVICE_VARIANT := v2
  DEVICE_DTS_CONFIG := config@1
  DEVICE_DTS := mt7622-ubnt-unifi-6-lr-v2
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-mt7915e
endef
TARGET_DEVICES += ubnt_unifi-6-lr-v2

define Device/ubnt_unifi-6-lr-v2-ubootmod
  DEVICE_VENDOR := Ubiquiti
  DEVICE_MODEL := UniFi 6 LR
  DEVICE_VARIANT := v2 U-Boot mod
  DEVICE_DTS := mt7622-ubnt-unifi-6-lr-v2-ubootmod
  DEVICE_DTS_DIR := ../dts
  DEVICE_PACKAGES := kmod-mt7915e
  KERNEL := kernel-bin | lzma
  KERNEL_INITRAMFS_SUFFIX := -recovery.itb
  KERNEL_INITRAMFS := kernel-bin | lzma | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 64k
  IMAGES := sysupgrade.itb
  IMAGE/sysupgrade.itb := append-kernel | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb external-static-with-rootfs | pad-rootfs | append-metadata
  ARTIFACTS := preloader.bin bl31-uboot.fip
  ARTIFACT/preloader.bin := bl2 nor-2ddr
  ARTIFACT/bl31-uboot.fip := bl31-uboot ubnt_unifi-6-lr
endef
TARGET_DEVICES += ubnt_unifi-6-lr-v2-ubootmod

define Device/xiaomi_redmi-router-ax6s
  DEVICE_VENDOR := Xiaomi
  DEVICE_MODEL := Redmi Router AX6S
  DEVICE_ALT0_VENDOR := Xiaomi
  DEVICE_ALT0_MODEL := Router AX3200
  DEVICE_DTS := mt7622-xiaomi-redmi-router-ax6s
  DEVICE_DTS_DIR := ../dts
  BOARD_NAME := xiaomi,redmi-router-ax6s
  DEVICE_PACKAGES := kmod-mt7915e
  UBINIZE_OPTS := -E 5
  IMAGES += factory.bin
  BLOCKSIZE := 128k
  PAGESIZE := 2048
  KERNEL_SIZE := 4096k
  KERNEL_INITRAMFS_SUFFIX := -recovery.itb
  IMAGE/factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi
  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
endef
TARGET_DEVICES += xiaomi_redmi-router-ax6s