SDK adaptation guide for non-AliOS Things environments

更新时间:
复制 MD 格式

This document describes how to adapt the software development kit (SDK) for non-AliOS Things environments.

Adaptation flow

The following figure shows the overall flow. To avoid header file dependency issues during compilation, compile the Hardware Abstraction Layer (HAL) and Transport Layer Security (TLS) as source files in your project.

C-SDK适配流程

Porting steps

This section uses SDK V1.6.0 for non-AliOS Things environments as an example.

  1. Download SDK V1.6.0 for non-AliOS Things environments. For more information, see Obtain the SDK.
  2. Compile the SDK for non-AliOS Things environments.
    1. Configure the cross compiler path.

      In the build-rules/settings.mk file, modify TOOLCHAIN_DLDIR := /home/mytoolchain to specify the path of the compiler folder. Then, in the build-rules/funcs.mk file, add the compiler's relative path to the Relative_TcPath function, as shown in the following code.

      define 
      ( \
          case $(1) in \
              xtensa-lx106-elf-gcc ) \
                  echo "gcc-xtensa-lx106-linux/main/bin" ;; \
              arm-none-eabi-gcc ) \
                  echo "gcc-arm-none-eabi-linux/main/bin" ;; \
              nds32le-elf-gcc ) \
                  echo "bin" ;; \
          esac \
      )
      endef
    2. Add a configuration file.

      In the src/board/ folder, add a new configuration file. For example, to adapt the SDK for a FreeRTOS system on an ESP8266 chip, you can add a config.freertos.esp8266 file. The following code provides an example.

      # Add chip platform-specific configurations
      CONFIG_ENV_CFLAGS += \
          -DBOARD_ESP8266 -u call_user_start \
          -fno-inline-functions \
          -ffunction-sections \
          -fdata-sections \
          -mlongcalls \
          -Wl,-static
      
      # Configure compiler options
      CONFIG_ENV_CFLAGS += -Os
      
      # Configure submodules that do not need to be compiled
      CONFIG_src/ref-impl/tls         :=
      CONFIG_src/ref-impl/hal         :=
      CONFIG_examples                 :=
      CONFIG_tests                    :=
      CONFIG_src/tools/linkkit_tsl_convert :=
      
      # Cross compiler prefix. Do not include the path here.
      CROSS_PREFIX := xtensa-lx106-elf-
    3. Compile the library file.
      1. Configure the SDK features.

        Choose one of the following methods:

        • Directly edit the make.settings file in the root directory.
        • Run the make menuconfig command to configure the settings.
      2. Run the make clean command.
      3. Run the make reconfig command to select a configuration.

        As shown in the following figure, enter 2 to select the config.freertos.esp8266 configuration.

        config.freertos.esp8266配置
      4. Run the make command.

        If the compilation is successful, the library file libiot_sdk.a is generated in the output/release/lib folder.

    Note We recommend that you compile the Hardware Abstraction Layer (HAL) and Transport Layer Security (TLS) code directly in your own project. If you must compile the HAL in the SDK project, first comment out CONFIG_src/ref-impl/hal := in the file. Then, place the HAL source files in the src/ref-impl/hal/os/freertos folder and the dependent header files in the prebuild/freertos/include folder. SDK versions earlier than V1.6.0 that do not include AliOS Things have a header file dependency issue. You need to modify the value of IMPORT_DIR in the file in the root directory to IMPORT_DIR := $(TOP_DIR)/prebuilt.
  3. Link the library file to your project.
    1. Link the library file output/release/lib/libiot_sdk.a to your project.
    2. Place the header files from the output/release/include folder into your project and configure the header file path.
    3. In your application, add the include "iot_import.h" header file.

      This header file includes other SDK header files.

    4. (Optional) If you compile the HAL and TLS code directly in your project, add the following code to the config.freertos.esp8266 file and run make reconfig for the changes to take effect.
      CONFIG_src/ref-impl/tls         :=
      CONFIG_src/ref-impl/hal         :=
      // This prevents the TLS and HAL libraries from being generated.
      Note After you modify the config.freertos.esp8266 file, you must run make reconfig for the changes to take effect.
    5. Place the files from the example/linkkit/living_platform folder into your project and compile them. Then, start a task to execute living_platform_main and run the entire SDK.
    Note After the SDK is running, you can debug runtime errors related to the adaptation. For example, if a Constrained Application Protocol (CoAP) error occurs, check whether HAL_UDP_xxx.c is adapted correctly.

Descriptions of make commands

Command Description
make distclean Purges all intermediate files generated during the build process, restoring the current directory to its state immediately after cloning.
make Starts compilation using the default or selected platform configuration file.
make env Displays the current build configuration. This is very useful for viewing information such as the cross-compilation toolchain and compilation CFLAGS.
make reconfig Displays a menu for selecting a platform. You can press a number key to make a selection and then start compilation based on the corresponding hardware platform configuration.
make config Displays the currently selected platform configuration file.
make menuconfig Edits and generates the feature configuration file make.settings in a graphical user interface. Directly editing the make.settings file is also effective.
make help Prints the help text.

Notes on adapting the HAL

  • If you are using Linux, you can refer to the C files in the src/ref-impl/hal/os/ubuntu folder. Most of these files can be used directly.
  • If you are not using Linux, for example, on a FreeRTOS system, you can refer to the files in the src/ref-impl/hal/os/ubuntu folder to implement each HAL function.
  • Many HAL functions are related to network provisioning. For more information, see Wi-Fi device network provisioning adaptation and development.