当前位置:网站首页>Hongmeng porting i.mx6ull (VI) kconfig_ GCC_ Mkefile

Hongmeng porting i.mx6ull (VI) kconfig_ GCC_ Mkefile

2022-06-09 14:50:00 da..

1.Kconfig Introduce

 Insert picture description here

Reference documents :

 Any one Linux Kernel Documentation\kbuild\kconfig-language.rst

https://www.rt-thread.org/document/site/programming-manual/kconfig/kconfig/

For all kinds of kernels , Just support menuconfig Configuration interface , Is to use Kconfig.
In the configuration interface , You can choose 、 set an option , These settings will be saved in .config In the document .
Makefile Will contain .config, Determine which files to compile according to the values inside 、 How to compile files .

1.1 Configuration interface example

 Insert picture description here

problem :

  • In this interface , Where do the configuration items come from
  • In this interface , How are these configuration items organized
  • In this interface , Our choice 、 Set up , Where to save the results

1.2 Save the configuration results

1.2.1 Example

The operation results in the configuration interface are saved in .config In file , Examples are as follows :

# LOSCFG_COMPILER_HIMIX_32 is not set
LOSCFG_COMPILER_CLANG_LLVM=y

#
# Platform
#
LOSCFG_PLATFORM="stm32mp157"
# LOSCFG_PLATFORM_HI3516DV300 is not set
# LOSCFG_PLATFORM_HI3518EV300 is not set
LOSCFG_PLATFORM_STM32MP157=y
# LOSCFG_PLATFORM_IMX6ULL is not set
LOSCFG_PLATFORM_BSP_GIC_V2=y
LOSCFG_ARCH_ARM=y
LOSCFG_ARCH_ARM_AARCH32=y
LOSCFG_ARCH_ARM_V7A=y
LOSCFG_ARCH_ARM_VER="armv7-a"
LOSCFG_ARCH_FPU_VFP_V4=y
LOSCFG_ARCH_FPU_VFP_D32=y
LOSCFG_ARCH_FPU_VFP_NEON=y
LOSCFG_ARCH_FPU="neon-vfpv4"
LOSCFG_ARCH_CORTEX_A7=y
LOSCFG_ARCH_CPU="cortex-a7"

Makefile Will contain .config file , It will be based on variables such as LOSCFG_PLATFORM_STM32MP157 Select a board related file .

1.2.2 Prefix of configuration item

stay Kconfig In file , Suppose the name of the configuration item is XXX, stay .config In file :

  • By default , Its corresponding variable name is CONFIG_XXX
  • If the environment variable is set CONFIG_=ABC, Then the corresponding variable name is ABC_XXX
  • stay Liteos-a Medium Makefile in export CONFIG_=LOSCFG_, So the corresponding variable name is LOSCFG_XXX

 Insert picture description here

1.3 Describe a single configuration item config

1.3.1 Example

stay make menuconfig Interface , You can see this configuration item :

 Insert picture description here

In the configuration interface , Use the direction arrow to swim to Enable FAT Cache Sync Thread after , Sure :

  • Input Y, Select configuration item , stay .config In the corresponding LOSCFG_FS_FAT_CACHE_SYNC_THREAD=y

  • Input N, Do not select configuration item , stay .config In the corresponding # LOSCFG_FS_FAT_CACHE_SYNC_THREAD is not set

How to implement the configuration items in the figure above ? ( Here is help . We can find through this kconfig file )

 Insert picture description here

grep "FS_FAT_CACHE_SYNC_THREAD" * -nr | grep Kconfig

 Insert picture description here

stay Kconfig In file , It corresponds to the following code :

 Insert picture description here

1.3.2 grammar

 Insert picture description here

Explain the following :

  • config Express config option, This is a Kconfig Basic entry; other entry Is to manage config Of . config Represents the beginning of a configuration option , Next to it FS_FAT_CACHE_SYNC_THREAD Is the name of the configuration option .

config The following lines define the properties of this configuration option .

