Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Understanding Kernel:Codes in RAM and Flash?

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!

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- 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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- 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?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.