Name

Setup — Preparing the Cyclone V SX board for eCos Development

Overview

In a typical development environment, the board boots from the SPI NOR and runs the RedBoot ROM monitor from SDRAM. eCos applications are configured for RAM startup and then downloaded and run on the board via the debugger arm-eabi-gdb. Preparing the board therefore usually involves programming a suitable RedBoot image into flash memory.

The following RedBoot configurations are supported:

ConfigurationDescriptionUseFile
ROMRedBoot loaded from SPI NOR flash to SDRAMredboot_ROM.ecmredboot_ROM.bin

For serial communications, all versions run with 8 bits, no parity, and 1 stop bit at 57600 baud. RedBoot also supports Ethernet communication and flash management.

Note that the use of the term ROM for the initial RedBoot configuration is a historical accident. RedBoot actually runs from SDRAM after being loaded there from NOR flash by the preloader. The use of ROM for this configuration is intended to indicate that it initializes the microprocessor and board peripherals, as opposed to the RAM configuration which assumes that this has already been done.

Initial Installation

The Cyclone V SX board comes with U-Boot and Linux installed by default on a micro-SD card. For eCos development we want to install RedBoot in the SPI NOR flash. The booting mechanism is that the on-chip firmware loads a small preloader from the start of NOR flash which then loads RedBoot from later in the flash.

To write RedBoot to the SPI NOR flash, you must use the command line tools from the Altera QuartusII SoC Embedded Development System.

Programming RedBoot into NOR flash using Altera Tools

The following gives the steps needed to program RedBoot into the SPI NOR Flash using the Altera EDS tools. This uses the quartus_hps flash programmer command line utility to do the work.

[Note]Note

