2

I've found various kernel configs in kernel/configs/q.

When I alter them, and run mm in kernel/msm-4.14 the kernel is not rebuilt.

Where do I edit the kernel config, such that a kernel rebuild is forced when mm is run?

fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • 1
    1. Does it build if you don't alter configuration? 2. How exactly did you alter them? – 0andriy Jul 23 '20 at 22:35
  • @0andriy 1. Yes, it does, in 21 seconds. 2. I added a line `!"£$%^&*()androidbase4.X` to each of the three files `kernel/configs/q/android-4.(9|14|19)/android-base.config` to provoke a syntax/build error to show that the files were being read. I have used vendor-specific instructions to use `lunch sdm660_64-userdebu` to set-up the system for Android 10. – fadedbee Jul 27 '20 at 08:28
  • 1
    `cd && source build/envsetup.sh && lunch sdm660_64-userdebug && cd kernel/msm-4.4/ && mm` does not at least create the expected output (`out/target/product/sdm660_64/kernel`). In order for me to build the kernel and create the boot.img successfully I had to make the bootimage target : `cd && source build/envsetup.sh && lunch sdm660_64-userdebug && make bootimage -j4`. – Lakindu Aug 01 '20 at 09:11
  • 1
    @Lakindu Thanks, that's much faster at 6 minutes (vs 45), but still a lot slower than Desktop kernel recompilation. – fadedbee Aug 02 '20 at 11:36

1 Answers1

5

The kernel is built separately from the Android platform first. Then the Android platform build system is pointed at where the kernel image is located, using the TARGET_PREBUILT_KERNEL environment variable.

Here is an outline of how I usually configure and build. I have done it this way for both Android 9 and 10, for various vendors. The scheme I use is mentioned in the docs here. Non-Google kernels usually don't come with version control (repo), I don't know what you're dealing with so I'll cover both.

Configuring the kernel

For repo-checkout kernels, you do the config in build/build.config. Basically, after defconfig was taken as basis, you use the ${KERNEL_DIR}/scripts/config tool to alter the config. This usually looks as follows:

POST_DEFCONFIG_CMDS="check_defconfig && update_config"
function update_config() {
${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
    -d CONFIG_SOMETHING_I_DISABLE \
    -e CONFIG_SOMETHING_I_ENABLE \
    --set-val CONFIG_FOO = 123
}

If you don't have a repo-checkout kernel, locations and details may differ but the basic idea is usually the same: Find/Create the script that kicks of the build, and add invocations of the config tool after making defconfig.

Run the config tool by its own to see full options and more info on its usage, but the above is usually all you need. Beware: If you make syntactically-correct invalid changes (e.g. enable symbols of which the dependencies are not met), the build system will NOT complain and ignore these changes silently. If you face this situation, e.g. use menuconfig to find out what's wrong, as it shows dependencies.

Building AOSP / Making boot.img

After you've built your kernel, you will have Image.lz4 in out/.../dist (or Image.gz in out/.../private/msm-google/arch/arm64/boot). You go to your Android source, and in addition to the usual things (source build/envsetup.sh, lunch) you point the build system at the image you built, e.g. export TARGET_PREBUILT_KERNEL=/path/to/Image.lz4. Then just start the build normally, e.g. make bootimage or m droid.



Note that for Android 10 at least in some cases, you'll have to copy over the kernel modules from out/.../dist too, since the new kernel can't load the old ones. With this part, I am having problems myself at the moment. I think they have to be copied to device/VENDOR/DEVICE (e.g. google/coral-kernel), you may also copy your kernel image there btw, since the original prebuilt one also is there by default. The problem is that at least in my case, the new kernel modules were not copied to device after all.

onetyone
  • 457
  • 4
  • 15
  • Thanks, this contains some very useful information. – fadedbee Aug 03 '20 at 13:26
  • does this apply to android-12? In my case, I copied my kernel and modules into ./kernel/prebuilt , but there are multiple versions of the prebuilt kernel ( kernel/prebuilt/[5.4 and 5.10] ), and I'm not sure how to tell the build which version to use? – jpx Dec 17 '21 at 04:56
  • I think I found my answer, use: TARGET_KERNEL_USE=[version] – jpx Dec 17 '21 at 06:15