1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/stage1/Makefile Sun Jun 07 23:06:08 2015 +0200
1.3 @@ -0,0 +1,73 @@
1.4 +# Makefile - Build the NanoNote payload
1.5 +#
1.6 +# Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.7 +# Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
1.8 +#
1.9 +# This program is free software; you can redistribute it and/or modify it under
1.10 +# the terms of the GNU General Public License as published by the Free Software
1.11 +# Foundation; either version 3 of the License, or (at your option) any later
1.12 +# version.
1.13 +#
1.14 +# This program is distributed in the hope that it will be useful, but WITHOUT
1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.16 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.17 +# details.
1.18 +#
1.19 +# You should have received a copy of the GNU General Public License along with
1.20 +# this program. If not, see <http://www.gnu.org/licenses/>.
1.21 +
1.22 +ARCH = mipsel-linux-gnu
1.23 +CC = $(ARCH)-gcc
1.24 +LD = $(ARCH)-ld
1.25 +NM = $(ARCH)-nm
1.26 +OBJCOPY=$(ARCH)-objcopy
1.27 +OBJDUMP=$(ARCH)-objdump
1.28 +
1.29 +# NOTE: -O2 is actually needed to prevent memcpy references, whereas probably
1.30 +# NOTE: one of the -f{freestanding, no-hosted, no-builtin} options should work.
1.31 +# NOTE: See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888
1.32 +
1.33 +ASM_INC = /usr/src/linux-headers-4.0.0-1-common/arch/mips/include
1.34 +CFLAGS = -O2 -Wall \
1.35 + -fno-unit-at-a-time -fno-zero-initialized-in-bss \
1.36 + -ffreestanding -fno-hosted -fno-builtin \
1.37 + -march=mips32 \
1.38 + -I../include -I$(ASM_INC) -I$(ASM_INC)/asm/mach-generic
1.39 +LDFLAGS = -nostdlib -EL
1.40 +
1.41 +PAYLOAD = stage1.bin
1.42 +TARGET = $(PAYLOAD:.bin=.elf)
1.43 +DUMP = $(PAYLOAD:.bin=.dump)
1.44 +MAP = $(PAYLOAD:.bin=.map)
1.45 +
1.46 +# Ordering of objects is important and cannot be left to replacement rules.
1.47 +
1.48 +SRC = head1.S stage1.c board-nanonote.c
1.49 +OBJ = head1.o stage1.o board-nanonote.o
1.50 +
1.51 +.PHONY: all clean distclean
1.52 +
1.53 +all: $(PAYLOAD)
1.54 +
1.55 +clean:
1.56 + rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(DUMP) *.map
1.57 +
1.58 +distclean: clean
1.59 + echo "Nothing else to clean."
1.60 +
1.61 +$(PAYLOAD): $(TARGET)
1.62 + $(OBJCOPY) -O binary $(@:.bin=.elf) $@+
1.63 + $(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump)
1.64 + $(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map)
1.65 + $(NM) -n $(@:.bin=.elf) > System.map
1.66 + chmod -x $@+
1.67 + mv -f $@+ $@
1.68 +
1.69 +stage1.elf: $(OBJ)
1.70 + $(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ) -o $@
1.71 +
1.72 +.c.o:
1.73 + $(CC) -c $(CFLAGS) $< -o $@
1.74 +
1.75 +.S.o:
1.76 + $(CC) -c $(CFLAGS) $< -o $@