IDP Programmer Guide

From ESS-WIKI
Revision as of 05:33, 25 July 2018 by Eric.liang (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Make the IDP Cross-compiler SDK includes kernel source

1. Configure a build and then add the following to your local.conf file. This could be included within a layer using, for example, a template.conf file too:
   TOOLCHAIN_TARGET_TASK_append = " python-dev kernel-dev"
2. Build and install the SDK:
   $ make export-sdk
   $ export/wrlinux-6.0.0.11-eglibc-x86_64-intel_x86_64-w rlinux-image-glibc-std-sdk.sh
   Enter target directory for SDK (default: /opt/windriver/wrlinux/6.0-intel-x86-64): /path/to/sdk
   You are about to install the SDK to "/path/to/sdk". Proceed[Y/n]?
   Extracting SDK...done 
   Setting it up...done
   SDK has been successfully set up and is ready to be used.
3. Source the SDK environment:
   $ cd /path/to/sdk/
   $ source env.sh
4.  Build the needed scripts
   $ cd /path/to/sdk/sysroots/x86_64-wrs-linux/usr/src/kernel
   $ make CROSS_COMPILE=$CROSS_COMPILE ARCH=$ARCH scripts
    HOSTCC  scripts/basic/fixdep
    CC       scripts/mod/empty.o
    HOSTCC  scripts /mod/mk_elfconfig
    MKELF   scripts/mod/elfconfig.h
    CC       scripts/mod/devicetable-offsets.s
    GEN      scripts/mod/devicetable-offsets.h
    HOSTCC  scripts/mod/file2alias.o
    HOSTCC  scripts/mod/modpost.o
    HOSTCC  scripts/mod/sumversion.o
    HOSTLD  scripts/mod/modpost
    HOSTCC  scripts/kallsyms
    HOSTCC  scripts/conmakehash
    HOSTCC  scripts/bin2c
    HOSTCC  scripts/recordmcount
    HOSTCC  scripts/sortextable
5. You should then be able to build your kernel module:
  $ cd /path/to/your/module
  $ make -C /path/to/sdk/sysroots/x86_64-wrs-linux/usr/src/kernel/ CROSS_COMPILE=$CROSS_COMPILE ARCH=$ARCH M=`pwd`
   make: Entering directory `/path/to/sdk/sysroots/x86_64-wrs-linux/usr/src/kerne l-3.10.38-ltsi-wr6.0.0.11-standard'
   CC [M]  /path/to/your/module/mymod.o
   Building modules, stage 2.
   MODPOST 1 modules 
   CC      /path/to/your/module/mymod.mod.o
   LD [M]  /path/to/your/module/mymod.ko
   make: Leaving directory `/path/to/sdk/sysroots/x86_64-wrs-lin ux/usr/src/kernel-3.10.38-ltsi-wr6.0.0.11-standard'

Add kernel source to your IDP SDK

sudo ln -s your_idp_project/bitbake_build/tmp/work-shared/intel-haswell-64/kernel-build-artifacts /opt/windriver/wrlinux/7.0-intel-haswell-64/sysroots/haswell-64-wrs-linux/lib/modules/3.14.44_IDP-XT_3.0-grsec-WR7.0.0.8_idp/build

Modify the kernel configure by manual

Kindly exit from the menuconfig and follow the steps as suggested below: 
1.) Clean the project
2.) Configure your project
04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)04:41, 7 April 2016 (UTC)
3.) Run make -C build linux-windriver.menuconfig command ( A new window will be prompted out. )
4.) Press <Exit> to exit from GUI
5.) Edit .config file:
    vi /Project/build/linux-windriver-*/lin ux-intel-atom-baytrail-*-*-build/.config          (*Please find attached screenshot)
6.) Search for value CONFIG_GRKERNSEC_IO=y and change it to CONFIG_GRKERNSEC_IO =n 
7.) Save it
8.) Run make fs command

Software Development Guide

Set Up the Cross-Compiler

Before you can develop applications or drivers on your Gateway you must have a compiler and set up your environment variables.

Creating Your Toolchain

