aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/mpc85xx/image/spi-loader/Makefile
blob: 45af2c3b538e842f6fdf902b7d013c24df5634a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (C) 2022 Matthias Schiffer <mschiffer@universe-factory.net>

CONFIG     ?= $(error No configuration set)

include config/$(CONFIG).mk

MKIMAGE    := mkimage
KARCH      := powerpc
CC         := $(CROSS_COMPILE)gcc
LD         := $(CROSS_COMPILE)ld
OBJCOPY    := $(CROSS_COMPILE)objcopy

PROGRAM_NAME := MPC85xx SPI loader

BIN_FLAGS  := -O binary --pad-to=$(PAD_TO)

CFLAGS     += -std=gnu17 -Os -Wall -Wstrict-prototypes \
		-fomit-frame-pointer -ffreestanding \
		-ffunction-sections -fno-pic \
		-Iinclude -include ../config/$(CONFIG).h \
		-DCONFIG_PROGRAM_NAME='"$(PROGRAM_NAME)"' \
		-DCONFIG_IMAGE_OFFSET=$(IMAGE_OFFSET)
ASFLAGS    := $(CFLAGS)

LDS        := loader.lds
LDFLAGS    := -static --gc-sections -T $(LDS) -Ttext $(TEXT_START)

OBJECTS    := head.o loader.o string.o stdio.o  drivers/serial/ns16550.o \
		drivers/spi/fsl_espi.o drivers/spi/spi-nor.o

OUTDIR     := out

all: $(OUTDIR)/uImage

-include $(OBJECTS:%.o=$(OUTDIR)/%.d)

$(OUTDIR)/%.o: %.c Makefile config/$(CONFIG).mk
	@mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -c -o $@ -MD -MP $<

$(OUTDIR)/%.o: %.S Makefile config/$(CONFIG).mk
	@mkdir -p $(dir $@)
	$(CC) $(ASFLAGS) -c -o $@ -MD -MP $<

$(OUTDIR)/loader.elf: $(OBJECTS:%=$(OUTDIR)/%) $(LDS)
	$(LD) $(LDFLAGS) -o $@ $(OBJECTS:%=$(OUTDIR)/%)

$(OUTDIR)/loader.bin: $(OUTDIR)/loader.elf
	$(OBJCOPY) $(BIN_FLAGS) $< $@

$(OUTDIR)/uImage: $(OUTDIR)/loader.bin
	$(MKIMAGE) -A $(KARCH) -O linux -T kernel -C none \
		-a $(TEXT_START) -e $(TEXT_START) -n '$(PROGRAM_NAME)' -d $< $@

clean:
	rm -rf $(OUTDIR)

.PHONY: all clean