ramips: lzma-loader: make FLASH_START configurable
[openwrt/staging/noltari.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_START :=
23 FLASH_OFFS :=
24 FLASH_MAX :=
25 PLATFORM :=
26 CACHE_FLAGS :=
27
28 CC := $(CROSS_COMPILE)gcc
29 LD := $(CROSS_COMPILE)ld
30 OBJCOPY := $(CROSS_COMPILE)objcopy
31 OBJDUMP := $(CROSS_COMPILE)objdump
32
33
34 include $(PLATFORM).mk
35
36 BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug \
37 -R .MIPS.abiflags -S
38
39 CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
40 -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 \
41 -mno-abicalls -fno-pic -ffunction-sections -pipe -mlong-calls \
42 -fno-common -ffreestanding -fhonour-copts -nostartfiles \
43 -mabi=32 -march=mips32r2 \
44 -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap
45 CFLAGS += -D_LZMA_PROB32
46 CFLAGS += -flto
47 CFLAGS += $(CACHE_FLAGS)
48
49 ASFLAGS = $(CFLAGS) -D__ASSEMBLY__
50
51 LDFLAGS = -static -Wl,--gc-sections -Wl,-no-warn-mismatch
52 LDFLAGS += -Wl,-e,startup -T loader.lds -Wl,-Ttext,$(LZMA_TEXT_START)
53 LDFLAGS += -flto -fwhole-program -Wl,-z,max-page-size=4096
54
55 O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
56
57 OBJECTS := head.o loader.o cache.o board-$(PLATFORM).o printf.o LzmaDecode.o
58
59 ifneq ($(strip $(LOADER_DATA)),)
60 OBJECTS += data.o
61 CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR)
62 endif
63
64 ifneq ($(strip $(KERNEL_CMDLINE)),)
65 CFLAGS += -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"'
66 endif
67
68 ifneq ($(strip $(FLASH_START)),)
69 CFLAGS += -DCONFIG_FLASH_START=$(FLASH_START)
70 endif
71
72 ifneq ($(strip $(FLASH_OFFS)),)
73 CFLAGS += -DCONFIG_FLASH_OFFS=$(FLASH_OFFS)
74 endif
75
76 ifneq ($(strip $(FLASH_MAX)),)
77 CFLAGS += -DCONFIG_FLASH_MAX=$(FLASH_MAX)
78 endif
79
80 all: loader.elf
81
82 # Don't build dependencies, this may die if $(CC) isn't gcc
83 dep:
84
85 install:
86
87 %.o : %.c
88 $(CC) $(CFLAGS) -c -o $@ $<
89
90 %.o : %.S
91 $(CC) $(ASFLAGS) -c -o $@ $<
92
93 data.o: $(LOADER_DATA)
94 $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $<
95
96 loader: $(OBJECTS)
97 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS)
98
99 loader.bin: loader
100 $(OBJCOPY) $(BIN_FLAGS) $< $@
101
102 loader2.o: loader.bin
103 $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
104
105 loader.elf: loader2.o
106 $(LD) -e startup -T loader2.lds -Ttext $(LOADADDR) -z max-page-size=4096 -o $@ $<
107
108 mrproper: clean
109
110 clean:
111 rm -f loader *.elf *.bin *.o
112
113
114