Linker Script - Placing a section at the end of a memory region

前端 未结 5 1514
后悔当初
后悔当初 2020-12-24 09:15

I have searched far and wide for how to do this and have failed to come up with an answer.

My memory layout is as follows:

Fake Address | Section
            


        
5条回答
  •  無奈伤痛
    2020-12-24 10:18

    I managed to solve it by calculating the size of the code by using the linker command: size. In my Makefile i set SIZE to the size of the code. I then call cpp (the preprocessor) to calculate all absolute addresses (using c-syntax). I then link using the generated linkfile: tmp.ld

    %.elf: %.o
        $(eval SIZE := $(shell arm-none-eabi-size -B $<  | tail -n 1 | awk -F ' ' '{print $$1}'))
        $(CC) -DSEG_SIZE=$(SIZE) -P -E -x c link.ld -o tmp.ld
        $(CC) -o $@ $< $(LDFLAGS)
    

    In the link.ld-file i can do all kinds of calculations (as SEG_SIZE is a constant):

    #define SEG_LAST_ADDR 1234
    #define MY_SEG        (SEG_LAST_ADDR - SEG_SIZE)
    
    MEMORY
    {
      bootloader     (rx)  : ORIGIN = MY_SEG,     LENGTH = SEG_SIZE
      ...
    }
    

    I finally link against the tmp.ld-file.

提交回复
热议问题