The property can be a property of the configuration option : type 、 Input prompt 、 Dependency relationship 、 The default value is 、 Help information .

  • bool Indicates the type of configuration option , Every config Menu items should have type definitions , The variables are 5 Types

    • bool Boolean type
    • tristate Tristate type
    • string character string
    • hex Hexadecimal
    • int integer
  • "Enable FAT Cache Sync Thread": Prompt information

  • depends on: Show dependency , Only FS_FAT_CACHE To be selected , You can choose FS_FAT_CACHE_SYNC_THREAD

  • select XXX: Indicates a reverse dependency , That is, after the current configuration option is selected ,XXX The option will be selected .

  • default Indicates the default value of configuration options ,bool The default value of type can be y/n.

  • help Help information , stay make menuconfig Interface input H Key time , You will be prompted with help information .

1.4 Implementation menu menu/endmenu

1.4.1 Example

 Insert picture description here
 Insert picture description here
 Insert picture description here

stay Kconfig in , The code is as follows :

menu "Lib"
config LIB_LIBC
    bool "Enable Libc"
    default y
    help
      Answer Y to enable libc for full code.

config LIB_ZLIB
    bool "Enable Zlib"
    default y
    depends on LIB_LIBC
    help
      Answer Y to enable LiteOS support compress file library.
endmenu

1.4.2 grammar

Explain the following :

  • menu "xxx" Represents a menu , Menu name is "xxx"

  • menu and endmenu Between entry All are "xxx" Menu options

  • In the example above, the submenu has 2 An option :“Enable Libc”、“Enable Zlib

  • Because the second menu item depends on the first menu item , So the second menu item is indented one space

1.5 Achieve radio choice/endchoice

1.5.1 Example

 Insert picture description here

In the above interface , about LiteOS_Compiler_Type, Yes 2 A choice :arm-linux-ohoseabiclang-llvm.
stay Kconfig How to describe in the document ? as follows :

menu "Compiler"
choice
    prompt "LiteOS_Compiler_Type"
    default COMPILER_CLANG_LLVM
    help
      Enable arm-himix100 or aarch64-himix100 or compiler.

config COMPILER_HIMIX_32
    bool "arm-linux-ohoseabi"
    depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_IMX6ULL || PLATFORM_STM32MP157

config COMPILER_CLANG_LLVM
    bool "clang-llvm"
        depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_IMX6ULL || PLATFORM_STM32MP157

endchoice
endmenu

1.5.2 grammar

Explain the following :

  • choice Express " choice "
  • choice and endchoice Between entry Are optional items
  • Between them , Only one can be set to "y": Means to program into the kernel
  • Between them , Multiple can be set to "m": Means to compile as a module
  • For example, a hardware has multiple drivers
    • Only one driver can be programmed into the kernel at a time
    • But multiple drivers can be compiled into modules separately

1.6 menuconfig

menuconfig XXX and config XXX similar , The only difference is that this option can be set except y/m/n Outside , You can also implement menu effects ( Enter the item by pressing enter ).

1.6.1 Example

 Insert picture description here

For the above interface ,Kconfig The code in the file is as follows :

menuconfig OF
        bool "Device Tree and Open Firmware support"
        help
          This option enables the device tree infrastructure.
          It is automatically selected by platforms that need it or can
          be enabled manually for unittests, overlays or
          compile-coverage.

if OF

config OF_UNITTEST
        bool "Device Tree runtime unit tests"
        depends on OF_IRQ
        select OF_EARLY_FLATTREE
        select OF_RESOLVE
        help
          This option builds in test cases for the device tree infrastructure
          that are executed once at boot time, and the results dumped to the
          console.

          If unsure, say N here, but this option is safe to enable.

config OF_OVERLAY
        bool "Device Tree overlays"
        select OF_DYNAMIC
        select OF_RESOLVE
        help
          Overlays are a method to dynamically modify part of the kernel's
          device tree with dynamically loaded data.
          While this option is selected automatically when needed, you can
          enable it manually to improve device tree unit test coverage.

