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