NanoPayload

Annotated stage2/Makefile

62:3409e8306134
2015-06-14 Paul Boddie Made a separate file containing CPU-specific operations. stage2-non-pic
paul@18 1
# Makefile - Build the NanoNote payload
paul@18 2
#
paul@18 3
# Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
paul@18 4
# Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
paul@18 5
#
paul@18 6
# This program is free software; you can redistribute it and/or modify it under
paul@18 7
# the terms of the GNU General Public License as published by the Free Software
paul@18 8
# Foundation; either version 3 of the License, or (at your option) any later
paul@18 9
# version.
paul@18 10
#
paul@18 11
# This program is distributed in the hope that it will be useful, but WITHOUT
paul@18 12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@18 13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@18 14
# details.
paul@18 15
#
paul@18 16
# You should have received a copy of the GNU General Public License along with
paul@18 17
# this program.  If not, see <http://www.gnu.org/licenses/>.
paul@18 18
paul@18 19
ARCH = mipsel-linux-gnu
paul@18 20
CC = $(ARCH)-gcc
paul@18 21
LD = $(ARCH)-ld
paul@46 22
MKIMAGE = mkimage
paul@18 23
NM = $(ARCH)-nm
paul@18 24
OBJCOPY=$(ARCH)-objcopy
paul@18 25
OBJDUMP=$(ARCH)-objdump
paul@18 26
paul@18 27
# NOTE: -O2 is actually needed to prevent memcpy references, whereas probably
paul@18 28
# NOTE: one of the -f{freestanding, no-hosted, no-builtin} options should work.
paul@18 29
# NOTE: See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888
paul@18 30
paul@18 31
CFLAGS = -O2 -Wall \
paul@18 32
	-fno-unit-at-a-time -fno-zero-initialized-in-bss \
paul@18 33
	-ffreestanding -fno-hosted -fno-builtin \
paul@58 34
	-march=mips32 \
paul@49 35
	-I../include
paul@58 36
LDFLAGS = -nostdlib -EL
paul@18 37
paul@54 38
UIMAGE = uImage
paul@18 39
PAYLOAD = stage2.bin
paul@18 40
TARGET = $(PAYLOAD:.bin=.elf)
paul@18 41
DUMP = $(PAYLOAD:.bin=.dump)
paul@18 42
MAP = $(PAYLOAD:.bin=.map)
paul@18 43
paul@43 44
# Configure target-specific objects.
paul@43 45
paul@43 46
NANONOTE_SRC = board-nanonote.c nanonote_gpm940b0.c
paul@43 47
NANONOTE_OBJ = board-nanonote.o nanonote_gpm940b0.o
paul@43 48
MINIPC_SRC = board-minipc.c minipc_claa070vc01.c
paul@43 49
MINIPC_OBJ = board-minipc.o minipc_claa070vc01.o
paul@43 50
paul@43 51
ifdef MINIPC
paul@43 52
BOARD_SRC = $(MINIPC_SRC)
paul@43 53
BOARD_OBJ = $(MINIPC_OBJ)
paul@43 54
BOARD_DEFS = -DCONFIG_CPU_JZ4730_MINIPC -DCONFIG_CPU_JZ4730
paul@43 55
else
paul@43 56
BOARD_SRC = $(NANONOTE_SRC)
paul@43 57
BOARD_OBJ = $(NANONOTE_OBJ)
paul@43 58
BOARD_DEFS =
paul@43 59
endif
paul@43 60
paul@43 61
DEFS = $(BOARD_DEFS)
paul@43 62
paul@18 63
# Ordering of objects is important and cannot be left to replacement rules.
paul@18 64
paul@62 65
SRC = head2.S stage2.c cpu.c lcd.c jzlcd.c board.c $(BOARD_SRC)
paul@62 66
OBJ = head2.o stage2.o cpu.o lcd.o jzlcd.o board.o $(BOARD_OBJ)
paul@18 67
paul@18 68
.PHONY:	all clean distclean
paul@18 69
paul@46 70
all:	$(PAYLOAD) $(UIMAGE)
paul@18 71
paul@18 72
clean:
paul@54 73
	rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(UIMAGE) $(DUMP) *.map
paul@18 74
paul@18 75
distclean: clean
paul@18 76
	echo "Nothing else to clean."
paul@18 77
paul@46 78
$(UIMAGE): $(PAYLOAD)
paul@58 79
	$(MKIMAGE) -A mips -O linux -T kernel -C none -a 0x80010000 -e 0x80010000 -n NanoPayload -d $(PAYLOAD) $(UIMAGE)
paul@46 80
paul@18 81
$(PAYLOAD): $(TARGET)
paul@18 82
	$(OBJCOPY) -O binary $(@:.bin=.elf) $@+
paul@18 83
	$(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump)
paul@18 84
	$(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map)
paul@18 85
	$(NM) -n $(@:.bin=.elf) > System.map
paul@18 86
	chmod -x $@+
paul@18 87
	mv -f $@+ $@
paul@18 88
paul@18 89
stage2.elf: $(OBJ)
paul@52 90
	$(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ) -o $@
paul@18 91
paul@18 92
.c.o:
paul@43 93
	$(CC) -c $(CFLAGS) $(DEFS) $< -o $@
paul@18 94
paul@18 95
.S.o:
paul@43 96
	$(CC) -c $(CFLAGS) $(DEFS) $< -o $@