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