[Icc-avr] CRC Check of Program Memory

Rodney Pearson rodney at junipersys.com
Thu Oct 4 09:02:19 PDT 2007


Michael - 

 

1.	How do I loop through the program memory?

 

Looping through memory is easy, reading it is the tricky part.  Unless I
missed something, I've found that ICCAVR does not handle very well
reading Flash above the 64KB boundary (ie - using ELPM v. LPM).  The
compiler doesn't know how to (1) implement ELPM to read flash directly
and (2) use RAMPZ...at least from what I've found in the Help and
experience.  Richard may have to set me straight on this one...=)

 

Since I am developing for the M2560, I had to implement the looping
through reading program memory in ASM to reach beyond the 64KB boundary.
I didn't bother messing with the compiler area names since I needed to
perform a CRC on the entire application space starting at 0x0000
(includes the startup code and variables) and going clear up to the
bootloader space (last 1/2/4/8 KB of Flash).

 

I have been unsuccessful at getting ICCAVR to generate proper ASM code
from C code to read a flash address directly [ie - something like
*(unsigned char*) (<word address>)], so I've written my routines in ASM
to read flash.  ICCAVR does not have a "FLASH" identifier like IAR to
let you tell the compiler that you wish to access a flash address
instead of normal SRAM.  There is also the issue of having to manually
manipulate RAMPZ on devices with >64KB flash...

 

2.	How do I store the correct CRC at the end of the Flash memory?

 

You can either use a small app to edit the HEX file to add the CRC bytes
to the proper location or you can hand-edit the HEX file (just google
"Intel HEX" to learn what to do).  I have implemented a bootloader, so I
built an application that adds the CRC into the HEX flash image when it
is creating the update file to feed to the bootloader.

 

Another option is to create the CRC routine that both generates and
checks the CRC.  Then you only have figure out a way to tell your code
to generate a CRC if one isn't there.  This way you do not have to
modify the HEX flash image at all.  This does require the use of the SPM
instruction in your code to burn Flash on-chip.

 

A standard CRC-16 routine will both generate and validate a CRC with the
same code.  My bootloader implements ASM CRC code (that I can send to
you) that will both generate and validate a CRC.  I currently only use
it to validate the CRC.

 

It all depends on how you plan to (1) generate the CRC and (2) use it on
the device.  Currently I do the following:

 

1.	A bootloader is implemented that performs the CRC check on the
application space only (no CRC on the bootloader).
2.	An external PC application takes the HEX file generated by
ICCAVR and converts it to a format the bootloader understands.
3.	Additionally, this app also calculates the CRC on the
application flash space and appends the CRC to the last 2 bytes of the
application memory space.  This is added to the update file built for
the bootloader.
4.	I burn the bootloader to the device and then use the bootloader
to update/burn the flash application memory.
5.	Now I can use the bootloader to perform the CRC check on the
entire flash application space anytime I want to.

 

I hope this helps more than confuses...or at least avoid stating the
obvious. =)  I have submitted my CRC code (including looping through
reading Flash) to Richard as a code sample, but I can send it to you as
well if you think it can help.

 

 

Cheers!

 

Rodney Pearson

Software Engineer

Juniper Systems, Inc.

www.junipersys.com

 

________________________________

From: Bate, Michael [mailto:michael.bate at integra-ls.com] 
Sent: Wednesday, October 03, 2007 1:54 PM
To: Rodney Pearson; icc-avr at imagecraft.com
Subject: RE: [Icc-avr] CRC Check of Program Memory

 

Rodney (and the ICC list),

 

Thank you!

 

Actually my problem should be fairly simple, since I already have a
routine (in C) to calculate CRCs.  I really have two questions:

 

1.	How do I loop through the program memory?
2.	How do I store the correct CRC at the end of the Flash memory?

 

Regarding question 1, I tried coding:

 

for (iprog = __func_lit_start; iprog <= __text_end; iprog++)

{

            Add contents of location "iprog" to CRC

}

 

Where __func_lit_start and _text_end are defined as external, but they
do not link (the map says they are "Global Symbols" but the linker
doesn't know about them).

 

Regarding the second question: if I can get the first part working, I
can run with the debugger to get the correct CRC, but then what do I do
with it?  How do I get it into Flash memory?

 

Am I doing something stupid?

 

Michael Bate

 

 

________________________________

From: Rodney Pearson [mailto:rodney at junipersys.com] 
Sent: Friday, September 28, 2007 12:09 PM
To: Discussion list for ICCAVR and ICCtiny Users. You do NOT need
tosubscribeto icc-announce if you are a member of this.; Bate, Michael
Subject: RE: [Icc-avr] CRC Check of Program Memory

 

Hello Michael -

 

I have worked on this.  I developed a bootloader for the M2560 that has
a bootstrap that does what you are trying to do.  The app note you refer
to has all the pieces, but it is not the clearest code in the world if
your plan on implementing it differently than Atmel has...I ended up
just stripping out the relevant CRC checking code (rot_word,rot_loop),
creating my own ASM routines and then called those from the C code.
This made it much more flexible for me since my CRC is pre-calculated
and stored in the last WORD of Flash...

 

 

Cheers!

 

Rodney Pearson

Software Engineer

Juniper Systems, Inc.

www.junipersys.com

 

________________________________

From: icc-avr-bounces at imagecraft.com
[mailto:icc-avr-bounces at imagecraft.com] On Behalf Of Bate, Michael
Sent: Friday, September 28, 2007 9:06 AM
To: icc-avr at imagecraft.com
Subject: [Icc-avr] CRC Check of Program Memory

 

This may have come up before; unfortunately I don't see how to search
the archives of this list.

 

I am looking for a way to validate the program memory of an AVR
Atmega168.  Atmel provides an application note (AVR236) which includes
some assembly language code, but I do not see how to combine this code
with my C program written for the ImageCraft C compiler.  There are
problems assembling this even with the assembler in AVR Studio.

 

Has anyone solved this problem already?

 

Thanks in advance.

 

----

Michael Bate

Principal Software Engineer

Integra Radionics

22 Terry Avenue

Burlington, MA 01803

Phone:  781-565-1313

Fax:    781-238-0606

E-mail: <mailto:michael.bate at integra-ls.com>                  

www.radionics.com

 

Integra Radionics, Trusted Accuracy

 

******************************

 

 

Confidentiality Notice: This e-mail transmission may contain material
that is confidential and/or proprietary. If the reader of this message
is not the intended recipient, dissemination, disclosure, distribution
or reliance on the contents is strictly prohibited. If you have received
this e-mail transmission in error, please reply to the sender and delete
the message and its contents from your system. Thank you.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20071004/e37ef429/attachment-0001.html


More information about the Icc-avr mailing list