Name

srec9s12 — convert hex files for MC9S12DP256 cpu and optionally download

Synopsis

srec9S12 [OPTIONS...] [ARGUMENTS...]

PURPOSE

srec9s12 converts srecords from the form used by the gnu-mc68hc11/hc12 tools to the form needed for downloading. It can also download flash, eeprom, and ram data directly through a D-BUG12 based BDM pod. It runs on Linux and Cygwin on top of windoze. Downloads are more than an order of magnitude faster than using either NoICE12 or Hyperterm when tested on Cygwin over XP with a belkin usb-serial adapter. Download time is about 1 minute for a 200K file at 115200 baud.

Download and installation information is near the bottom of this page.

OPTIONS

Options are specified in the form "--name=value". For boolean arguments, a 0 is false and a 1 is true, "--name" is equivalent to "--name=1".

--input_file="-"

Input File name. If unspecified or "-", use stdin.

--output_file="-"

Output File name. If unspecified or "-", use stdin.

--input_map=0

No translation is performed on input.

--input_map=1

Input addresses are interpreted as simple 16 bit addresses. Currently treated like banked addresses. All RAM, EEPROM, and FLASH is accessable. This is the form used internally.

--input_map=2

Input addresses are banked. Addresses between 0x4000 and 0xFFFF are translated into page 3E,30, and 3F. Note that 0x301000, for example, refers to internal RAM not the flash at 1000 bytes into page 30 which is correctly refered to as 0x309000.

--input_map=3

Input addresses are in motorola linear format 20 bit addresses. MC9S12DP256 flash is addressed from 0xC0000 to 0xFFFFF. Internal RAM and EEPROM are not addressable.

--input_map=4

(default) Input addresses are in the perverse offset 0x10000 form used by the gnu-m68hc11 tools.

--input_format=0

Input is in motorola srecords.

--output_map=1

Output addresses are interpreted as simple 16 bit addresses. Note: currently does not reverse the translation performed by the CPU16 input map.

--output_map=2

Output addresses are banked. No translation.

--output_map=3

(default) Output addresses are in motorola linear format 20 bit addresses. Internal RAM and EEPROM are not addressable.

--output_map=4

(default) Output addresses are in the perverse offset 0x10000 form used by the gnu-m6811 tools.

--output_format=0

(default) Output motorola srecords.

--output_format=1

Produce hex and ascii dump of data.

--debug=1

Enable debugging.

--show_args=1

Print the value of the arguments after parsing.

--help=1

Print a summary of command line options.

--send_to_pod=1

Send data to the BDM Pod via serial port instead of to outfile.

--pod_port="/dev/ttyS1"

Serial port to send data to. Typically /dev/ttyS0, /dev/ttyS1, /dev/com1, /dev/com2, /dev/cua0, /dev/cua1.

--pod_baud=115200

Set baud rate to communicate with the Pod. Pod must have previously configured to reset to this baud rate using a terminal emulator.

--serial_debug=1

Show date being sent to or from the pod. Does not affect the actual hex data which is controled by echo_hex.

--srec_bytes=32

Number of bytes per srecord line.

--srec_id="srec9s12"

This is the string encoded in the header record of the file.

--line_termination=1

Hex lines are terminated with a newline.

--line_termination=2

Hex lines are terminated with a carriage return.

--line_termination=3

Hex lines are terminated with a carriage return line feed.

--use_downloaded_flash_routine=1

Download a custom flash programming routine instead of using FLOAD. Note that performance is actually better if you use the optimized FLOAD driver instead of this option.

--xtal=4000000

XTAL oscilator frequency in hertz on the target CPU. Required if you use the downloaded custom flash programming routine; incorrect value could result in improper programming or damage to the chip.

--bulk_erase=0

Do not perform a bulk erase before programming. This will probably cause fload to choke.

--bulk_erase=1

(default) Perform a bulk erase before programming.

--read_after_each_char=1

read serial port after each character. This can significantly slow performance.but can speed response to XON/XOFF.

--line_delay=10

Number of milliseconds to delay after sending each delay_interval lines during hex transfers.

--delay_interval=2

Number of lines between delays. The LOAD command requires a delay_interval of 1 so it will override this value. FLOAD works faster with a value of 2.

--slurp_interval=1

At the end of each slurp_interval lines, the program will read the serial port to check for XON/XOFF, progress characters, and error messages.