endif # OF

1.6.2 grammar

menuconfig Common formats are 2 Kind of :

  menuconfig M
  if M
      config C1
      config C2
  endif

or :

  menuconfig M
  config C1
      depends on M
  config C2
      depends on M

The first 1 term menuconfig M Follow config M The grammar is the same , The difference is menuocnfig M It can be followed by several dependencies M Of config C1config C2 And other sub configuration items .

1.7 if/endif

1.7.1 grammar

Above menuconfig in if/endif Use , Its syntax is as follows :

"if" <expr>
<if block>
"endif"

1.7.2 Example

Examples are as follows , Only defined OF term ,OF_UNITTEST and OF_OVERLAY Will be displayed :

if OF

config OF_UNITTEST
        bool "Device Tree runtime unit tests"
        depends on OF_IRQ
        select OF_EARLY_FLATTREE
        select OF_RESOLVE
        help
          This option builds in test cases for the device tree infrastructure
          that are executed once at boot time, and the results dumped to the
          console.

          If unsure, say N here, but this option is safe to enable.

config OF_OVERLAY
        bool "Device Tree overlays"
        select OF_DYNAMIC
        select OF_RESOLVE
        help
          Overlays are a method to dynamically modify part of the kernel's
          device tree with dynamically loaded data.
          While this option is selected automatically when needed, you can
          enable it manually to improve device tree unit test coverage.

endif # OF

1.8 source

source Statement is used to read from another file Kconfig file , Such as :

source "../../kernel/liteos_a/platform/Kconfig"

1.9 comment

comment The statement appears in the first line of the interface , Used to define some prompt messages , Such as :

config ARCH_ARM
   bool

source "arch/arm/Kconfig"

comment "Extra Configurations"

config ARCH_FPU_DISABLE
    bool "Disable Floating Pointer Unit"
    default n
    help
      This option will bypass floating procedure in system.

The interface is as follows :

 Insert picture description here

2. preparation

Install the software in GIT Warehouse :

doc_and_source_for_openharmony\ Tools \
    codeblocks-20.03mingw-setup.exe
    make-3.81.exe

2.1. arm-linux-gcc and gcc It's similar

  • arm-linux-gcc
  • to ARM Chip compiler
  • gcc
  • stay x86 compiler
  • The usage is basically the same
  • For the convenience of demonstration , We use gcc
  • For convenience in windows Next presentation , We use Code::Blocks
  • Its installation program comes with gcc

2.2. Code::Blocks

It is based on GCC Of windows IDE, Can be used for development C/C++/Fortran.
Official website address :http://www.codeblocks.org/

In what we offer GIT There are also... In the warehouse :git clone https://e.coding.net/weidongshan/openharmony/doc_and_source_for_openharmony.git
download GIT after , stay Tools Under the table of contents .

2.2.1 install

Follow the instructions to install .

2.2.2 Set up windows environment variable

stay Path Add... To the environment variable :C:\Program Files\CodeBlocks\MinGW\bin

2.2.3 Command line example

start-up Git Bash, compiler hello.c:


#include <stdio.h>

int main(void)
{
    
	printf("hello, world!\n");
	return 0;
}

compile 、 Run the command as follows :

gcc -o hello  hello.c
./hello.exe

2.3. Make

install make-3.81.exe after , stay Path Add... To the environment variable :C:\Program Files (x86)\GnuWin32\bin

3.gcc Detailed explanation of compilation process

The supporting source code is in GIT Of all the boards in the warehouse source\02_ Source code written when recording video \01_gcc_options in .

3.1. Program compilation 4 step

 Insert picture description here

We use it a lot “ compile ” Generally referring to the above 4 One of the first steps , Sometimes it even includes these four steps .

3.2. gcc How to use

gcc  [ Options ]    file name 

3.2.1 gcc Examples of use

gcc hello.c                   //  Output a file called a.out Executable program of , Then you can execute ./a.out
gcc -o hello hello.c          //  The output name is hello Executable program of , Then you can execute ./hello
gcc -o hello hello.c -static  //  Static links 

