[Android]How to Build Kernel to Add Driver?

Which system do you use? Android, Ubuntu, OOWOW or others?


Which version of system do you use? Khadas official images, self built images, or others?

I like to build the kernel used by Android 11 to add a driver for an I2C device. I think I should use this branch (https://github.com/khadas/linux/tree/khadas-vim4-r-64bit but am not sure.

Please describe your issue below:

I cloned the repository and switched to the branch above. What do I do next to build the 64-bit kernel which I can then use to build Android 11?

Post a console log of your issue below:

make config
  LEX     scripts/kconfig/lexer.lex.c
/bin/sh: 1: flex: not found
scripts/Makefile.host:9: recipe for target 'scripts/kconfig/lexer.lex.c' failed
make[1]: *** [scripts/kconfig/lexer.lex.c] Error 127
Makefile:615: recipe for target 'config' failed
make: *** [config] Error 2

@Gunter You can refer to the following two methods for adding new drivers.

commit a0bddf011dd54a2ccda9389febe5e67276e4707a
Date:   Tue Nov 30 21:29:52 2021 +0800

    TP: add khadas-ft5x06 touchscreen drivers

 arch/arm64/boot/dts/amlogic/kvim4.dts     |   14 +++
 arch/arm64/configs/kvim4_a64_R_defconfig  |    1 +
 drivers/input/touchscreen/Kconfig         |   13 ++
 drivers/input/touchscreen/Makefile        |    1 +
 drivers/input/touchscreen/khadas-ft5x06.c | 1214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 1243 insertions(+)

commit 113890ac6a205c2f754d1bbb9f8fb55a075c7bdb
Date:   Wed Nov 10 18:23:00 2021 +0800

    watchdog: Add tps3851 driver

 arch/arm64/boot/dts/amlogic/kvim4.dts    |   8 ++++++++
 arch/arm64/configs/kvim4_a64_R_defconfig |   1 +
 drivers/watchdog/Kconfig                 |  14 +++++++++++++-
 drivers/watchdog/Makefile                |   1 +
 drivers/watchdog/tps3851_wdt.c           | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 178 insertions(+), 1 deletion(-)

Hi “Go Enjoy”,

Thanks for your quick answer. But before I add a driver I would like, as a prerequisite, build the kernel. How do I do that?

Best wishes,


@Gunter Building Android Source Code | Khadas Documentation

The toolchain link mentions Ubuntu version 16.04, but the Android website mentions Ubuntu version 18.04. Which one should I use?

@Gunter We use Ubuntu version 16.04. Not verified in Ubuntu version 18.04 version. But I think both are OK.

I tried Ubuntu version 16.04 but it comes only with Python 3.5 whereas repo requires Python 3.6. I’ll let you know how building the image goes under Ubuntu 18.04.

BTW, the repo wrapper does not work since it requires Python 2. Such, the repo calls should be: python3 ./repo/repo/repo init … (see Step 2)

I could build the image under Ubuntu 18.04. Which one should I select in oowow under the menu item “Write image to eMMC”? It does not accept update.img with the error message “this share not mounted” in file “.NOT_MOUNTED.info”, although I see it through smb. What is the easiest way to burn the image using LAN?

I could use the Windows burn tool (Aml_USB_Burn_Tool V3.2.0) to update the image (update.img). Thanks for helping me along in the process of rebuilding the Android 11 image plus kernel and burning it to eMMC.