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 \ 32 -fno-unit-at-a-time -fno-zero-initialized-in-bss \ 33 -ffreestanding -fno-hosted -fno-builtin \ 34 -march=mips32 -fPIC \ 35 -I../include -I$(ASM_INC) -I$(ASM_INC)/asm/mach-generic 36 LDFLAGS = -nostdlib -EL -pie 37 38 PAYLOAD = stage2.bin 39 TARGET = $(PAYLOAD:.bin=.elf) 40 DUMP = $(PAYLOAD:.bin=.dump) 41 MAP = $(PAYLOAD:.bin=.map) 42 43 # Configure target-specific objects. 44 45 NANONOTE_SRC = board-nanonote.c nanonote_gpm940b0.c 46 NANONOTE_OBJ = board-nanonote.o nanonote_gpm940b0.o 47 MINIPC_SRC = board-minipc.c minipc_claa070vc01.c 48 MINIPC_OBJ = board-minipc.o minipc_claa070vc01.o 49 50 ifdef MINIPC 51 BOARD_SRC = $(MINIPC_SRC) 52 BOARD_OBJ = $(MINIPC_OBJ) 53 BOARD_DEFS = -DCONFIG_CPU_JZ4730_MINIPC -DCONFIG_CPU_JZ4730 54 else 55 BOARD_SRC = $(NANONOTE_SRC) 56 BOARD_OBJ = $(NANONOTE_OBJ) 57 BOARD_DEFS = 58 endif 59 60 DEFS = $(BOARD_DEFS) 61 62 # Ordering of objects is important and cannot be left to replacement rules. 63 64 SRC = head2.S stage2.c lcd.c jzlcd.c board.c $(BOARD_SRC) 65 OBJ = head2.o stage2.o lcd.o jzlcd.o board.o $(BOARD_OBJ) 66 67 .PHONY: all clean distclean 68 69 all: $(PAYLOAD) 70 71 clean: 72 rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(DUMP) *.map 73 74 distclean: clean 75 echo "Nothing else to clean." 76 77 $(PAYLOAD): $(TARGET) 78 $(OBJCOPY) -O binary $(@:.bin=.elf) $@+ 79 $(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump) 80 $(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map) 81 $(NM) -n $(@:.bin=.elf) > System.map 82 chmod -x $@+ 83 mv -f $@+ $@ 84 85 stage2.elf: $(OBJ) 86 $(LD) $(LDFLAGS) -pie -T $(@:.elf=.ld) $(OBJ) -o $@ 87 88 .c.o: 89 $(CC) -c $(CFLAGS) $(DEFS) $< -o $@ 90 91 .S.o: 92 $(CC) -c $(CFLAGS) $(DEFS) $< -o $@