This section shows you how to set up your Wind River toolchain. The toolchain is the cross compiler based on the GNU Compiler Collection (GCC).

  1. While in $HOME/Project, export the software development kit (SDK).
    make export-sdk


  1. Change to the export directory:
    cd export


  1. Run the SDK installer. Use the command appropriate for your Gateway and replace rcpl with the rcpl number, such as 10:
    • IoT Gateways based on Intel® Atom™ processors:
      ./ wrlinux-7.0.0.<rcpl>-glibc-x86_64-intel_baytrail_64-wrlinux-image-idp-sdk.sh


  • IoT Gateways based on Intel® Core™ processors:
    ./wrlinux-7.0.0.<rcpl>-glibc-x86_64-intel_haswell_64-wrlinux-image-idp-sdk.sh


  • IoT Gateways based on Intel® Quark™ processors:
    ./wrlinux-7.0.0.<rcpl>-glibc-x86_64-intel_quark-wrlinux-image-idp-sdk.sh


  1. When prompted to Enter target directory for SDK, choose a location in which you have access from which you can run commands without using sudo. For example $HOME/opt/toolchain
  2. Type Y when prompted to proceed. The extraction will take about 10 minutes and a message on the screen will inform you when it is complete: 

SDK has been successfully set up and is ready to be used

  1. Change to the directory you chose in step 4.
  2. Make the file system. This make command will execute quickly:
    make fs


Setting up Environment Variables

  1. Locate your environment setup script:
    • IoT Gateways based on Intel® Atom™ processors:
      source environment-setup-atom-wrs-linux


  • IoT Gateways based on Intel® Core™ processors:
    source environment-setup-core-wrs-linux


  • IoT Gateways based on Intel® Quark™ processors:
    source environment-i586-wrs-linux


  1. See what the compiler is configured to do.
    echo $CC

Your response is similar to: 

i586-wrswrap-linux-gnu-gcc -tpentium -Wa,-momit-lock-prefix=yes --sysroot=/data/cross/2.0.3/sysroots/<processor>-wrs-linux

In this response: --sysroot=/data/cross/2.0.3/sysroots/<processor>-wrs-linux is the location in which the compiler will look for the .h files and libraries. <processor> is replaced by the name of the processor in your Gateway.

  1. Recommended: Review the files in /data/cross/2.0.3/sysroots/<processor>-wrs-linux to become familiar with it's contents.

Creating the Application Code

This section guides you through creating a small piece of application code in C. The example in this document shows you how to work with the modbus and read data from either RS232 or RS485. To complete these steps, your environment variables must be correctly configured. See Setting up Environment Variables. You have these choices:

  • Create and compile your sample code on your Development Computer and then copy the compiled code to your Gateway.
  • Create your sample code on your Development Computer and then copy it to your Gateway before you compile and run it.
  • Create, compile, and run your sample code directly on your Gateway.


You can begin these steps in the directory of your choice on either your Gateway or on your Development Computer. Create a directory if necessary and then go to that directory. The example uses $HOME/code/application on the Development Computer.

  1. Create a file called modbus.c that contains the following content:

Note: To copy and paste this code or command, hold your mouse over it and look for this icon: 


#include <stdio.h>
#include <errno.h>
#include <modbus/modbus.h>

int main(int argc, char *argv[] ) 
{
    modbus_t *mb;
    uint16_t tab_reg[32];
    int rc;

    if (argc != 3) {
        printf("Error: modbus expects 2 parameters\n");
        printf("   1. Device (eg. /dev/ttyS0)\n");
        printf("   2. 0 (RS232) or 1 (RS485)\n");
        return -1;
    }

    mb = modbus_new_rtu(argv[1], 9600, 'N', 8, 1);
    if (mb == NULL) {
        fprintf(stderr, "Unable to create the libmodbus context\n");
        return -1;
    }

    rc = modbus_set_slave(mb, 1);
    if (rc != 0) {
        fprintf(stderr, "set slave failed: %s\n", modbus_strerror(errno));
        modbus_free(mb);
        return -1;
    }

    modbus_rtu_set_serial_mode(mb, atoi(argv[2]));
    rc = modbus_connect(mb);
    if (rc != 0) {
        fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free(mb);
        return -1;
    }

    rc = modbus_read_registers(mb, 0x030, 1, tab_reg);
    if (rc == -1) {
        fprintf(stderr, "write failed: %d %s\n", errno, modbus_strerror(errno));
        modbus_free(mb);

        return -1;
    }
    printf("result was :%d\n", tab_reg[0]);

    modbus_close(mb);
    modbus_free(mb);

    return 0;
}

2. Compile the modbus application:

CC -o modbus –lmodbus modbus.c