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 -T target.ld 36 37 PAYLOAD = stage1.bin 38 TARGET = $(PAYLOAD:.bin=.elf) 39 DUMP = $(PAYLOAD:.bin=.dump) 40 MAP = $(PAYLOAD:.bin=.map) 41 SRC = head.S stage1.c board-nanonote.c 42 OBJ = $(filter %.o,$(SRC:.c=.o) $(SRC:.S=.o)) 43 44 .PHONY: all clean distclean 45 46 all: $(PAYLOAD) 47 48 clean: 49 rm -f $(OBJ) $(TARGET) $(PAYLOAD) 50 51 distclean: clean 52 echo "Nothing else to clean." 53 54 $(PAYLOAD): $(TARGET) 55 $(OBJCOPY) -O binary $< $@+ 56 $(OBJDUMP) -D $< > $(DUMP) 57 $(OBJDUMP) -h $< > $(MAP) 58 $(NM) -n $< > System.map 59 chmod -x $@+ 60 mv -f $@+ $@ 61 62 $(TARGET): $(OBJ) 63 $(LD) $(LDFLAGS) $(OBJ) -o $@ 64 65 .c.o: 66 $(CC) -c $(CFLAGS) $< -o $@ 67 68 .S.o: 69 $(CC) -c $(CFLAGS) $< -o $@