From c1670dcdda1ab0f5310f76e5ae6e710bd16892c7 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Sat, 18 Jul 2020 08:53:44 +0200
Subject: [PATCH 01/38] ipq807x: add the Qualcomm AX target support

Signed-off-by: John Crispin <john@phrozen.org>
---
 config/Config-kernel.in                       |     9 +
 include/image.mk                              |     6 +-
 include/kernel-version.mk                     |     2 +-
 package/boot/uboot-envtools/files/ipq807x     |    37 +
 .../etc/hotplug.d/firmware/11-ath10k-caldata  |     5 +
 target/linux/ipq807x/109-logspam.patch        |    24 +
 target/linux/ipq807x/Makefile                 |    22 +
 .../ipq807x/base-files/etc/board.d/01_leds    |    38 +
 .../ipq807x/base-files/etc/board.d/02_network |    81 +
 .../ipq807x/base-files/etc/board.d/03_wifi    |    17 +
 .../etc/hotplug.d/firmware/10-ath11k-caldata  |   111 +
 .../etc/hotplug.d/firmware/11-ath10k-caldata  |    16 +
 .../ipq807x/base-files/etc/hotplug.d/net/macs |     3 +
 .../ipq807x/base-files/etc/init.d/aq_phy      |    21 +
 .../ipq807x/base-files/etc/init.d/bootcount   |    12 +
 .../linux/ipq807x/base-files/etc/init.d/wdt   |    14 +
 ...G4_v5.4.B-AQR_CIG_WIFI_ID44715_VER1673.cld |   Bin 0 -> 391170 bytes
 .../base-files/lib/upgrade/platform.sh        |    73 +
 target/linux/ipq807x/config-4.4               |   828 +
 .../arm/boot/dts/qcom-ipq6018-cig-wf188.dts   |    18 +
 .../arm/boot/dts/qcom-ipq6018-cig-wf188n.dts  |    18 +
 .../boot/dts/qcom-ipq6018-edgecore-eap101.dts |    18 +
 .../boot/dts/qcom-ipq6018-miwifi-ax1800.dts   |    18 +
 .../boot/dts/qcom-ipq6018-wallys-dr6018.dts   |    18 +
 .../arch/arm/boot/dts/qcom-ipq807x-eap102.dts |    26 +
 .../arch/arm/boot/dts/qcom-ipq807x-eap106.dts |    26 +
 .../arch/arm/boot/dts/qcom-ipq807x-ex227.dts  |    26 +
 .../arch/arm/boot/dts/qcom-ipq807x-ex447.dts  |    26 +
 .../boot/dts/qcom-ipq807x-sercomm-wallaby.dts |    26 +
 .../arch/arm/boot/dts/qcom-ipq807x-wf194c.dts |    26 +
 .../arm/boot/dts/qcom-ipq807x-wf194c4.dts     |    26 +
 .../dts/qcom/qcom-ipq6018-miwifi-ax1800.dts   |   419 +
 .../dts/qcom/qcom-ipq6018-wallys-dr6018.dts   |   441 +
 .../boot/dts/qcom/qcom-ipq807x-eap102.dts     |   918 +
 .../boot/dts/qcom/qcom-ipq807x-wf194c4.dts    |   942 +
 target/linux/ipq807x/image/Makefile           |    26 +
 target/linux/ipq807x/image/ipq50xx.mk         |    10 +
 target/linux/ipq807x/image/ipq60xx.mk         |    56 +
 target/linux/ipq807x/image/ipq807x.mk         |    90 +
 target/linux/ipq807x/ipq50xx/config-default   |    84 +
 target/linux/ipq807x/ipq50xx/config-lowmem    |    73 +
 target/linux/ipq807x/ipq50xx/target.mk        |    10 +
 target/linux/ipq807x/ipq60xx/config-default   |   122 +
 .../linux/ipq807x/ipq60xx/profiles/default.mk |     9 +
 target/linux/ipq807x/ipq60xx/target.mk        |     8 +
 target/linux/ipq807x/ipq807x/config-default   |    78 +
 .../linux/ipq807x/ipq807x/profiles/default.mk |     9 +
 target/linux/ipq807x/ipq807x/target.mk        |     7 +
 target/linux/ipq807x/modules.mk               |    61 +
 .../linux/ipq807x/patches/100-qrtr-ns.patch   |   976 +
 .../linux/ipq807x/patches/101-squashfs.patch  |    16 +
 .../linux/ipq807x/patches/102-cig-wf188.patch |   869 +
 .../ipq807x/patches/103-sercomm-wallaby.patch |   816 +
 target/linux/ipq807x/patches/104-wf194c.patch |   816 +
 .../patches/105-fix-dtc-gcc10-build.patch     |    11 +
 target/linux/ipq807x/patches/106-eap101.patch |   993 +
 .../linux/ipq807x/patches/108-log-spam.patch  |    37 +
 target/linux/ipq807x/patches/109-tplink.patch |  1518 +
 .../ipq807x/patches/110-add-esmt-nand.patch   |    37 +
 target/linux/ipq807x/patches/111-eap106.patch |   765 +
 target/linux/ipq807x/patches/112-pstore.patch |   147 +
 .../ipq807x/patches/200-bpf_backport.patch    | 44780 ++++++++++++++++
 toolchain/kernel-headers/Makefile             |     8 +
 63 files changed, 56741 insertions(+), 2 deletions(-)
 create mode 100644 package/boot/uboot-envtools/files/ipq807x
 create mode 100644 target/linux/ipq807x/109-logspam.patch
 create mode 100644 target/linux/ipq807x/Makefile
 create mode 100755 target/linux/ipq807x/base-files/etc/board.d/01_leds
 create mode 100755 target/linux/ipq807x/base-files/etc/board.d/02_network
 create mode 100755 target/linux/ipq807x/base-files/etc/board.d/03_wifi
 create mode 100755 target/linux/ipq807x/base-files/etc/hotplug.d/firmware/10-ath11k-caldata
 create mode 100644 target/linux/ipq807x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
 create mode 100644 target/linux/ipq807x/base-files/etc/hotplug.d/net/macs
 create mode 100755 target/linux/ipq807x/base-files/etc/init.d/aq_phy
 create mode 100755 target/linux/ipq807x/base-files/etc/init.d/bootcount
 create mode 100755 target/linux/ipq807x/base-files/etc/init.d/wdt
 create mode 100644 target/linux/ipq807x/base-files/lib/firmware/AQR-G4_v5.4.B-AQR_CIG_WIFI_ID44715_VER1673.cld
 create mode 100755 target/linux/ipq807x/base-files/lib/upgrade/platform.sh
 create mode 100644 target/linux/ipq807x/config-4.4
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq6018-cig-wf188.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq6018-cig-wf188n.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq6018-edgecore-eap101.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq6018-miwifi-ax1800.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq6018-wallys-dr6018.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq807x-eap102.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq807x-eap106.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq807x-ex227.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq807x-ex447.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq807x-sercomm-wallaby.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq807x-wf194c.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm/boot/dts/qcom-ipq807x-wf194c4.dts
 create mode 100755 target/linux/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq6018-miwifi-ax1800.dts
 create mode 100755 target/linux/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq6018-wallys-dr6018.dts
 create mode 100755 target/linux/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq807x-eap102.dts
 create mode 100644 target/linux/ipq807x/files/arch/arm64/boot/dts/qcom/qcom-ipq807x-wf194c4.dts
 create mode 100644 target/linux/ipq807x/image/Makefile
 create mode 100644 target/linux/ipq807x/image/ipq50xx.mk
 create mode 100644 target/linux/ipq807x/image/ipq60xx.mk
 create mode 100644 target/linux/ipq807x/image/ipq807x.mk
 create mode 100644 target/linux/ipq807x/ipq50xx/config-default
 create mode 100644 target/linux/ipq807x/ipq50xx/config-lowmem
 create mode 100644 target/linux/ipq807x/ipq50xx/target.mk
 create mode 100644 target/linux/ipq807x/ipq60xx/config-default
 create mode 100644 target/linux/ipq807x/ipq60xx/profiles/default.mk
 create mode 100644 target/linux/ipq807x/ipq60xx/target.mk
 create mode 100644 target/linux/ipq807x/ipq807x/config-default
 create mode 100644 target/linux/ipq807x/ipq807x/profiles/default.mk
 create mode 100644 target/linux/ipq807x/ipq807x/target.mk
 create mode 100644 target/linux/ipq807x/modules.mk
 create mode 100644 target/linux/ipq807x/patches/100-qrtr-ns.patch
 create mode 100644 target/linux/ipq807x/patches/101-squashfs.patch
 create mode 100644 target/linux/ipq807x/patches/102-cig-wf188.patch
 create mode 100644 target/linux/ipq807x/patches/103-sercomm-wallaby.patch
 create mode 100644 target/linux/ipq807x/patches/104-wf194c.patch
 create mode 100644 target/linux/ipq807x/patches/105-fix-dtc-gcc10-build.patch
 create mode 100644 target/linux/ipq807x/patches/106-eap101.patch
 create mode 100644 target/linux/ipq807x/patches/108-log-spam.patch
 create mode 100644 target/linux/ipq807x/patches/109-tplink.patch
 create mode 100644 target/linux/ipq807x/patches/110-add-esmt-nand.patch
 create mode 100644 target/linux/ipq807x/patches/111-eap106.patch
 create mode 100644 target/linux/ipq807x/patches/112-pstore.patch
 create mode 100644 target/linux/ipq807x/patches/200-bpf_backport.patch

