[How to] replace the kernel source before building image?

Hi, I am trying to build a image that support MultiPath-TCP feature(MPTCP).
As MPTCP offers a customized kernel source that was modified from original kernel source v4.14, and OpenWRT v18.06.2 is based on v4.14.x kernel, I want to replace the kernel source of OpenWRT v18.06.2 before the image starts to be built.

Can I do so in some way?
How should I do?

This may sound snippy, but it's not meant to be: "If you have to ask, you won't be able to do it."

The reasoning for that is OpenWrt requiring quite a lot of kernel patches on its own, both generic ones to "make $functionality work" and to support architectures and devices boot, run and work in the first place. Without these patches (and they differ between targets and are stacked upon each other, depending on which target you're going to build), most (basically all) devices other than x86/ x86_64 simply won't be able to start up. On the other hand you have MPTCP (I haven't looked into that one, but if they release their own kernel tree, it's supposedly non-trivial as well) and its assorted patch set - to get both working, you'd have to go knee deep into patch juggling, rebasing, understanding the code and merging both code bases to an intrinsic amount of work, that figuring out how to do it is trivial in comparison.

Simply replacing OpenWrt's kernel with another one (even plain vanilla upstream) isn't possible, you have to make rather significant changes to boot on anything != x86/ x86_64, and even while vanilla should 'boot' on x86_64 unchanged, a lot of functionality won't work without these changes. And if you were on x86/ x86_64, not using OpenWrt and experimenting with a more general purpose distribution and your MPTCP kernel would probably be easier, Working with invasive kernel changes is a lot easier on self-hosting distributions, which allow you to compile on the host system, to install multiple kernels in parallel and toggling between them at boot time, with a 'normal' (g)libc and git bisect at your disposal (without having to rebuild the whole system and reflash between intermediate bisection steps).

https://openwrt.org/docs/start does have a lot of information, but that won't save you from rather intimate patch/ tree juggling either.


Thank you very much!
Maybe I had thought it too simple.

Hello. I am trying to do the EXACT same thing as OP. I want to compile OpenWrt with an MPTCP-enabled kernel. OpenWrt seems to have had an MPTCP project but its too old (last updated 5 years ago and using ancient kernel 3.14). For several days, I have tried many ways of doing this:

i) Use this guide of someone who accomplished the same thing for OpenWrt, but he is using a Raspberry Pi. I am stuck at "git fetching" from mptcp, because for some reason I don't know, the command starts fetching >6GB of data (which is weird because if I instead go to the repo and manually click download, I get a 170MB file. I don't know how to use git at all and I had to give up on this.

ii) Merge the source files manually, in a very archaic manner. Basically, I download MPTCP kernel (not to be confused with OpenWrt's MPTCP Kernel; this one is from the MPTCP developers) from here and then search for "mptcp" in the whole folder. I got about 50 files. Then I go to "/home/nero/openwrt/build_dir/target-mips_24kc_musl/linux-4.20" (this is where OpenWrt places the kernel source after downloading and extracting), then I replace the parts of code that are different from the mptcp kernel, one by one. Very time consuming and tiring. As you can imagine, it doesn't work when I try to compile. Mostly because its almost impossible to know what should be merged into what, without actually understanding the code. Which is thousands of lines. I gave up on this.

iii) I tried to make OpenWrt use their ancient kernel with MPTCP. It wont compile because of missing "gcc-compiler7.h". I tried all sorts of remedies to make that work, I eventually had to give up. See my post here

iv) Just delete the already downloaded kernel sources, and replace them with kernel sources of MPTCP (effectively tricking OpenWrt into compiling the kernel sources we want. Obviously, doesn't work (possibly because of Makefiles and Kconfigs). Gave up on this too.

v) Download an MPTCP kernel patch from here corresponding to the kernel system I am trying to patch. I am not sure how this works, but I think the patch is supposed to magically patch the whole kernel sources to support MPTCP (it is 22,000 lines, and from looking at the code, it seems to be doing what I was trying to do in (ii), albeit in a more sophisticated manner. It appears to me that just the patch file is enough to convert a raw, unmodified kernel source to support MPTCP. Again, not sure on this. After placing the patch in "target/linux/ath79/patches-420" and running make, it stops compiling at some point, due to the patch file. Some of the patch file does patch though, which makes me think this could be another solution. Again, no idea what I am doing here.

Right now what I think could work is to instruct OpenWrt to use a kernel from a different source. However, I don't know how to do that (It's possible though). If I can do that, then I can make it use the kernel from MPTCP and hopefully everything works.

I wish OpenWrt would work on this feature. I tested it before on my computer and I was able to merge WiFi and Ethernet into one super fast internet connection (the whole reason why I am trying to enable MPTCP on the router, so every device I have can benefit from this).