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++
12599 Discussions

Understanding Kernel:Codes in RAM and Flash?

Altera_Forum
Honored Contributor II
976 Views

Understanding Kernel: 

There is a piece of code in Head.S like this: 

nextpc r1 /* Find out where we are */ 

chkadr:  

movia r2,chkadr 

beq r1,r2,finish_move /* We are running in RAM done */  

In my opinion, r1 equals r2 no matter the code exits in the RAM or Flash memory. But here it means r1==r2 will be true only if the codes executing from RAM.Maybe r1==r2 will be false if the codes executing from flash memory? 

Thanks in advance!
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
296 Views

 

--- Quote Start ---  

originally posted by xunios@Jul 5 2006, 05:32 PM 

understanding kernel: 

there is a piece of code in head.s like this: 

      nextpc        r1 /* find out where we are */ 

chkadr:         

        movia        r2,chkadr 

        beq          r1,r2,finish_move        /* we are running in ram done */  

in my opinion, r1 equals r2 no matter the code exits in the ram or flash memory.  but here it means r1==r2 will  be true only if the codes executing from  ram.maybe  r1==r2 will  be  false  if the codes executing from flash memory? 

thanks in advance! 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16661) 

--- quote end ---  

 

--- Quote End ---  

 

It is different. 

The kernel is linked to sdram. 

The nextpc will get the real pc. 

If it is from flash, real pc will be different from the (linked address of) chkadr. 

It will them move the code from flash to sdram, and then jump start on sdram. 

 

But actually, there is a altera supplied boot loader (either cfi or epcs) inserted during elf2flash conversion. So from reset, it will start from altera boot loader, and which will move the kernel to sdram.  

Finally you will say the move code in head.S was not taken.
0 Kudos
Altera_Forum
Honored Contributor II
296 Views

 

--- Quote Start ---  

originally posted by hippo+jul 10 2006, 01:03 am--><div class='quotetop'>quote (hippo @ jul 10 2006, 01:03 am)</div> 

--- quote start ---  

<!--quotebegin-xunios@Jul 5 2006, 05:32 PM 

understanding kernel: 

there is a piece of code in head.s like this: 

      nextpc        r1 /* find out where we are */ 

chkadr:         

        movia        r2,chkadr 

        beq           r1,r2,finish_move        /* we are running in ram done */  

in my opinion, r1 equals r2 no matter the code exits in the ram or flash memory.  but here it means r1==r2 will  be true only if the codes executing from  ram.maybe   r1==r2 will  be  false  if the codes executing from flash memory? 

thanks in advance! 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16661) 

--- quote end ---  

 

--- Quote End ---  

 

It is different. 

The kernel is linked to sdram. 

The nextpc will get the real pc. 

If it is from flash, real pc will be different from the (linked address of) chkadr. 

It will them move the code from flash to sdram, and then jump start on sdram. 

 

But actually, there is a altera supplied boot loader (either cfi or epcs) inserted during elf2flash conversion. So from reset, it will start from altera boot loader, and which will move the kernel to sdram.  

Finally you will say the move code in head.S was not taken. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16743)</div> 

[/b] 

--- Quote End ---  

 

Thanks hippo.This has been puzzling me for a long time!  

If it is from flash, real pc will be different from the (linked address of) chkadr. 

--------------Then ,if excuting from the flash,the will pc will be what ?Are there any relative documents?
0 Kudos
Altera_Forum
Honored Contributor II
296 Views

say, the kernel is linked to sdram_base. 

if you program the kernel to the cfi flash at flash_base WITHOUT altera supplied cfi boot loader, 

and the reset vector is pointed to flash_base. 

 

after reset, the nios2 will start at flash_base, and the real pc will be (flash_base + xxx), while 

the chkadr was (sdram_base + xxx) . so they are different. 

 

but it is rarely the case. usually the altera cfi boot loader is inserted by elf2flash conversiont utility. 

after reset, the nios2 will start at flash_base, and run the cfi boot loader, which move the kernel image to sdram_base, and jump to sdram_base. 

 

you may find more from user guide of nios2 flash programmer.
0 Kudos
Reply