MC9S08DZ Bootloader in C - request

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC9S08DZ Bootloader in C - request

2,840 Views
DDuckDDuck
Contributor II

Looking for a MC9S08DZ bootloader written in C. Not very good at assembler so the AN2295 doesn't help out to well as I need to rewrite it to bootload from a MicroSD. Any bootloader available for the DZ family with simple C routines would be highly appreciated.

 

Many thanks in advance.

Labels (1)
9 Replies

909 Views
Francois
Contributor I

Hello,

 

Here is what I've done on a DZ32 :

 

User code is : 7C00 to F0FF

Bootloader is : F100 to FCFF

Bootloader in EEprom is : 1760 to 17FF (this contain only the program to erase a sector and to program bytes because it can't be located in Flash, it is as small as possible)

 

The bootloader is a ModBus bootloader (only function 16) and it sends every line of the .s19 file, it is never erased.

Only the user code can be reprogrammed.

 

It is slow (because my ModBus network is slow) but it works and it is quite reliable. The problem is that it needs a program to send ModBus frames (the lines of the .s19 file)

 

I would be very interested to find a bootloader on the DZ32 which could input directly the .s19 file, my objective was to send directly the .s19 file with hyperterminal for example.

 

I've tried to write it but the two main problems Im 'unable to solve are :

1) Sector erase is quite long and hyperterminal does't wait for erase of sectors

 

2) I've tried to implement a Xon Xoff protocol to slow down flux of data incomming on the DZ32 but :

When hyperterminal receives a Xoff, it continues to send several bytes.

In my case, hyperterminal skips some bytes when receiving Xoff and then Xon

 

I've been unable to solve these problems (with ModBus the  advantage is that the response is send only when the sectors are erased)

 

Otherways the bootloader in the DZ32 can analyse .s19 lines and program the corresponding bytes.

Any help or idea on this subject is welcome ...

 

Best regards

francois

0 Kudos

909 Views
tonyp
Senior Contributor II

 


I would be very interested to find a bootloader on the DZ32 which could input directly the S19 file, my objective was to send directly the .s19 file with hyperterminal for example.

 

I've tried to write it but the two main problems Im 'unable to solve are :

1) Sector erase is quite long and hyperterminal doesn't wait for erase of sectors

 

2) I've tried to implement a Xon Xoff protocol to slow down flux of data incoming on the DZ32 but :

When hyperterminal receives a Xoff, it continues to send several bytes.

In my case, hyperterminal skips some bytes when receiving Xoff and then Xon

 

I've been unable to solve these problems (with ModBus the  advantage is that the response is send only when the sectors are erased)

 

François


No offense, but I think you're drowning in a glass of water.  Why don't you erase all sectors before you start programming?  There, both of your problems solved.

 

I've written a bootloader that understands S19 files directly, so upgrades are simple copy-paste operations (copy the file from our web page and paste into whatever terminal emulator).  It breezes at 57600 bps @ ~8MHz bus (for QE32/QE128, 38400 for QG8) using the internal oscillator.

 

The approach is this:

 

* Upon reset, the IRQ pin is tested for deliberate entry into the bootloader. If so, it enters boot mode.

* If no IRQ, then the CRC is computed and compared to an application/part specific location.  If CRC fails, it enters boot mode.

* In boot mode, there are two commands: one to start the S19 loading, and the other to cause a reset.

* If IRQ pin is high and the CRC verifies, then the application is executed.

* Vectors are automatically redirected, so one writes the application as if it were stand-alone, being careful only to keep out of the last (two) pages of Flash where the bootloader is (except for vectors which are taken care of automatically).

 

When the S19 Load command is entered, the bootloader erases all Flash (you can have it erase only certain sections if you want to preserve user data between firmware upgrades -- this is application specific) and waits for S records.  It then simply decodes, and programs each byte as it is received.

 

No interrupts are used, the CCR[I] bit is never cleared.

 

If ESC is pressed during the upgrade, the process is canceled, and you're back at the boot menu to try again.

 

