Forum Discussion
Altera_Forum
Honored Contributor
21 years agoThe file format sent to your application over the serial can be anything you want: raw binary, s-record, etc. You'll just need code in you Nios application to parse whatever format you use and construct an image in RAM that you can then program into flash.
I would also add some sanity checks to the image you download. First, add a unique hardware specific signature string at a known offset (I put one just after the "Nios" string that the GERMs boot loader looks for) so your code can verify that that the downloaded image is indeed a code image intended for your particular hardware. This will prevent problems if your users accidently try and download the wrong file. Second, add some sort of self-consistency check in the image itself to ensure that the image in RAM is complete and uncorrupted before programming the flash. I embedd the size of the downloaded image near the start (again, at a known offset), and append a 16-bit CRC check code to the end of the image. The code recalculates the CRC of the downloaded image (using the length) and ignores the image if the CRCs don't match.