NUTTX Build System

Source: Internet
Author: User
Tags srec


(Embedded RTOs NUTTX 7.1 makefile)
NUTTX Construction System Reprint Please specify Source: http://blog.csdn.net/zhumaill/article/details/24400441

1 Brief introduction
NUTTX is compiled by the Makefile file organization. The Makefile file describes the rules for compiling, linking, and so on for the entire NUTTX project, telling make what files to compile, how to compile, and under what conditions.





NUTTX does not use Autoconf, Automake, CMake, scons and other self-motivated compilation tools. Its Makefile files are written entirely by hand. Easier to read than the compiled files that you use to proactively compile the tools. Easier to understand the software's compilation process.



That's the sentence: trying to make things simple in a way that makes things more complicated.

2 Makefile File organization structure


    • Nuttx/makefile: Top-level Makefile file. The content is very easy, depending on the host environment. Conditions include Makefile.unix or Makefile.win.
    • Makefile files in the Nuttx/makefile.unix:linux environment.
    • Makefile files in the nuttx/makefile.win:windows environment.



    • Nuttx/make.defs: Copied from nuttx/config/< board >/< target configuration >/make.defs.



    • Makefile, Make.defs, and MAKE.DEP under sub-folders of all levels.
3 Makefile files include tree
(Top-level folder is NUTTX)

