DeviceMaster Software Developer Kit Downloading a Program

There are several methods available for downloading and running a DeviceMaster application:

  • RedBoot

    • TFTP via Ethernet (binary file or S-record)

    • X-Modem via RS-232 (binary file or S-record)

  • DeviceMaster Utilities

    • PortVision DX (binary, Windows XP through Windows 10 operating systems)

    • RTS Command-line Updater utility (binary file)

    • nslinkadmin program (binary file, Linux only)

  • GDB

    • GDB via JTAG interface

    • GDB via remote protocol on Diagnostic Port 2

Each of these will be described. It is also possible to download a program and save it in flash ROM so that it is executed automatically when the DeviceMaster starts.

Using RedBoot

Use the following discussions to download a program using RedBoot. Use Disabling Auto-Load if you want to disable or remove the default application

Disabling Auto-Load

When shipped, the DeviceMaster will be configured so that RedBoot waits for 15 seconds after start-up before loading and running the default application from flash ROM. Since several of the download methods require that RedBoot be running, it may be convenient to disable auto-loading of the default application. You may configure RedBoot to not load a default application from flash ROM either of two ways.

  • To disable the default application, do the following:

    At the RedBoot command prompt, disable default application loading by setting the time-out parameter to zero:

    RedBoot> timeout 0

    Timeout 0 seconds
    RedBoot>
  • To delete the default application from flash, use the fis delete command at the RedBoot prompt:

    RedBoot> fis delete default

    Delete image ’default’ - are you sure (y/n)? y 
     ... Erase from 0x05030000-0x050c0000: ......... 
     ... Erase from 0x053f0000-0x05400000: . 
     ... Program from 0x007a0000-0x007b0000 at 0x053f0000: . 
     + 
     RedBoot>

Locating Further Information

The DeviceMaster platform includes a customized version of the RedBoot bootloader from RedHat. RedBoot is described in detail in Using the RedBoot Bootloader. RedBoot can be used to download application programs using either TFTP (via Ethernet) or X-Modem (via serial port). Examples of loading using the RedBoot load command can be found in Default Application. Once the file is loaded, it may be run using the RedBoot go command as shown in Default Application. For more information on using RedBoot on the DeviceMaster platform, see the documents listed below:

Using DeviceMaster Utilities

There are several DeviceMaster utilities (Linux and Windows) that can also be used to download and run a DeviceMaster applications. Instructions for using the utilities to download are found in the help files.

  • PortVision DX

    If you are using a Windows XP through Windows 10 system, you can use PortVision DX to load binary files. PortVision DX is the fastest and easiest way to update binary files, as long as you are connected to the same local network segment. For information about using PortVision DX, refer to the PortVision DX help system or the DeviceMaster Installation and Configuration Guide. .

  • RTS Command Line Updater

    This is a Python program that can be used to download an application.

  • nslinkadmin tool (Linux)

    The nslinkadmin utility that is included with the Linux NS-Link device driver can be used to download and run a DeviceMaster application that has been converted to a binary file with an entry point at Address 0.

Using the RTS Command Line Updater

The download.py file is a Python program that can be used to download an application to the DeviceMaster. The program to be downloaded must be a pure binary file to be loaded starting at address 0x00000000. The RTS Command Line Updater is provided in the SDK.

Usage

download.py [-r] [-q] [-s] [-g] [hostname] [filename]

Options

The following table describes download.py options.

OptionDescriptions
-r Reset Sends a reset command to the DeviceMaster before it is downloaded. This is required if the DeviceMaster is running the SocketServer or NS-Link application. This is not required if RedBoot is already running (LED is flashing).
-q Quiet mode -- do not display address and byte count as program is loaded.
-sSkip vectors -- skips the first 0x20 bytes in the file. This is required if the downloaded program is to be debugged using GDB.
-gGo. After downloading start execution of the program at address 0x00000000.

Using download.py with GDB

