[Add script to ease sync from OpenWRT]

[Description]
Add script to ease sync from OpenWRT
1. cover mac80211/mt76/firmware sync

[Release-log]
N/A

diff --git a/scripts/filogic_sync_openwrt.sh b/scripts/filogic_sync_openwrt.sh
new file mode 100755
index 0000000..3862f90
--- /dev/null
+++ b/scripts/filogic_sync_openwrt.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+echo "clone.........."
+git clone --branch master https://gerrit.mediatek.inc/openwrt/lede mac80211_package
+git clone --branch openwrt-21.02 https://gerrit.mediatek.inc/openwrt/lede openwrt
+git clone --branch master https://gerrit.mediatek.inc/openwrt/feeds/mtk_openwrt_feeds
+git clone https://gerrit.mediatek.inc/gateway/rdk-b/meta-filogic
+
+echo "copy.........."
+mkdir -p mac80211_package/package/kernel/mt76/patches 
+cp openwrt/package/kernel/mt76/patches/100-Revert-of-net-pass-the-dst-buffer-to-of_get_mac_addr.patch mac80211_package/package/kernel/mt76/patches 
+cp -rfa mtk_openwrt_feeds/autobuild_mac80211_release/package/ mac80211_package/
+
+echo "gen mt76 patches.........."
+cp rdkb_inc_helper mac80211_package/package/kernel/mt76
+cd mac80211_package/package/kernel/mt76
+./rdkb_inc_helper patches
+mv patches.inc patches
+cd -
+rm -rf meta-filogic/recipes-kernel/linux-mt76/files/patches
+cp -rf mac80211_package/package/kernel/mt76/patches meta-filogic/recipes-kernel/linux-mt76/files/
+
+echo "gen mac80211 patches.........."
+cp rdkb_inc_helper mac80211_package/package/kernel/mac80211/patches
+cd mac80211_package/package/kernel/mac80211/patches
+./rdkb_inc_helper subsys/
+./rdkb_inc_helper build/
+mv subsys.inc subsys
+mv build.inc build
+mkdir patches
+cp -r subsys patches
+cp -r build patches
+cd -
+rm -rf meta-filogic/recipes-kernel/linux-mac80211/files/patches
+cp -rf mac80211_package/package/kernel/mac80211/patches/patches meta-filogic/recipes-kernel/linux-mac80211/files
+
+echo "copy mt76 firmware.........."
+rm -rf meta-filogic/recipes-kernel/linux-mt76/files/src
+cp -rf mac80211_package/package/kernel/mt76/src meta-filogic/recipes-kernel/linux-mt76/files/
+
+echo "Update bb file version.........."
+ver=`grep "PKG_SOURCE_VERSION" mac80211_package/package/kernel/mt76/Makefile | cut -c 21-`
+sed -i 's/SRCREV ?=.*/SRCREV ?= "'$ver'"/g' meta-filogic/recipes-kernel/linux-mt76/linux-mt76.bb
+ver2=`grep "PKG_VERSION:=" mac80211_package/package/kernel/mac80211/Makefile | cut -c 14-`
+sed -i 's/PV =.*/PV = "'${ver2%-*}'"/g' meta-filogic/recipes-kernel/linux-mac80211/linux-mac80211.bb
+ver3=`grep "PKG_HASH" mac80211_package/package/kernel/mac80211/Makefile | cut -c 11-`
+sed -i 's/SRC_URI\[sha256sum\].*/SRC_URI[sha256sum] = "'${ver3}'"/g' meta-filogic/recipes-kernel/linux-mac80211/linux-mac80211.bb
+
+echo "Sync from OpenWRT done , ready to commit meta-filogic!!!"
diff --git a/scripts/rdkb_inc_helper b/scripts/rdkb_inc_helper
new file mode 100755
index 0000000..07745ee
--- /dev/null
+++ b/scripts/rdkb_inc_helper
@@ -0,0 +1,82 @@
+#!/usr/bin/python3 -u
+import argparse
+import os
+import sys
+import traceback
+
+__author__ = "Sam Shih <sam.shih@medaitek.com>"
+__copyright__ = "Copyright 2022,  MediaTek Inc"
+
+
+class formatter(argparse.HelpFormatter):
+    def _format_usage(self, usage, actions, groups, prefix):
+        if prefix is None:
+            prefix = "usage: "
+        if usage is not None:
+            usage = usage % dict(prog=self._prog)
+
+        elif usage is None and not actions:
+            usage = "%(prog)s" % dict(prog=self._prog)
+        elif usage is None:
+            prog = "%(prog)s" % dict(prog=self._prog)
+            action_usage = self._format_actions_usage(actions, groups)
+            usage = " ".join([s for s in [prog, action_usage] if s])
+        return "%s%s\n\n" % (prefix, usage)
+
+
+parser = argparse.ArgumentParser(formatter_class=formatter)
+parser.add_argument(
+    "input", nargs="+", help="openwrt patch folder which should be converted"
+)
+parser.add_argument(
+    "--output", help="output .inc file used by RDKB", default="$(name).inc"
+)
+args = parser.parse_args()
+
+
+def find_patch_series(root, level=0, max_level=1):
+    patch = []
+    dir_l = os.listdir(root)
+    dir_l.sort()
+    for name in dir_l:
+        path = os.path.join(root, name)
+        if not os.path.isdir(path):
+            if "." in name:
+                if name.split(".")[-1] == "patch":
+                    if "cover-letter" not in name:
+                        patch.append(name)
+    patch.sort()
+    return patch
+
+
+def create_inc_file(output, name, patch_l):
+    f = open(output, "w")
+    header_code = (
+        "#patch %s (come from openwrt/lede/target/linux/mediatek)\n" % name
+    )
+    script_code = "SRC_URI_append = \" \\\n"
+    space = "    "
+    prefix = "%sfile://" % space
+    postfix = " \\"
+    patch_l_code = "\n".join((prefix + t + postfix) for t in patch_l) + "\n"
+    footer = '%s"\n' % space
+    code = header_code + script_code + patch_l_code + footer
+    f.write(code)
+    f.close()
+
+
+try:
+    input_l = args.input
+    if len(input_l) == 1:
+        name = os.path.basename(os.path.realpath(input_l[0]))
+    else:
+        name = "_".join(os.path.basename(os.path.realpath(t)) for t in input_l)
+    output = args.output.replace("$(name)", name)
+    patch_l = []
+    for input in input_l:
+        patch_l.extend(find_patch_series(input))
+    create_inc_file(output, name, patch_l)
+    print('saved RDKB .inc file to "%s"' % output)
+
+except:
+    traceback.print_exc()