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