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 18LOADADDR := 19LZMA_TEXT_START := 0x80a00000 20LOADER_DATA := 21BOARD := 22FLASH_OFFS := 23FLASH_MAX := 24 25CC := $(CROSS_COMPILE)gcc 26LD := $(CROSS_COMPILE)ld 27OBJCOPY := $(CROSS_COMPILE)objcopy 28OBJDUMP := $(CROSS_COMPILE)objdump 29 30BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug \ 31 -R .MIPS.abiflags -S 32 33CFLAGS = -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 39CFLAGS += -D_LZMA_PROB32 40 41ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ 42 43LDFLAGS = -static --gc-sections -no-warn-mismatch 44LDFLAGS += -e startup -T loader.lds -Ttext $(LZMA_TEXT_START) 45 46O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32) 47 48OBJECTS := head.o loader.o cache.o board.o printf.o LzmaDecode.o 49 50ifneq ($(strip $(LOADER_DATA)),) 51OBJECTS += data.o 52CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR) 53endif 54 55ifneq ($(strip $(KERNEL_CMDLINE)),) 56CFLAGS += -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"' 57endif 58 59ifneq ($(strip $(FLASH_OFFS)),) 60CFLAGS += -DCONFIG_FLASH_OFFS=$(FLASH_OFFS) 61endif 62 63ifneq ($(strip $(FLASH_MAX)),) 64CFLAGS += -DCONFIG_FLASH_MAX=$(FLASH_MAX) 65endif 66 67BOARD_DEF := $(shell echo $(strip $(BOARD)) | tr a-z A-Z | tr - _) 68ifneq ($(BOARD_DEF),) 69CFLAGS += -DCONFIG_BOARD_$(BOARD_DEF) 70endif 71 72all: loader.elf 73 74# Don't build dependencies, this may die if $(CC) isn't gcc 75dep: 76 77install: 78 79%.o : %.c 80 $(CC) $(CFLAGS) -c -o $@ $< 81 82%.o : %.S 83 $(CC) $(ASFLAGS) -c -o $@ $< 84 85data.o: $(LOADER_DATA) 86 $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $< 87 88loader: $(OBJECTS) 89 $(LD) $(LDFLAGS) -o $@ $(OBJECTS) 90 91loader.bin: loader 92 $(OBJCOPY) $(BIN_FLAGS) $< $@ 93 94loader2.o: loader.bin 95 $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $< 96 97loader.elf: loader2.o 98 $(LD) -e startup -T loader2.lds -Ttext $(LOADADDR) -o $@ $< 99 100mrproper: clean 101 102clean: 103 rm -f loader *.elf *.bin *.o 104 105 106 107