When debugging with GDB via diagnostic serial port, downloading large applications can take a long time. It is possible to speed up the process by downloading the application binary file via Ethernet before starting GDB. This process uses a small download utility written in Python. The download.py program has been tested under Cygwin and Linux. The procedure is shown below:

  1. Connect serial cable to Diagnostic Port 2.

  2. Make sure RedBoot is running (status LED should be flashing at about 2 Hz). If necessary, cycle power to reset the DeviceMaster.

  3. Use the download.py program to download (but not start) the program. Use the -s option to tell download.py to skip downloading the vector table since overwriting the vector table will confuse RedBoot:

    $ download.py -s 10.0.0.12 socket.bin

    320:1400
    1720:1400
    3120:1400
    [...]
    564520:1400
    565920:1400
    567320:1120
    downloaded 568440 bytes
        
    $ _

    At this point, RedBoot should still be running (status LED flashing).

  4. Start GDB.

    $ agdb -b 57600

    GNU gdb 5.1.1
    Copyright 2002 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "--host=i586-pc-linux-gnu --target=arm-elf".
    The target is assumed to be big endian
    0x007c6968 in ?? ()
    (gdb)
  5. Load symbol info:

    (gdb) sym socket.elf

    Reading symbols from socket.elf...done.
  6. Set the starting address:

    (gdb) set $pc = reset_vector

    Current language: auto; currently asm
  7. Set a breakpoint:

    (gdb) tbreak cyg_user_start

    Breakpoint 1 at 0x91c: file main.c, line 70.
  8. Begin execution with the continue command:

    (gdb) cont

    Continuing.
    [New Thread 0]
    [Switching to Thread 0]
    cyg_user_start () at main.c:70
    70        LedOff();
    Current language:  auto; currently c
    (gdb)

To reload the application, exit GDB, reset the DeviceMaster, and repeat the process. It is not possible to download via network while a GDB session is active.

Using nslinkadmin

The nslinkadmin utility that is included with the Linux NS-Link device driver can be used to download and run a DeviceMaster application that has been converted to a binary file with an entry point at Address 0. The nslinkadmin program must run as root in order to access an Ethernet interface in raw mode. Therefore, you must be logged in as root or have nslinkadmin suid root. There are two ways to run nslinkadmin: interactive mode and command-line mode. For more information, see the nslinkadmin(8) manual page.

Interactive Mode

If your DeviceMaster is connected to an Ethernet interface other than eth0, use the -d option to specify the interface:

# /usr/sbin/nslinkadmin -d eth1

Using network device ‘eth1’
Checking network for any possible remotes. 
1) 00:c0:4e:0b:ff:f9  DeviceMaster          (idle,free) 
q) quit 
 ->_ 

If you have more than one DeviceMaster connected to the Ethernet network, the list shows each DeviceMaster found. Select the appropriate device by entering the corresponding number:

->1 
Other Comtrol Hub: 00:c0:4e:0b:ff:f9 
IP Utility 
?                        Display help information. 
ig                       Get/display flash IP config 
ic                       Get/display current IP config 
is <addr> <mask> <gate>  Set IP info 
ie                       Erase IP info 
l                        Load the remote. 
s                        Start the remote. 
z                        Shortcut for l, s 
r                        Reset the remote. 
x <filename>             Load and start the specified file. 
q                        Quit the test. 
 ->_ 

To download and start a DeviceMaster application, enter x followed by the file name of the binary file:

-> x serecho.bin 

Loading remote 
 .................................................................. 
Starting remote 
->_ 

While loading, a “.�? displays for each packet downloaded. Once the file is downloaded, it starts automatically. Once the application starts, NS-Link will no longer be able to communicate with the DeviceMaster. To exit nslinkadmin, enter q and press the Return key.

Command Line Mode

Downloading using nslinkadmin in non-interactive command-line mode is done by specifying command line switches:

nslinkadmin Command Line SwitchesDescription
-d <ethdev> Controls the ethernet interface used: eth0 (default), eth1, etc.
-e <macaddr> Specifies the Ethernet address of the DeviceMaster device in xx:xx:xx:xx:xx:xx format.
-f <binfile>Specifies the path of the file to be downloaded.
-l Tells nslinkadmin to load and run the file.

For example:

nslinkadmin -d eth1 -e 00:c0:4e:0b:ff:f9 -l -f serecho.bin

Using GDB

This section discusses the following topics:

The gdbinit File

