Issue with compiling "Hello World" OS setup
Posted: Thu Nov 10, 2016 4:05 pm
Hi all!
It's my first time here at the forum and I have a beginner issue with compiling my simple OS for an Raspberry Pi Zero.
Here is my MakeFile:
Which unfortunately gives me an annoying error I cannot seem to understand why it is there:
Any ideas about the issue? Furthermore, should I compile my kernel C-library externally and link it with the kernel makefile afterwards? I appreciate your help.
Best regards,
Simon
It's my first time here at the forum and I have a beginner issue with compiling my simple OS for an Raspberry Pi Zero.
Here is my MakeFile:
Code: Select all
# Target definitions.
ARCH = arch/arm
TARGET_BOARD = pi-zero
TARGET_CPU = arm1176jzf-s
# Compiler setup.
COMPILER = /home/simonha/opt/cross/bin/arm-none-eabi
AS = $(COMPILER)-as
CC = $(COMPILER)-g++
LD = $(COMPILER)-ld
CP = $(COMPILER)-objcopy
OD = $(COMPILER)-objdump
ASFLAGS = -mcpu=$(TARGET_CPU)
CFLAGS = -mcpu=$(TARGET_CPU) -ffreestanding -Wall -Wextra -fpic -std=c++11 \
-nodefaultlibs -lgcc
LDFLAGS =
# Directory setup.
BUILD = build/
SOURCE = src/
# The name of the output file to generate.
KERNEL_TARGET = kernel.img
# The name of the assembler listing file to generate.
LIST = kernel.list
# The name of the map file to generate.
MAP = kernel.map
# The name of the linker script to use.
LINKER = $(ARCH)/$(TARGET_BOARD)/kernel.ld
# Header includes
HEADER_INCLUDES = \
-I$(SOURCE) \
-I$(SOURCE)/lib/libc/include \
-I$(ARCH) \
-I$(ARCH)/$(TARGET_BOARD)
# Assembly files.
KERNEL_AS = \
$(wildcard $(ARCH)/kernel/*.s) \
$(wildcard $(ARCH)/$(TARGET_BOARD)/lib/*.s)
# Source files.
KERNEL_SRC = \
$(wildcard $(ARCH)/kernel/*.cpp) \
$(wildcard $(ARCH)/$(TARGET_BOARD)/driver/*.cpp) \
$(wildcard $(SOURCE)/kernel/*.cpp)
# Kernel C-library files.
KERNEL_C_LIB = \
$(wildcard $(SOURCE)/lib/libc/string/*.c)
KERNEL_AS_OBJ = $(patsubst %.s, %.o, $(KERNEL_AS))
KERNEL_SRC_OBJ = $(patsubst %.cpp, %.o, $(KERNEL_SRC))
KERNEL_C_LIB_OBJ = $(patsubst %.c, %.o, $(KERNEL_C_LIB))
# Rule to make everything.
all: build_kernel_c_lib build_kernel build_binary build_list
# Rule to make kernel C library.
build_kernel_c_lib: $(KERNEL_C_LIB_OBJ)
%.o : %.c
mkdir -p $(dir $(BUILD)$@)
$(CC) $(CFLAGS) $(HEADER_INCLUDES) -c $< -o $(BUILD)$@
# Rule to make the object files.
build_kernel: $(KERNEL_AS_OBJ) $(KERNEL_SRC_OBJ)
%.o : %.s
mkdir -p $(dir $(BUILD)$@)
$(AS) $(ASFLAGS) $< -o $(BUILD)$@
%.o : %.cpp
mkdir -p $(dir $(BUILD)$@)
$(CC) $(CFLAGS) $(HEADER_INCLUDES) -c $< -o $(BUILD)$@
# Rule to make the kernel image file.
build_binary: $(KERNEL_AS_OBJ) $(KERNEL_SRC_OBJ) $(KERNEL_C_LIB_OBJ))
$(CC) $(CFLAGS) \
$(addprefix $(BUILD), $(KERNEL_C_LIB_OBJ)) \
$(addprefix $(BUILD), $(KERNEL_AS_OBJ)) \
$(addprefix $(BUILD), $(KERNEL_SRC_OBJ)) \
-T $(LINKER) -o $(BUILD)MinOS.elf
$(LD) $(LDFLAGS) -Map $(BUILD)$(MAP)
$(CP) $(BUILD)MinOS.elf -O binary $(BUILD)$(KERNEL_TARGET)
# Rule to make the listing file.
build_list: $(BUILD)MinOS.elf
$(OD) -D $(BUILD)MinOS.elf > $(BUILD)$(LIST)
# Rule to clean the project.
clean:
rm -f $(addprefix $(BUILD), $(KERNEL_C_LIB_OBJ))
rm -f $(addprefix $(BUILD), $(KERNEL_AS_OBJ))
rm -f $(addprefix $(BUILD), $(KERNEL_SRC_OBJ))
rm -f $(BUILD)MinOS.elf
rm -f $(BUILD)$(MAP)
rm -f $(BUILD)$(KERNEL_TARGET)
rm -f $(BUILD)$(LIST)
find $(BUILD) -type d -empty -delete
Code: Select all
mkdir -p build/src//lib/libc/string/
/home/simonha/opt/cross/bin/arm-none-eabi-g++ -mcpu=arm1176jzf-s -ffreestanding -Wall -Wextra -fpic -std=c++11 -nodefaultlibs -lgcc -Isrc/ -Isrc//lib/libc/include -Iarch/arm -Iarch/arm/pi-zero -c src//lib/libc/string/strlen.c -o build/src//lib/libc/string/strlen.o
mkdir -p build/arch/arm/kernel/
/home/simonha/opt/cross/bin/arm-none-eabi-as -mcpu=arm1176jzf-s arch/arm/kernel/boot.s -o build/arch/arm/kernel/boot.o
mkdir -p build/arch/arm/pi-zero/lib/
/home/simonha/opt/cross/bin/arm-none-eabi-as -mcpu=arm1176jzf-s arch/arm/pi-zero/lib/ok_led.s -o build/arch/arm/pi-zero/lib/ok_led.o
mkdir -p build/arch/arm/pi-zero/driver/
/home/simonha/opt/cross/bin/arm-none-eabi-g++ -mcpu=arm1176jzf-s -ffreestanding -Wall -Wextra -fpic -std=c++11 -nodefaultlibs -lgcc -Isrc/ -Isrc//lib/libc/include -Iarch/arm -Iarch/arm/pi-zero -c arch/arm/pi-zero/driver/uart.cpp -o build/arch/arm/pi-zero/driver/uart.o
mkdir -p build/src//kernel/
/home/simonha/opt/cross/bin/arm-none-eabi-g++ -mcpu=arm1176jzf-s -ffreestanding -Wall -Wextra -fpic -std=c++11 -nodefaultlibs -lgcc -Isrc/ -Isrc//lib/libc/include -Iarch/arm -Iarch/arm/pi-zero -c src//kernel/kernel.cpp -o build/src//kernel/kernel.o
make: *** No rule to make target 'src//lib/libc/string/strlen.o)', needed by 'build_binary'. Stop.
[Finished in 0.5s with exit code 2]
[shell_cmd: make]
[dir: /media/sf_MinOS]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
Best regards,
Simon