在裸机臂示例和链接器中运行链接器无法找到存在的加载程序文件

时间:2015-04-05 04:00:14

标签: gcc makefile arm bare-metal

我找到了一个与我不同的板子的裸机示例,因此我将不得不修改加载器脚本,但是现在我只想能够编译和链接示例。

我将arm-none-eabi交叉编译器复制到c_blinky上面的目录,这是源文件所在的目录。 (我在website上的页面上有一个目录结构图表)

这是makefile:

ifeq ($(GNU_ARM),)
GNU_ARM = ../arm-none-eabi/bin
endif
CC    := $(GNU_ARM)/arm-none-eabi-gcc
CPP   := $(GNU_ARM)/arm-none-eabi-g++
ASM   := $(GNU_ARM)/arm-none-eabi-as
LINK  := $(GNU_ARM)/arm-none-eabi-gcc
BIN   := $(GNU_ARM)/arm-none-eabi-objcopy
RM    := rm -rf
MKDIR := mkdir
BLDDIR  = .
CCINC   = -I$(BLDDIR)
APP_DEP = $(BLDDIR)/bsp.h \
    $(BLDDIR)/arm_exc.h \
    $(BLDDIR)/isr.h
APP_NAME = blinky
ARM_CORE = arm7tdmi
ifeq (rel, $(CONF))       # Release configuration 
BINDIR = rel
CCFLAGS = -c -mcpu=$(ARM_CORE) -mthumb-interwork -Os \
-mlong-calls -ffunction-sections -Wall -DNDBEBUG -o$@
ASMFLAGS = -mcpu=$(ARM_CORE) -mthumb-interwork -o$@
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
    -Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
else                     # default Debug configuration 
BINDIR = dbg
CCFLAGS = -g -c -mcpu=$(ARM_CORE) -mthumb-interwork -O \
    -mlong-calls -ffunction-sections -Wall -o$@
ASMFLAGS = -g -mcpu=$(ARM_CORE) -mthumb-interwork -o$@
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
    -Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
endif
all: $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).bin : $(BINDIR)/$(APP_NAME).elf
    $(BIN) -O binary $(BINDIR)/$(APP_NAME).elf $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).elf : \
    ./$(APP_NAME).ld \
    $(BINDIR)/startup.o \
    $(BINDIR)/arm_exc.o \
    $(BINDIR)/low_level_init.o \
    $(BINDIR)/isr.o \
    $(BINDIR)/bsp.o \
    $(BINDIR)/blinky.o
    $(LINK) \
    $(BINDIR)/startup.o \
    $(BINDIR)/arm_exc.o \
    $(BINDIR)/low_level_init.o \
    $(BINDIR)/isr.o \
    $(BINDIR)/bsp.o \
    $(BINDIR)/blinky.o \
    $(LINKFLAGS)
$(BINDIR)/startup.o: $(BLDDIR)/startup.s
    $(ASM) $(ASMFLAGS) $<
$(BINDIR)/arm_exc.o: $(BLDDIR)/arm_exc.s
    $(ASM) $(ASMFLAGS) $<
# choose the ARM or THUMB compilation for each module...
$(BINDIR)/low_level_init.o: $(BLDDIR)/low_level_init.c $(APP_DEP)
    $(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/isr.o: $(BLDDIR)/isr.c $(APP_DEP)
    $(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/bsp.o: $(BLDDIR)/bsp.c $(APP_DEP)
    $(CC) -mthumb $(CCFLAGS) $(CCINC) $<
$(BINDIR)/blinky.o: $(BLDDIR)/blinky.c $(APP_DEP)
    $(CC) -mthumb $(CCFLAGS) $(CCINC) $<

我将makefile中的GNU_ARM设置为../arm-none-eabi/bin并运行make并出现以下错误:  (文件blinky.ld确实存在于源目录中)

../arm-none-eabi/bin/arm-none-eabi-gcc \
    dbg/startup.o \
    dbg/arm_exc.o \
    dbg/low_level_init.o \
    dbg/isr.o \
    dbg/bsp.o \
    dbg/blinky.o \
    -T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: cannot open linker script file     .blinky.ld: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [dbg/blinky.elf] Error 1

我认为开头的LINK分配应该是:

LINK  := $(GNU_ARM)/arm-none-eabi-ld

而不是

LINK  := $(GNU_ARM)/arm-none-eabi-gcc

我得到了:

../arm-none-eabi/bin/arm-none-eabi-ld \
    dbg/startup.o \
    dbg/arm_exc.o \
    dbg/low_level_init.o \
    dbg/isr.o \
    dbg/bsp.o \
    dbg/blinky.o \
    -T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
../arm-none-eabi/bin/arm-none-eabi-ld: cannot open linker script file .blinky.ld: No such file or directory
make: *** [dbg/blinky.elf] Error 1

看起来arm-none-eabi-gcc在lib / gcc / arm-none-eabi / 4.9.3中调用了collect2,后者又调用了不在主bin目录中的ld:

/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:

我尝试使用arm-none-eabi-ld作为ld的符号链接并得到同样的错误。

0 个答案:

没有答案