The .gdbinit file that is included in the demo application package assumes that we are using a JTAG interface that uses the RDI protocol over UDP/IP (such as the EPI Jeeni), and that hostname for the JTAG interface is jeeni.

If you are using a serial or serial/parallel connection to your JTAG interface, or the hostname for your JTAG interface is not jeeni, you must edit the .gdbinit file and modify the target command before running GDB

When GDB is started, it reads an initialization file from the current directory. This file contains GDB commands that are executed just as they would be if they were entered at the GDB command prompt.

[Note]
Note

Under UNIX, .gdbinit is the name of this file. Under Cygwin, GDB with the Insight GUI reads a file named gdb.ini instead of .gdbinit.

In the examples below, several macros were used that were defined in the .gdbinit file contained in the demo.tar.gz package:

  1. Turn off paging of GDB output:.

    1  set width 0 
    2  set height 0
  2. Turn of RDI/ADP heartbeat feature; it does not seem to work with either the Jeeni or the EmbeddedICE JTAG interface units.

    3  set rdiheartbeat off 
  3. Tell the debugger that we have ROM at zero to prevent it from automatically setting breakpoints on the interrupt vectors:

    4  set rdiromatzero on 
    5
  4. Define the resetcpu macro:

    6  # macro to "reset" the processor to a known state 
    7  # mostly just shut of the timers and disable all 
    8  # of the interrupts 
    9  
    10  define resetcpu 
    11    # map internal SRAM to 3fe0000 
    12    # map special regs to  3ff0000 
    13    # cache disabled 
    14    set *0x7ff0000 = 0x83ffffa0 
    15    
    16    # shut off timers 
    17    set *0x7ff6000  = 0 
    18    
    19    # set all port pins to input (disabling WD timer) 
    20    set *0x7ff5000  = 0 
    21    
    22    # disable WD in dallas part 
    23    set *(char*)0x760800f &= 0xfc 
    24    
    25    # shut off Ethernet MAC and BDMA 
    26    set *0x7ffa000 = 0 
    27    set *0x7ffa004 = 0 
    28    set *0x7ffa008 = 0 
    29    set *0x7ffa010 = 0 
    30  
    31    set *0x7ff9000 = 0 
    32    set *0x7ff9004 = 0 
    33    set *0x7ff9008 = 0 
    34    set *0x7ff900c = 0 
    35    
    36    # reset UARTS 
    37    set *0x7ffc000 = 0 
    38    set *0x7ffc004 = 0 
    39    set *0x7ffd000 = 0 
    40    set *0x7ffd004 = 0 
    41  
    42    # disable/clear interrupts 
    43    set *0x7ff4000 = 0 
    44    set *0x7ff4008 = 0xffffffff 
    45    set *0x7ff4004 = 0xffffffff 
    46  end 
    47
  5. Define the memconfig macro. The memconfig program is linked so that it runs in the 8K SRAM that is built into the Samsung uController. This will not work if the cache is enabled, so do a resetcpu first to disable cache.

    48  # macro to load memory config program into SRAM and run it 
    49  
    50  define memconfig      
    51    delete 
    52    symbol-file memconfig 
    53    load memconfig 
    54    tbreak __memoryConfigDone 
    55    cont 
    56    symbol-file 
    57  end 
  6. Define a macro that loads a program and sets breakpoints on the interrupt vectors. Note the display command at the end of the macro – that will tell GDB to evaluate and display the expression *(char*)0x760800f &= 0xfc every time execution is stopped. That expression disables the watchdog timer in the Dallas DS1511W – thus preventing the board from being reset while you are trying to decide what to do next after a breakpoint has been hit.

    59  define reload-with-break 
    60    resetcpu 
    61    delete 
    62    symbol-file 
    63    symbol-file $arg0 
    64    load $arg0 
    65    break *0x00 
    66    break *0x04 
    67    break *0x08 
    68    break *0x0c 
    69    break *0x10 
    70    break *0x14 
    71    break *0x18 
    72    break *0x1c
    73    display   *(char*)0x760800f &= 0xfc 
    74  end  
    75 
    The same macro without the breakpoints on the interrupt vectors.
    76  define reload 
    77    resetcpu 
    78    delete 
    79    symbol-file 
    80    symbol-file $arg0 
    81    load $arg0 
    82    display   *(char*)0x760800f &= 0xfc 
    83  end  
    84  
    85  # the "display *(char*)0x760800f &= 0xfc" will disable the 
    86  # watchdog timer in the Dallas Semi part whenever execution 
    87  # stops (when breakpoint is hit or when the user stops the 
    88  # program.)  If we don’t do this, the board will reset after 
    89  # a breakpoint has been hit. 
    90  
  7. Pick which set of register names you like:

    91  set dis std 
    92 
    8.	Make sure the debugger knows we’re running big-endian:
    93  set endian big 
        
  8. The target command tells the debugger what protocol (rdi) and communications link (ethernet) we are going to use.

    94  # target rdi /dev/ttyS0 19200 
    95  # target rdi s=/dev/ttyS0,p=/dev/par0 19200 
    96  target rdi e=jeeni 
        
  9. The target command tells the debugger what protocol (rdi) and communications link (ethernet)

  10. Force the CPU into a benign state using the macro we defined above:

    98  resetcpu
     99

