NuttX Binary Loader

Last Updated: January 26, 2019



Table of Contents

1.0 Introduction

Binary Loaders. The purpose of a binary loader is to load and execute modules in various binary formats that reside in a file system. Loading refers instantiating the binary module in some fashion, usually copy all or some of the binary module into memory and then linking the module with other components. In most architectures, it is the base FLASH code that is the primary component that the binary module must link with because that is where the RTOS and primary tasks reside. Program modules can then be executed after they have been loaded.

Binary Formats. The binary loader provides generic support for different binary formats. It supports a registration interface that allows the number of support binary formats to be loaded at run time. Each binary format provides a common, interface for use by the binary loader. When asked to load a binary, the binary loader will query each registered binary format, providing it with the path of the binary object to be loaded. The binary loader will stop when first binary format the recognizes the binary object and successfully loads it or when all registered binary formats have attempt loading the binary object and failed.

At present, the following binary formats are support by NuttX:

Executables and Libraries The generic binary loader logic does not care what it is that it being loaded. It could load an executable program or a library. There are no strict rules, but a library will tend to export symbols and a program will tend to import symbols: The program will use the symbols exported by the library. However, at this point in time, none of the supported binary formats support exporting of symbols.

binfmt. In the NuttX source code, the short name binfmt is used to refer to the NuttX binary loader. This is the name of the directory containing the binary loader and the name of the header files and variables used by the binary loader.

The name binfmt is the same name used by the Linux binary loader. However, the NuttX binary loader is an independent development and shares nothing with the Linux binary loader other the same name and the same basic functionality.

2.0 Binary Loader Interface

2.1 Binary Loader Header Files

The interface to the binary loader is described in the header file include/nuttx/binfmt/binfmt.h. A brief summary of the data structurs and interfaces prototyped in that header file are listed below.

2.2 Binary Loader Data Structures

When a binary format registers with the binary loader, it provides a pointer to a write-able instance of the following data structure:

The load method is used to load the binary format into memory. It returns either OK (0) meaning that the binary object was loaded successfully, or a negated errno indicating why the object was not loaded.

The type struct binary_s is use both to (2) describe the binary object to be loaded, and if successfully loaded, (2) to provide information about where and how the binary object was loaded. That structure is shown below:

Where the types binfmt_ctor_t and binfmt_dtor_t define the type of one C++ constructor or destructor:

2.3 Binary Loader Function Interfaces

Binary format management:

Basic module management:

PATH traversal logic:

2.3.1 register_binfmt()

Function Prototype:

Description:

Returned Value:

2.3.2 unregister_binfmt()

Function Prototype:

Description:

Returned Value:

2.3.3 load_module()

Function Prototype:

Description:

Returned Value:

2.3.4 unload_module()

Function Prototype:

Description:

Returned Value:

2.3.5 exec_module()

Function Prototype:

Description:

Returned Value:

2.3.7 exec()

Function Prototype:

Description:

Input Parameters:

Returned Value:

2.3.8 envpath_init()

Function Prototype:

Description:

Input Parameters: None

Returned Value:

2.3.9 envpath_next()

Function Prototype:

Description:

Input Parameters:

Returned Value:

2.3.10- envpath_release()

Function Prototype:

Description:

Input Parameters:

Returned Value: None

3.0 Symbol Tables

Symbol Tables. Symbol tables are lists of name value mappings: The name is a string that identifies a symbol, and the value is an address in memory where the symbol of that name has been positioned. In most NuttX architectures symbol tables are required, as a minimum, in order to dynamically link the loaded binary object with the base code on FLASH. Since the binary object was separately built and separately linked, these symbols will appear as undefined symbols in the binary object. The binary loader will use the symbol table to look up the symbol by its name and to provide the address associated with the symbol as needed to perform the dynamic linking of the binary object to the base FLASH code.

3.1 Symbol Table Header Files

The interface to the symbol table logic is described in the header file include/nuttx/binfmt/symtab.h. A brief summary of the data structurs and interfaces prototyped in that header file are listed below.

3.2 Symbol Table Data Structures

struct symbtab_s describes one entry in the symbol table.

A symbol table is a fixed size array of struct symtab_s. The information is intentionally minimal and supports only:

  1. Function pointers as sym_values. Of other kinds of values need to be supported, then typing information would also need to be included in the structure.
  2. Fixed size arrays. There is no explicit provisional for dyanamically adding or removing entries from the symbol table (realloc might be used for that purpose if needed). The intention is to support only fixed size arrays completely defined at compilation or link time.

3.3 Symbol Table Function Interfaces

3.3.1 symtab_findbyname()

Function Prototype:

Description:

Returned Value:

3.3.2 symtab_findorderedbyname()

Function Prototype:

Description:

Returned Value:

3.3.3 symtab_findbyvalue()

Function Prototype:

Description:

Returned Value:

4.0 Configuration Variables

Additional configuration options may be required for the each enabled binary format.