Site Search

Application development

We were able to implement μClinux, but since it is still an embedded device, it is essential to develop applications that are specific to the final product. There are two ways to build an application that runs on Linux: building at the same time as the kernel is built, and building the application alone. We will introduce the build of the edition according to the steps shown in Figure 8.

 

Figure 8 Application debug build and debug procedure

 

 

Debug build of the application

First, prepare the application source code (hello_world.c).

Next, build the application, but run "nios2-linux-uclibc-gcc" with the "-g" option to add debug information.

In addition, in the case of μClinux, it is necessary to use a flat binary format executable file, so add “-elf2flt” to the option.

If it finishes without errors, an executable file (hello) and a debug information file (hello.gdb) will be generated. Transfer the completed executable file (hello) to a directory on μClinux that has an execution path through ftp or the like.

 

 

Application debugging

Next, I will show you how to remotely debug your application using “gdbserver” and Insight.

“gdbserver” spawns the debuggee program as a child process using the “vfork” system call. In addition, the "ptrace" system call is used to implement functions such as reading and writing registers and memory, and setting breakpoints.

The “gdbserver” source code is included in the “gdb” source package and must be built for each CPU architecture. For this reason, Next Dimension ported “gdbserver” for Nios II, which runs on μClinux, and built an application debugging environment.

In this porting, we mainly add and modify the following parts.

・Correction of ptrace.c in uClinux-dist

・Addition and modification of break_handler and exception_handler

・Development of CPU dependent part in gdbserver

・Modification of hardware such as deletion of JTAG_Debug module

See below for details. (http://www.next-dimension.co.jp/Nios2uClinux.html) Figure 9 shows the application debugging environment.

 

Figure 9 Application debug environment

 

First, execute the “gdbserver” command on μClinux with options for the IP address of the host PC, port number, and application to be debugged (“hello” here).

“gdbserver” spawns a “hello” process and stops it. After that, "gdbserver" waits for a connection from the host PC (debugger).

 

Next, launch Insight Debugger with the “nios2-elf-insight” command and open the “hello.gdb” file generated by the debug build. Start the “Target Selection” screen from “File ⇒ Target Setting”, set as follows, and click the Run button.

・target: “Remote/TCP”

・Hostname: <target IP address>

・Port: <Port number specified in nios2-gdb-server.exe>

・Uncheck More Option ⇒ Download Program

“gdbserver” and Insight Debugger are connected, and the program stops at the first line of the main function. Note that Linux does not know where the application will be loaded in memory, so the base address of the application is set during the connection process.

 

Figure 10 Application debug screen

 

Normally, the program is downloaded from the debugger, but when using "gdbserver", the process is already created by "gdbserver", so please note that the program will not be downloaded from the Insight Debugger. .

 

 

Application release build and run

Once you have finished debugging your application and are ready to incorporate it into your final product, you need to run a release build. The release build method is to build without the "-g" option added when running "nios2-linux-uclibc-gcc". Copy the generated executable file (hello) to the /bin directory of μClinux as described in the section "Application debug build and debug" and rebuild the kernel.

After starting μClinux, execute “hello” and if it works normally, the application development is finished. Figure 11 shows the execution result of “hello”.

 

Figure 11 Executing hello

 

Nios II MPU/MMU support

With Ver8.0 released in 2Q this year, Nios II officially started supporting MPU (Memory Protection Unit) and MMU (Memory Management Unit). In order to take advantage of these functions, the combination with a Linux-based OS is optimal. I think that the two types of Linux I introduced at the beginning will eventually support it, but I'm thinking about porting it on my own in the future.

 

in conclusion

Last time and twice, I asked Mr. Fukushima of Tokyo Keiki Kogyo to explain the Nios II software. The advantage of Linux-based OS is that it is open source and can be used freely by anyone, and drivers created by the community can be used. Of course, it is your responsibility to check the operation, so porting it to a board designed in-house requires a certain amount of man-hours, but being able to use network protocol stacks and server applications is quite attractive. prize.

If you are interested in porting it yourself, but feel free to contact us. In addition to the Nios II development kit Cyclone II edition used this time, demonstrations can be performed on multiple development kits.

 

Soft-core CPUs are designed to meet various needs, from logic to tool support, so making good use of them is the real pleasure of users.

Please experience the soft-core CPU + FPGA that "can realize a user-oriented SoC (System On Chip) from a single minimum order".

 

Next time, we will finally wrap up as the final round.