Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12603 Discussions

Need a way to make firmware upgrade

Altera_Forum
Honored Contributor II
1,037 Views

Hello, 

I'm using altera cyclone with flash and Sram and usb_uart. 

My goal is to upgrade the commands to the nios processor(upgrade the Nios code) without using jtag. 

I want the cpu to read its commands from the flash device and If I want to change the commands I will simply write them to the flash using a elf file that will written by the PC to the Flash. 

 

after the write, I'll reset the system and the processor would run with the new commands. 

 

Is there a way to do that? 

If so, I would love to get all of the commands that do that. 

 

Thanks. 

asaf
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
342 Views

Please do a search for "NIOS" and "Remote Update". This topic has been addressed many many times in the forum. I've answered at least twice this week. See what you can find then post back when you have questions. Start here: 

 

http://www.alteraforum.com/forum/showthread.php?t=24616&referrerid=2226 

 

Jake
0 Kudos
Altera_Forum
Honored Contributor II
342 Views

10x, but these files intended for cyclone III 

I'm using cyclone I... 

I need to know how to change the cpu instructions address Inside the NIOS code.
0 Kudos
Altera_Forum
Honored Contributor II
342 Views

Technically, changing the cpu's program counter (PC) is easy. You just make a function call to the address of the new code or execute a JMP instruction in assembly. However, there are a lot of other things to take into account like your current stack pointer, heap, hardware state. 

 

Also, how are you going to upload new firmware without simultaneously overwriting the old stuff while you are still running out of it. 

 

However, if all you want to do is make a non-returnable jump. Here is a bit of inline assembly: 

register unsigned int my_reg; 

my_reg = (unsigned int)<address_that_I_want_to_jump_to>; 

__asm__("jmp %0;" :/*no output*/ :"r"(my_reg)); 

 

I'm writing this without reference so I might have some syntax error. 

 

An easier method which results in a "CALLR" instruction rather than "JMP" would be: 

((void (*)())<address_that_I_want_to_jump_to>)(); 

 

The latter simply casts your address as a pointer to a function and calls it. However because you are trying to update firmware; before doing either of these, I would ensure that you have disabled interrupts, reduced the stack to it's minimum, free'd any allocated memory, and put any hardware to its initialization state. 

 

Jake
0 Kudos
Altera_Forum
Honored Contributor II
342 Views

10x!... 

Just for you to know... 

I'm intending to write 2 codes: 

 

1. Code that manage the flash. 

that means that It will supervise on the codes that I will write in the flash(will make sure the code is good, no problems,check versions update,write the versions to the flash and so) 

this code will be permenant and I'll put it on other device(mabye on-chip memory). 

2. the actuall version of the program.it will be writen on the flash. 

 

If I got your right, if I want to read the code from the flash I just need to write(assuming that the on-chip code will manage the flash right and watch for errors): 

register unsigned int my_reg; 

my_reg = (unsigned int)<the flash address like defined in SOPC>; 

__asm__("jmp %0;" :/*no output*/ :"r"(my_reg)); 

 

10x alot.
0 Kudos
Reply