Difference between revisions of "Nvidia Jetson TX1 and TX2"

From ERIKA WIKI
Jump to: navigation, search
(Simple example)
 
(45 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
  
The ERIKA3 RTOS can be run as a guest OS of the [https://github.com/siemens/jailhouse Jailhouse hypervisor] on the [http://www.nvidia.com/object/jetson-tx1-dev-kit.html Nvidia Tegra Jetson TX1] board.<br>
+
The ERIKA3 RTOS can be run as a guest OS of the [https://github.com/siemens/jailhouse Jailhouse hypervisor] on the [http://www.nvidia.com/object/jetson-tx1-dev-kit.html Nvidia Tegra Jetson] TX1 and TX2 boards.<br>
 
Such support has been developed in the context of the [http://hercules2020.eu HERCULES European project].  
 
Such support has been developed in the context of the [http://hercules2020.eu HERCULES European project].  
 
It has been also shown through a [https://www.youtube.com/watch?v=skIcAkXfNWQ&t=3s YouTube video].
 
It has been also shown through a [https://www.youtube.com/watch?v=skIcAkXfNWQ&t=3s YouTube video].
  
This section explains how to build and install Jailhouse on the TX1 target and how to create an ERIKA3 guest (AKA Jailhouse inmate).
+
This section explains how to build and install Jailhouse on the Jetson target and how to create an ERIKA3 guest (AKA Jailhouse inmate) running a simple application.
  
== Platform setup ==
+
The Eclipse-based RT-Druid tool (for generating the RTOS configuration) requires an x86 platform with a fair amount of resources (in terms of both processing and memory). This requirement, therefore, implies a cross-compilation of ERIKA3.
 +
Additionally, since the build process of ERIKA3 needs a compiled copy of Jailhouse which, in turn, needs a compiled copy of the Linux kernel, we suggest proceeding by '''cross-compiling all software components (i.e., Linux kernel, Jailhouse and ERIKA3 RTOS) on a host x86 machine'''.
  
Use [https://developer.nvidia.com/embedded/jetpack Nvidia Jetpack 3.1] to flash the Linux distribution by Nvidia onto the TX1 platform.<br>
+
== Jetson platform setup ==
JetPack is a tool that runs on an Ubuntu host machine and installs Linux on the TX1 platform.
 
Note that the host machine and the platform must be connected through an OTG USB cable.
 
  
== Jailhouse support ==
+
Use [https://developer.nvidia.com/embedded/jetpack Nvidia Jetpack] to flash the Linux distribution by Nvidia onto the Jetson platform.
 +
JetPack is a tool that runs on an Ubuntu host machine and installs Linux on the Jetson platform.
 +
Note that the host machine and the platform must be connected through an OTG USB cable during flashing.
  
For installing Jailhouse on the TX1 platform, please refer to the [https://github.com/evidence/linux-jailhouse-tx1/blob/master/README.md README] available on the [https://github.com/evidence/linux-jailhouse-tx1 Jailhouse tree on our GitHub].
+
Once the Linux distribution has been correctly flashed on the device, it is important to configure Linux to reserve the memory to the hypervisor, and to not use the serial interface (that will be used by the ERIKA3 guest). The instructions for this set-up can be found on the [https://github.com/evidence/linux-jailhouse-jetson/blob/master/README.md README file of our Jailhouse tree on GitHub]. The README also explains how to set a static IP address (strongly encouraged).
It also provides information about serial port and static IP configuration.
 
  
Note that the information is provided for the default Linux kernel provided by Nvidia (not Vanilla).
+
== x86 host platform setup ==
You can refer to the [https://github.com/siemens/jailhouse original project page] in case you run a Vanilla Linux kernel.
 
  
== ERIKA3 on Jailhouse ==
+
A cross-compiler for aarch64 is needed. On Ubuntu (tested on version 16.04), this can be installed by typing
 
+
<pre>
Once Jailhouse has been successfully installed on the platform, you have to set-up the RT-Druid development environment and the compile the ERIKA3 RTOS.
+
sudo apt install gcc-aarch64-linux-gnu
 
+
</pre>
Given the processing performance of the TX1 platform, as well as the availability of a real OS like Linux, we aim at doing a native compilation rather than a cross-compilation.  
 
Unfortunately, the Eclipse IDE requires an x86 platform with a fair amount of resources (in terms of both processing and memory).
 
We therefore need to set-up a host-target environment, where the x86 host runs the Eclipse IDE (with the RT-Druid plugin for code generation) and the TX1 target performs the final step of compilation.
 
  
The [[Remote projects on RT-Druid]] page explains how to set-up the RT-Druid package for such an environment.<br>
+
== Jailhouse cross-compiling ==
  
== Simple example ==
+
The [https://github.com/evidence/linux-jailhouse-jetson/blob/master/README.md README] available on the [https://github.com/evidence/linux-jailhouse-jetson Jailhouse tree on our GitHub] explains how to cross-compile and install Jailhouse.
 +
Note that the information is provided for the default Linux kernel by Nvidia (not Vanilla).
 +
You can refer to the [https://github.com/siemens/jailhouse original Jailhouse page] in case you run a Vanilla Linux kernel.
  
We now illustrate how a simple example of two tasks printing a message on the serial interface can be run on the Nvidia TX1 platform.
+
== RT-Druid set-up ==
  
On the target:
+
Once Jailhouse has been successfully built, transferred and installed onto the Jetson platform, you have to set-up the RT-Druid development environment to compile the ERIKA3 RTOS.<br>
  
 +
Follow the next instructions for installing RT-Druid on the host platform used for cross-compiling:
 
<ol>
 
<ol>
<li> Configure and install Jailhouse following the instructions on the [https://github.com/evidence/linux-jailhouse-tx1/blob/master/README.md README file] available on the [https://github.com/evidence/linux-jailhouse-tx1 Jailhouse tree on our GitHub]
+
<li> Download the RT-Druid package from [http://www.erika-enterprise.com/index.php/download/erika-v3-download.html the download section] of the ERIKA3 website
<li> Get a copy the ERIKA3 RTOS from GitHub:
+
<li> Extract the downloaded archive
<pre>
+
<li> Open a shell and type
$ cd /home/nvidia
 
$ git clone https://github.com/evidence/erika3.git
 
</pre>
 
<li> Create the project directory:
 
 
<pre>
 
<pre>
$ mkdir /home/nvidia/erika3/pkg/arch/aarch64/examples/test/
+
export JAILHOUSE_VERSION=0.8
 +
export JAILHOUSE_DIR=/path/to/compiled/jailhouse
 +
export JAILHOUSE_AARCH64_GCCPREFIX=aarch64-linux-gnu-
 
</pre>
 
</pre>
<li> Create the <code>/home/nvidia/erika3/pkg/arch/aarch64/examples/test/main.c</code> file with the following content:<br>
+
Note that RT-Druid allows to set these variables also from within Eclipse. Just press the right mouse button on the Eclipse project and select Properties as shown in the following figure.
<pre>
+
[[File:Eclipse_project_properties.png|thumb|center|Figure 1: Eclipse project properties.]]
#include "ee.h"
 
#include <inmate.h>
 
  
static volatile u32 counter = 0;
+
Then, select Generator properties, enable project specific settings (as shown in the next figure), and set the desired values.
 +
[[File:Generator_properties.jpg|thumb|center|Figure 2: Generator properties.]]
 +
<li> Finally, using the same shell where the environment variables have been set, enter the directory containing the extracted archive and run <pre>./eclipse</pre>
 +
</ol>
  
DeclareTask(Task1);
+
== Simple application ==
DeclareTask(Task2);
 
  
/* First task */
+
We now show a simple "helloworld" application consisting of two tasks printing on the serial interface.
TASK(Task1)
+
<ol>
{
+
<li> Run the RT-Druid tool as explained above
        GetResource(SharedUartResource);
+
<li> Create a new project by clicking on <code>New</code> &rarr; <code>RT-Druid v3 Oil and C/C++ Project</code> as shown in the next Figure:
        printk("Hello world from Task1! (%lu)\n", counter);
+
[[File:Eclipse_new_project1.jpg|thumb|center|Figure 3: Create a new RT-Druid project.]]
        counter++;
+
<li> Name the new project (e.g., <code>mytest</code>) and select the Cross-GCC as shown in the next Figure:
        ReleaseResource(SharedUartResource);
+
[[File:Eclipse_new_project2.jpg|thumb|center|Figure 4: Naming the new RT-Druid project.]]
        TerminateTask();
+
<li> Check the box for using an existing template and select <code>aarch64</code> &rarr; <code>Jailhouse</code> &rarr; <code>Helloworld OSEK demo on Jailhouse</code>as shown in the next Figure:
}
+
[[File:Eclipse_new_project3.jpg|thumb|center|Figure 5: Selecting the Helloworld template.]]
 
+
<li> Eclipse will then show the new project, and RT-Druid will generate the configuration files, as shown in the next Figure:
 
+
[[File:Eclipse_new_project4.jpg|thumb|center|Figure 6: New Helloworld project created.]]
/* Second task */
+
<li> In the the <code>conf.oil</code> file, set:
TASK(Task2)
+
    <ul>
{
+
     <li> <code>SOC_DATA=NVIDIA_TEGRA_X1</code> for TX1
        GetResource(SharedUartResource);
+
     <li> <code>SOC_DATA=NVIDIA_TEGRA_X2</code> for TX2
        printk("Hello world from Task2! (%lu)\n", counter);
+
     </ul>
        counter++;
+
<li> Click with the right mouse key on the project and select <code>Build project</code> as shown in the next Figure:
        ReleaseResource(SharedUartResource);
+
[[File:Eclipse_new_project5.jpg|thumb|center|Figure 7: Building the Helloworld project.]]
        TerminateTask();
+
<li> Open a shell, enter the workspace and transfer the <code>erika_inmate.bin</code> binary to the Jetson platform (e.g. using <code>scp</code>)
}
+
<li> Then, on the Jetson platform:
 
+
<ol>
 
+
<li> Install the Jailhouse driver: <code>sudo modprobe jailhouse</code>
void idle_hook(void);
+
<li> Enable Jailhouse:
 
+
  <ul>
void idle_hook(void)
+
  <li> For TX1: <code>sudo jailhouse enable jetson-tx1.cell</code>
{
+
  <li> For TX2: <code>sudo jailhouse enable jetson-tx2.cell</code>
        printk("Starting communication over UART\n");
+
  </ul>
 
+
<li> Create the cell for ERIKA3:
        /* endless loop*/
+
  <ul>
        while(1) {
+
  <li> For TX1: <code>sudo jailhouse cell create jetson-tx1-demo.cell</code>
                asm volatile("wfi": : : "memory");
+
  <li> For TX2: <code>sudo jailhouse cell create jetson-tx2-demo.cell</code>
        }
+
  </ul>
}
+
<li> Load the ERIKA3 application:
 
+
  <ul>
 
+
  <li> For TX1: <code>sudo jailhouse cell load jetson-tx1-demo erika_inmate.bin</code>
int main(void)
+
  <li> For TX2: <code>sudo jailhouse cell load jetson-tx2-demo erika_inmate.bin</code>
{
+
  </ul>
        printk("Starting OS...\n");
+
<li> Start the ERIKA3 application:
        StartOS(OSDEFAULTAPPMODE);
+
  <ul>
        return 0;
+
  <li> For TX1: <code>sudo jailhouse cell start jetson-tx1-demo</code>
}
+
  <li> For TX2: <code>sudo jailhouse cell start jetson-tx2-demo</code>
</pre>  
+
  </ul>
<li> Create the <code>/home/nvidia/erika3/pkg/arch/aarch64/examples/test/conf.oil</code> file with the following content:
+
</ol>
<pre>
+
<li> Then, on the Jetson platform, you will see the two tasks printing alternatively on the serial interface, as shown in the next figure:
CPU mySystem {
+
[[File:Helloworld_output.jpg|thumb|center|Figure 8: Output of the helloworld example.]]
 
+
</ol>
  OS myOs {
 
 
 
     /* EE_OPT = "OS_EE_VERBOSE"; */
 
     EE_OPT = "OSEE_DEBUG";
 
    EE_OPT = "OS_EE_APPL_BUILD_DEBUG";
 
    EE_OPT = "OS_EE_BUILD_DEBUG";
 
    EE_OPT = "OSEE_ASSERT";
 
 
 
    CPU_DATA = AARCH64 {
 
      MULTI_STACK = TRUE;
 
      COMPILER = GCC;
 
      IDLEHOOK = TRUE {
 
        HOOKNAME = "idle_hook";
 
      };
 
    };
 
 
 
    SOC_DATA = NVIDIA_TEGRA_X1;
 
 
 
     KERNEL_TYPE = OSEK {
 
      CLASS = ECC1;
 
    };
 
  };
 
 
 
  COUNTER SystemTimer {
 
    MINCYCLE = 1;
 
    MAXALLOWEDVALUE = 2147483647;
 
    TICKSPERBASE = 1;
 
    TYPE = HARDWARE {
 
      SYSTEM_TIMER = TRUE;
 
      PRIORITY    = 1;
 
      DEVICE      = "GTIMER";
 
    };
 
    SECONDSPERTICK = 0.001;
 
  };
 
 
 
  ALARM AlarmTask1 {
 
    COUNTER = SystemTimer;
 
    ACTION = ACTIVATETASK {
 
      TASK = Task1;
 
    };
 
    AUTOSTART = TRUE {
 
      ALARMTIME = 500;
 
      CYCLETIME = 100;
 
    };
 
  };
 
 
 
  ALARM AlarmTask2 {
 
    COUNTER = SystemTimer;
 
    ACTION = ACTIVATETASK {
 
      TASK = Task2;
 
    };
 
    AUTOSTART = TRUE {
 
      ALARMTIME = 500;
 
      CYCLETIME = 100;
 
    };
 
  };
 
 
 
  TASK Task1 {
 
    PRIORITY = 1;
 
    STACK = PRIVATE {
 
      SIZE = 1024;
 
    };
 
    SCHEDULE = FULL;
 
    APP_SRC = "main.c";
 
    RESOURCE = SharedUartResource;
 
  };
 
  
  TASK Task2 {
+
== Libc support ==
    PRIORITY = 2;
 
    STACK = PRIVATE {
 
      SIZE = 1024;
 
    };
 
    SCHEDULE = FULL;
 
    RESOURCE = SharedUartResource;
 
  };
 
  
  RESOURCE SharedUartResource { RESOURCEPROPERTY = STANDARD; };
+
If the application on ERIKA needs to use services provided by the libc library (e.g. <code>memcpy()</code>)
};
+
please refer to [https://github.com/evidence/linux-jailhouse-jetson/blob/master/README.md#toolchain-selection the "Toolchain selection" section on the GitHub tree]
</pre>
+
for building the Jailhouse inmate library (and also ERIKA) using a bare-metal toolchain.
</ol>
 
  
Then, on the host:
+
Additionally, to link the ERIKA application agains the libc library, you will need to set the following variables in the OIL file:
<ol>
 
<li> Run Eclipse and follow the instructions at [[Remote projects on RT-Druid]] to set-up a remote project on Eclipse.<br>
 
Specify
 
 
<ul>
 
<ul>
<li><code>/home/nvidia/erika3/pkg/arch/aarch64/examples/test/</code> as project directory
+
<li><code>LIBS = "-lc";</code>
<li><code>/home/nvidia/erika3/pkg/arch/aarch64/examples/test/conf.oil</code> as oil file
+
<li><code>LDFLAGS = "-L /path/containing/libc/";</code>
 +
<li><code>CFLAGS = "-mstrict-align";</code> for accessing fields in data structures.
 
</ul>
 
</ul>
<li> Generate the project configuration files from Eclipse.
 
</ol>
 
  
Finally, on the target:
+
== Virtual machine ==
<ol>
+
 
<li> Set the <code>JAILHOUSE_DIR</code> environment variable equal to the path where Jailhouse has been built:
+
A VirtualBox virtual machine containing the development environment (i.e. toolchain, ERIKA RTOS and RT-Druid) already installed for the TX1 and TX2 boards is available on the [http://www.erika-enterprise.com/index.php/download/virtual-machines.html ERIKA website].
<pre>
 
$ export JAILHOUSE_DIR=...
 
</pre>
 
<li> Enter the project directory and build the ERIKA3 binary:
 
<pre>
 
$ cd /home/nvidia/erika3/pkg/arch/aarch64/examples/test/out/
 
$ make
 
</pre>
 
<li> Create the jailhouse cell:
 
<pre>
 
$ sudo jailhouse cell create jailhouse/configs/jetson-tx1-demo.cell
 
</pre>
 
<li> Load the ERIKA3 binary:
 
<pre>
 
$ sudo jailhouse cell load jetson-tx1-demo /home/nvidia/erika3/pkg/arch/aarch64/examples/test/out/erika_inmate.bin
 
</pre>
 
<li>Start ERIKA3:
 
<pre>
 
$ sudo jailhouse cell start jetson-tx1-demo
 
</pre>
 
  
  
 
[[Category:Boards]]
 
[[Category:Boards]]
 +
[[Category:Tutorial]]

Latest revision as of 14:22, 25 June 2018

Introduction

The ERIKA3 RTOS can be run as a guest OS of the Jailhouse hypervisor on the Nvidia Tegra Jetson TX1 and TX2 boards.
Such support has been developed in the context of the HERCULES European project. It has been also shown through a YouTube video.

This section explains how to build and install Jailhouse on the Jetson target and how to create an ERIKA3 guest (AKA Jailhouse inmate) running a simple application.

The Eclipse-based RT-Druid tool (for generating the RTOS configuration) requires an x86 platform with a fair amount of resources (in terms of both processing and memory). This requirement, therefore, implies a cross-compilation of ERIKA3. Additionally, since the build process of ERIKA3 needs a compiled copy of Jailhouse which, in turn, needs a compiled copy of the Linux kernel, we suggest proceeding by cross-compiling all software components (i.e., Linux kernel, Jailhouse and ERIKA3 RTOS) on a host x86 machine.

Jetson platform setup

Use Nvidia Jetpack to flash the Linux distribution by Nvidia onto the Jetson platform. JetPack is a tool that runs on an Ubuntu host machine and installs Linux on the Jetson platform. Note that the host machine and the platform must be connected through an OTG USB cable during flashing.

Once the Linux distribution has been correctly flashed on the device, it is important to configure Linux to reserve the memory to the hypervisor, and to not use the serial interface (that will be used by the ERIKA3 guest). The instructions for this set-up can be found on the README file of our Jailhouse tree on GitHub. The README also explains how to set a static IP address (strongly encouraged).

x86 host platform setup

A cross-compiler for aarch64 is needed. On Ubuntu (tested on version 16.04), this can be installed by typing

sudo apt install gcc-aarch64-linux-gnu

Jailhouse cross-compiling

The README available on the Jailhouse tree on our GitHub explains how to cross-compile and install Jailhouse. Note that the information is provided for the default Linux kernel by Nvidia (not Vanilla). You can refer to the original Jailhouse page in case you run a Vanilla Linux kernel.

RT-Druid set-up

Once Jailhouse has been successfully built, transferred and installed onto the Jetson platform, you have to set-up the RT-Druid development environment to compile the ERIKA3 RTOS.

Follow the next instructions for installing RT-Druid on the host platform used for cross-compiling:

  1. Download the RT-Druid package from the download section of the ERIKA3 website
  2. Extract the downloaded archive
  3. Open a shell and type
    export JAILHOUSE_VERSION=0.8
    export JAILHOUSE_DIR=/path/to/compiled/jailhouse
    export JAILHOUSE_AARCH64_GCCPREFIX=aarch64-linux-gnu-
    

    Note that RT-Druid allows to set these variables also from within Eclipse. Just press the right mouse button on the Eclipse project and select Properties as shown in the following figure.

    Figure 1: Eclipse project properties.

    Then, select Generator properties, enable project specific settings (as shown in the next figure), and set the desired values.

    Figure 2: Generator properties.
  4. Finally, using the same shell where the environment variables have been set, enter the directory containing the extracted archive and run
    ./eclipse

Simple application

We now show a simple "helloworld" application consisting of two tasks printing on the serial interface.

  1. Run the RT-Druid tool as explained above
  2. Create a new project by clicking on NewRT-Druid v3 Oil and C/C++ Project as shown in the next Figure:
    Figure 3: Create a new RT-Druid project.
  3. Name the new project (e.g., mytest) and select the Cross-GCC as shown in the next Figure:
    Figure 4: Naming the new RT-Druid project.
  4. Check the box for using an existing template and select aarch64JailhouseHelloworld OSEK demo on Jailhouseas shown in the next Figure:
    Figure 5: Selecting the Helloworld template.
  5. Eclipse will then show the new project, and RT-Druid will generate the configuration files, as shown in the next Figure:
    Figure 6: New Helloworld project created.
  6. In the the conf.oil file, set:
    • SOC_DATA=NVIDIA_TEGRA_X1 for TX1
    • SOC_DATA=NVIDIA_TEGRA_X2 for TX2
  7. Click with the right mouse key on the project and select Build project as shown in the next Figure:
    Figure 7: Building the Helloworld project.
  8. Open a shell, enter the workspace and transfer the erika_inmate.bin binary to the Jetson platform (e.g. using scp)
  9. Then, on the Jetson platform:
    1. Install the Jailhouse driver: sudo modprobe jailhouse
    2. Enable Jailhouse:
      • For TX1: sudo jailhouse enable jetson-tx1.cell
      • For TX2: sudo jailhouse enable jetson-tx2.cell
    3. Create the cell for ERIKA3:
      • For TX1: sudo jailhouse cell create jetson-tx1-demo.cell
      • For TX2: sudo jailhouse cell create jetson-tx2-demo.cell
    4. Load the ERIKA3 application:
      • For TX1: sudo jailhouse cell load jetson-tx1-demo erika_inmate.bin
      • For TX2: sudo jailhouse cell load jetson-tx2-demo erika_inmate.bin
    5. Start the ERIKA3 application:
      • For TX1: sudo jailhouse cell start jetson-tx1-demo
      • For TX2: sudo jailhouse cell start jetson-tx2-demo
  10. Then, on the Jetson platform, you will see the two tasks printing alternatively on the serial interface, as shown in the next figure:
    Figure 8: Output of the helloworld example.

Libc support

If the application on ERIKA needs to use services provided by the libc library (e.g. memcpy()) please refer to the "Toolchain selection" section on the GitHub tree for building the Jailhouse inmate library (and also ERIKA) using a bare-metal toolchain.

Additionally, to link the ERIKA application agains the libc library, you will need to set the following variables in the OIL file:

  • LIBS = "-lc";
  • LDFLAGS = "-L /path/containing/libc/";
  • CFLAGS = "-mstrict-align"; for accessing fields in data structures.

Virtual machine

A VirtualBox virtual machine containing the development environment (i.e. toolchain, ERIKA RTOS and RT-Druid) already installed for the TX1 and TX2 boards is available on the ERIKA website.