Building image - replacing source version?

I have followed this guide to build (rebuild) LEDE image.
https://lede-project.org/docs/guide-developer/quickstart-build-images
I have noticed that before executing "make" there is no linux kernel source (and also packages source).

testbed@testbed:~/lede$ find . -type f -iname "linux-4.4.61.tar.xz"
testbed@testbed:~/lede$ find . -type f -iname "linux*.xz"

However, once make is executed it starts to download "sources" of packages and also Linux-Kernel. It creates dl dir, downloads it there (and probably compiles it right away once downloaded?)

Questions:

  1. how can I manually replace linux-kernel source?
  2. how can I manually replace any package source?

The answer to both of your questions is:
edit the proper Makefile, patches and/or .mk files.

You can download and expand kernel sources before build to /build_dir/target... with "make target/linux/prepare V=s". That downloads and expands the kernel sources base on kernel Makefile definitions.

For packages, you can do the same with "make package/xxxx/prepare".

For both packages and kernel, you should do final changes to the Makefile and/or patches in the pckage directory, as build_dir is not permament. So amy code changes to the upstream source code needs to be done via patches in that package's directory.

E.g. for kernel, the details depends a bit on what you want to do.
These files are related to kernel (copy from an old post):

in brief

  • define the kernel major version and its patchver in kernel-version.mk
  • adjust generic kernel patches (~100 files) and config to the changes in kernel between a supported version and your target version, e.g. 4.4
  • adjust platform patches (~100 files) and config to the changes in kernel between 4.4
  • adjust platform Makefile to use kernel 4.x

Example ar71xx and kernel 4.4 support:
https://github.com/lede-project/source/blob/master/include/kernel-version.mk
https://github.com/lede-project/source/blob/master/target/linux/generic/config-4.4
https://github.com/lede-project/source/tree/master/target/linux/generic/patches-4.4
https://github.com/lede-project/source/blob/master/target/linux/ar71xx/config-4.4
https://github.com/lede-project/source/tree/master/target/linux/ar71xx/patches-4.4
https://github.com/lede-project/source/blob/master/target/linux/ar71xx/Makefile

Unless you are really familiar with the kernel, your platform and LEDE/Openwrt details, a major change like a kernel version change, can be pretty difficult.

If you just want to edit a single file in kernel sources, you just create the respective patch and place it in the kernel patch series

For packages, there are similarly Makefile, patches and native files like init scripts.

Core packages are in https://github.com/lede-project/source/tree/master/package while extra packages are in feeds like https://github.com/openwrt/packages

Wiki contains lots of info, both in LEDE wiki and Openwrt wiki.
e.g.
https://lede-project.org/docs/guide-developer/use-patches-with-buildsystem

https://wiki.openwrt.org/doc/devel/patches

EDIT
I added a second copy from an old message below:
https://forum.openwrt.org/viewtopic.php?pid=295780#p295780

rough framework:

  • Openwrt package Makefile defines the sources to be donwloaded
  • Openwrt package patches define the modifications to the downloaded original package sources
  • Openwrt make first downloads the sources (make download), then expands them and applies the Openwrt patches (make prepare), and finally compiles sources (make compile).

The sources are retrieved during the build, if you have included the package in your build.
(or by "make download" before the build)

You could do "make package/openvpn/prepare" to get the sources downloaded and expanded into /build_dir/target.../openvpn... and to get all the patches applied.

Yes, you should create a patch in openvpn/patches. (And probably place it last in the alphabetically evaluated quilt patch queue.) If you place it earlier, you might need to "refresh" the existing patches.
http://wiki.openwrt.org/doc/devel/patches#refreshing_patches

It helps to understand something about "quilt", but I have never needed to really deeply learn it.

To get a short intro of the steps, do:
make package/openvpn/download V=s
make package/openvpn/clean
make package/openvpn/prepare V=s

(or combine: make package/openvpn/{clean,prepare} V=s

ok so since i need some serious help with editing some patches maybe you can advise me on how to do this properly, cuz im kind of confused on what to edit in an existing patch to apply to the updated lede source for ar71xx.

for starters i use these patches .config and files

im having issues with these mtune, remove-debug, lzma-loader, and bbr:
004-kernel-mtune74kc.patch
005-lzma-mips74kc-optimize.patch
008-remove-kernel-debug.patch
812-enable-bbr-congestion-control.patch

what can i do to resolve these issues