Makefile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #
  2. # Copyright (C) 2006 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. RAMSTART = 0x80000000
  8. RAMSIZE = 0x00100000 # 1MB
  9. LOADADDR = 0x80400000 # RAM start + 4M
  10. KERNEL_ENTRY = 0x80001000
  11. IMAGE_COPY:=0
  12. CROSS_COMPILE = mips-linux-
  13. OBJCOPY:= $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S
  14. CFLAGS := -fno-builtin -Os -G 0 -ffunction-sections -mno-abicalls -fno-pic -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap -Wall -DRAMSTART=${RAMSTART} -DRAMSIZE=${RAMSIZE} -DKERNEL_ENTRY=${KERNEL_ENTRY} -D_LZMA_IN_CB
  15. ifeq ($(IMAGE_COPY),1)
  16. CFLAGS += -DLOADADDR=${LOADADDR} -DIMAGE_COPY=1
  17. endif
  18. .S.s:
  19. $(CPP) $(CFLAGS) $< -o $*.s
  20. .S.o:
  21. $(CC) $(CFLAGS) -c $< -o $*.o
  22. .c.o:
  23. $(CC) $(CFLAGS) -c $< -o $*.o
  24. CC = $(CROSS_COMPILE)gcc
  25. LD = $(CROSS_COMPILE)ld
  26. OBJDUMP = $(CROSS_COMPILE)objdump
  27. O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32)
  28. # Drop some uninteresting sections in the kernel.
  29. # This is only relevant for ELF kernels but doesn't hurt a.out
  30. drop-sections = .reginfo .mdebug .comment
  31. strip-flags = $(addprefix --remove-section=,$(drop-sections))
  32. all : lzma.elf lzma.bin
  33. lzma.lds: lzma.lds.in
  34. sed -e 's,@LOADADDR@,$(LOADADDR),g' -e 's,@ENTRY@,_start,g' $< >$@
  35. kernel.o: vmlinux.lzma lzma.lds
  36. $(LD) -r -b binary --oformat $(O_FORMAT) -o $@ $<
  37. lzma.bin: lzma.elf
  38. $(OBJCOPY) $< $@
  39. ifeq ($(IMAGE_COPY),1)
  40. LOADER_ENTRY ?= $(KERNEL_ENTRY)
  41. lzma.o: decompress.o LzmaDecode.o kernel.o
  42. sed -e 's,@LOADADDR@,$(LOADADDR),g' -e 's,@ENTRY@,entry,g' lzma.lds.in >lzma-stage2.lds
  43. $(LD) -static --no-warn-mismatch -e entry -Tlzma-stage2.lds -o temp-$@ $^
  44. $(OBJCOPY) temp-$@ lzma.tmp
  45. @echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > lzma-data.lds
  46. $(LD) -no-warn-mismatch -T lzma-data.lds -r -o $@ -b binary lzma.tmp --oformat $(O_FORMAT)
  47. lzma.elf: start.o lzma.o
  48. sed -e 's,@LOADADDR@,$(LOADER_ENTRY),g' lzma-copy.lds.in >lzma-copy.lds
  49. $(LD) -s -Tlzma-copy.lds -o $@ $^
  50. else
  51. lzma.elf: start.o decompress.o LzmaDecode.o kernel.o
  52. $(LD) -s -Tlzma.lds -o $@ $^
  53. endif
  54. clean:
  55. rm -f *.o lzma.elf lzma.bin *.tmp *.lds