[PATCH] Add option to build external kernel tree (experimental)

Daniel Santos daniel.santos at pobox.com
Tue Oct 30 21:54:00 EDT 2018


This patch modifies quilt and adds the root .config options that can be
configured to cause the OpenWRT / quilt build to re-construct a real git
tree using a base git reference and then applying the kernel patches
using git am or git apply.

You only need to enable this and run the build one time, after which you
should generally disable the option and configure OpenWRT to *use* the
external kernel directory, which inhibits OpenWRT from reconstructing
(extracting and patching) your kernel tree.

This patch still needs cleanup (removal of commented out code, etc.)
land probably also refinement.  Also, it is not perfect at
reconstructing the logical patch history due to the "files" directories
that must be applied as a set of mega-patches (one for generic and one
for the arch files), but it's step in the right direction.

Signed-off-by: Daniel Santos <daniel.santos at pobox.com>
---
 config/Config-devel.in  | 28 +++++++++++++++++++++++++
 include/quilt.mk        |  6 ++++++
 scripts/patch-kernel.sh | 45 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/config/Config-devel.in b/config/Config-devel.in
index fd7c3ead1e..06110a14da 100644
--- a/config/Config-devel.in
+++ b/config/Config-devel.in
@@ -73,6 +73,34 @@ menuconfig DEVEL
 		string "Use external kernel tree" if DEVEL
 		default ""
 
+	config EXTERNAL_KERNEL_TREE_BUILD_GIT
+		bool "Build git tree from OpenWRT patches." if DEVEL
+		depends on !KERNEL_GIT_CLONE_URI
+		default n
+		help
+		  Uses git to clone the upstream kernel and then apply OpenWRT
+		  patches with git-am or git-apply to create a proper Linux
+		  kernel git tree.
+
+                  TODO: needs more explanation.
+
+	config EXTERNAL_KERNEL_TREE_BUILD_GIT_URI
+		bool "Upstream git URI" if DEVEL
+		depends on EXTERNAL_KERNEL_TREE_BUILD_GIT
+		default "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
+		help
+		  Where to clone the Linux tree from.  You probably want the
+		  default unless you already have a local copy you want to
+		  clone.
+
+	config EXTERNAL_KERNEL_TREE_BUILD_GIT_REF
+		bool "Local referenceBuild git tree from OpenWRT patches." if DEVEL
+		depends on EXTERNAL_KERNEL_TREE_BUILD_GIT
+		default ""
+		help
+		  Use git clone --dissociate --reference-if-able <local_dir>
+		  when cloning to reduce network traffic.
+
 	config KERNEL_GIT_CLONE_URI
 		string "Enter git repository to clone" if DEVEL
 		default ""
diff --git a/include/quilt.mk b/include/quilt.mk
index 61dcc7964c..1f52d53176 100644
--- a/include/quilt.mk
+++ b/include/quilt.mk
@@ -95,7 +95,13 @@ endef
 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
 define Kernel/Patch/Default
 	$(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
+
+	#echo "copy files is next"
+	#read
 	$(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
+
+	#echo "remove (old?) rejects and patch..."
+	#read
 	find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
 	if [ -d $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER)) ]; then \
 		echo "generic patches directory is present. please move your patches to the pending directory" ; \
diff --git a/scripts/patch-kernel.sh b/scripts/patch-kernel.sh
index c2b7e72049..b52d16f61c 100755
--- a/scripts/patch-kernel.sh
+++ b/scripts/patch-kernel.sh
@@ -18,7 +18,20 @@ if [ ! -d "${patchdir}" ] ; then
     echo "Aborting.  '${patchdir}' is not a directory."
     exit 1
 fi
-    
+
+fixit() {
+    op="$1"
+    file="$2"
+    patch="$3"
+    shift 3
+    echo "$op failed on $file ($patch).  $@"
+    /bin/bash
+    while [ -n "`git status --porcelain`" ]; do
+	echo "git repo not clean, please try again"
+	/bin/bash
+    done
+}
+
 for i in ${patchdir}/${patchpattern} ; do 
     case "$i" in
 	*.gz)
@@ -37,12 +50,34 @@ for i in ${patchdir}/${patchpattern} ; do
     [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue	
     echo ""
     echo "Applying ${i} using ${type}: " 
-    ${uncomp} ${i} | ${PATCH:-patch} -f -p1 -d ${targetdir}
-    if [ $? != 0 ] ; then
-        echo "Patch failed!  Please fix $i!"
-	exit 1
+    if true; then
+	if ! ${uncomp} ${i} | ${PATCH:-patch} -f -p1 -d ${targetdir}; then
+	    echo "Patch failed!  Please fix $i!"
+	    exit 1
+	fi
+    else
+	pushd "${targetdir}"
+	p=/tmp/patch.$$
+	${uncomp} ${i} > ${p}
+	if ! git am < ${p}; then
+	    git am --abort || fixit "git am --abort" $i $p
+	    [ -z "`git status --porcelain`" ] || fixit "git status" $i $p "tree not clean"
+	    git apply < $p || fixit "git apply" $i $p
+	    git add -A && git commit -am "`basename $i`" || fixit "git add and commit" $i $p
+# 	    if [ -n "`git status --porcelain`" ]; then
+# 		echo "files left over, please fix (maybe git add -A and git commit --amend)"
+# 		/bin/bash
+# 	    fi
+
+#	    echo "maybe git am -3i < $p"
+#	    echo "maybe git apply < $p && git commit -am '`basename $i`'"
+#	    fixit "git am" $i $p
+	fi
+	rm $p
+	popd
     fi
 done
+popd
 
 # Check for rejects...
 if [ "`find $targetdir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ] ; then
-- 
2.19.2


--------------DD197D3BFD3CFA42C1923885
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

--------------DD197D3BFD3CFA42C1923885--




More information about the openwrt-devel mailing list