From 1749748819caa03e249e8a5df1311498550cbd3b Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Sat, 18 Jul 2020 08:53:44 +0200
Subject: [PATCH 68/83] 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 +++++++++++++++++++++++
 toolchain/kernel-headers/Makefile         |  8 +++++
 5 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 package/boot/uboot-envtools/files/ipq807x

diff --git a/config/Config-kernel.in b/config/Config-kernel.in
index d4648a5064..2d5c9f1437 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 c7aba61cd7..efecf2f919 100644
--- a/include/kernel-version.mk
+++ b/include/kernel-version.mk
@@ -11,7 +11,7 @@ LINUX_VERSION-4.14 = .193
 LINUX_VERSION-5.4 = .158
 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.158 = 6e018fecdc8fc24553756e582d83b82d65b10a6b03ef36262a24911f839b8d59
 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

