Migrating Projects from Arm Compiler 5 to Arm Compiler 6

Follow the steps in this tutorial to migrate an existing Arm Compiler 5 bare-metal project to an Arm Compiler 6 bare-metal project. Once you have completed the migration, you can rebuild your executable and run it on a Fixed Virtual Platform (FVP) model provided with DS-5.

The Fireworks project

To show you the steps to migrate your project, this tutorial uses the Fireworks example project built with Arm Compiler 5. This example is included in DS-5. The steps in this tutorial can be easily adapted to work on your individual projects.

We also provide the Fireworks example built with Arm Compiler 6, but for the purposes of this tutorial, we are ignoring it.

Importing the Fireworks project example into the DS-5 Eclipse workspace

  1. Launch Eclipse for DS-5 from the Start Menu.

  2. Select a workspace for your DS-5 projects. The default workspace is fine.

  3. Close the Welcome screen, if it appears.

  4. Select File > Import.... to open the Import Selection dialog.

  5. Expand the DS-5 group and select Examples and Programming Libraries. Click Next.

  6. Expand the Examples group, then expand the Armv7 Bare-Metal group.

  7. Several Armv7-based bare-metal examples are provided, including startup code and simple applications for a variety of Cortex-A, -R and M-family platforms. For this tutorial, select fireworks_A9-FVP_AC5.




  8. Click Finish. The Project Explorer view populates with the project.

    You can view the imported example in the Project Explorer view.

Building the Fireworks example

The Fireworks project we just imported is pre-built, that is, the executable is already available in the project. But it is worthwhile rebuilding the project to understand how to start the project build process and to ensure DS-5 is setup correctly.

Depending on your version of DS-5, the imported project may attempt to auto-generate makefiles instead of using the provided one which we will be modifying in this tutorial. To fix this, make sure that “generate makefiles automatically” is unticked and then remove “/Debug” from the end of the “Build directory” path.

You can find these settings by right clicking on the imported example project, then Properties > C/C++ Build.

This will allow DS-5 to use the provided makefile and the makefile to write into the obj directory in the project root directory.

To clean the project, right-click the fireworks project and select Clean Project to remove the contents of the obj directory, if it already exists.

Then, to build the project, you can either:

  • Right-click the project and select Build Project.

  • Or, on the main menu, click Build button to start the build process. That is it, you have now built your project!

Running your application

To run the application you just built, you can use the Cortex-A9 FVP models provided with DS-5.

You can use FVP models to run your image when you do not have access to hardware, for example when the design is not yet completed, or where hardware prototype boards are scarce. Your software development can start early with FVPs which reduces the time to market for your product.

The Fireworks project contains .launch files.

Project Explorer view launch files

  • fireworks-AC5-Cortex-A9x1-FVP.launch - Simulates a single-core Cortex-A9 system.

  • fireworks_AC5-Cortex-A9x4-FVP.launch - Simulates a quad-core Cortex-A9 system.

A .launch file instructs DS-5 Debugger what target to connect to, what files to download, which breakpoints to set, and so forth. Launch files are created from the Debug Configurations dialog. We provide them with our examples as an easy method to get you up and running out of the box.

For this tutorial, we are using the single-core configuration.

  1. Right-click fireworks_AC5-Cortex-A9x1-FVP.launch and select Debug As > fireworks_AC5-Cortex-A9x1-FVP.

  2. If DS-5 asks if you want to change perspective, click Yes to switch to the Debug perspective.

    DS-5 automatically launches the FVP model, downloads the application, sets a breakpoint on the main() function, loads debug information into DS-5 Debugger, and runs to main(). You should get a view similar to the following screenshot.

     
  3. To continue execution, click Continue Button.

    The fireworks display starts up in a separate window.

You have now imported the project, rebuilt it, and then run the application on a FVP model. Now, click Disconnect Button to stop the simulation.

Changing the default compiler for the project

Now that we have built and verified that the example project is working, it is time to change the default compiler.

  1. At the top-right corner of DS-5, click C/C++ perspective button to return to the C/C++ Perspective.

  2. Right-click the fireworks project, and select Properties.

  3. Select C/C++ Build to view the C/C++ Build Builder Settings section in the project properties dialog.

  4. In Makefile generation, untick the Generate Makefiles automatically option.

  5. Select C/C++ Build > Tool Chain Editor to view the Tool Chain Editor section in the project properties dialog.

  6. In Current toolchain, select Arm Compiler 6 (DS-5 built-in) from the list of available compilers.

  7. Click Yes in the Confirm toolchain change dialog.

    You have now changed the compiler. From now on, DS-5 will use Arm Compiler 6 when rebuilding this project.

Clean and rebuild the project

Changing the compiler means we have to rebuild all the object files from scratch. Right-click the fireworks project and select Clean Project to remove the contents of the obj directory.

The changes are not complete yet, but just to see what happens, we are going to build the project. Right-click the fireworks project and select Build Project. You can view the results of the build in the Console view. The build fails with the error message:

