1 # Makefile - Build the NanoNote payload 2 # 3 # Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> 4 # Copyright (C) Xiangfu Liu <xiangfu@sharism.cc> 5 # 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 3 of the License, or (at your option) any later 9 # version. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 # details. 15 # 16 # You should have received a copy of the GNU General Public License along with 17 # this program. If not, see <http://www.gnu.org/licenses/>. 18 19 ARCH = mipsel-linux-gnu 20 CC = $(ARCH)-gcc 21 LD = $(ARCH)-ld 22 NM = $(ARCH)-nm 23 OBJCOPY=$(ARCH)-objcopy 24 OBJDUMP=$(ARCH)-objdump 25 26 # NOTE: -O2 is actually needed to prevent memcpy references, whereas probably 27 # NOTE: one of the -f{freestanding, no-hosted, no-builtin} options should work. 28 # NOTE: See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 29 30 ASM_INC = /usr/src/linux-headers-4.0.0-1-common/arch/mips/include 31 CFLAGS = -O2 -Wall -fno-pic -fno-unit-at-a-time -fno-zero-initialized-in-bss \ 32 -ffreestanding -fno-hosted -fno-builtin \ 33 -march=mips32 -mno-abicalls \ 34 -Iinclude -I$(ASM_INC) -I$(ASM_INC)/asm/mach-generic 35 LDFLAGS = -nostdlib -EL 36 37 PAYLOAD = stage1.bin stage2.bin 38 TARGET = $(PAYLOAD:.bin=.elf) 39 DUMP = $(PAYLOAD:.bin=.dump) 40 MAP = $(PAYLOAD:.bin=.map) 41 42 # Ordering of objects is important and cannot be left to replacement rules. 43 44 SRC1 = head1.S stage1.c board-nanonote.c 45 SRC2 = head2.S stage2.c board-nanonote.c nanonote_gpm940b0.c 46 OBJ1 = head1.o stage1.o board-nanonote.o 47 OBJ2 = head2.o stage2.o board-nanonote.o nanonote_gpm940b0.o 48 OBJ = $(OBJ1) $(OBJ2) 49 50 .PHONY: all clean distclean 51 52 all: $(PAYLOAD) 53 54 clean: 55 rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(DUMP) *.map 56 57 distclean: clean 58 echo "Nothing else to clean." 59 60 $(PAYLOAD): $(TARGET) 61 $(OBJCOPY) -O binary $(@:.bin=.elf) $@+ 62 $(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump) 63 $(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map) 64 $(NM) -n $< > System-$(@:.bin=.map) 65 chmod -x $@+ 66 mv -f $@+ $@ 67 68 stage1.elf: $(OBJ1) 69 $(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ1) -o $@ 70 71 stage2.elf: $(OBJ2) 72 $(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ2) -o $@ 73 74 .c.o: 75 $(CC) -c $(CFLAGS) $< -o $@ 76 77 .S.o: 78 $(CC) -c $(CFLAGS) $< -o $@