`        |<--.config
         |
         |                 |<--.config
         |                 |<--tools/Config.mk
         |<--Makefile.unix-|
Makefile-|                 |             |<--.config
         |                 |<--Make.defs-|<--tools/Config.mk
         |                               |<--arch/arm/src/armv7-m/Toolchain.defs
         |
         |<--Makefile.win-(Skip over)
It can be seen that the. config file generated in the NUTTX configuration system is included in the Makefile file.

Makefile, Make.defs, and MAKE.DEP under sub-folders are not included through include. Instead, it is called when you run the make command in the Makefile file.

4 Build goals and options 4.1 build goals:
The following is an overview of the build goals available in the top-level Makefile file:

All
Default target, build the NUTTX executable file in the selected output format.

Clean
Removes derived object files, static library files, executable files, and temporary files, but preserves the configuration and context of files and folders. Also retains the MAKE.DEP file.







Distclean
In addition to completing the "clean" work, it also contains files that remove all configuration and context. The essence is to restore the folder structure to its original, non-configured state.

4.2 Application housekeeping targets
The Appdir variable references the user application folder. Such as NUTTX includes the app/folder, however, this is not considered part of the NUTTX and can be replaced by a different application folder. In most cases, the application folder is seen in the Makefile script as if no other build folder. However, for convenience, the following targets are included to support the housekeeping functionality in the User application folder from the Nuttx build folder.





Apps_clean
Run the clean operation only on the user application folder.

Apps_distclean
Run the Distclean operation only on the user application folder. Apps/.config files are retained, so this is not a complete distclean. But more than the configuration reset.

Export
The export target will package the NUTTX library and header files to the output package.



Note: (1) It is necessary to make some extensions to KERNEL construction.



(2) The logic in tools/mkexport.sh only supports GCC, for example, explicitly assuming that the static library generator is "AR".

Download
This is an assistant goal that will rebuild the NUTTX and download it to the target system in just one step.



The operation of this target depends entirely on the implementation of the DOWNLOAD command in the user's Make.defs file. Assume that the DOWNLOAD command is not defined. It will produce an error.





4.3 Internal targets
The following targets are used internally by make logic, but are assumed to be necessary. Can be called from the command line under certain conditions.

Depend
Create build dependencies to generate MAKE.DEP files and. depend files. (Note: Build dependencies are currently not supported under Cygwin using the Windows local toolchain)

Context
Call the context target each time the target is built to ensure that NUTTX is configured correctly.



The basic configuration steps include creating Config.h and Version.h header files in the Include/nuttx folder and establishing symbolic links to the configuration folders.

Clean_context
This is part of the Distclean goal. It removes all header files and symbolic links created by the context target.

4.4 Build Options
Of course. The value of the make variable can be overwritten from the command line, no matter what. However, there is a special variable assignment option that may be useful to you:

V=1

This is the build specific level flag. Assuming you specify v=1 on the command line, you will see the exact command you are using at build time. It can be useful when adding new boards or tracking compile-time errors and warnings.





5 All target dependent tree


`                          |<--pass1dep-|<----------------------------------------╮
|<--pass1deps-|            |<--tools/mkdeps$(HOSTEXEEXT)             |
|     |       |                                                      |
|╭╯| < -- $(userlibs) (empty for plane construction)|
|  |                                                                 |
|  |           |<--pass2dep-|<---------------------------------------|
|<---pass2deps-|            |<--tools/mkdeps$(HOSTEXEEXT)            |
|  |  |        |                                                     |
||||< -- $(nuttxlibs) (configuration related) < --╮|
|  |  |                                      |                       |
|  |  |  ╭-----------------------------------╯                       |
|  |  |  |                                                           |
|  |  |  |<--lib/libsched$(LIBEXT)<--sched/libsched$(LIBEXT)<--------|
|  |  |  |<--lib/libc$(LIBEXT)<--libc/libc$(LIBEXT)<-----------------|
|  |  |  |<--lib/libmm$(LIBEXT)<--mm/libmm$(LIBEXT)<-----------------|
all<--$(BIN)-|  |  |  |<--lib/libarch$(LIBEXT)<--$(ARCH_SRC)/libarch$(LIBEXT)<----|
|  |  |  |<--lib/libcxx$(LIBEXT)<--libxx/libcxx$(LIBEXT)<------------|
|  |  |  |<--lib/libapps$(LIBEXT)<--$(APPDIR)/libapps$(LIBEXT)<------|
|  |  |  |<--lib/libnet$(LIBEXT)<--net/libnet$(LIBEXT)<--------------|
|  |  |  |<--lib/libfs$(LIBEXT)<--fs/libfs$(LIBEXT)<-----------------|
|  |  |  |<--lib/libdrivers$(LIBEXT)<--drivers/libdrivers$(LIBEXT)<--|
|  |  |  |<--lib/libbinfmt$(LIBEXT)<--binfmt/libbinfmt$(LIBEXT)<-----|
|  |  |                                                              |
|  |  ╰---------╮                                                    |
|  |            |                                                    |
|  ╰--------╮   |                                                    |
|           |   |                                                    |
|<--pass1<--╯   |                                                    |
|               |                                                    |
|<--pass2<------╯                                                    |
A kind of
╭---------------------------------------------------------------------------╯
A kind of
|           |<--check_context
|           |
|           |<--include/nuttx/config.h-|<--$(TOPDIR)/.config
|           |                          |<--tools/mkconfig$(HOSTEXEEXT)
|           |
|           |<--include/nuttx/version.h-|<--$(TOPDIR)/.version
|           |                           |<--tools/mkversion$(HOSTEXEEXT)
|           |
|<--context-|<--include/math.h<--include/nuttx/math.h
|<--include/float.h<--include/nuttx/float.h
|<--include/stdarg.h<--include/nuttx/stdarg.h
A kind of
|            |<--include/arch<-Make.defs
|            |
|            |<--include/arch/board-|<--include/arch<--Make.defs
|            |                      |<--Make.defs
|            |
|<--dirlinks-|<--include/arch/chip-|<--include/arch<--Make.defs
|                     |<--Make.defs
A kind of
|<--$(ARCH_SRC)/board<--Make.defs
|<--$(ARCH_SRC)/chip<--Make.defs
|<--include/apps<--Make.defs
6 all target compilation process 6.1 context target
Because the all target is the default target. So running the make command without parameters is the compile all target. The first attempt is to compile the context target, in which config.h is generated from the. config file, and many C files include config.h for user configuration. Note that the 2 folders in the soft link, the following will be used:

$ (ARCH_SRC)/board:
Link the Nuttx/configs/shenzhou/src folder to the Nuttx/arch/arm/src/board folder.







$ (ARCH_SRC)/chip:
Link the Nuttx/arch/arm/src/stm32 folder to the Nuttx/arch/arm/src/chip folder.

However, since the make context was already run once when BuildRoot was installed, and making clean does not delete the files generated by the context target, this step did nothing.

6.2 PASS1DEP Target



Pass1dep:context tools/mkdeps$ (Hostexeext)        $ (Q) for Dir in $ (userdepdirs), do                 $ (make)-C $ $dir topdir= "$ (topdir ) "Depend;         Done
Planar build is the compilation of NUTTX into a single binary file, all of which are built in the same address space, and all the components are able to access all other components.





The plane was built when $ (userdepdirs) was empty, and it didn't do anything either.





6.3 $ (userlibs) target
The plane was built when $ (userlibs) was empty, and it didn't do anything either.



So the whole pass1deps goal is over.





6.4 PASS2DEP Target



