Makefile 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. LOADADDR :=
  18. LZMA_TEXT_START := 0x80a00000
  19. LOADER_DATA :=
  20. BOARD :=
  21. FLASH_OFFS :=
  22. FLASH_MAX :=
  23. CC := $(CROSS_COMPILE)gcc
  24. LD := $(CROSS_COMPILE)ld
  25. OBJCOPY := $(CROSS_COMPILE)objcopy
  26. OBJDUMP := $(CROSS_COMPILE)objdump
  27. BIN_FLAGS := -O binary -R .reginfo -R .note -R .comment -R .mdebug \
  28. -R .MIPS.abiflags -S
  29. CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
  30. -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 \
  31. -mno-abicalls -fno-pic -ffunction-sections -pipe -mlong-calls \
  32. -fno-common -ffreestanding -fhonour-copts \
  33. -mabi=32 -march=mips32r2 \
  34. -Wa,-32 -Wa,-march=mips32r2 -Wa,-mips32r2 -Wa,--trap
  35. CFLAGS += -D_LZMA_PROB32
  36. ASFLAGS = $(CFLAGS) -D__ASSEMBLY__
  37. LDFLAGS = -static --gc-sections -no-warn-mismatch
  38. LDFLAGS += -e startup -T loader.lds -Ttext $(LZMA_TEXT_START)
  39. O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
  40. OBJECTS := head.o loader.o cache.o board.o printf.o LzmaDecode.o
  41. ifneq ($(strip $(LOADER_DATA)),)
  42. OBJECTS += data.o
  43. CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR)
  44. endif
  45. ifneq ($(strip $(KERNEL_CMDLINE)),)
  46. CFLAGS += -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"'
  47. endif
  48. ifneq ($(strip $(FLASH_OFFS)),)
  49. CFLAGS += -DCONFIG_FLASH_OFFS=$(FLASH_OFFS)
  50. endif
  51. ifneq ($(strip $(FLASH_MAX)),)
  52. CFLAGS += -DCONFIG_FLASH_MAX=$(FLASH_MAX)
  53. endif
  54. BOARD_DEF := $(shell echo $(strip $(BOARD)) | tr a-z A-Z | tr - _)
  55. ifneq ($(BOARD_DEF),)
  56. CFLAGS += -DCONFIG_BOARD_$(BOARD_DEF)
  57. endif
  58. all: loader.elf
  59. # Don't build dependencies, this may die if $(CC) isn't gcc
  60. dep:
  61. install:
  62. %.o : %.c
  63. $(CC) $(CFLAGS) -c -o $@ $<
  64. %.o : %.S
  65. $(CC) $(ASFLAGS) -c -o $@ $<
  66. data.o: $(LOADER_DATA)
  67. $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $<
  68. loader: $(OBJECTS)
  69. $(LD) $(LDFLAGS) -o $@ $(OBJECTS)
  70. loader.bin: loader
  71. $(OBJCOPY) $(BIN_FLAGS) $< $@
  72. loader2.o: loader.bin
  73. $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
  74. loader.elf: loader2.o
  75. $(LD) -e startup -T loader2.lds -Ttext $(LOADADDR) -o $@ $<
  76. mrproper: clean
  77. clean:
  78. rm -f loader *.elf *.bin *.o