Forum Discussion
Altera_Forum
Honored Contributor
20 years agoUpgrading Nios Software - external flash
Dear all,
I would like to upgrade my NIOS code by RS232. The NIOS runs from external memory. This is my procedure: - I transfer the .elf file to the .flash file by the instruction elf2bin. (bin file for dowloading to the flash) - I have a RS232 GUI from which I can send the bin file to the flash. I have written a procedure which is stored in FPGA internal memory. This procedure receives the bin file from the UART and writes the data to flash. (byte by byte) Now, what is the problem: my problem is that my NIOS stops working from the moment I erase the flash sector in which the original NIOS code is stored. Nevertheless, the procedure that erases this sector is placed internal. And I keep running my code from internal memory untill the new nios bin file is stored in the flash. The nios core is placed from 0x00000. When I declare an instruction to be placed in internal memory. ex following function is placed in internal memory void test (void) { } Will the instruction always be in internal memory or will it be placed in internal memory from the moment this instruction is called? Has someone an idea what the problem is? Has someone experience with how to upgrade a NIOS that is running from external memory. Regards28 Replies
- Altera_Forum
Honored Contributor
probably problem is that you erasing the flash also erasing your self.
to make firmware update you need to do one of following things. 1. make bootloader. this program is placed in internal rom or external flash in area that will never erased or reprogrammed on normal condition. set reset pointer to that area. when bootloader starts it will decide what to do: update firmware or execute firmware. advantages: easier to debug, your system will stable even on errors during updating. disadvantages: you need to make two modes - firmware update and normal mode and switch between them. 2. include updating subprogram in your main program, on update, place that portion of code in ram and switch context to there. advantages: very flexible, harder to debug disadvantages: your system will not functional if some errors occurred while updating. - Altera_Forum
Honored Contributor
Yes, I also think that I erase myself :-)
But, I should be running in internal memory. So, that is something strange. Regards Karel - Altera_Forum
Honored Contributor
Hi Karel,
can you specify what the procedure that runs out of internal memory is doing exactly. Are you using the hal api to access flash or are you using your own implementation. You are writing that your program runs from external memory. Is this flash or ram? By the way, are you copying the procedure to internal memory by yourself or is alteras bootloader doing this job for you? --wolfgang - Altera_Forum
Honored Contributor
Hi pfab,
My NIOS code is running from external flash memory. What I'm doing is the follow. I first of all receive the whole bin file from RS232. I save this file into an free flash sector. This works fine. So, the following thing I have to do is copy this flash sector to the flash sector my nios core is running from. Therefore I have written a routine that is placed in internal memory by the section habdler: extern void UpdataSoftware(void)__attribute__((section(".OnChipMem"))); void UpdateSoftware(void) { alt_irq_context count3; count3 = alt_irq_disable_all(); for(FlashAd = 0x0000000; FlashAd < 0x0140000; FlashAd += 0x0020000) { EraseFlashSector(FlashAd); } /* HERE MY PROGRAM FAILS. I erase the flash sector 0 (sector from which the nios is running from). The instruction "EraseFlashSector" is also placed in internal memory*/ unsigned int FlAdW; unsigned int FlAdR; unsigned char Byte; for(FlAdW = 0x0000000,FlAdR = 0x0640000;FlAdW < 0x0140000; FlAdR++,FlAdW++) { unsigned char * ReadFlashData = (unsigned char*)(FlAdR); Byte = *ReadFlashData; WriteFlash(Byte,FlAdW); } UART1_T('O'); UART1_T('K'); } Regards Karel - Altera_Forum
Honored Contributor
I think that my function "eraseflashsector" is loaded from external flash
memory and placed into internal memory. This instruction erases the flash sector the NIOS is running from. From the moment the next instruction has to be executed, for example a print instruction (also declared by the section handler in internal memory), the NIOS tries to copy this instruction into internal memory. That is impossible, because the sector in which the instruction is stored is erased by the "eraseflashsector" instrcution. Is my idea correct? Are the instructions loaded from external flash memory into internal memory from the moment they are called by the main program? If yes, is it possible to save these instrcutions "always" in internal memory Regards Karel - Altera_Forum
Honored Contributor
Hi Karel,
your function UpdateSoftware should be written to the onchip memory by the altera bootloader that gets linked into the .flash file for your project. This is quite important, because the .flash file is the one you should use to upgrade your software! You can convert it to a bin file using a tool like srec2bin. You should also check the objdump file for your project if everything is placed in the correct memory. During the update process avoid function calls and make sure to disable all interrupts if you are using any (e.g. system_timer). hope this helps, --wolfgang - Altera_Forum
Honored Contributor
p.s.: at the end of the update process, your function can not return! you must jump to the reset address.
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by pfab@Mar 1 2006, 06:26 AM hi karel,your function updatesoftware should be written to the onchip memory by the altera bootloader that gets linked into the .flash file for your project.
can you explain me how you can do that? do you have an example?
this is quite important, because the .flash file is the one you should use to upgrade your software! you can convert it to a bin file using a tool like srec2bin.
you should also check the objdump file for your project if everything is placed in the correct memory.
during the update process avoid function calls and make sure to disable all interrupts if you are using any (e.g. system_timer).
hope this helps,
--wolfgang
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=13024)
--- quote end ---
--- Quote End ---
- Altera_Forum
Honored Contributor
I was not right on the bootloader. That just gets linked in by the IDE if the .text section is not located in flash memory.
You will find more information about this in the "Nios II Software Developer's Handbook" under "Memory Usage". The HAL API provides a function you must call in order to write a section to the onchip memory. - Altera_Forum
Honored Contributor
Yes indeed,
I exexute the load function: ALT_LOAD_SECTION_BY_NAME(OnChipMem); after a reset (at start up) The function "UpdateSoftware" must be placed internal. So, I still do'nt know why my program stops after erasing the flash.