Pass2dep:context tools/mkdeps$ (Hostexeext)        $ (Q) for Dir in $ (kerndepdirs), do                 $ (make)-C $ $dir topdir= "$ (topdir ) "extradefines=$ (kdefine) depend;         Done
Generate MAKE.DEP and. Depend files under sub-folders at all levels, based on the value of the $ (kerndepdirs) variable.

The subfolders for generating MAKE.DEP and. Depend files under the Nuttx folder are:
    • Nuttx/arch/arm/src
    • Nuttx/binfmt
    • Nuttx/configs/shenzhou/src
    • Nuttx/drivers
    • Nuttx/fs
    • nuttx/libc
    • Nuttx/libxx
    • nuttx/mm
    • Nuttx/net
    • Nuttx/sched
6.5 $ (nuttxlibs) target
The next step is to compile $ (nuttxlibs) in the Pass2deps target, which is a multi-objective. Depending on the configuration, the detailed objectives are different. Its job is to generate multiple static library files. There are 10 static library files generated:
    • Nuttx/lib/libapps.a
    • Nuttx/lib/libarch.a
    • Nuttx/lib/libbinfmt.a
    • Nuttx/lib/libc.a
    • Nuttx/lib/libcxx.a
    • Nuttx/lib/libdrivers.a
    • Nuttx/lib/libfs.a
    • Nuttx/lib/libmm.a
    • Nuttx/lib/libnet.a
    • Nuttx/lib/libsched.a
The following is an example of LIBARCH.A. Examine the compilation process of the static library.








$ (ARCH_SRC)/libarch$ (libext): Context        $ (Q) $ (make)-C $ (ARCH_SRC) topdir= "$ (topdir)" libarch$ (Libext)
Among them: $ (ARCH_SRC) = Nuttx/arch/arm/src. $ (libext) =. A. Instead of the variable name, the value in the variable is passed. The 2nd line means to switch to the folder Nuttx/arch/arm/src first. Run the make command again to pass the number of parameters Topdir. Compile the target libarch.a. The make call here is the Makefile in the folder Nuttx/arch/arm/src, which compiles the target in the Makefile. In Nuttx/arch/arm/src/makefile, first define BIN = libarch$ (Libext), and then:

$ (BIN) $ (Kbin): $ (OBJS)        $ (call ARCHIVE, [email protected], $ (OBJS))
Among: Objs = $ (AOBJS) $ (COBJS), while
AOBJS = $ (asrcs:. s=$ (Objext))
Asrcs = $ (CHIP_ASRCS) $ (CMN_ASRCS)

COBJS = $ (csrcs:.c=$ (Objext))
Csrcs = $ (CHIP_CSRCS) $ (CMN_CSRCS)

Nuttx/arch/arm/src/makefile includes nuttx/arch/arm/src/chip/make.defs,4 variables Chip_asrcs, Cmn_asrcs, CHIP_CSRCS, CMN_CSRCS are defined in the nuttx/arch/arm/src/chip/make.defs. The value of the variable after multiple assignments is as follows:

Chip_asrcs = (empty)

Cmn_asrcs = Up_saveusercontext. S Up_fullcontextrestore. S Up_switchcontext. S vfork. S

Chip_csrcs = stm32_allocateheap.c stm32_start.c stm32_rcc.c stm32_lse.c stm32_lsi.c stm32_gpio.c stm32_exti_gpio.c STM32_FLASH.C stm32_irq.c stm32_timerisr.c stm32_dma.c stm32_lowputc.c stm32_serial.c stm32_spi.c stm32_sdio.c stm32_ TIM.C stm32_waste.c stm32_ccm.c stm32_i2c.c stm32_idle.c stm32_pmstop.c stm32_pmstandby.c stm32_pmsleep.c stm32_ pminitialize.c stm32_eth.c stm32_pwr.c STM32_RTC.C

Cmn_csrcs = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c up_mdelay.c up_udelay.c up_exit.c up_ initialize.c up_initialstate.c up_interruptcontext.c up_memfault.c up_modifyreg8.c up_modifyreg16.c up_modifyreg32.c UP_RELEASEPENDING.C up_releasestack.c up_reprioritizertr.c up_schedulesigaction.c up_sigdeliver.c up_systemreset.c UP_UNBLOCKTASK.C up_usestack.c up_doirq.c up_hardfault.c up_svcall.c up_vfork.c

From here you can find out which source files are compiled and which source files are not compiled.

Command $ (call ARCHIVE, [email protected], $ (OBJS)) to package the static library LIBARCH.A.

Now return to Nuttx/makefile.unix:

