-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (55 loc) · 1.53 KB
/
Copy pathMakefile
File metadata and controls
67 lines (55 loc) · 1.53 KB
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
# Toolchain
TOOLCHAIN=arm-none-eabi
CC=$(TOOLCHAIN)-gcc
AS=$(TOOLCHAIN)-as
LD=$(TOOLCHAIN)-ld
OBJCP=$(TOOLCHAIN)-objcopy
# Build options
ASOPTS=-mcpu=cortex-a7 -mfpu=neon-vfpv4
COPTS=-mfpu=neon-vfpv4 -mfloat-abi=soft -march=armv7-a -mtune=cortex-a7
CFLAGS=$(COPTS) -g -O3 -DRPI2 -Iinc -Wall
LDFLAGS=-T kernel.ld -Xlinker -Map=$(TARGET).map
# Directories
BUILD=build/
SOURCE=src/
TARGET=$(BUILD)kernel7.img
# All assembler and C files in src are automatically added
OBJECTS := $(patsubst $(SOURCE)%.S,$(BUILD)%.o,$(wildcard $(SOURCE)*.S)) \
$(patsubst $(SOURCE)%.c,$(BUILD)%.o,$(wildcard $(SOURCE)*.c))
# Output formatting
# Set Q= for verbose output
ifndef Q
Q=@
endif
C_GREEN=\033[0;32m
C_RED=\033[0;31m
C_ORANGE=\033[0;33m
C_NONE=\033[0m
all: $(BUILD) $(TARGET)
remake: clean all
# Build dir
$(BUILD):
mkdir build
# Link ELF and generate binary image
$(TARGET): $(OBJECTS) kernel.ld
@echo "$(C_RED)Linking $@$(C_NONE)"
$(Q)$(CC) $(LDFLAGS) -nostartfiles $(OBJECTS) -o $@.elf
$(Q)$(OBJCP) $@.elf -O binary $@
# Build assembler files
$(BUILD)%.o: $(SOURCE)%.S
@echo "$(C_GREEN)AS $<$(C_NONE)"
$(Q)$(AS) $(ASOPTS) $< -o $@
# Build C files
$(BUILD)%.o: $(SOURCE)%.c
@echo "$(C_GREEN)CC $<$(C_NONE)"
$(Q)$(CC) $(CFLAGS) -nostartfiles -c $< -o $@
# Remove build artifacts
clean:
@echo "$(C_ORANGE)Cleaning...$(C_NONE)"
$(Q)rm -rf $(BUILD)*.elf
$(Q)rm -rf $(BUILD)*.img
$(Q)rm -rf $(BUILD)*.o
# Load kernel onto SD card, assuming mounted at /media/user/boot
install:
cp build/kernel7.img /media/${USER}/boot/kernel7.img
umount /media/${USER}/boot