Difference between revisions of "IDP Programmer Guide"
(Created page with "=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,...") |
Eric.liang (talk | contribs) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | =Make the IDP Cross-compiler SDK includes kernel source= | + | = 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: | 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" | TOOLCHAIN_TARGET_TASK_append = " python-dev kernel-dev" | ||
Line 41: | Line 42: | ||
LD [M] /path/to/your/module/mymod.ko | 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' | 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 = | ||
+ | |||
+ | == <u>[https://software.intel.com/en-us/node/735092 Set Up the Cross-Compiler]</u> == | ||
+ | |||
+ | 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). | ||
+ | |||
+ | #While in <samp>$HOME/Project</samp>, export the software development kit (SDK).<pre>make export-sdk</pre> | ||
+ | |||
+ | |||
+ | |||
+ | #Change to the export directory:<pre>cd export</pre> | ||
+ | |||
+ | |||
+ | |||
+ | #Run the SDK installer. Use the command appropriate for your Gateway and replace <samp>'''rcpl'''</samp> with the rcpl number, such as 10: | ||
+ | #*'''IoT Gateways based on Intel<sup>®</sup> Atom™ processors:'''<pre>./ wrlinux-7.0.0.<rcpl>-glibc-x86_64-intel_baytrail_64-wrlinux-image-idp-sdk.sh</pre> | ||
+ | |||
+ | |||
+ | |||
+ | # | ||
+ | *'''IoT Gateways based on Intel<sup>®</sup> Core™ processors:'''<pre>./wrlinux-7.0.0.<rcpl>-glibc-x86_64-intel_haswell_64-wrlinux-image-idp-sdk.sh</pre> | ||
+ | |||
+ | |||
+ | |||
+ | # | ||
+ | *'''IoT Gateways based on Intel<sup>®</sup> Quark™ processors:'''<pre>./wrlinux-7.0.0.<rcpl>-glibc-x86_64-intel_quark-wrlinux-image-idp-sdk.sh</pre> | ||
+ | |||
+ | |||
+ | |||
+ | #When prompted to <samp>Enter target directory for SDK</samp>, choose a location in which you have access from which you can run commands without using <samp>sudo</samp>. For example <samp>$HOME/opt/toolchain</samp> | ||
+ | #Type <samp>Y</samp> when prompted to proceed. The extraction will take about 10 minutes and a message on the screen will inform you when it is complete: | ||
+ | |||
+ | {| cellpadding="4" cellspacing="0" summary="" id="463750BF-E2E7-44C3-94C4-3AA858A04630__GUID-9F058D97-F201-4113-95B2-B33957AB5107" frame="border" border="1" rules="all" | ||
+ | |- valign="top" | ||
+ | | align="left" valign="top" width="600pt" | | ||
+ | <samp>SDK has been successfully set up and is ready to be used</samp> | ||
+ | |||
+ | |} | ||
+ | |||
+ | #Change to the directory you chose in step 4. | ||
+ | #Make the file system. This make command will execute quickly:<pre>make fs</pre> | ||
+ | |||
+ | |||
+ | |||
+ | == Setting up Environment Variables == | ||
+ | |||
+ | #Locate your environment setup script: | ||
+ | #*'''IoT Gateways based on Intel<sup>®</sup> Atom™ processors:'''<pre>source environment-setup-atom-wrs-linux</pre> | ||
+ | |||
+ | |||
+ | |||
+ | # | ||
+ | *'''IoT Gateways based on Intel<sup>®</sup> Core™ processors:'''<pre>source environment-setup-core-wrs-linux</pre> | ||
+ | |||
+ | |||
+ | |||
+ | # | ||
+ | *'''IoT Gateways based on Intel<sup>®</sup> Quark™ processors:'''<pre>source environment-i586-wrs-linux</pre> | ||
+ | |||
+ | |||
+ | |||
+ | #See what the compiler is configured to do.<pre>echo $CC</pre> | ||
+ | |||
+ | Your response is similar to: | ||
+ | |||
+ | {| cellpadding="4" cellspacing="0" summary="" id="463750BF-E2E7-44C3-94C4-3AA858A04630__GUID-E3BB585B-A8C8-4C57-BA7D-AEE19B138168" frame="border" border="1" rules="all" | ||
+ | |- valign="top" | ||
+ | | align="left" valign="top" width="600pt" | <samp>i586-wrswrap-linux-gnu-gcc -tpentium -Wa,-momit-lock-prefix=yes --sysroot=/data/cross/2.0.3/sysroots/<processor>-wrs-linux</samp> | ||
+ | |} | ||
+ | |||
+ | In this response: <samp>--sysroot=/data/cross/2.0.3/sysroots/<processor>-wrs-linux</samp> is the location in which the compiler will look for the <samp>.h</samp> files and libraries. <samp><processor></samp> is replaced by the name of the processor in your Gateway. | ||
+ | |||
+ | #Recommended: Review the files in <samp>/data/cross/2.0.3/sysroots/<processor>-wrs-linux</samp> 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 [https://software.intel.com/node/463750bf-e2e7-44c3-94c4-3aa858a04630#463750BF-E2E7-44C3-94C4-3AA858A04630__GUID-691F5F6C-593A-4B71-9266-A6A9D5F27140 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 <samp>$HOME/code/application</samp> on the Development Computer. | ||
+ | |||
+ | #Create a file called <samp>modbus.c</samp> that contains the following content: | ||
+ | |||
+ | Note: To copy and paste this code or command, hold your mouse over it and look for this icon: | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang="C"> | ||
+ | #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; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | 2. Compile the modbus application: | ||
+ | <pre>CC -o modbus –lmodbus modbus.c</pre> |
Latest revision as of 05:33, 25 July 2018
Contents
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).
- While in $HOME/Project, export the software development kit (SDK).
make export-sdk
- Change to the export directory:
cd export
- 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® Atom™ processors:
- 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
- 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
- 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 |
- Change to the directory you chose in step 4.
- Make the file system. This make command will execute quickly:
make fs
Setting up Environment Variables
- Locate your environment setup script:
- IoT Gateways based on Intel® Atom™ processors:
source environment-setup-atom-wrs-linux
- IoT Gateways based on Intel® Atom™ processors:
- 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
- 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.
- 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.
- 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