ralink: update patches
[openwrt/svn-archive/archive.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
26 CC := $(CROSS_COMPILE)gcc
27 LD := $(CROSS_COMPILE)ld
28 OBJCOPY := $(CROSS_COMPILE)objcopy
29 OBJDUMP := $(CROSS_COMPILE)objdump
30
31 BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug -S
32
33 CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
34 -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 \
35 -mno-abicalls -fno-pic -ffunction-sections -pipe -mlong-calls \
36 -fno-common -ffreestanding -fhonour-copts \
37 -mabi=32 -march=mips32r2 \
38 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap
39 CFLAGS += -D_LZMA_PROB32 -DARCH=$(PLATFORM)
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-$(PLATFORM).o printf.o LzmaDecode.o
49
50 include $(PLATFORM).mk
51 CFLAGS+=$(CACHE_FLAGS)
52 ASFLAGS+=$(CACHE_FLAGS)
53
54 ifneq ($(strip $(LOADER_DATA)),)
55 OBJECTS += data.o
56 CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR)
57 endif
58
59 ifneq ($(strip $(KERNEL_CMDLINE)),)
60 CFLAGS += -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"'
61 endif
62
63 ifneq ($(strip $(FLASH_OFFS)),)
64 CFLAGS += -DCONFIG_FLASH_OFFS=$(FLASH_OFFS)
65 endif
66
67 ifneq ($(strip $(FLASH_MAX)),)
68 CFLAGS += -DCONFIG_FLASH_MAX=$(FLASH_MAX)
69 endif
70
71 BOARD_DEF := $(shell echo $(strip $(BOARD)) | tr a-z A-Z | tr - _)
72 ifneq ($(BOARD_DEF),)
73 CFLAGS += -DCONFIG_BOARD_$(BOARD_DEF)
74 endif
75
76 all: loader.elf
77
78 # Don't build dependencies, this may die if $(CC) isn't gcc
79 dep:
80
81 install:
82
83 %.o : %.c
84 $(CC) $(CFLAGS) -c -o $@ $<
85
86 %.o : %.S
87 $(CC) $(ASFLAGS) -c -o $@ $<
88
89 data.o: $(LOADER_DATA)
90 $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $<
91
92 loader: $(OBJECTS)
93 $(LD) $(LDFLAGS) -o $@ $(OBJECTS)
94
95 loader.bin: loader
96 $(OBJCOPY) $(BIN_FLAGS) $< $@
97
98 loader2.o: loader.bin
99 $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
100
101 loader.elf: loader2.o
102 $(LD) -e startup -T loader2.lds -Ttext $(LOADADDR) -o $@ $<
103
104 mrproper: clean
105
106 clean:
107 rm -f loader *.elf *.bin *.o
108
109
110