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

Modifing the Makefile

Altera_Forum
Honored Contributor II
1,238 Views

Are there settings in the Nios II IDE that are capable of automatically modifying a makefile? I need to link a particular .obj file last so that it's S-Records appears last in my .flash file. If anyone has a suggestion or has done this please let me know.

0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
251 Views

This kind of thing is best achieved by using the linker script rather than relying on command line ordering, since this can be (and is) overridden by the ordering of the linker sections. 

 

To place a particular function or variable into a given section, you should use either the section attribute or .section directives. Examples of how to use these can be found in the section "Advanced Placement Options" in the Nios II Software Developers Handbook. 

 

You may need to create a new linker section to hold your code to ensure it gets placed in the correct relative location. In which case you should create a custom linker script based on the default generated.x. You can direct the IDE to use your new linker script from the system library properties page. 

 

Documentation on how to write linker scripts can be found in the GNU ld manual, although you should hopefully be able to figure out how to define a new section using the examples given in generated.x.
0 Kudos
Altera_Forum
Honored Contributor II
251 Views

After doing some research, I am not sure if this approach will be suitable for my needs. My task is to verify, every 24 hours, that our application code in flash memory has not been corrupted. Before the code is burned to flash, I plan to calculate a checksum on the application code, from the .flash file, and have those checksum values be incorporated into the app code after linking. To do this, 

 

1.) I need to have a c file with markers in it. This is the file that I need to be  

linked in last so that I know where the end of the app code is in .flash. 

2.) I need to have control of the link process to ensure I link this file last 

everytime. 

 

This link will then produce a .flash file that contains (first) the app code and (last) the c file with the markers in it. I then have code that takes command line parameters and an S_Record file (.flash). It calculates checksum values from the app code in the .flash file. It looks for these end markers to know where the app code ends. This code then auto-regenerates the c file with the markers in it and adds the checksum values to that file. Then, the c file with the markers and the checksum values needs to be recompiled and linked back with the app code. Now the code has what I need to do a diagnostic on the code in flash. To check the code in flash, I have diagnostic code in the app that accomplishes this using the checksum values. 

 

I do not have any experience with linker scripts and my co-workers do not as well, but I am trying to use this process they developed. They developed this on the Motorola 332 using the MRI compiler/linker, where they had to supply their own makefile. Thus, they could order the link of their objs. Please let me know if using the linker script is useful for this application or not. Thanks.
0 Kudos
Altera_Forum
Honored Contributor II
251 Views

Hi  

I'm not really sure if this is what you want to do but this way you can add some labels and have some binary markers inserted in you binary image. 

The following is the concept - beware of typo's - this is not tested. 

Add an assembler file with this contents:  

    .section .mystart     .globl labelmystart     labelmystart:     .byte    0,1,2,3,'N','i','o','s','2' # Inserted into binary image verbatime 

 

You might be able to do this with some sort of __attribute__ from within a C/C++ file but I dunno. 

In your linker script add the following line to SECTIONS as the first line  

   .mystart : {KEEP (*(.mystart)) . = 0x20;} > sram 

 

This outputs the mystart section first and advances the location counter with 32 bytes. You will probably have to change the > sram into > flash  

I suggest that you add a similiar line just before the closing brace of SECTIONS with a myend etc...  

Somthing along these lines should enable you to do a CRC on the entire area inbetween. 

The 32 bytes allocated at the beginning provides you with a nice place to patch the CRC into the file with a post link tool of sorts.  

Hope this helps you somehow.
0 Kudos
Reply