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 SRC1 = head1.S stage1.c board-nanonote.c 43 SRC2 = head2.S stage2.c board-nanonote.c 44 OBJ1 = $(filter %.o,$(SRC1:.c=.o) $(SRC1:.S=.o)) 45 OBJ2 = $(filter %.o,$(SRC2:.c=.o) $(SRC2:.S=.o)) 46 OBJ = $(OBJ1) $(OBJ2) 47 48 .PHONY: all clean distclean 49 50 all: $(PAYLOAD) 51 52 clean: 53 rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(DUMP) $(MAP) #System.map 54 55 distclean: clean 56 echo "Nothing else to clean." 57 58 $(PAYLOAD): $(TARGET) 59 $(OBJCOPY) -O binary $(@:.bin=.elf) $@+ 60 $(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump) 61 $(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map) 62 #$(NM) -n $< > System.map 63 chmod -x $@+ 64 mv -f $@+ $@ 65 66 stage1.elf: $(OBJ1) 67 $(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ1) -o $@ 68 69 stage2.elf: $(OBJ2) 70 $(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ2) -o $@ 71 72 .c.o: 73 $(CC) -c $(CFLAGS) $< -o $@ 74 75 .S.o: 76 $(CC) -c $(CFLAGS) $< -o $@