diff --git a/config/Config-kernel.in b/config/Config-kernel.in
index f71114b5da..4a85d83118 100644
--- a/config/Config-kernel.in
+++ b/config/Config-kernel.in
@@ -2,6 +2,15 @@
 #
 # Copyright (C) 2006-2014 OpenWrt.org
 
+config KERNEL_IPQ_MEM_PROFILE
+	int "Different memory profile "
+	range 0 1024
+	default 512
+	depends on TARGET_ipq807x
+	help
+	  This option select memory profile to be used,which defines
+	  the reserved memory configuration used in device tree.
+
 config KERNEL_BUILD_USER
 	string "Custom Kernel Build User Name"
 	default "builder" if BUILDBOT
diff --git a/include/image.mk b/include/image.mk
index 6fc02a3f6b..92b23321b1 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -179,6 +179,10 @@ define Image/pad-root-squashfs
 	$(call Image/pad-to,$(KDIR)/root.squashfs,$(if $(1),$(1),$(ROOTFS_PARTSIZE)))
 endef
 
+ifeq ($(CONFIG_IPQ_MEM_PROFILE),512)
+DTC_CFLAGS = -D __IPQ_MEM_PROFILE_512_MB__
+endif
+
 # $(1) source dts file
 # $(2) target dtb file
 # $(3) extra CPP flags