--nulls_per_char=0

Number of nulls to send after each character.

--nulls_per_line=0

Number of nulls to send after each line.

--kernel_xon_xoff=1

Enable XON/XOFF processing at the OS kernel serial driver level. Decreases response time to XON/XOFF but slows performance.

--ignore_xon_xoff=0

Ignore XON/XOFF characters. This can increase performance. Requires appropriate delay settings to keep from overloading D-BUG12.

--flush_each_char=1

Issue a fflush() after each character. This can seriously hurt performance.

--flush_each_line=1

Issue a fflush() after each line. This can hurt performance.

--buf_size=0

Use line buffered output for the serial port and stderr. One operating system call will be made for each line sent.

--buf_size=1

Tell stdio to not buffer the output to the serial port and stderr. One operating system call will be made for each character sent. This can seriously hurt performance.

--buf_size=4096

(default) Use a 4096 byte buffer for output. Other values up to 4096 can be used.

--echo_hex=1

(default) display hex data after each value. Default = on.

--header_delay=5000

Number of milliseconds to delay after sending the first (S0 header) line of srecord data to the Pod. This is when D-BUG12 apparently does its inialization.

--delay_after_load_command=5000

Number of milliseconds to delay after sending a load or fload command to the pod, to allow it to do any needed initialization before streaming data.

--flash_load_command="fload"

This sets the command used to download FLASH data.

--ram_load_command="load"

This sets the command used to download RAM data.

--eeprom_load_command="load"

This sets the command used to download EEPROM data.

--ram_start=4096

This sets the start address of RAM. Data between ram_start and ram_end will be downloaded using the flash_load_command. Currently must be specified in decimal. RAM data will be downloaded after FLASH and EEPROM so data won't be overwritten by BDM helper routines.

--ram_end=16383

This sets the end address of RAM. Currently must be specified in decimal.

--eeprom_start=1024

This sets the start address of EEPROM Data between eeprom start and eeprom_end will be downloaded using the eeprom_load_command. Currently must be specified in decimal.

--eeprom_end=4095

This sets the end address of EEPROM Currently must be specified in decimal.

--flash_start=3145728

This sets the start address of FLASH Data between flash start and ram_end will be downloaded using the flash_load_command. Currently must be specified in decimal.

--flash_end=4128768

This sets the end address of FLASH Currently must be specified in decimal.

ARGUMENTS

The program does not take any positional arguments.

RETURN VALUES

Will return 0 on success and 1 on failure.

DESCRIPTION

D-BUG12 based pods.

This should work with any D-BUG12 v4.x based BDM pod including the MiniDragon+, Some Technological Arts models, the Motorola EVB in pod mode, and any MC9S12DP256 development board with a BDM out connector and an appropriately configured version of D-BUG12 loaded. You should be able to get this program to download code on a development board without BDM but there are serious limitations to which areas of memory you can use in this case and you must be careful not to bulk erase or otherwise overwrite the flash. Due to limitations of the monitor, you won't be able to debug programs in flash without a BDM pod.

ERRORS

Error messages and other output from the BDM pod are displayed to the user.

DIAGNOSTICS

EXAMPLES

bash$ srec9s12 --input_file=m6811-elf-objcopy-format.s19 --send_to_pod --pod_port=/dev/ttyS0            # Linux

bash$ /cygdrive/c/windows/system32/mode.com com4: baud=115200 parity=n data=8 stop=1 dtr=on rts=on odsr=off idsr=off xon=off

bash$ srec9s12 --input_file=m6811-elf-objcopy-format.s19 --send_to_pod --pod_port=/dev/com1 --line_delay=0 --slurp_interval=128           # Cygwin

bash$ srec9s12 --input_file=m6811-elf-objcopy-format.s19  --output_file=motorola_format.s19

bash$ srec9s12 --input_file=motorola_format.s19 --input_map=3 --send_to_pod 

ENVIRONMENT

This program does not use any environment variables.

SIGNALS

The program uses the default signal handlers.

CONFORMING TO

Motorola srecord format.

PORTABILITY

This program should port easily to most UNIX compatible systems.

Linux

Program has been primarily tested under Linux.

windoze+Cygwin

