-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
73 lines (61 loc) · 1.87 KB
/
Copy pathmakefile
File metadata and controls
73 lines (61 loc) · 1.87 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
68
69
70
71
72
73
# Toolchain prefix
CROSS_COMPILE = aarch64-elf-
# Files
TARGET = kernel8.img
BUILD_DIR = build
LINKER_SCRIPT = linker.ld
ASM_SRCS = startup/start.s startup/uart_init.s startup/init_system.s
ASM_OBJS = $(patsubst %.s,$(BUILD_DIR)/%.o,$(ASM_SRCS))
C_SRCS = $(wildcard *.c drivers/*.c)
C_OBJS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(C_SRCS))
OBJS = $(ASM_OBJS) $(C_OBJS)
# Commands
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
CLEAN = rm -rf
# Flags
ASFLAGS = -mcpu=cortex-a53
CFLAGS = -mcpu=cortex-a53 -ffreestanding -O2 -Wall -Wextra -g -nostdinc -nostdlib
LDFLAGS = -nostdlib -T $(LINKER_SCRIPT)
# Build rules
.PHONY: all clean flash debug
all: $(BUILD_DIR) $(TARGET)
@echo "Build completed successfully!"
@echo "Kernel image: $(TARGET)"
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
mkdir -p $(BUILD_DIR)/startup
mkdir -p $(BUILD_DIR)/drivers
@echo "Creating build directory..."
@echo "Build directory created at $(BUILD_DIR)"
$(BUILD_DIR)/%.o: %.s
@echo "Assembling $<..."
$(AS) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/%.o: %.c
@echo "Compiling $<..."
$(CC) $(CFLAGS) -c -o $@ $<
$(TARGET): $(OBJS)
@echo "Linking with debug symbols..."
$(CC) $(CFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/kernel.elf $^
$(OBJCOPY) -O binary $(BUILD_DIR)/kernel.elf $@
@echo "Generated $@"
# Debug target (runs GDB)
debug: $(TARGET)
aarch64-elf-gdb $(BUILD_DIR)/kernel.elf
# Assumes SD card is mounted at /Volumes/boot - adjust as needed
flash: $(TARGET)
@echo "Copying $(TARGET) to SD card..."
@if [ -d "/Volumes/bootfs" ]; then \
cp $(TARGET) /Volumes/bootfs/ && \
echo "Kernel copied to SD card successfully!"; \
else \
echo "Error: /Volumes/bootfs not found. Is the SD card mounted?"; \
exit 1; \
fi
clean:
@echo "Cleaning build files..."
$(CLEAN) $(BUILD_DIR) $(TARGET)
@echo "Clean complete"
run:
qemu-system-aarch64 -M raspi3b -kernel kernel8.img -serial null -serial stdio