@@ -188,7 +192,7 @@ define Image/BuildDTB
 		-I$(DTS_DIR) \
 		-I$(DTS_DIR)/include \
 		-I$(LINUX_DIR)/include/ \
-		-undef -D__DTS__ $(3) \
+		-undef -D__DTS__ $(DTC_CFLAGS) $(3) \
 		-o $(2).tmp $(1)
 	$(LINUX_DIR)/scripts/dtc/dtc -O dtb \
 		-i$(dir $(1)) $(DTC_FLAGS) $(4) \
diff --git a/include/kernel-version.mk b/include/kernel-version.mk
index 3c109c13c8..dff01895be 100644
--- a/include/kernel-version.mk
+++ b/include/kernel-version.mk
@@ -11,7 +11,7 @@ LINUX_VERSION-4.14 = .193
 LINUX_VERSION-5.4 = .142
 LINUX_VERSION-5.10 = .27
 
-LINUX_KERNEL_HASH-4.4.60 = 2cd8df6f1ac6a5329c5a286ec9b5956215977221a1b731597ed169fff74a9659
+LINUX_KERNEL_HASH-4.4.60 = e7f2f47acf17497d6ffd713eda65c025b3df0bce09faa8c04712bf1b3cfc9fdb
 LINUX_KERNEL_HASH-4.14.193 = 0b0fb41d4430e1a42738b341cbfd2f41951aa5cd02acabbd53f076119c8b9f03
 LINUX_KERNEL_HASH-5.4.142 = 99785728968564ba27c7e552d024b560072dcbc885540912eabb5c021e231451
 LINUX_KERNEL_HASH-5.10.27 = d99dc9662951299c53a0a8d8c8d0a72a16ff861d20e927c0f9b14f63282d69d9
diff --git a/package/boot/uboot-envtools/files/ipq807x b/package/boot/uboot-envtools/files/ipq807x
new file mode 100644
index 0000000000..6c429f1852
--- /dev/null
+++ b/package/boot/uboot-envtools/files/ipq807x
@@ -0,0 +1,37 @@
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+ubootenv_mtdinfo () {
+	UBOOTENV_PART=$(cat /proc/mtd | grep APPSBLENV)
+	mtd_dev=$(echo $UBOOTENV_PART | awk '{print $1}' | sed 's/:$//')
+	mtd_size=$(echo $UBOOTENV_PART | awk '{print "0x"$2}')
+	mtd_erase=$(echo $UBOOTENV_PART | awk '{print "0x"$3}')
+	nor_flash=$(find /sys/bus/spi/devices/*/mtd -name ${mtd_dev})
+
+	if [ -n "$nor_flash" ]; then
+		ubootenv_size=$mtd_size
+	else
+		# size is fixed to 0x40000 in u-boot
+		ubootenv_size=0x40000
+	fi
+
+	sectors=$(( $ubootenv_size / $mtd_erase ))
+	echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors
+}
+
+case "$board" in
+*)
+	ubootenv_add_uci_config $(ubootenv_mtdinfo)
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/toolchain/kernel-headers/Makefile b/toolchain/kernel-headers/Makefile
index c33f26d46d..06236b5a47 100644
--- a/toolchain/kernel-headers/Makefile
+++ b/toolchain/kernel-headers/Makefile
@@ -12,6 +12,14 @@ BUILD_DIR := $(KERNEL_BUILD_DIR)
 override QUILT:=
 override HOST_QUILT:=
 
+include $(INCLUDE_DIR)/target.mk
+
+ifeq ($(KERNEL_PATCHVER),4.4)
+  KERNEL_PATCHVER := 5.10
+  KERNEL_NAME_SUFFIX:=
+endif
+
+include $(INCLUDE_DIR)/kernel-version.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=linux
-- 
2.25.1

