Adding support for menuconfig / Kconfig in my proj

2020-06-16 01:29发布

问题:

I am planning to add support for menuconfig in my project. The project is not associated with Linux kernel so, I have to write everything from scratch in menuconfig and Makefile.

How do I add support for menuconfig and create Kconfig and make the makefile read the defines in .config?

Any good tutorial to begin with?

回答1:

If you are interested on using KBuild/KConfig for your custom applications, you may try the following Github projects. They aim to provide an initial template for projects using KBuild/KConfig and, therefore, supporting menuconfig.

  • Kbuild skeleton: https://github.com/masahir0y/kbuild_skeleton
  • Kbuild template: https://github.com/embedded-it/kbuild-template


回答2:

I'll assume you are making a driver that is outside of the kernel directory. Information for that can be found here: https://www.kernel.org/doc/Documentation/kbuild/modules.txt.

Outside of that, if you want a userspace file to see the .config variables, you can have it depend on the kernel build, and then include autoconf.h, which is in the include/generated folder for recent versions of the kernel. Userspace does not use kbuild directly.



回答3:

First you need to copy the folders and files below from linux folder 'scripts' into your own project

  • basic
  • kconfig
  • Kbuild.include
  • Makefile.build
  • Makefile.host
  • Makefile.lib

Sources in folders basic and kconfig need to be built for your processor architecture. How to do it is written in the linux Makefile. You can change some names using next variables

  • KCONFIG_CONFIG = .config
  • KCONFIG_AUTOHEADER = application/autoconf.h
  • KCONFIG_AUTOCONFIG = build/include/config/auto.conf
  • KCONFIG_TRISTATE = build/include/config/tristate.conf

The following project initially created for ARM MCUs can help you to understand kconfig

https://github.com/mcu/kconfig