lib/libarch$ (Libext): $ (ARCH_SRC)/libarch$ (libext)        $ (Q) install $ (ARCH_SRC)/libarch$ (libext) lib/libarch$ ( Libext)
Middle: Install is the Linux command. This is equivalent to copying. Copy the LIBARCH.A to the Nuttx/lib folder.

6.6 Pass1 Target

pass1: pass1deps
ifeq ($(CONFIG_BUILD_2PASS),y)
        $(Q) if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then                 echo "ERROR: CONFIG_PASS1_BUILDIR not defined";                 exit 1;         fi
        $(Q) if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then                 echo "ERROR: CONFIG_PASS1_BUILDIR does not exist";                 exit 1;         fi
        $(Q) if [ ! -f "$(CONFIG_PASS1_BUILDIR)/Makefile" ]; then                 echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR";                 exit 1;         fi
        $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" LINKLIBS="$(LINKLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)"
endif
The plane is built without doing whatever it is.







6.7  pass2 target
Last compiled Pass2


pass2: pass2deps
        $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(LINKLIBS)" EXTRADEFINES=$(KDEFINE) $(BIN)
        $(Q) if [ -w /tftpboot ] ; then                 cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH};         fi
ifeq ($(CONFIG_RRLOAD_BINARY),y)
        @echo "MK: $(BIN).rr"
        $(Q) $(TOPDIR)/tools/mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
        $(Q) if [ -w /tftpboot ] ; then                 cp -f $(BIN).rr /tftpboot/$(BIN).rr.$(CONFIG_ARCH);         fi
endif
ifeq ($(CONFIG_INTELHEX_BINARY),y)
        @echo "CP: $(BIN).hex"
        $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).hex
endif
ifeq ($(CONFIG_MOTOROLA_SREC),y)
        @echo "CP: $(BIN).srec"
        $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
endif
ifeq ($(CONFIG_RAW_BINARY),y)
        @echo "CP: $(BIN).bin"
        $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
endif
        @echo "DUMP: $(BIN).out"
        $(Q) $(OBJDUMP) -x $(BIN) > $(HOME)/$(BIN).out
        @echo "DUMP: $(BIN).S"
        $(Q) $(OBJDUMP) -d -j .text -j .init_section -j .ARM.exidx -j .data -j .bss $(BIN) > $(HOME)/$(BIN).S
        cp -f $(BIN) $(BIN).hex $(BIN).bin $(HOME)
Link static libraries to executable files in elf format. and convert it to. Hex,. bin, and other formats.





I added the last 5 lines. Generate symbol files, disassembly files, and copy some finally files to the Linux User home folder. Implemented by the following lines in the NUTTX installation script:



if !(grep -q ‘    @echo "DUMP: $(BIN).out"‘ Makefile.unix); then
  sed -i ‘/pass2:/,/^$/{
    /^$/i\    @echo "DUMP: $(BIN).out"
    /^$/i\    $(Q) $(OBJDUMP) -x $(BIN) > $(HOME)/$(BIN).out
    /^$/i\    @echo "DUMP: $(BIN).S"
    /^$/i\    $(Q) $(OBJDUMP) -d -j .text -j .init_section -j .ARM.exidx -j .data -j .bss $(BIN) > $(HOME)/$(BIN).S
    /^$/i\    cp -f $(BIN) $(BIN).hex $(BIN).bin $(HOME)
  }‘ Makefile.unix
fi

7 Nuttx/make.defs File
The Nuttx/make.defs file is a Makefile fragment. Copied from the nuttx/config/< board >/< target configuration >/make.defs.





Implemented by the following lines in the NUTTX installation script:



Echo "nuttx configuration"
cd $BASEDIR/$TOPDIR/nuttx/tools
./configure.sh $TARGETCONFIG
The Makefile fragment provides architectural and tool-specific build options.





It will be included in all other Makefile files at build time (once it is installed). The makefile fragment should be defined as:


    • Tools: CC, LD, AR, NM, Objcopy, OBJDUMP
    • Tool options: CFLAGS, Ldflags
When the Makefile fragment executes, it is passed the path topdir of the build root folder. The Makefile fragment should include:

$ (topdir)/.CONFIG:NUTTX configuration
$ (Topdir)/TOOLS/CONFIG.MK: general definition

The definitions in the Nuttx/make.defs file may depend on some of the settings in the. config file. Like what. Suppose Config_debug=y. Cflags will most likely be different.

The Tools/config.mk file includes additional definitions. These definitions may be overwritten by schema-specific make.defs files if necessary:
COMPILE, ASSEMBLE, ARCHIVE, clean, and MKDEP macros


Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.



NUTTX Build System


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.