Unfortunately due to proprietary decryption etc I cannot provide the (assembly language) code for this.   Maybe at a later time, if I find the time to remove the proprietary stuff.

 

 

0 Kudos

909 Views
bigmac
Specialist III

Hello Francois,

 


Fran�ois wrote:

I would be very interested to find a bootloader on the DZ32 which could input directly the .s19 file, my objective was to send directly the .s19 file with hyperterminal for example.

 

I've tried to write it but the two main problems Im 'unable to solve are :

1) Sector erase is quite long and hyperterminal does't wait for erase of sectors

 

2) I've tried to implement a Xon Xoff protocol to slow down flux of data incomming on the DZ32 but :

When hyperterminal receives a Xoff, it continues to send several bytes.

In my case, hyperterminal skips some bytes when receiving Xoff and then Xon

 


The number of characters sent by Hyperterminal, after Xoff character is returned, I assume is dictated by the size of the send FIFO buffer within the PC UART.  Hardware handshaking, using CTS or DSR signals may be more responsive.

 

I assume that you would buffer and process each received S19 format line, before continuing with the next line.  You would therefore set CTS/DSR inactive whenever you received CR/LF (specifically tested within the SCI receive ISR, prior to storing in the receive buffer).  You would also need to cater for an additional character or two to be received and buffered after the signal is made inactive.  With this in mind, your SCI receive process would probably require use of a conventional FIFO (circular) buffer, rather than a simple "line" buffer.

 

An alternative method might be to set an end-of-line delay within Hyperterminal, applicable when the S19 file is sent as ASCII text.  A delay of maybe 100 milliseconds would allow for a potential sector erase, and the programming of however many bytes in each line.

 

Of course it should be possible to simultaneously apply both methods without any problem.

 

Regards,

Mac

 

 

 

0 Kudos

909 Views
egoodii
Senior Contributor III

I don't suppose you're still looking....

 

I have some decent bootloader functions for S08 with CRC checks I can give.

 

 

0 Kudos

909 Views
DDuckDDuck
Contributor II

Hey Dude!

 

Thanks for asking, you´re tottaly right :smileywink: I did write my own one... Botting from a microSD card.... working very well... now when "all" bugs are found and removed :smileyhappy:

 

Thanks for aksing though!

0 Kudos

909 Views
freerunner
Contributor I

hi Lars, 

 

How did you write your own? Did you follow any documentation that describes how to develop the bootloader in c?

 

I tried looking at the an2295 code, but i'm not really good with assembler.

 

Thanks

0 Kudos

909 Views
DDuckDDuck
Contributor II

Ciao Freerunnner,

 

With a lot of help from this forum and FSL I finally got it working. It’s now in a lot of products and seems to work very well. I can't give you the complete solution as it’s company property, but I will for sure share some basics with you.

 

The attached package holds the necessary assembler routines with a c integration header so that you can call them as you probably are used to. You need to be able to erase and write the flash to be successful. So with those two "simple" routines you can do whatever you want. Then you just add the boot loader interface routines, such as RS232, CF, and MicroSD as I did or similar so that you can receive the data you want to write to your flash.

 

When you figured out what interface to use for data transfer, write a spec of an header so that you can keep track on if you need to reflash or not. Why reflash if you already have the latest FW :smileyhappy: I solved this by writing some data to specific addresses, like in my example file. 0x1900 hold my FW rev etc.

 

Else, you already found it...  AN2295.... It holds more or less everything you need to know to write the boot loader.

 

Note that the attached files are designed for the MC9S08DZ60 and might need some tuning to match your processor.

 

Good luck!

 

//Lars

 

 

 

 

0 Kudos

909 Views
DDuckDDuck
Contributor II

Gee... a lot of "t"'s in that mess... sorry...didn't check before posting :smileysad:

0 Kudos

909 Views
Octavian_D_Iosu
Contributor I

Hi there,

I saw your post is very recent and incidentally I am looking for a bootloader written in C for MC9S08LG32.

Any help / code / direction would be appreciated

Thanks

Octavian

0 Kudos