bmips: add new target
[openwrt/staging/ldir.git] / target / linux / bmips / image / lzma-loader / src / Makefile
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 #
4 # Makefile for the LZMA compressed kernel loader for BMIPS based boards
5 #
6 # Copyright (C) 2020 Álvaro Fernández Rojas <noltari@gmail.com>
7 # Copyright (C) 2014 Jonas Gorski <jogo@openwrt.org>
8 # Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
9 #
10 # Some parts of this file was based on the OpenWrt specific lzma-loader
11 # for the BCM47xx and ADM5120 based boards:
12 # Copyright (C) 2004 Manuel Novoa III (mjn3@codepoet.org)
13 # Copyright (C) 2005 Mineharu Takahara <mtakahar@yahoo.com>
14 # Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su>
15 #
16
17 LOADER_ADDR :=
18 KERNEL_ADDR :=
19 LZMA_TEXT_START := 0x80a00000
20 LOADER_DATA :=
21
22 CC := $(CROSS_COMPILE)gcc
23 LD := $(CROSS_COMPILE)ld
24 OBJCOPY := $(CROSS_COMPILE)objcopy
25 OBJDUMP := $(CROSS_COMPILE)objdump
26
27 BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug \
28 -R .MIPS.abiflags -S
29
30 CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
31 -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 \
32 -mno-abicalls -fno-pic -ffunction-sections -pipe \
33 -ffreestanding -fhonour-copts \
34 -mabi=32 -march=mips32 \
35 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap
36 CFLAGS += -D_LZMA_PROB32
37 CFLAGS += -DUART_BASE=$(UART_BASE)
38
39 ASFLAGS = $(CFLAGS) -D__ASSEMBLY__
40
41 LDFLAGS = -static --gc-sections -no-warn-mismatch
42 LDFLAGS += -e startup -T loader.lds -Ttext $(LZMA_TEXT_START)
43
44 O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
45
46 OBJECTS := head.o loader.o cache.o board.o printf.o LzmaDecode.o
47
48 ifneq ($(strip $(LOADER_DATA)),)
49 OBJECTS += data.o
50 CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(KERNEL_ADDR)
51 endif
52
53
54 all: loader.elf
55
56 # Don't build dependencies, this may die if $(CC) isn't gcc
57 dep:
58
59 install:
60
61 %.o : %.c
62 $(CC) $(CFLAGS) -c -o $@ $<
63
64 %.o : %.S
65 $(CC) $(ASFLAGS) -c -o $@ $<
66
67 data.o: $(LOADER_DATA)
68 $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $<
69
70 loader: $(OBJECTS)
71 $(LD) $(LDFLAGS) -o $@ $(OBJECTS)
72
73 loader.bin: loader
74 $(OBJCOPY) $(BIN_FLAGS) $< $@
75
76 loader2.o: loader.bin
77 $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
78
79 loader.elf: loader2.o
80 $(LD) -e startup -T loader2.lds -Ttext $(LOADER_ADDR) -o $@ $<
81
82 mrproper: clean
83
84 clean:
85 rm -f loader *.elf *.bin *.o