This program works under Cygwin on Windoze eXtra Pain. Some versions may not support termios emulation properly and you may need to use the DOS mode command to configure the serial port. If you have kernel level xon/xoff processing enabled and you interrupt the program after an XOFF character, the program will not exit (windoze limitation). Hitting the reset button on the pod will give you the required XON character. To compile, use "make CYGWIN=1".

windoze without Cygwin

Serial port setup will need modification.

other un*x systems

This program should work with little modification other than changing include files.

DEPENDENCIES

Requires the symbol table package by Mark Whitis. http://www.freelabs.com/~whitis/software/symbol/

. This has been included in the tarball.

On windoze, requires Cygwin. http://www.cygwin.com/

LOCATION

/usr/local/bin/srec9s12

FILES

This program doesn't use any files other than those specified by the user.

TIPS

If you have trouble, try resetting the BDM pod. If you manually reset the target, you will also need to reset the BDM pod.

NOTES

I have written a flash downloading program for the DBUG12 based pods which is an order of magnitude faster than using NoICE or hyperterm with the FLOAD command. However, I didn't get the speed the way I expected to.

For a 213K program, 115200 baud, 4Mhz target CPU clock:

  • windoze, NoICE12: about 45 minutes
  • windoze, hyperterm & fload command: about an hour
  • - Linux, unoptimized srec9s12, using fload: 5 minutes
  • Linux, srec9s12, downloading custom flash sector routine: 6 minutes (performance actually got worse when I optimized for FLOAD downloads).
  • Linux, minicom and fload: about 1 minute but the ascii-xfr program used by minicom is ignoring xon/xoff flow control and overloading DBUG12 and fails to print the error messages. aciii-xfr must be configured for a 400ms delay per line to work with dbug12, at which point it is MUCH slower than srec9S12 which only delays when delays are actually needed. printf "\rfload\r" >/dev/ttyS1; time ascii-xfr -dsv -l300 ../bank_hello/bankhello_load.s19 >/dev/ttyS1
  • Linux, srec9s12, fload, optimized delays: 1 minute 18 seconds. this is 35 times faster than NoICE.
  • Linux, cat, 43 seconds > printf "\rfload\r" >/dev/ttyS1; printf "S00B0000737265633973313238\r" \ >/dev/ttyS1; sleep 5; time cat ../bank_hello/bankhello_load.s19 \ >/dev/ttyS1 Cat doesn't have the additional overhead of displaying the data on screen and doesn't show you errors (unless you run another cat reading serial port or of parsing and converting the hex characters. And it doesn't pause when it receives an XOFF character. Cat time doesn't include delays surrounding header lines. And, cat doesn't wait for all the data to be sent out the port before it returns. Xoff appears to be sent after each line. On a faster machine, this is likely to overload D-BUG12. When I try to duplicate this performance with my program, I blow D-BUG12s doors off (even with kernel xon/xoff), perhaps because I don't have to wait for disk i/o and I can't benchmark it because the program somehow finishes in 7 seconds even though D-BUG reports receiving the end record. I think this is a side effect of running with O_NONBLOCK.

So, it is looking like the problems I was having had to do with windoze serial port performance. I am using a belkin usb to serial adapter but it seems to be able to handle 115200 baud, though perhaps there are some latency issues for flow control. Hyperterm is configured not to delay after each character or each line but it still takes about 1 second per line of srecord data (that should only take 6.25ms to send).

If I had known it was a serial perfomance issue, I wouldn't have bothered writing a custom flash helper routine and the interface to it. Oh well, I will need a good flash routine later anyway. It is currently slower than fload because of the extra interacion need.

Oddly, however, it looks like DBUG12 only sends XOFF once, apparently after the first line of the transfer (the S0 header record) and before the first line of data. It looks like DBUG12 foolishly delays initialization until after the first line of data. By sending a dummy header line and a delay, it looks like ascii-xfr can be used at full speed. Well, full speed for ascii-xfr, which is about half full wire speed. Apparently there is a default delay which you can eliminate by specifying "-l0", though it still doesn't run as fast as my program can push data without delays.

A slight modification in my program will send the entire file in 33 seconds but it does overload DBUG12 fairly quickly (5120 bytes of data (not ascii) into the file) even with flow control in the kernel. With flow control handled in the application, I can see that D-BUG sends an XOFF character for every 40 binary bytes of data on average before it dies. With that mod, it sends 6383 data bytes, not ascii characters, per second. That change eliminated an unintended 2ms delay (plus context switching and scheduling delays) at the end of each line. Since Linux schedules in 10ms intervals, that delay in reality would be at least 10ms and more if other processes wanted attention. A single line of data takes about 6.25ms to send. The delay was originally to aid in recognizing a command prompt.

I optimized the delays so it used a 10ms delay every other line of hex data and that worked in preliminary tests. Basically, this was a trick to allow me to effectively achieve delays shorter than the Linux process scheduling interval ("jiffie" clock). With flow control handled at the application level, I could see i was getting one XOFF/XON pair for every pair of lines at that rate, perfectly synchronized, so I may have succeeded in more than just statistically matching the delay on one particular machine.

Basically, DBUG12 cannot handle 115200 full speed even with efficient handling of XON/XOFF characters. Perhaps they forgot that a typical PC has a 16 byte hardware FIFO (better serial ports, which I don't have, have 256 byte hardware FIFOs) which means you can receive quite a few characters after you send an XOFF at any baud rate.

Under Cygwin, I was able to duplicate the dismal performance of other programs. It seems that while you can send data at high speed out the serial port, you can only do so if you are not reading data back. Windoze has traditionally had such poor interrupt latency that it is notorious for losing characters without the aid of hardware FIFOs. If you are doing XON/XOFF (apparently at either application or system level), you effectively render the FIFO useless and be subject to either the windoze latencies or, perhaps in this case, the USB latencies.

To complicate matters, you can't use usleep() under windows/Cygwin. It has a granularity of 1 second instead of 1 microsecond (actually 10ms on Linux). ven worse, if you specify a delay of less than 1 second, you get NO DELAY at all which violates the requirement that usleep delay NO LESS THAN the specified interval. nanosleep() however, does appear to work properly.

Also, under windoze+Cygwin with the usb to serial adapter if you do not try to read a character (xon/xoff, "*", or error message) after each hex write, you end up blowing D-BUG12s doors off. The usb serial adapter apparently has a lower per character latency than Linux. D-BUG12 appears to even get its doors blown off without even sending an XOFF character or perhaps it is just the extra time before responding to the initial XOFF character (maybe it sends it mid line instead of end of line).

The performance of your terminal emulator could potentially affect download speed with srecords echoed to display. Time to cat a 200K file to screen:

  • Linux, gnome-terminal: 20.4 seconds smooth scrolling off
  • Linux, xterm: 10.13 seconds
  • Cygwin, command tool window: 17.67 seconds (faster cpu)
  • Cygwin, xterm: 8.68 seconds (faster cpu)

BUGS

This is a preliminary version that has not been extensively tested or completed. Error checking is minimal. If you download to EEPROM or RAM, it will say download failed because D-BUG12 does not output an asterisk for each line but instead about 1 every 16 lines.

REPORTING BUGS

Report bugs to whitis@freelabs.com.

AUTHORS

This program and manpage were written by Mark Whitis

COPYRIGHT

Copyright 2004 by Mark Whitis.

LICENSE

http://wwww.freelabs.com/~whitis/software/license.html

HISTORY

This program was originally created on 2004-09-16 by Mark Whitis

DOWNLOAD

http://www.freelabs.com/~whitis/software/srec9s12/download/

INSTALLATION

Linux

bash$ mkdir /dist
bash$ cd /dist
bash$ wget http://www.freelabs.com/~whitis/software/srec9s12/srec9s12-0.01.tar.gz
bash$ cd /usr/local/src/
bash$ tar zxvf /dist/srec9s12-0.01.tar.gzz
bash$ cd srec9s12/0.01/
bash$ cd symbol
bash$ make clean
bash$ make
bash$ cd ..
bash$ make clean
bash$ make
bash$ make install

windoze+Cygwin

bash$ mkdir /dist
bash$ cd /dist
bash$ wget http://www.freelabs.com/~whitis/software/srec9s12/srec9s12-0.01.tar.gz
bash$ cd /usr/local/src/
bash$ tar zxvf /dist/srec9s12-0.01.tar.gz
bash$ cd srec9s12/0.01/
bash$ cd symbol
bash$ make clean
bash$ make
bash$    # ln `libsymtab.so': File Exists  
bash$ cd ..
bash$ make clean
bash$ make
bash$ make install

SEE ALSO

Discussions on gnu-m68hc11 mailing list.

MORE INFORMATION