Shortened guide for setting up nxtOSEK on Linux (and a bit Windows)

The original version of this document was written to help fellow Linux programmers setting up nxtOSEK under Linux. Since the windows installation is already very well covered, I thought it might be a good idea to write some to-go installation instructions and explain how to setup a basic workflow that should work for both Linux and Windows.

1. nxtOSEK installation on Linux

1.1. Requirements, installation environment

First of all, you'll need Wine, GCC and most probably internet. On my system (Linux Mint 9, based on Ubuntu) I've installed Wine 1.2.2 and GCC 4.4.3 as well as APT for installating required packages, so I can assure you that it works quite well using this combination. You don't need to build all tools except the compiler, there are already binaries available.

1.2 Download and build ARM GCC

First of all we need to modify an existing GCC compiler to compile for our ARM target platform. Install these packages using your favorite package manager:

tk-dev ncurses-dev libmpfr-dev texinfo

and download + execute this script, it'll build you one. Better bring a game or book, stuff could take it's time. Place it in a directory you can remember later ("~/bin/gnuarm" in my case) cause you'll need it's path in nxtOSEK's settings.

1.3 Download and setup nxtOSEK

Here comes the step most forget to do. Download not only nxtOSEK itself from the download page but also the OIL parser/generator "sg.exe". Currently, there's a yellowish box below the download links explaning where to pug "sg.exe" in the main folder. If you don't put it there, Wine won't be able to do anything except dumping useless error messages. I'll describe the OIL thing in 2., so stick with this at first.

In "/nxtOSEK/ecrobot/tool_gcc.mak" set "GNUARM_ROOT" to the folder you put your build ARM GCC compiler to, this tells it where to look for the binaries when building.

1.4 Replace original NXT firmware

It's described quite well on the official page, so simply follow 3b there. If you already used NXC/NBC with extended firmware or leJOS, you've probably already found a way to flash on your own.

1.5 Compiling and uploading

In "nxtOSEK/samples_c" just pick one and execute "make all" there. It uses a special makefile you can use later with some minor modifications. If everything went right, there should now be an *.rxe file (along with others) you can upload to your brick using NeXTTool (step 4b). And again, NXC/NBC users will probably know how this works. Otherwise follow the page instructions or study it's help function. Don't waste your time with those makefile-generated shell scrips, they only work on windows using cygwin (atleast on my system I couldn't get it generate wine commands).

2. Everyday compiling, setting up a proper workflow

(The following instructions should be similar on Windows, provided you've correctly installed cygwin and know how to run and edit makefiles/know a bit about bash and your home directory etc...)

If you don't use Eclipse/Netbeans or whatever plugin stuff exists for nxtOSEK, you'll need to compile it directly using make and an *.oil file. You can simply copy one of the makefiles under "nxtOSEK/samples_c/" for C programs and "nxtOSEK/sample_c++/cpp/" for C++ program. Let's take a look at helloworld's Makefile:

# Target specific macros
TARGET = helloworld_OSEK
TOPPERS_OSEK_OIL_SOURCE = ./helloworld.oil

# Don't modify below part
O_PATH ?= build
include ../../ecrobot/ecrobot.mak

TARGET specifies the name our app, TARGET_SOURCES is the list of all our source files. TOPPERS_OSEK_OIL_SOURCE specifies our *.oil file. For everyday programs you can keep "helloworld.oil" as your base and extend it later if you want. It's basically a specification for how the OSEK kernel should be compiled. Every time you change your *.oil file a new kernel will be generated which automagically includes your program. So in the end you get the whole package you need to start and manage threads/tasks/etc in one program. However, I won't explain all the details here. There's a so called "Quickstart" for nxtOSEK which pretty much summarizes everything you'd want or need to know about OSEK and it's OIL stuff. So before you start going wild you better take deeper look at either sample projecs or reference documents.
What's left in our makefile is the the last line which includes ecrobot.mak. It's the part which actually compiles your sources and requires a relative or absolute path. Unfortunately, (atleast I do this sort of thing) most of your source files will probably NOT lie inside the nxtOSEK folder itself, so it's advicable to move the nxtOSEK directory to "~/bin" or whereever you usually put your binary files. So when creating your own makefile you only need to put this fixed path into the last line. If you also move NeXTTool to "~/bin" and append to your PATH variable in .bashrc, you should be able to build, upload and run projects from anywhere with no problem. For Windows user, you can simply edit project files using an external editor and the running make inside cygwin. Since cygwin mimics a simple Linux environment, all commands will be equal (I haven't yet tested it). Alternatively, run the *.sh files make generates for you in your project folder. They are callled "rxeflash.sh", "ramboot.sh" etc. Can't test this at the moment, but be aware of what exactly they do. Not that you accidently flash aways your BIOS.

For specific questions you can take a look at the FAQ.

No comments: