[][MAC80211][Hacking MT76 Makefile]

[Description]
Add hacking MT76 Makefile to support new chips (MT7986/Bersa)
The patch files is based on Openwrt trunk's mt76 package only

[Release-log]
N/A

Change-Id: I51e97660cf6a399f1e5ee7e168f6b8cb29d12236
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/5784804
diff --git a/autobuild_mac80211_release/0003-master-mt76-makefile-for-new-chip.patch b/autobuild_mac80211_release/0003-master-mt76-makefile-for-new-chip.patch
new file mode 100644
index 0000000..e622f89
--- /dev/null
+++ b/autobuild_mac80211_release/0003-master-mt76-makefile-for-new-chip.patch
@@ -0,0 +1,113 @@
+From 80c0f2a42e6a44fb11c4256848d85c9f8f552eb7 Mon Sep 17 00:00:00 2001
+From: Evelyn Tsai <evelyn.tsai@mediatek.com>
+Date: Mon, 21 Mar 2022 10:27:08 +0800
+Subject: [PATCH] mt76: add MT7986/MT7916/Bersa support in makefile
+
+---
+ Makefile | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 61 insertions(+), 1 deletion(-)
+
+diff --git a/package/kernel/mt76/Makefile b/package/kernel/mt76/Makefile
+index d683059..bf1db07 100644
+--- a/package/kernel/mt76/Makefile
++++ b/package/kernel/mt76/Makefile
+@@ -220,12 +220,20 @@ endef
+ 
+ define KernelPackage/mt7915e
+   $(KernelPackage/mt76-default)
+-  TITLE:=MediaTek MT7915e wireless driver
++  TITLE:=MediaTek MT7915e/MT7986/MT7916 wireless driver
+   DEPENDS+=@PCI_SUPPORT +kmod-mt7615-common +kmod-hwmon-core +kmod-thermal +@DRIVER_11AX_SUPPORT +@KERNEL_RELAY
+   FILES:= $(PKG_BUILD_DIR)/mt7915/mt7915e.ko
+   AUTOLOAD:=$(call AutoProbe,mt7915e)
+ endef
+ 
++define KernelPackage/bersa
++  $(KernelPackage/mt76-default)
++  TITLE:=MediaTek MT7902/MT7990 wireless driver
++  DEPENDS+=@PCI_SUPPORT +kmod-mt76-core +kmod-mt76-connac +kmod-hwmon-core +kmod-thermal +@DRIVER_11AX_SUPPORT
++  FILES:= $(PKG_BUILD_DIR)/bersa/bersa.ko
++  AUTOLOAD:=$(call AutoProbe,bersa)
++endef
++
+ define KernelPackage/mt7921-common
+   $(KernelPackage/mt76-default)
+   TITLE:=MediaTek MT7615 wireless driver common code
+@@ -281,6 +289,11 @@ ifdef CONFIG_PACKAGE_MAC80211_MESH
+   NOSTDINC_FLAGS += -DCONFIG_MAC80211_MESH
+ endif
+ 
++ifdef CONFIG_PACKAGE_MAC80211_DEBUGFS
++  NOSTDINC_FLAGS += -DCONFIG_MAC80211_DEBUGFS
++  PKG_MAKE_FLAGS += CONFIG_MAC80211_DEBUGFS=y
++endif
++
+ ifdef CONFIG_PACKAGE_CFG80211_TESTMODE
+   NOSTDINC_FLAGS += -DCONFIG_NL80211_TESTMODE
+   PKG_MAKE_FLAGS += CONFIG_NL80211_TESTMODE=y
+@@ -343,6 +356,13 @@ ifdef CONFIG_PACKAGE_kmod-mt7663u
+ endif
+ ifdef CONFIG_PACKAGE_kmod-mt7915e
+   PKG_MAKE_FLAGS += CONFIG_MT7915E=m
++ifdef CONFIG_TARGET_mediatek_mt7986
++  PKG_MAKE_FLAGS += CONFIG_MT7986_WMAC=y
++  NOSTDINC_FLAGS += -DCONFIG_MT7986_WMAC
++endif
++endif
++ifdef CONFIG_PACKAGE_kmod-bersa
++  PKG_MAKE_FLAGS += CONFIG_BERSA=m
+ endif
+ ifdef CONFIG_PACKAGE_kmod-mt7921-common
+   PKG_MAKE_FLAGS += CONFIG_MT7921_COMMON=m
+@@ -447,8 +467,48 @@ define KernelPackage/mt7915e/install
+ 		$(PKG_BUILD_DIR)/firmware/mt7915_wa.bin \
+ 		$(PKG_BUILD_DIR)/firmware/mt7915_wm.bin \
+ 		$(PKG_BUILD_DIR)/firmware/mt7915_rom_patch.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7916_wa.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7916_wm.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7916_rom_patch.bin \
++		$(1)/lib/firmware/mediatek
++ifdef CONFIG_TARGET_mediatek_mt7986
++	cp \
++		$(PKG_BUILD_DIR)/firmware/mt7986_wa.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_wm.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_wm_mt7975.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_rom_patch.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_rom_patch_mt7975.bin \
+ 		$(1)/lib/firmware/mediatek
++endif
++	cp \
++		$(PKG_BUILD_DIR)/firmware/mt7916_eeprom.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7915_eeprom.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7915_eeprom_dbdc.bin \
++		$(1)/lib/firmware/mediatek
++ifdef CONFIG_TARGET_mediatek_mt7986
++	cp \
++		$(PKG_BUILD_DIR)/firmware/mt7986_eeprom_mt7976_dual.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_eeprom_mt7976.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_eeprom_mt7976_dbdc.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_eeprom_mt7975_dual.bin \
++		$(PKG_BUILD_DIR)/firmware/mt7986_eeprom_mt7975.bin \
++		$(1)/lib/firmware/mediatek
++endif
++endef
++
++ifdef CONFIG_PACKAGE_kmod-bersa
++define KernelPackage/bersa/install
++        $(INSTALL_DIR) $(1)/lib/firmware/mediatek
++        cp \
++                $(PKG_BUILD_DIR)/firmware/mt7902_wa.bin \
++                $(PKG_BUILD_DIR)/firmware/mt7902_wm.bin \
++                $(PKG_BUILD_DIR)/firmware/mt7902_rom_patch.bin \
++                $(PKG_BUILD_DIR)/firmware/mt7902_wf_rom.bin \
++                $(PKG_BUILD_DIR)/firmware/mt7902_wf_rom_sram.bin \
++                $(PKG_BUILD_DIR)/firmware/mt7902_eeprom.bin \
++                $(1)/lib/firmware/mediatek
+ endef
++endif
+ 
+ define KernelPackage/mt7921e/install
+ 	$(INSTALL_DIR) $(1)/lib/firmware/mediatek
+-- 
+2.29.2
+
diff --git a/autobuild_mac80211_release/default_bins/mt7915_eeprom.bin b/autobuild_mac80211_release/default_bins/mt7915_eeprom.bin
new file mode 100644
index 0000000..007df1b
--- /dev/null
+++ b/autobuild_mac80211_release/default_bins/mt7915_eeprom.bin
Binary files differ
diff --git a/autobuild_mac80211_release/default_bins/mt7915_eeprom_dbdc.bin b/autobuild_mac80211_release/default_bins/mt7915_eeprom_dbdc.bin
new file mode 100644
index 0000000..6c0b64e
--- /dev/null
+++ b/autobuild_mac80211_release/default_bins/mt7915_eeprom_dbdc.bin
Binary files differ
diff --git a/autobuild_mac80211_release/default_bins/mt7916_eeprom.bin b/autobuild_mac80211_release/default_bins/mt7916_eeprom.bin
new file mode 100644
index 0000000..35b287c
--- /dev/null
+++ b/autobuild_mac80211_release/default_bins/mt7916_eeprom.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_iPAiLNA_EEPROM_AX7800.bin b/autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7975.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_iPAiLNA_EEPROM_AX7800.bin
rename to autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7975.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_iPAiLNA_EEPROM_AX6000.bin b/autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7975_dual.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_iPAiLNA_EEPROM_AX6000.bin
rename to autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7975_dual.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_ePAeLNA_EEPROM_AX7800.bin b/autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7976.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_ePAeLNA_EEPROM_AX7800.bin
rename to autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7976.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_ePAeLNA_EEPROM_ONEADIE_DBDC.bin b/autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7976_dbdc.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_ePAeLNA_EEPROM_ONEADIE_DBDC.bin
rename to autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7976_dbdc.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_ePAeLNA_EEPROM_AX6000.bin b/autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7976_dual.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/MT7986_ePAeLNA_EEPROM_AX6000.bin
rename to autobuild_mac80211_release/default_bins/mt7986_eeprom_mt7976_dual.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7622_mt7915_mac80211/lede-branch-build-sanity.sh b/autobuild_mac80211_release/mt7622_mt7915_mac80211/lede-branch-build-sanity.sh
index dc741ee..a5ae07f 100755
--- a/autobuild_mac80211_release/mt7622_mt7915_mac80211/lede-branch-build-sanity.sh
+++ b/autobuild_mac80211_release/mt7622_mt7915_mac80211/lede-branch-build-sanity.sh
@@ -41,8 +41,15 @@
 
 prepare_final ${branch_name}
 