Build fail

This is because even though we have changed the default compiler for the project to be Arm Compiler 6, the Eclipse project for Fireworks is a makefile project as opposed to a managed project), and the makefile still references Arm Compiler 5 (armcc). As part of switching the compiler, you need to make some additional changes to the project for it to build correctly with Arm Compiler 6 (armclang).

Modifying the makefile

This project uses a makefile with the actual compiler calls embedded in it. We need to make changes in the file.

We are going to make changes in two stages:

  • In the first stage, we are going to specify which compiler to use.

  • In the second stage, we are going to specify which compiler options to use.

Specifying which compiler to use

  1. In the Project Explorer view, browse the Fireworks project and locate the makefile file.

  2. Double-click the file to open it in the editor.

  3. Change the entry CC = armcc to CC = armclang.
    armcc is the name of the Arm Compiler 5 binary. We are replacing this with the name of the Arm Compiler 6 binary, which is armclang.

  4. Save the makefile.

We have not finished making changes, but to see what happens, right-click and rebuild the project. The build fails with the following errors:

Build fail clang

This is because the makefile is attempting to use armcc command-line options with armclang. armclang and armcc use different command-line options. The second set of changes translate the armcc options into armclang options.

Specifying which compiler options to use

  1. Locate the below text in the makefile:

    DEPEND_FLAGS = --depend=$@.d --depend_format=unix_escaped 
    CFLAGS = --cpu=$(CPU) $(DEBUG_FLAGS) --$(CODE_TYPE) -O$(OPT_LEVEL) -O$(OPT_FOR) $(DEFINES) $(INCLUDES) $(DEPEND_FLAGS) --no_depend_system_headers $(SUPPRESS)
    AFLAGS = --cpu=$(CPU) $(DEBUG_FLAGS) --apcs=/interwork $(DEPEND_FLAGS) $(SUPPRESS)
  2. Replace it with:

    DEPEND_CFLAGS = -MF $@.d
    DEPEND_AFLAGS = --depend=$@.d --depend_format=unix_escaped
    CFLAGS = --target=arm-arm-none-eabi -m$(CODE_TYPE) $(DEBUG_FLAGS) -O$(OPT_LEVEL) -mcpu=$(CPU) $(DEFINES) $(INCLUDES) $(DEPEND_CFLAGS) -MMD $(SUPPRESS)
    AFLAGS = --cpu=$(CPU) $(DEBUG_FLAGS) --apcs=/interwork $(DEPEND_AFLAGS) $(SUPPRESS)                          

None of the assembler options (AFLAGS and DEPEND_AFLAGS) or linker options (LFLAGS) need changing since these tools are included in Arm Compiler 6 and are backwards compatible with Arm Compiler 5.

To summarize the changes required in the makefile:

Description Arm Compiler 5 Arm Compiler 6
Change compiler binary name armcc armclang
Specify the target architecture None (only AArch32) --target=arm-arm-none-eabi
Select CPU --cpu -mcpu
Generate Thumb code --thumb -mthumb
Optimize for time -Otime None (default)
Writes makefile dependency lines to a file during compilation --depend=$@.d -MF $@.d
Specifies the format of output dependency files --depend_format=unix_escaped None (default)
Disables the output of system include dependency lines --no_depend_system_headers -MMD

See the Arm Compiler Migration and Compatibility Guide for more information about migrating from older versions of Arm Compiler to Arm Compiler 6.

Modifying your code

Now that you have made the necessary modifications to your makefile, you have to make some changes to your code.

  1. Rebuild the project and view the errors and warnings generated in the Console view:

    Build fail after makefile changes completed

  2. Diagnose and fix the errors and warnings:

    1. The return type of the main function: void is not allowed in standard C. You can fix this by replacing the following line in main.c:

      __attribute__((noreturn)) void main(void)

      With

      __attribute__((noreturn)) int main(void)
    2. The function __enable_irq() is supported by Arm Compiler 6 in a compatibility header file. Add #include <arm_compat.h> to the top of main.c.

    3. #pragma import is not supported by Arm Compiler 6 and must be replaced by the assembler directive equivalent. Replace the following line in retarget.c:

      #pragma import(__use_no_semihosting)

      With

      asm(".global __use_no_semihosting");
  3. Rebuild the project again.

Running the modified application

You have completed all required changes to the project and the executable is ready to be run on the FVP.

  1. Switch to the DS-5 Debug perspective.

  2. In the Debug Control view, either double-click fireworks_AC5-Cortex-A9x1-FVP or right-click and select Connect to target.

  3. Click Continue.

    Continue execution

    You can view the fireworks output running successfully.

Converting assembly code

A further step would be to convert the assembler format used from armasm format to GAS format that can be consumed by armclang's built-in assembler. The instructions are the same in both formats, but the assembler directives, predefined macros and comment characters are different. If you are writing new assembler in GAS format, it can be assembled with armclang -x assembler-with-cpp.