Running GDB

This example will show how to use GDB to run a program via the JTAG interface. If you do not have a JTAG interface, please read and understand the differences between using the JTAG (Using GDB with the JTAG Interface) and serial port (Using GDB with Diagnostic Port 2) interfaces.

First we will start GDB in non-Window mode so that we can show the commands and their output.

  1. If you are using the insight GUI for GDB, enter the commands shown below in the console window.

    $ arm-elf-gdb -nw 

    GNU gdb 5.0 
    Copyright 2000 Free Software Foundation, Inc. 
    GDB is free software, covered by the GNU General Public License, 
    and you are welcome to change it and/or distribute copies of it  
    under certain conditions.
    Type "show copying" to see the conditions. 
    There is absolutely no warranty for GDB.  Type "show warranty" for 
    details. 
    This GDB was configured as "--host=i586-pc-linux-gnu --target=arm-elf". 
    JEENI (ADP,ARM7TDI,RST) Rev 2.2 
    Rebuilt on Jan 12 2001 at 14:22:34 
    SN=0102J069 ENET=00:80:CF:00:0C:CD IP=10.0.0.100 (255.255.0.0) 
    Connected to ARM RDI target. 
    (gdb) 
  2. Run the resetcpu macro which will put the CPU into a known state:

     (gdb) resetcpu

  3. Load the serecho program using the reload macro.

    (gdb) reload serecho

    Warning: the current language does not match this frame. 
    Loading section .rom_vectors, size 0x44 lma 0x340 
    Loading section .text, size 0x27cf4 lma 0x384 
    Loading section .rodata, size 0x167f lma 0x28078 
    Loading section .data, size 0x1610 lma 0x296f8 
    Loading section .boot, size 0x4 lma 0x0 
    Start address 0x384 , load size 174539 
    Transfer rate: 465437 bits/sec, 505 bytes/write.
  4. Set a temporary breakpoint at the cyg_user_start() function:

    (gdb) tbreak cyg_user_start 

    Breakpoint 1 at 0x99c: file serecho.c, line 72.
  5. Start execution with the continue command:

    (gdb) c

    Continuing. 
    cyg_user_start () at serecho.c:72 
    72        diag_printf("Entering cyg_user_start() function\n"); 
    1: *(char *) 123764751 &= 252 = 128 ’\200’ 
    Current language:  auto; currently c 
    We hit the breakpoint and stopped (at Line 72 in serecho.c).
    If we were using a GUI, the source window would show 
    serecho.c with Line 72 highlighted.
  6. Continue (no breakpoints are set, so it will run until you enter Ctrl-C to stop it).

    (gdb) c

    Continuing. 
  7. Press Ctrl-C, and the emulator stops the processor:

    JEENI: halt request 
    JEENI: halted 
    RDI_execute: you pressed Escape 
        
    Program received signal SIGINT, Interrupt. 
    idle_thread_main (data=1040807) at /opt/ecos/ecos-cvs/ecos/
    packages/kernel/current/src/common/thread.cxx:1148 
    1148    /opt/ecos/ecos-cvs/ecos/packages/kernel/current/
    src/common/thread.cxx: No such file or directory. 
    1: *(char *) 123764751 &= 252 = 128 ’\200’ 
    Current language:  auto; currently c++ 
    (gdb)

    In the example, the program was stopped in the built-in eCos idle task. This is typical, since the program does not do much and will spend most of its time idle. Since we do not have the eCos source files installed, the debugger can not display the source file line and warns us that it can not find the source file.

  8. If you had been watching the output from the diagnostic serial port, you should have seen something like this:

    ARM DeviceMaster HAL (no virtual vectors) 
    AIOPIC serial driver: 16 channels 
    ks32c5000 old_init_handler() 
    Network stack using 262144 bytes for misc space 
    262144 bytes for mbufs 
    524288 bytes for mbuf clusters 
    ks32c5000_eth_init() 
    found MAC address 00:C0:4E:0B:FF:F9 
    ks5000_ether: installInterrupts() 
    EthInit(00:C0:4E:0B:FF:F9) 
    ks32C5000 eth: 00:C0:4E:0B:FF:F9  Hardware CRC 
    Entering cyg_user_start() function 
    0: Beginning execution 
    2: Beginning execution 
    3: Beginning execution 
    4: Beginning execution 
    5: Beginning execution 
    6: Beginning execution 
    7: Beginning execution 
    8: Beginning execution 
    9: Beginning execution 
    10: Beginning execution 
    11: Beginning execution 
    12: Beginning execution 
    13: Beginning execution 
    14: Beginning execution 
    15: Beginning execution 
    1: Beginning execution 
    Bytes transferred: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  -- Idle Loops/Sec: 337263
    Bytes transferred: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  -- Idle Loops/Sec: 338232
    Bytes transferred: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  -- Idle Loops/Sec: 338233
    Bytes transferred: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  -- Idle Loops/Sec: 338232
    Bytes transferred: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  -- Idle Loops/Sec: 338234
    Bytes transferred: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  -- Idle Loops/Sec: 338234
    Bytes transferred: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  -- Idle Loops/Sec: 338229 

