<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Perhaps it is a checksum, not a real CRC? It is a common technique to calculate the checksum of some data, and then add whatever value it takes to make it zero to the end of the data. That way, a simple non-zero result indicates an error. Much the same way that parity works.<div><br></div><div>For example, the 8 bit checksum of "ABC" is 0x86. Adding an 0x79 character (z) to the end of our data so that we have "ABCz" produces a checksum of 0.<br><div><br></div><div>Steve</div><div><br></div><div> <br><div><div>On Jun 5, 2008, at 4:35 PM, Andrew wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div><div><font face="Arial">Hi,</font></div><div><font face="Arial"></font> </div><div><font face="Arial">Has anybody used the AES bootloader from the Atmel website? i have a port sort of working for the ICCAVR compiler but the memory check sum fails every time (basically after thr bootloader restarts and the does not select to bootload the bootloader does a check sum on the entire memory.</font></div><div><font face="Arial" size="2"></font> </div><div><p><font face="Arial" color="#000080">#ifdef CRC_CHECK<br>// Check that the Application Section contents is undamaged<br>// by calculating the CRC of the whole memory.<br>{<span class="Apple-converted-space"> </span><br> unsigned int crc = 0;<br> unsigned i;<br><br> const unsigned char *p = ( const unsigned char *)0x000000;<br> const unsigned char *n = ( const unsigned char *)MEM_SIZE;<br><br> busSendText("Skip the Loader routine\r\n");<br><br> do<br> {<br> crc = CRC(crc, *p++);<br> }<br> while (--n);<br><br> // Application Section damaged<br> // do not jump to Reset Vector of the Application Section<br>if (crc)<span class="Apple-converted-space"> </span><br> {<br> busSendText("\r\nApplication Section damaged\r\n");<span class="Apple-converted-space"> </span><br> while(1);<br> }<br>}<br>#endif</font></p></div><div><font face="Arial" size="2"><font size="3">To me the 'if (crc)' should be' if(!crc)' as it cannot be a very good check sum if it passes as long as the crc is any number but zero.</font><span class="Apple-converted-space"> </span><font size="3">If i force the check sum to pass my sent code works fine / as written.</font></font></div><div><font face="Arial"></font> </div><div><font face="Arial">Note i changed the above code from IAR which was: -</font></div><div><font face="Arial"></font> </div><div><font face="Arial"></font> </div><div><font size="2"><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; ">#ifdef</span><span style="font-size: 10pt; font-family: Arial, sans-serif; "><span class="Apple-converted-space"> </span>CRC_CHECK<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: green; font-family: Arial, sans-serif; ">// Check that the Application Section contents is undamaged<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: green; font-family: Arial, sans-serif; ">// by calculating the CRC of the whole memory.<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">{<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; "><span> </span>unsigned</span><span style="font-size: 10pt; font-family: Arial, sans-serif; "><span class="Apple-converted-space"> </span><span style="color: blue; ">int</span><span class="Apple-converted-space"> </span>crc = 0;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; "><span> </span>unsigned</span><span style="font-size: 10pt; font-family: Arial, sans-serif; "><span class="Apple-converted-space"> </span><span style="color: blue; ">char</span><span class="Apple-converted-space"> </span>APPFLASH *p = (<span style="color: blue; ">unsigned</span><span class="Apple-converted-space"> </span><span style="color: blue; ">char</span><span class="Apple-converted-space"> </span>APPFLASH *)0x000000;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; "><span> </span>unsigned</span><span style="font-size: 10pt; font-family: Arial, sans-serif; "><span class="Apple-converted-space"> </span><span style="color: blue; ">char</span><span class="Apple-converted-space"> </span>APPFLASH *n = (<span style="color: blue; ">unsigned</span><span class="Apple-converted-space"> </span><span style="color: blue; ">char</span><span class="Apple-converted-space"> </span>APPFLASH *)MEM_SIZE;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; "><span> </span>do<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">{<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">crc = CRC(crc, *p++);<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">}<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; ">while</span><span style="font-size: 10pt; font-family: Arial, sans-serif; "><span class="Apple-converted-space"> </span>(--n);<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: green; font-family: Arial, sans-serif; ">// Application Section damaged<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: green; font-family: Arial, sans-serif; ">// -> do not jump to Reset Vector of the Application Section<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; ">if</span><span style="font-size: 10pt; font-family: Arial, sans-serif; "><span class="Apple-converted-space"> </span>(crc) {<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">DDRB = 0xff;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; ">do</span><span style="font-size: 10pt; font-family: Arial, sans-serif; "><span class="Apple-converted-space"> </span>{<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">PORTB ^= 0xff;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">__delay_cycles( 1000000 );<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">}<span class="Apple-converted-space"> </span><span style="color: blue; ">while</span>(1);<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: green; font-family: Arial, sans-serif; ">// continue;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">}<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; font-family: Arial, sans-serif; ">}<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; ">#endif</span></div><p style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; "><font face="Arial"></font></span> </p><div style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; ">Where the folling are defined:-</span></div><p style="margin-top: 0cm; margin-right: 0cm; margin-bottom: 0pt; margin-left: 0cm; "><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; "><font face="Arial"></font></span> </p><span style="font-size: 10pt; color: blue; font-family: Arial, sans-serif; "><font size="4"></font><p><font size="3">#if MEM_SIZE < 65536<br><font color="#008000"><font color="#008000">//#define BOOTFLASH __flash</font></font><br><font color="#008000"><font color="#008000">//#define APPFLASH __flash</font></font><br>#else<br><font color="#008000"><font color="#008000">// #define BOOTFLASH __farflash</font></font><br><font color="#008000"><font color="#008000">// #define APPFLASH __hugeflash</font></font><br>#endif</font><font size="4"></font></p><font size="4"></font></span></font></div><div><font face="Arial" size="2">i have commented the defines out as they don't work with ICCAVR.</font></div><div><font face="Arial" size="2"></font> </div><div><font face="Arial" size="2">any Ideas help / sugestion, i will finish commenting my modified code as best i understand and post it.</font></div><div><font face="Arial" size="2"></font> </div><div><font face="Arial" size="2">Many Thanks</font></div><div><font face="Arial" size="2"></font> </div><div><font face="Arial" size="2">Andy</font></div><div><font face="Arial" size="2"></font> </div><div><font face="Arial" size="2"></font> </div><div><font face="Arial" size="2"></font> </div><div><font face="Arial" size="2"></font> </div>_______________________________________________<br>Icc-avr mailing list<br><a href="mailto:Icc-avr@imagecraft.com">Icc-avr@imagecraft.com</a><br><a href="http://dragonsgate.net/mailman/listinfo/icc-avr">http://dragonsgate.net/mailman/listinfo/icc-avr</a><br></div></span></blockquote></div><br></div></div></body></html>