-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
134 lines (93 loc) · 3.24 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# Arm FastModels Hello World Boot
#
# Copyright 2020 Reto Achermann
# SPDX-License-Identifier: GPL-3.0
#
IMGNAME=bootimg
# the fastmodels simgen binary, for running the
SIMGEN := $(shell PATH=$(PATH) which simgen)
#
# Setting up the tools to be used for compilation and linking
#
# The C Compiler to be used
CC=aarch64-linux-gnu-gcc
CPP=aarch64-linux-gnu-cpp
OBJCOPY=aarch64-linux-gnu-objcopy
OBJDUMP=aarch64-linux-gnu-objdump
#
# Compiler flags for linking and compiling
#
BUILDFLAGS =\
-O2 -g -Wall -Wextra -std=c17 -Werror \
-fno-builtin \
-fno-unwind-tables \
-fno-stack-check -ffreestanding -fomit-frame-pointer \
-nostdinc \
-std=c99 \
-mcpu=cortex-a57 \
-march=armv8-a+nofp
LDFLAGS=\
-O2 -g -Wl,-N -pie \
-fno-builtin -nostdlib \
-Wl,--no-warn-rwx-segments \
-Wl,--fatal-warnings -Wl,--build-id=none
INC=-I./src/include
CFILES=src/boot.c src/string.c src/processor.c src/printf.c src/serial.c src/exceptions.c \
src/mmu.c src/cachectrl.c src/ptable.c
SFILES=src/entry.S src/exception_vectors.S
OBJS=$(CFILES:%.o=%.c) $(SFILES:%.o=%.S)
#
# build target
#
all: $(IMGNAME).elf $(IMGNAME).bin
#
# cleanup
#
clean:
rm -rf build $(IMGNAME).elf $(IMGNAME).bin
#
# Compiling single files
#
build:
mkdir -p build
build/%.o : src/%.S build
$(CC) $(BUILDFLAGS) $(INC) -o $@ -c $<
build/%.o : src/%.c build
$(CC) $(BUILDFLAGS) $(INC) -o $@ -c $<
# this generates the linker script for the bootimage
build/$(IMGNAME).lds : src/boot.lds.in build
$(CPP) $(INC) -D__ASSEMBLER__ -P src/boot.lds.in $@
#
# Building the boot image
#
# This is the bootloader elf with all debug symbols etc included
build/$(IMGNAME).full : $(OBJS) build/$(IMGNAME).lds
$(CC) $(LDFLAGS) $(INC) -T./build/$(IMGNAME).lds -Wl,-Map,./build/$(IMGNAME).map -o $@ $(OBJS)
bash -c "echo -e '\0002'" | dd of=$@ bs=1 seek=16 count=1 conv=notrunc status=noxfer 2>&1
# This is the debug information of the bootloader elf
build/$(IMGNAME).debug : build/$(IMGNAME).full
$(OBJCOPY) --only-keep-debug ./build/$(IMGNAME).full $@
# This is the assembly dump of the bootloader
build/$(IMGNAME).asm : build/$(IMGNAME).elf
$(OBJDUMP) -D build/$(IMGNAME).elf > $@
# this is the bootimage elf
build/$(IMGNAME).elf : build/$(IMGNAME).full build/$(IMGNAME).debug
$(OBJCOPY) -g --add-gnu-debuglink=./build/$(IMGNAME).debug ./build/$(IMGNAME).full $@
# this is the boot image elf
$(IMGNAME).elf : build/$(IMGNAME).elf build/$(IMGNAME).asm
cp build/$(IMGNAME).elf $(IMGNAME).elf
# this is the boot image binary
$(IMGNAME).bin : $(IMGNAME).elf
$(OBJCOPY) -O binary $(IMGNAME).elf $(IMGNAME).bin
build/platforms/armv8_minimal/isim_system : platforms/armv8_minimal/ARMv8_Minimal.lisa platforms/armv8_minimal/ARMv8_Minimal.sgproj
ifndef SIMGEN
$(error "No 'simgen' in PATH, please source 'FAST_MODELS_ROOT/source_all.sh'")
endif
$(SIMGEN) --num-comps-file 50 --gen-sysgen --warnings-as-errors \
--build-directory ./build/platforms/armv8_minimal \
-p platforms/armv8_minimal/ARMv8_Minimal.sgproj -b
run_armv8_minimal: $(IMGNAME).bin build/platforms/armv8_minimal/isim_system
build/platforms/armv8_minimal/isim_system --data Memory0=$(IMGNAME).bin@0x0
run_armv8_minimal_debug: $(IMGNAME).bin build/platforms/armv8_minimal/isim_system
bash ./tools/run_debugger.sh $(IMGNAME).bin $(IMGNAME).elf