Using GDB with the JTAG Interface

The example in Running GDB shows how to use GDB to run a program via the JTAG interface.

The main things to make note of the example are:

  • Use the target rdi e=jeeni command instead of the target remote command. Replace with the device name of the serial port connected to the second diagnostic port (e.g. /dev/ttyS0).

  • To use JTAG debugging, make sure that the shorting jumper is placed on Pins 1 and 2 of the three-pin header on the DeviceMaster board (J1 on 4/8-port boards or J4 on the 16-port board that has one Ethernet port). Location of the jumpers is shown in Using the Diagnostic Serial Port.

    [Note]
    Note

    Contact Technical Support for information about the DeviceMaster 1-port or DeviceMaster 16 or 32-port devices with one Ethernet port..

Using GDB with Diagnostic Port 2

If you do not have a JTAG interface, it is possible to use the GDB stubs via the GDB remote protocol that is implemented by the RedBoot bootloader. Using GDB via Diag Port 2 is similar to using GDB via JTAG, but changes to the GDB initialization file (.gdbinit or gdb.ini) will need to be made. The differences are:

  • Use the target remote <dev> command instead of the target rdi command. Replace <dev> with the device name of the serial port connected to the second diagnostic port (e.g. /dev/ttyS0).

  • Start GDB with the command line flag \tt -b 57600 to specify the proper baud rate.

  • Do not execute the resetcpu or memconfig macros that were shown in the sample .gdbinit file. The GDB stubs in the Bootloader will insure that the processor and memory controller are in the proper states.

  • When starting an eCos program, you must set a breakpoint and stop execution somewhere after the eCos initialization code. The cyg_user_start function is a good place. If you load an eCos program and do a continue without any breakpoints, you will not be able to stop execution of the eCos application. After you have stopped at a breakpoint and then resumed execution you can interrupt the eCos application and return control to the debugger at any time by pressing Control-C, sending GDB a SIGINT signal, or pressing the stop button in Insight.

The easiest way to do this is to add the command tbreak cyg_user_start if 0 to the end of the reload macro (or whatever macro you use to load an eCos application). This will place a temporary breakpoint at the cyg_user_start function, but when that breakpoint is reached, execution will continue immediately because the condition if 0 is not true.


nice color