Close

The make file for the RED-V compilation

A project log for Sparkfun RED-V bare metal

I wanted to learn RISC-V, not on an emulator, but on a real bare metal RISC-V processor. Even though Sparkfun RED-V is no longer produced.

olaf-baeyensOlaf Baeyens 10/21/2024 at 16:480 Comments

The correct compiler and the linker options is now in the make file.

The make file is still in its basic trial and error form.

# Compiler and Linker options
CC = riscv64-unknown-elf-gcc
OBJCOPY = riscv64-unknown-elf-objcopy
ASFLAGS = -march=rv32g -mabi=ilp32 -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles
LDFLAGS = -T sparkfun-red-v.ld
#LDFLAGS = -T red-v.ld

# Source files
SRC_DIR = src
BOOT_DIR = $(SRC_DIR)/boot
INCLUDE_DIR = $(SRC_DIR)/include
DATA_DIR = $(SRC_DIR)/data
UNIT_TESTS_DIR = $(SRC_DIR)/unit-tests
STRINGS_TEST_UNIT_TESTS_DIR = $(UNIT_TESTS_DIR)/strings-module

MODULES_DIR= $(SRC_DIR)/modules
DEBUG_MODULE_DIR = $(MODULES_DIR)/debug-module
STRINGS_MODULE_DIR= $(MODULES_DIR)/strings-module

SRC = $(SRC_DIR)/main.s \
	$(STRINGS_TEST_UNIT_TESTS_DIR)/strings-tests.s \
	$(DEBUG_MODULE_DIR)/debug.s \
	$(STRINGS_MODULE_DIR)/strings.s \
	$(BOOT_DIR)/boot.s

INCLUDES = $(INCLUDE_DIR)/constants.s \
	$(INCLUDE_DIR)/macros.s \
	$(INCLUDE_DIR)/string-macros.s

DATA = $(DATA_DIR)/data.s  \
	$(DATA_DIR)/rodata.s \
	$(DATA_DIR)/bss.s


# Output files
ELF = ./build/main.elf
HEX = ./build/main.hex

all: $(HEX)

$(HEX): $(ELF)
	$(OBJCOPY) -O ihex $< $@

$(ELF): $(SRC) $(INCLUDES) $(DATA)
	$(CC) $(ASFLAGS) $(LDFLAGS) $(SRC) -o $@

clean:
	rm -f $(ELF) $(HEX)

.PHONY: all clean

Discussions