Forum Discussion

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

Problem generating Hex files for on chip memories.

I have two on chip memories for my Nios system. ("instruction_rom" and "data_ram", both are actually RAM's)

I am having problems with .hex files generated for these internal memories.

The IDE creates me instruction_rom.hex and data_ram.hex as expected.

But, The hex files only contain zero's for the data?

--- Quote Start ---

says the process has changed in 9.1, and well I am using 9.1 sp1.

So what is the process to do this in 9.1

Can anybody help

Cheers

7 Replies

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

    i tried a similar exercise from commans shell using

    elf2hex --base=0x0 --end=0x1fff <input elf file > <output hex file name > --width=32

    earlier i tried with the actual start and end base addresses of the onchip memories used in the design. Then i too got a hex file will only 0s.

    with base starting from 0 to the actual size i was able to get hex file other than 0s.

    what bothers me though is when quartus is asked to update the memory init file, it gives a warning that data in hex file is greater than that can be accomodated and hence will be wrapped around .

    Hope it does not cause data corruption :)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This is quite helpful :-)

    Using elf2hex as above I can generate a hex file that contains data rather than just 0's.

    My problem now is that I have two rams. One for instructions and one for data.

    eg

    (.text) in Instruction_Rom

    (.rodata, .rwdata, heap and stack) in Data_RAM

    I assume that both of these are contained within the elf file. So how do I extract the relevant sections?

    Cheers

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

    In order to extract different sections of the elf, i suggest u make 2 elf files

    one which has only .text

    and the other with all the remainng sections ( without .text )

    in order to do so use the nios2-elf-strip --remove-section < section name >

    hope this helps:)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok I tried the following.

    nios2-elf-strip.exe -R=.text -o my_nios_text.elf my_nios.elf

    and

    nios2-elf-strip.exe -R=.entry -R=.exceptions -R=.rodata -R=.rwdata -R=.bss -R=.comment -o my_nios_other.elf my_nios.elf

    But I end up with two Identical files (my_nios_text.elf and my_nios_other.elf)

    Am I trying to do the right thing? Or did I completely miss your point.

    Cheers

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

    Use objcopy to copy extract the data from each segment.

    Something like: nios2-elf-objcopy.exe -O hex -j .text prog.elf prog_text.hex

    You probably need to use 'objdump -h' to sort out which elf sections exist in the input file, and may need to get the linker to generate a map file in order to find out what ends up where (and why).
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you for the help..

    You are definitely on the right track. I tried many combinations and produced hex files with data, but alas nothing I did would actually run!

    (I am not a SW engineer)

    So I cheated. I replace the two rams with a single ram. The IDE produces a single HEX file with the correct data :-)

    This gets me past this point for the time being. I will revisit later.

    I have logged this as a bug with Altera, I will share any response.

    Cheers

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

    The IDE (9.0) seems to generate an image where all the initialised data directly follows the code, and initialisation code copies it to the 'correct' address.

    This may not be what you want! And may be one of the problems.

    You can persuade objdump to disassemble raw binary (and I presume hex) files, which you let you check that the code is approximately right.