Skip to content
Francois Bedard edited this page Aug 9, 2014 · 34 revisions

This document describes how to use GNU tools for ARC with EM Starter Kit.

Building application

Different core templates in EM Starter Kit use different memory maps, and custom linker scripts are required to compile applications that work properly on those templates.

EM4

EM4 template has ICCM starting at 0x100 and DCCM at 0x80000000. Linker script and custom crt0.s file can be downloaded from Gist: https://gist.github.com/anthony-kolesov/7214970. To compile the application use the following command:

$ arc-elf-gcc -mEM -Wl,-Tem4.lds -nostartfiles crt0.s test.c

EM4_16CR

The GNU toolchain for DesignWare ARC Processors does not support the EM4 core configured with reduced register set. Users wishing to use this configuration need to use the MetaWare Development Toolkit.

EM6

EM6 template has ICCM starting at 0x100 address and 256 MiB RAM starting at 0x10000000. It is assumed that both code and data segments are mapped to RAM and ICCM is not used. Linker script and custom start up file can be downloaded this Gist https://gist.github.com/anthony-kolesov/7214970. To compile the application use the following command:

$ arc-elf-gcc -mEM -Wl,-Tem6.lds -nostartfiles crt0.s test.c

Prerequisites

Windows

Windows installer can be downloaded here. It includes GNU tools, OpenOCD and Eclipse IDE with required ARC GNU plugins pre-installed.

Linux

Toolchain for Linux hosts can be downloaded from the GNU Toolchain Releases page as a prebuilt package. It includes GNU tools only. OpenOCD should be built separately. Documentation is available in OpenOCD GitHub repository.

In a nutshell:

$ git clone https://github.com/foss-for-synopsys-dwc-arc-processors/openocd.git
$ cd openocd
$ ./bootstrap
$ ./configure --enable-maintainer-mode --disable-werror
$ make
$ make install

Starting OpenOCD

First you need to build OpenOCD on your machine. Follow this document for instructions: https://github.com/foss-for-synopsys-dwc-arc-processors/openocd/blob/arc-0.8-dev-4.8-R3/doc/README.ARC

Start OpenOCD:

# On Linux:
$ openocd -f /usr/local/share/openocd/scripts/board/snps_em_sk.cfg

@rem on Windows:
> openocd -f C:\ARC48\share\openocd\scripts\target\snps_em_sk.cfg

OpenOCD will be waiting for GDB connections on TCP port 3333. OpenOCD can be closed by CTRL+C. It is possible to start OpenOCD from Eclipse as an external application.

Connecting GDB to OpenOCD

Write a sample application:

/* simple.c */
int main(void) {
    int a, b, c;
    a = 1;
    b = 2;
    c = a + b;
    return c;
}

Compile it (refer to "Building application" section for details):

$ arc-elf-gcc -mEM -Wl,-Tem4.lds -nostartfiles crt0.s simple.c

Run GDB, connect to target and run it:

$ arc-elf32-gdb --quiet simple.elf
# connect
(gdb) target remote :3333
# Increase timeout, because OpenOCD sometimes can be slow
(gdb) set remotetimeout 15
# load application into target
(gdb) load
# Go to start of main function
(gdb) break main
(gdb) continue
# Resume with usual GDB commands
(gdb) step
(gdb) next
# Go to end of the application
(gdb) break _exit_halt
(gdb) continue
(gdb) info reg r0 

Execution should stop at function _exit_halt(). Value of register r0 should be 3.

Known Issues and Limitations

  • Out of the box it is impossible to perform any input/output operations, like printf, scanf, file IO, etc. Calling any of those function in application will result in a hang (unhandled system call to be exact). It is possible to use UART for text console I/O operations, consult EM Starter Kit documentation and examples for details.
  • Bare metal applications has nowhere to exit, and default implementation of exit is an infinite loop. To catch exit from application you should set breakpoint at function _exit_halt() like in the example. Note that _exit_halt() is defined in crt0.s.

Big-endian Targets Support

Both OpenOCD and GDB support big-endian applications and target. No special build of those applications is required to support big-endian, however other parts of toolchain must be build for big-endian. Refer to toolchain readme for details on building big-endian toolchain.

EM Starter Kit doesn't have built-in big-endian configuration, however it is possible to program its FPGA with big-endian image. Consult EM Starter Kit databook for details on FPGA programming. Following steps assume that your FPGA system (either EM Starter Kit, or another) is already flashed with big-endian image.

Build target application:

$ arceb-elf-gcc -mEM -Wl,-Tem4.lds -nostartfiles crt0.s simple.c

Edit OpenOCD configuration script (EM Starter Kit is assumed):

--- snps_starter_kit_arc-em.cfg 2013-11-13 17:03:21.556183900 +0400
+++ snps_starter_kit_arc-em_eb.cfg      2013-11-13 17:03:17.858983900 +0400
@@ -36,7 +36,7 @@
 echo "Using dbgbase = [format 0x%x $_dbgbase]"

 target create $_TARGETNAME arc32 -chain-position $_TARGETNAME \
-  -coreid 0 -dbgbase $_dbgbase -endian little
+  -coreid 0 -dbgbase $_dbgbase -endian big

 # SRAM: 56KiB at 0x4030.0000
 $_TARGETNAME configure -work-area-phys 0x00000000 \

Subsequent steps are same as for little-endian targets. Note that there is no real difference between arc-elf32-gdb and arceb-elf32-gdb GDB executables.

Clone this wiki locally