gcc -c -o hello.o hello.c  //  To compile the first ( Don't link )
gcc -o hello hello.o       //  Link again 

3.2.2 gcc Common options

3.2.2.1 Manually control the compilation process

Options function
-v see gcc The version of the compiler , Show gcc Detailed process of execution
-o Specify the output file name as file, This name cannot have the same name as the source file name
-E Just preprocessing , I can't compile 、 assembly 、 link t
-S Compile only , I can't compile 、 link
-c Compile and assemble , Will not link

One c/c++ The document has to be preprocessed 、 compile 、 Assembly and linking can become executable files .
(1) Preprocessing
C/C++ In the source file , With “#” The first command is called a preprocessing command , If it contains a command “#include”、 Macro definition command “#define”、 Conditional compilation command “#if”、“#ifdef” etc. . Preprocessing is about to include (include) Insert the file into the original file 、 Expand the macro definition 、 Select the code to use according to the conditional compilation command , Finally, output these things to a “.i” Waiting for further processing in the file .
(2) compile
Compiling is to put C/C++ Code ( Such as the above “.i” file )“ translate ” Into assembly code .
(3) assembly
Assembly is to translate the assembly code output in the second step into machine code in a certain format , stay Linux The general performance of the system is ELF Target file (OBJ file ).“ Disassembly ” It refers to converting machine code into assembly code , This is often used in debugging programs .
(4) link
The link will be generated in the previous step OBJ Of file and system libraries OBJ file 、 Linking library files , Finally, an executable file that can run on a specific platform is generated .

hello.c( Preprocessing )->hello.i( compile )->hello.s( assembly )->hello.o( link )->hello The detailed commands for each step are as follows :

gcc -E -o hello.i hello.c
gcc -S -o hello.s hello.i
gcc -c -o hello.o hello.s
gcc -o hello hello.o

The above series of commands are troublesome ,gcc Would be right .c The file is preprocessed by default , Use -c Let's go back to compilation 、 assembly , To get .o file , then .o File links , Get the executable application . Simplified as follows :

gcc -c -o hello.o hello.c// The first three steps 
gcc -o hello hello.o

3.2.2.2 Use the suffix to determine the compilation process

Reference resources 《 The embedded Linux Application development complete manual 》

  • summary * The input file's suffix and options are jointly determined gcc What are the operations to be performed
  • During the compilation process , The last step is to link
  • Unless you use -E、-S、-c Options
  • Or a compilation error prevents the complete compilation process

3.2.2.3 Specify the header directory

Where is the header file ?

  • System catalog * Where is the system directory ? Somewhere in the tool chain include Catalog
    • How to determine ?
```
echo 'main(){}'| gcc -E -v -  //  It lists the header file directory 、 The library catalog (LIBRARY_PATH)
```
  • The system may not be used include Catalogue ? Sure , Specify parameters at compile time -nostdinc
  • You can specify your own header file directory
-I < Header Directory >

3.2.2.4 Specify the library file

Where are the library files ?

  • System catalog * Where is the system directory ? Somewhere in the tool chain lib Catalog
    • How to determine ?
```
echo 'main(){}'| gcc -E -v -  //  It lists the header file directory 、 The library catalog (LIBRARY_PATH)
```
  • The system may not be used lib Catalogue ? Sure , Specify parameters at compile time -nostdlib
  • You can specify your own library file directory
-L < Library file directory >
  • Specify the library file
-l  <abc>   //  link  libabc.so  or  lib.a

3.3 Development board program compilation example

Last link , Use arm-linux-ld Instead of using arm-linux-gcc

  • The former can completely specify the connected file itself
  • The latter will link some default startup files

3.4 Reference books

《 The embedded Linux Application development complete manual 》 Medium 《3.1 Description of cross compilation tool options 》

4.makefile

Look at this

原网站

版权声明
本文为[da..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091402596885.html