7

I am currently working on the Linux kernel for an Android phone. My workflow is:

  1. Make changes to kernel code
  2. Build with make bootimage
  3. Flash with fastboot flash boot

This works fine. However building takes unnecessary long because make bootimage first goes through the entire tree and includes all Android.mk files. This takes longer than actually compiling the kernel and creating a boot image. Including these files should not be necessary since there are no changes to them. To decrease turnaround time in my workflow, I would like to speed up the build step.

When building other other projects, there are ways to to not build dependencies and thus skip reading all Android.mk files (for instance mm).

There is a make target bootimage-nodeps which seems to do the right thing: It makes a new boot image without going through all Android.mk files. Unfortunately dependencies also include the kernel itself (which therefore does not get built although there are changes).

My question is: Is there a way to build the kernel and create a boot image withouth having to read all Android.mk files.

justfortherec
  • 1,590
  • 1
  • 13
  • 17
  • This is a copy of the same question that I asked over at android.stackexchange.com where it was marked as off topic: https://android.stackexchange.com/questions/173347/how-can-i-build-bootimage-without-going-through-all-makefiles. I hope to find an answer in this community. – justfortherec Apr 19 '17 at 15:35
  • You have to deeply understand build process of Android sources, thus you *have to* do a research of how Makefiles are written and what they call. – 0andriy Apr 19 '17 at 17:09
  • I just hope someone already knows. – justfortherec Apr 20 '17 at 07:51
  • Not sure if we can skip other Android.mk files but you can assign more jobs to make command, which can save your time. Eg. make bootimage -j32 – Daud Arfin Apr 20 '17 at 09:46
  • Thanks. That's good advice. I already use `-j6` (my laptop has two hyperthreaded cores). I left this information out for clarity's sake. I doubt that increasing the number will help much with only four threads being able to run simultaneously. I will test how much I can gain. – justfortherec Apr 20 '17 at 11:47
  • bootimage is made of alot of projects, the environment need to find them all, and must go through all the Android.mk tree – skoperst Apr 20 '17 at 14:35
  • But all dependencies are already built: The only missing piece is the kernel. The make target `bootimage-nodeps` takes care of assembling everything. On the other hand, building the kernel should be fairly self-contained, shouldn't it? – justfortherec Apr 20 '17 at 16:33
  • 1
    @justfortherec, but how build system, in particular `make`, will **know** that? – 0andriy Apr 20 '17 at 18:34
  • So, you mean I do `cd kernel/` and run `make` in there? Does that build for the right architecture and use the right configuration? It's such a simple idea that I have not tried it yet. Will do so. – justfortherec Apr 21 '17 at 08:58
  • @0andriy, running `make` in `kernel/` does not work. As expected, it is missing configuration. – justfortherec Apr 21 '17 at 09:02
  • @justfortherec if you are missing configuration - try to run "make help" in the kernel to see which configurations you can build. – IIIIIIIIIIIIIIIIIIIIII Apr 21 '17 at 10:51

3 Answers3

3

In case you 're still looking into it, try using the showcommands goal at make, for example :

make bootimage showcommands

The showcommands goals will show all commands needed to build the kernel and the bootimage. Some of the commands, including the one to create the bootimage have $(hide) in front and are not shown.

Once you know the commands and the arguments, next time you need to make the bootimage you can run the commands manually (without using make bootimage and without including all the makefiles). I have exactly the same problem and this is the only working solution I've found.

Joo
  • 46
  • 4
0

I am not sure if you can save time this way (since this solution needs to zip/unzip multiple times which needs more time then to search for all Android.mks on my machine) but since your question is:

Is there a way to build the kernel and create a boot image withouth having to read all Android.mk files.

you could give this a try:

Preperations:

  1. call make dist once
  2. unzip the target_files.zip in out/dist/

now create a script that does the following for you:

  1. overwrite the kernel in your unpacked target_files with your newly build kernel
  2. zip your target_files with your new kernel
  3. use the python script img_from_target_files from build/tools/releasetools/ with the extra parameter -z. Example: img_from_target_files -z out/dist/target_files.zip new_imgs.zip
  4. inside the newly created new_imgs.zip you will find your new boot.img with your new kernel
IIIIIIIIIIIIIIIIIIIIII
  • 3,958
  • 5
  • 45
  • 70
  • This is an interesting idea. However, this skips the crucial step that I want a solution for: How can I create my "newly built kernel" without going through all make files? Creating the bootimage from a kernel is not the issue: The make target `bootimage-nodeps` that I mention in my question does exactly that. But for that I need a kernel in the first place. I am looking for a way to build this kernel that does not involve including all `Android.mk` files. – justfortherec Apr 20 '17 at 16:30
  • @justfortherec better add more context to your question. Like your android version, rom version and the kernel you are using because with the kernels I know I was able to simply run make to build them. – IIIIIIIIIIIIIIIIIIIIII Apr 20 '17 at 16:45
  • So, you just `cd kernel/` and `make` there? I will try that. – justfortherec Apr 21 '17 at 08:58
  • I have tried, that does not work. @IIIIIIIIIIIIIIIIIIIIII, what do you mean with "simply run make"? – justfortherec Apr 21 '17 at 09:00
  • @justfortherec exactly in my case I have a Makefile to build the kernel alone. Without knowing which rom/kernel/etc you use we can just guess what will work for you. – IIIIIIIIIIIIIIIIIIIIII Apr 21 '17 at 09:35
  • I am using a build system from Codeaurora. For all intents and purposes this should be equivalent to AOSP with kernel in tree. The manifest is here: https://code.fairphone.com/gerrit/fp2-dev/manifest – justfortherec Apr 21 '17 at 12:57
0

You can try the make SINGLE_SHOTcommand - if you know the path to your Andorid.mk:-

m -j8 ONE_SHOT_MAKEFILE=build/target/board/Android.mk bootimage

This worked for me pretty well in Android L/M/N releases

Zakir
  • 2,222
  • 21
  • 31
  • This does look interesting. Doe you know what the difference to using `mm`/`mmm` is? Reading your answer makes me realize that I should just try to find out what makefile is relevant for the kernel and `mmm` that directory. Issues is: I do not know which makefile that would be. – justfortherec Jun 03 '17 at 16:32
  • No sorry I have no idea about `mmm` Not sure if just doing a `mm` on the module would force linking the newly built module with the kernel image - Unless you just want to push the module lib (`.so`/ `.o`) to the target – Zakir Jun 03 '17 at 16:37