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 MKIMAGE = mkimage 23 NM = $(ARCH)-nm 24 OBJCOPY=$(ARCH)-objcopy 25 OBJDUMP=$(ARCH)-objdump 26 27 # NOTE: -O2 is actually needed to prevent memcpy references, whereas probably 28 # NOTE: one of the -f{freestanding, no-hosted, no-builtin} options should work. 29 # NOTE: See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 30 31 ASM_INC = /usr/src/linux-headers-4.0.0-1-common/arch/mips/include 32 CFLAGS = -O2 -Wall \ 33 -fno-unit-at-a-time -fno-zero-initialized-in-bss \ 34 -ffreestanding -fno-hosted -fno-builtin \ 35 -march=mips32 -fPIC \ 36 -I../include -I$(ASM_INC) -I$(ASM_INC)/asm/mach-generic 37 LDFLAGS = -nostdlib -EL -pie 38 39 PAYLOAD = stage2.bin 40 UIMAGE = uImage 41 TARGET = $(PAYLOAD:.bin=.elf) 42 DUMP = $(PAYLOAD:.bin=.dump) 43 MAP = $(PAYLOAD:.bin=.map) 44 45 # Configure target-specific objects. 46 47 NANONOTE_SRC = board-nanonote.c nanonote_gpm940b0.c 48 NANONOTE_OBJ = board-nanonote.o nanonote_gpm940b0.o 49 MINIPC_SRC = board-minipc.c minipc_claa070vc01.c 50 MINIPC_OBJ = board-minipc.o minipc_claa070vc01.o 51 52 ifdef MINIPC 53 BOARD_SRC = $(MINIPC_SRC) 54 BOARD_OBJ = $(MINIPC_OBJ) 55 BOARD_DEFS = -DCONFIG_CPU_JZ4730_MINIPC -DCONFIG_CPU_JZ4730 56 else 57 BOARD_SRC = $(NANONOTE_SRC) 58 BOARD_OBJ = $(NANONOTE_OBJ) 59 BOARD_DEFS = 60 endif 61 62 DEFS = $(BOARD_DEFS) 63 64 # Ordering of objects is important and cannot be left to replacement rules. 65 66 SRC = head2.S stage2.c lcd.c jzlcd.c board.c $(BOARD_SRC) 67 OBJ = head2.o stage2.o lcd.o jzlcd.o board.o $(BOARD_OBJ) 68 69 .PHONY: all clean distclean 70 71 all: $(PAYLOAD) $(UIMAGE) 72 73 clean: 74 rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(DUMP) *.map 75 76 distclean: clean 77 echo "Nothing else to clean." 78 79 $(UIMAGE): $(PAYLOAD) 80 $(MKIMAGE) -A mips -O linux -T standalone -C none -a 0x80000000 -e 0x80000000 -n NanoPayload -d $(PAYLOAD) $(UIMAGE) 81 82 $(PAYLOAD): $(TARGET) 83 $(OBJCOPY) -O binary $(@:.bin=.elf) $@+ 84 $(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump) 85 $(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map) 86 $(NM) -n $(@:.bin=.elf) > System.map 87 chmod -x $@+ 88 mv -f $@+ $@ 89 90 stage2.elf: $(OBJ) 91 $(LD) $(LDFLAGS) -pie -T $(@:.elf=.ld) $(OBJ) -o $@ 92 93 .c.o: 94 $(CC) -c $(CFLAGS) $(DEFS) $< -o $@ 95 96 .S.o: 97 $(CC) -c $(CFLAGS) $(DEFS) $< -o $@