-#apply hostapd patch
+#copy mt7915/mt7916/mt7986 default eeprom
+FW_SOURCE_DIR=${BUILD_DIR}/package/kernel/mt76/src/firmware
+mkdir -p ${FW_SOURCE_DIR}
+cp -rf ../mtk-openwrt-feeds/autobuild_mac80211_release/default_bins/* ${FW_SOURCE_DIR}
+
+#hack hostapd/mac80211/mt76 package in master branch
 patch -f -p1 -i ${BUILD_DIR}/autobuild/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch
 patch -f -p1 -i ${BUILD_DIR}/autobuild/0002-master-hostapd-makefile-for-utils.patch
+patch -f -p1 -i ${BUILD_DIR}/autobuild/0003-master-mt76-makefile-for-new-chip.patch
+
 #step2 build
 build ${branch_name} -j1 || [ "$LOCAL" != "1" ]
diff --git a/autobuild_mac80211_release/mt7986_mac80211/lede-branch-build-sanity.sh b/autobuild_mac80211_release/mt7986_mac80211/lede-branch-build-sanity.sh
index c62e55e..817a585 100755
--- a/autobuild_mac80211_release/mt7986_mac80211/lede-branch-build-sanity.sh
+++ b/autobuild_mac80211_release/mt7986_mac80211/lede-branch-build-sanity.sh
@@ -25,7 +25,7 @@
 #use hostapd master package revision, remove hostapd 2102 patches
 find ../mtk-openwrt-feeds/openwrt_patches-21.02 -name "*-2102-hostapd-*.patch" -delete
 
-#use mt76 lastest commit, remove mt76 master patches
+#have MT7986 specific non-upstream patches, remove feeds mt76 master patches
 find ../mtk-openwrt-feeds/openwrt_patches-21.02 -name "*-master-mt76-*.patch" -delete
 
 #step1 clean
@@ -44,40 +44,18 @@
 echo "CONFIG_WPS_UPNP=y"  >> ./package/network/services/hostapd/files/hostapd-full.config
 
 prepare_final ${branch_name}
-#hack mt76 firmware/eeprom
-FW_BIN_DIR=${BUILD_DIR}/package/kernel/mt76/firmware/mt7986/rebb
+
+#copy mt7915/mt7916/mt7986 default eeprom
 FW_SOURCE_DIR=${BUILD_DIR}/package/kernel/mt76/src/firmware
 mkdir -p ${FW_SOURCE_DIR}
-#===================firmware bin name format=========================
-#define MT7915_FIRMWARE_WA		"mediatek/mt7915_wa.bin"
-#define MT7915_FIRMWARE_WM		"mediatek/mt7915_wm.bin"
-#define MT7915_ROM_PATCH		"mediatek/mt7915_rom_patch.bin"
-#define MT7986_FIRMWARE_WA		"mediatek/mt7986_wa.bin"
-#define MT7986_FIRMWARE_WM		"mediatek/mt7986_wm.bin"
-#define MT7986_FIRMWARE_WM_MT7975	"mediatek/mt7986_wm_mt7975.bin"
-#define MT7986_ROM_PATCH		"mediatek/mt7986_rom_patch.bin"
-#define MT7986_ROM_PATCH_MT7975		"mediatek/mt7986_rom_patch_mt7975.bin"
-cp -rf ${FW_BIN_DIR}/7986_WACPU_RAM_CODE_release.bin ${FW_SOURCE_DIR}/mt7986_wa.bin
-cp -rf ${FW_BIN_DIR}/WIFI_RAM_CODE_MT7986.bin ${FW_SOURCE_DIR}/mt7986_wm.bin
-cp -rf ${FW_BIN_DIR}/mt7986_patch_e1_hdr.bin ${FW_SOURCE_DIR}/mt7986_rom_patch.bin
-cp -rf ${FW_BIN_DIR}/WIFI_RAM_CODE_MT7986_MT7975.bin ${FW_SOURCE_DIR}/mt7986_wm_mt7975.bin
-cp -rf ${FW_BIN_DIR}/mt7986_patch_e1_hdr_mt7975.bin ${FW_SOURCE_DIR}/mt7986_rom_patch_mt7975.bin
+cp -rf ../mtk-openwrt-feeds/autobuild_mac80211_release/default_bins/* ${FW_SOURCE_DIR}
+cp -rf ../mtk-openwrt-feeds/autobuild_mac80211_release/default_bins/* ${FW_SOURCE_DIR}/src/firmware/
 
-#===================eeprom bin name format=========================
-#define MT7986_EEPROM_MT7975_DEFAULT		"mediatek/mt7986_eeprom_mt7975.bin"
-#define MT7986_EEPROM_MT7975_DUAL_DEFAULT	"mediatek/mt7986_eeprom_mt7975_dual.bin"
-#define MT7986_EEPROM_MT7976_DEFAULT		"mediatek/mt7986_eeprom_mt7976.bin"
-#define MT7986_EEPROM_MT7976_DEFAULT_DBDC	"mediatek/mt7986_eeprom_mt7976_dbdc.bin"
-#define MT7986_EEPROM_MT7976_DUAL_DEFAULT	"mediatek/mt7986_eeprom_mt7976_dual.bin"
-cp -rf ${FW_BIN_DIR}/MT7986_iPAiLNA_EEPROM_AX7800.bin ${FW_SOURCE_DIR}/mt7986_eeprom_mt7975.bin
-cp -rf ${FW_BIN_DIR}/MT7986_iPAiLNA_EEPROM_AX6000.bin ${FW_SOURCE_DIR}/mt7986_eeprom_mt7975_dual.bin
-cp -rf ${FW_BIN_DIR}/MT7986_ePAeLNA_EEPROM_AX7800.bin ${FW_SOURCE_DIR}/mt7986_eeprom_mt7976.bin
-cp -rf ${FW_BIN_DIR}/MT7986_ePAeLNA_EEPROM_ONEADIE_DBDC.bin ${FW_SOURCE_DIR}/mt7986_eeprom_mt7976_dbdc.bin
-cp -rf ${FW_BIN_DIR}/MT7986_ePAeLNA_EEPROM_AX6000.bin ${FW_SOURCE_DIR}/mt7986_eeprom_mt7976_dual.bin
-
-#apply hostapd patch
+#hack hostapd/mac80211/mt76 package in master branch
 patch -f -p1 -i ${BUILD_DIR}/autobuild/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch
 patch -f -p1 -i ${BUILD_DIR}/autobuild/0002-master-hostapd-makefile-for-utils.patch
+patch -f -p1 -i ${BUILD_DIR}/autobuild/0003-master-mt76-makefile-for-new-chip.patch
+
 #step2 build
 if [ -z ${1} ]; then
 	build ${branch_name} -j1 || [ "$LOCAL" != "1" ]
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7915_wa.bin b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7915_wa.bin
new file mode 100644
index 0000000..434e757
--- /dev/null
+++ b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7915_wa.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7915_wm.bin b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7915_wm.bin
new file mode 100644
index 0000000..fef6005
--- /dev/null
+++ b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7915_wm.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/mt7986_patch_e1_hdr.bin b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_rom_patch.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/mt7986_patch_e1_hdr.bin
rename to autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_rom_patch.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/mt7986_patch_e1_hdr_mt7975.bin b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_rom_patch_mt7975.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/mt7986_patch_e1_hdr_mt7975.bin
rename to autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_rom_patch_mt7975.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/7986_WACPU_RAM_CODE_release.bin b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_wa.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/7986_WACPU_RAM_CODE_release.bin
rename to autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_wa.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/WIFI_RAM_CODE_MT7986.bin b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_wm.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/WIFI_RAM_CODE_MT7986.bin
rename to autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_wm.bin
Binary files differ
diff --git a/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/WIFI_RAM_CODE_MT7986_MT7975.bin b/autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_wm_mt7975.bin
similarity index 100%
rename from autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/firmware/mt7986/rebb/WIFI_RAM_CODE_MT7986_MT7975.bin
rename to autobuild_mac80211_release/mt7986_mac80211/package/kernel/mt76/src/firmware/mt7986_wm_mt7975.bin
Binary files differ