The examples below are for a Linux host where eCosPro is typically installed in the /opt/ecospro/ecospro-<version> sub-directory. On a Windows host eCosPro will typically be installed in the C:\eCosPro\ecos-<version> sub-directory.

  1. Install QuartusII and the SoC EDS as described by Altera onto your host system. Start an Embedded Command Shell by running either <SoC EDS Installation Folder>\embedded\Embedded_Command_Shell.bat in Windows or <SoC EDS Installation Folder>/embedded/embedded_command_shell.sh in Linux.
  2. Ensure that the BOOTSEL jumpers are set as follows: BOOTSEL0(J28) 2-3, BOOTSEL1(J29) 1-2, BOOTSEL2(J30) 1-2.
  3. Connect USB cables between the mini USB socket at J37 (used by the USB-Blaster), and the mini USB socket at J8 (used to provide serial device access) and your host. Power up the board and run a terminal emulator on your host, attaching it to the serial USB channel which should appear on your host, setting the baud rate to 57600.
  4. Run the following command on the host to detect the USB-Blaster:

    # jtagconfig
    1) USB-BlasterII [USB 1-1]
      4BA00477   SOCVHPS
      02D020DD   5CS(EBA6ES|XFC6C6ES)/..
    
    #

    It may be necessary to run this a couple of times before the above result is obtained. If the program failure persists then you should check that your EDS installation is correct.

  5. Run the following command to configure the JTAG interface:

    # jtagconfig --setparam 1 JtagClock 16M
    #

    This program terminates silently if it is successful.

  6. Run the following command to install the preloader, passing it a path to the preloader image from the installed eCos distribution. This preloader was built with the Altera bsp-editor according to the instructions in the "Altera SoC Embedded Design Suite User Guide", chapter "HPS Preloader User Guide". The BOOT_FROM_QSPI boot option was used.

    # quartus_hps -c 1 -o PV /opt/ecospro/ecos-<version>/loaders/cyclone5_sx/preloader-mkpimage.bin
    Info: *******************************************************************
    Info: Running Quartus II 32-bit Programmer
        Info: Version 13.0.0 Build 156 04/24/2013 SJ Full Version
        Info: Copyright (C) 1991-2013 Altera Corporation. All rights reserved.
        Info: Your use of Altera Corporation's design tools, logic functions
        Info: and other software and tools, and its AMPP partner logic
        Info: functions, and any output files from any of the foregoing
        Info: (including device programming or simulation files), and any
        Info: associated documentation or information are expressly subject
        Info: to the terms and conditions of the Altera Program License
        Info: Subscription Agreement, Altera MegaCore Function License
        Info: Agreement, or other applicable license agreement, including,
        Info: without limitation, that your use is for the sole purpose of
        Info: programming logic devices manufactured by Altera and sold by
        Info: Altera or its authorized distributors.  Please refer to the
        Info: applicable agreement for further details.
        Info: Processing started: Wed Jun 26 12:51:47 2013
    Info: Command: quartus_hps -c 1 -o PV /path/to/preloader-mkpimage.bin
    Current hardware is: USB-BlasterII [USB 1-1]
    Found HPS device at index 0
    HPS Device IDCODE: 0x4BA00477
    AHB Port is located at port 0
    APB Port is located at port 1
    Boot Info: 1.8V QSPI Flash
    Start HPS Quad SPI flash programming ...
    Initialize QSPI peripheral and flash controller ...
    Read Silicon ID of Quad SPI flash ...
       Quad SPI Flash silicon ID is 0x1021BA20
          Flash device matched
             Manufacturer: Micron
             Device: QSPI_1024
    Enable Four Byte Addressing ...
    Sector Erase Quad SPI flash ...
       Sector Erase Info: Start Addr at 0x00000000 for 4 sector(s)
          Sector Erase Quad SPI flash at 0x00000000
          Sector Erase Quad SPI flash at 0x00010000
          Sector Erase Quad SPI flash at 0x00020000
          Sector Erase Quad SPI flash at 0x00030000
    Program Quad SPI flash ...
    Verify Quad SPI flash ...
    Info: Quartus II 32-bit Programmer was successful. 0 errors, 0 warnings
        Info: Peak virtual memory: 46 megabytes
        Info: Processing ended: Wed Jun 26 12:53:55 2013
        Info: Elapsed time: 00:02:08
        Info: Total CPU time (on all processors): 00:00:04
    #
  7. Now run the following commands to install RedBoot, passing a path to the RedBoot image from the installed eCos distribution. Note that the quartus_hps command can only accept files with a .bin extension, so it is necessary to copy the generated RedBoot image to a file with the correct extension before running the command. The RedBoot image file will be located alongside preloader-mkpimage.bin in the loaders/cyclone5_sx sub-directory of the eCosPro installation as illustrated above. You may ignore the .bin, .elf and .srec files also located in the same sub-directory. Also note that the commands provided are for a Linux host so the PATH and copy command will vary.

    # cp /opt/ecospro/ecos-<version>/loaders/cyclone5_sx/redboot_ROM.img /tmp/redboot.bin
    # quartus_hps -c 1 -a 0x60000 -o PV /tmp/redboot.bin
    Info: *******************************************************************
    Info: Running Quartus II 32-bit Programmer
        Info: Version 13.0.0 Build 156 04/24/2013 SJ Full Version
        Info: Copyright (C) 1991-2013 Altera Corporation. All rights reserved.
        Info: Your use of Altera Corporation's design tools, logic functions
        Info: and other software and tools, and its AMPP partner logic
        Info: functions, and any output files from any of the foregoing
        Info: (including device programming or simulation files), and any
        Info: associated documentation or information are expressly subject
        Info: to the terms and conditions of the Altera Program License
        Info: Subscription Agreement, Altera MegaCore Function License
        Info: Agreement, or other applicable license agreement, including,
        Info: without limitation, that your use is for the sole purpose of
        Info: programming logic devices manufactured by Altera and sold by
        Info: Altera or its authorized distributors.  Please refer to the
        Info: applicable agreement for further details.
        Info: Processing started: Wed Jun 26 13:02:07 2013
    Info: Command: quartus_hps -c 1 -a 0x60000 -o PV /tmp/redboot.bin
    Current hardware is: USB-BlasterII [USB 1-1]
    Found HPS device at index 0
    HPS Device IDCODE: 0x4BA00477
    AHB Port is located at port 0
    APB Port is located at port 1
    Boot Info: 1.8V QSPI Flash
    Start HPS Quad SPI flash programming ...
    Initialize QSPI peripheral and flash controller ...
    Read Silicon ID of Quad SPI flash ...
       Quad SPI Flash silicon ID is 0x1021BA20
          Flash device matched
             Manufacturer: Micron
             Device: QSPI_1024
    Enable Four Byte Addressing ...
    Sector Erase Quad SPI flash ...
       Sector Erase Info: Start Addr at 0x00060000 for 2 sector(s)
          Sector Erase Quad SPI flash at 0x00060000
          Sector Erase Quad SPI flash at 0x00070000
    Program Quad SPI flash ...
    Verify Quad SPI flash ...
    Info: Quartus II 32-bit Programmer was successful. 0 errors, 0 warnings
        Info: Peak virtual memory: 46 megabytes
        Info: Processing ended: Wed Jun 26 13:03:10 2013
        Info: Elapsed time: 00:01:03
        Info: Total CPU time (on all processors): 00:00:02
    #
  8. Detach the USB cable for the USB Blaster from the mini USB socket at J37 and connect an ethernet cable to J2 on the board (located on the opposite side from the ENET1 and ENET2 dual ethernet interfaces) and an ethernet hub that is connected to your host's network.
  9. Power cycle the board. You should see the following output on the serial line:

    +**Warning** FLASH configuration checksum error or invalid key
    Ethernet eth0: MAC address 12:34:aa:bb:cc:ee
    IP: 10.0.2.4/255.0.0.0, Gateway: 10.0.0.3
    Default server: 10.0.1.1
    
    RedBoot(tm) bootstrap and debug environment [ROM]
    Non-certified release, version UNKNOWN - built 11:45:41, Jun 26 2013
    
    Copyright (C) 2000-2009 Free Software Foundation, Inc.
    Copyright (C) 2003-2012 eCosCentric Limited
    RedBoot is free software, covered by the eCos license, derived from the
    GNU General Public License. You are welcome to change it and/or distribute
    copies of it under certain conditions. Under the license terms, RedBoot's
    source code and full license terms must have been made available to you.
    Redboot comes with ABSOLUTELY NO WARRANTY.
    
    Platform: Altera Cyclone V SX Development Kit (Cortex-A9)
    RAM: 0x00000000-0x40000000 [0x00259208-0x3ffed000 available]
    FLASH: 0x80000000-0x87ffffff, 2048 x 0x10000 blocks
    RedBoot>

    Since the serial USB bridge is also power cycled, you may lose the serial device under Windows or one or two lines from the beginning of this output. If this happens, simply reconnect if necessary and type version to see the full output again.

  10. Run the following commands to initialize RedBoot's flash file system and flash configuration:

    RedBoot> fis init
    About to initialize [format] FLASH image system - continue (y/n)? y
    *** Initialize FLASH Image System
    ... Erase from 0x87ff0000-0x87ffffff: .
    ... Program from 0x3fff0000-0x40000000 to 0x87ff0000: .
    RedBoot>
    RedBoot> fconfig -i
    Initialize non-volatile configuration - continue (y/n)? y
    Run script at boot: false
    Use BOOTP for network configuration: true
    Default server IP address: 10.0.1.1
    Console baud rate: 57600
    Network hardware address [MAC] for eth0: 0x12:0x34:0xAA:0xBB:0xCC:0x08
    GDB connection port: 9000
    Force console for special debug messages: false
    Network debug at boot time: false
    Default network device: dwc_gmac
    Update RedBoot non-volatile configuration - continue (y/n)? y
    ... Erase from 0x87ff0000-0x87ffffff: .
    ... Program from 0x3fff0000-0x40000000 to 0x87ff0000: .
    RedBoot>

    You should substitute your own server IP address for the one shown above. You may also want to change the MAC address if more than one board is present on the network, or use one of the MAC addresses assigned by Altera to this board. If you want to use a static IP address, then choose false for the "Use BOOTP" option and enter the gateway, IP address and netmask that you have assigned.

