ramips: Add support for mt7621 to lzma-loader
[openwrt/openwrt.git] / target / linux / ramips / 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) 2011 Gabor Juhos <juhosg@openwrt.org>
6 #
7 # Some parts of this file was based on the OpenWrt specific lzma-loader
8 # for the BCM47xx and ADM5120 based boards:
9 # Copyright (C) 2004 Manuel Novoa III (mjn3@codepoet.org)
10 # Copyright (C) 2005 Mineharu Takahara <mtakahar@yahoo.com>
11 # Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su>
12 #
13 # This program is free software; you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License version 2 as published
15 # by the Free Software Foundation.
16 #
17
18 LOADADDR :=
19 LZMA_TEXT_START := 0x80a00000
20 LOADER_DATA :=
21 BOARD :=
22 FLASH_OFFS :=
23 FLASH_MAX :=
24 PLATFORM :=
25 CACHE_FLAGS :=
26
27 CC := $(CROSS_COMPILE)gcc
28 LD := $(CROSS_COMPILE)ld
29 OBJCOPY := $(CROSS_COMPILE)objcopy
30 OBJDUMP := $(CROSS_COMPILE)objdump
31
32
33 include $(PLATFORM).mk
34
35 BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug \
36 -R .MIPS.abiflags -S
37
38 CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
39 -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 \
40 -mno-abicalls -fno-pic -ffunction-sections -pipe -mlong-calls \
41 -fno-common -ffreestanding -fhonour-copts -nostartfiles \
42 -mabi=32 -march=mips32r2 \
43 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap
44 CFLAGS += -D_LZMA_PROB32
45 CFLAGS += -flto
46 CFLAGS += $(CACHE_FLAGS)
47
48 ASFLAGS = $(CFLAGS) -D__ASSEMBLY__
49
50 LDFLAGS = -static -Wl,--gc-sections -Wl,-no-warn-mismatch
51 LDFLAGS += -Wl,-e,startup -T loader.lds -Wl,-Ttext,$(LZMA_TEXT_START)
52 LDFLAGS += -flto -fwhole-program -Wl,-z,max-page-size=4096
53
54 O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
55
56 OBJECTS := head.o loader.o cache.o board-$(PLATFORM).o printf.o LzmaDecode.o
57
58 ifneq ($(strip $(LOADER_DATA)),)
59 OBJECTS += data.o
60 CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR)
61 endif
62
63 ifneq ($(strip $(KERNEL_CMDLINE)),)
64 CFLAGS += -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"'
65 endif
66
67 ifneq ($(strip $(FLASH_OFFS)),)
68 CFLAGS += -DCONFIG_FLASH_OFFS=$(FLASH_OFFS)
69 endif
70
71 ifneq ($(strip $(FLASH_MAX)),)
72 CFLAGS += -DCONFIG_FLASH_MAX=$(FLASH_MAX)
73 endif
74
75 all: loader.elf
76
77 # Don't build dependencies, this may die if $(CC) isn't gcc
78 dep:
79
80 install:
81
82 %.o : %.c
83 $(CC) $(CFLAGS) -c -o $@ $<
84
85 %.o : %.S
86 $(CC) $(ASFLAGS) -c -o $@ $<
87
88 data.o: $(LOADER_DATA)
89 $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $<
90
91 loader: $(OBJECTS)
92 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
93
94 loader.bin: loader
95 $(OBJCOPY) $(BIN_FLAGS) $< $@
96
97 loader2.o: loader.bin
98 $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
99
100 loader.elf: loader2.o
101 $(LD) -e startup -T loader2.lds -Ttext $(LOADADDR) -z max-page-size=4096 -o $@ $<
102
103 mrproper: clean
104
105 clean:
106 rm -f loader *.elf *.bin *.o
107
108
109