The RedBoot installation is now complete. This can be tested by power cycling the board again. Output similar to the following should be seen on the serial port.

+Ethernet eth0: MAC address 12:34:aa:bb:cc:08
IP: 10.0.2.6/255.0.0.0, Gateway: 10.0.0.3
Default server: 10.0.1.1

RedBoot(tm) bootstrap and debug environment [ROM]
Non-certified release, version UNKNOWN - built 11:45:41, Jun 26 2013

Copyright (C) 2000-2009 Free Software Foundation, Inc.
Copyright (C) 2003-2013 eCosCentric Limited
RedBoot is free software, covered by the eCos license, derived from the
GNU General Public License. You are welcome to change it and/or distribute
copies of it under certain conditions. Under the license terms, RedBoot's
source code and full license terms must have been made available to you.
Redboot comes with ABSOLUTELY NO WARRANTY.

Platform: Altera Cyclone V SX Development Kit (Cortex-A9)
RAM: 0x00000000-0x40000000 [0x00259208-0x3ffed000 available]
FLASH: 0x80000000-0x87ffffff, 2048 x 0x10000 blocks
RedBoot> fis list
Name              FLASH addr  Mem addr    Length      Entry point
(reserved)        0x80000000  0x80000000  0x00060000  0x00000000
RedBoot           0x80060000  0x80060000  0x000A0000  0x00000000
FIS directory     0x87FF0000  0x87FF0000  0x0000F000  0x00000000
RedBoot config    0x87FFF000  0x87FFF000  0x00001000  0x00000000
RedBoot>

If it proves necessary to install a new version of RedBoot, this may be done from RedBoot itself. Place the new image on a TFTP server on the configured server. From RedBoot run the following commands:

RedBoot> load -r -b %{freememlo} redboot.img
Using default protocol (TFTP)
Raw file loaded 0x00259400-0x00277c0b, assumed entry at 0x00259400
RedBoot> fis cre RedBoot
An image named 'RedBoot' exists - continue (y/n)? y
... Erase from 0x80060000-0x800fffff: ..........
... Program from 0x00259400-0x00277c0c to 0x80060000: ..
... Erase from 0x87ff0000-0x87ffffff: .
... Program from 0x3fff0000-0x40000000 to 0x87ff0000: .
RedBoot>

Rebuilding RedBoot

Should it prove necessary to rebuild a RedBoot binary, this is done most conveniently at the command line. The steps needed to rebuild the ROM version of RedBoot for the Cyclone V SX are:

$ mkdir redboot_cyclone5_sx_rom
$ cd redboot_cyclone5_sx_rom
$ ecosconfig new cyclone5_sx redboot
$ ecosconfig import $ECOS_REPOSITORY/hal/arm/cortexa/cyclone5_sx/VERSION/misc/redboot_ROM.ecm
$ ecosconfig resolve
$ ecosconfig tree
$ make

At the end of the build the install/bin subdirectory should contain the file redboot.img. This is a binary file that includes a header needed by the preloader to load and run RedBoot successfully.

[Note]Note

The flashimg_cv host executable provided within your eCosPro installation is required on the build host to wrap the RedBoot binary image into an image that can be programmed by the tools from the Altera QuartusII SoC Embedded Development System. This executable must be on your path when you build RedBoot and will normally located in the /opt/ecospro/ecos-<version>/host/bin-<hostos> sub-directory of your eCosPro installation. Shells created by future revisions of the eCos GUI configuration tool or ecosprofileenv will add this directory to the PATH environment variable.

Installing user applications into Flash

If you wish to install a ROM startup application into Flash to be automatically booted instead of RedBoot, you can follow a similar procedure to installing RedBoot into Flash. However before you can do so, you must first prepend a header to your application image in order for the preloader to recognise it as a valid application.

You will need the flashimg_cv command, which should be in the host tools binary directory as described above. You will also need to generate a binary image of your program using the arm-eabi-objcopy command. The following gives an example simplified command sequence which can be run at a command shell prompt:

$ arm-eabi-objcopy -O binary myapp myapp.bin
$ flashimg_cv myapp.bin myapp.img

You will need to subsitute your own paths and filenames where applicable.

Once you have the .img file, you can follow the same process as above for installing RedBoot via the USB-BlasterII. Once the initial setup has been done once, it is only then necessary to re-install the ROM executable. It is not necessary to reinstall the preloader each time. A typical command sequence might be:

$ arm-eabi-objcopy -O binary myapp myapp.bin0
$ flashimg_cv myapp.bin0 myapp.bin
$ quartus_hps -c 1 -a 0x60000 -o PV myapp.bin