Skip to content

Commit

Permalink
unify mps2 platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
mkannwischer committed Jul 22, 2024
1 parent dfbbb89 commit c19d212
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 172 deletions.
89 changes: 89 additions & 0 deletions envs/common/mps2.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
CC = arm-none-eabi-gcc
LD := $(CC)

SRC_DIR=./src
BUILD_DIR=./build/$(TARGET)

COMMON_INC=../common/inc/
ENV_INC=./inc/
TEST_COMMON=../../tests/common/
MBED_OS_DIR=../../submodules/mbed-os/


MBED_OS_CMSIS = $(MBED_OS_DIR)/cmsis/CMSIS_5/CMSIS/TARGET_CORTEX_M/

SYSROOT := $(shell $(CC) --print-sysroot)

CFLAGS += \
-O3 \
-std=gnu99 \
--sysroot=$(SYSROOT) \
-Wall -Wextra -Wshadow -Werror \
-MMD \
-fno-common \
-I$(COMMON_INC) \
-I$(ENV_INC) \
-I$(SRC_DIR) \
-I$(TESTDIR) \
-I$(MBED_OS_CMSIS)/Include \
-I$(MBED_OS_TARGET_DIR) \
-I$(TEST_COMMON)

CFLAGS += \
$(ARCH_FLAGS) \
--specs=nosys.specs

LDFLAGS += \
-Wl,--wrap=_sbrk \
-Wl,--wrap=_open \
-Wl,--wrap=_close \
-Wl,--wrap=_isatty \
-Wl,--wrap=_kill \
-Wl,--wrap=_lseek \
-Wl,--wrap=_read \
-Wl,--wrap=_write \
-Wl,--wrap=_fstat \
-Wl,--wrap=_getpid \
--specs=nosys.specs \
-T$(LDSCRIPT) \
$(ARCH_FLAGS)

all: $(TARGET)

HAL_SOURCES = ../common/src/hal-mps2.c
HAL_ASMS = $(MBED_OS_TARGET_DIR)/TOOLCHAIN_GCC_ARM/startup_MPS2.S
OBJECTS_HAL = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(HAL_SOURCES)))
OBJECTS_HAL += $(patsubst %.S, $(BUILD_DIR)/%.S.o, $(abspath $(HAL_ASMS)))
OBJECTS_SOURCES=$(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(SOURCES)))
OBJECTS_C = $(OBJECTS_SOURCES) $(OBJECTS_HAL) $(OBJECTS_TEST_COMMON)
OBJECTS_ASM = $(patsubst %.s, $(BUILD_DIR)/%.s.o, $(abspath $(ASMS)))

OBJECTS = $(OBJECTS_C) $(OBJECTS_ASM)

$(OBJECTS_C): $(BUILD_DIR)/%.o: %
mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<

$(OBJECTS_ASM): $(BUILD_DIR)/%.o: %
mkdir -p $(@D)
$(CC) -x assembler-with-cpp $(CFLAGS) -c -o $@ $<

$(TARGET): $(OBJECTS) $(LDSCRIPT)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)

.PHONY: build
build: $(TARGET)

run: $(TARGET)
qemu-system-arm -M $(QEMU_PLATFORM) -nographic -semihosting -kernel $(TARGET)

check: $(TARGET)
qemu-system-arm -M $(QEMU_PLATFORM) -nographic -semihosting -kernel $(TARGET) | tail -n 2 | grep "ALL GOOD!" || exit 1

$(LDSCRIPT): $(MBED_OS_TARGET_DIR)/TOOLCHAIN_GCC_ARM/MPS2.ld
[ -d $(@D) ] || $(Q)mkdir -p $(@D); \
$(CC) -x assembler-with-cpp -E -Wp,-P $(CFLAGS) $< -o $@

clean:
rm -f *.elf
rm -rf $(BUILD_DIR)
86 changes: 3 additions & 83 deletions envs/m4-an386/Makefile
Original file line number Diff line number Diff line change
@@ -1,96 +1,16 @@
# Makefile for images for AN386

CC = arm-none-eabi-gcc
LD := $(CC)

SRC_DIR=./src
BUILD_DIR=./build/$(TARGET)

COMMON_INC=../common/inc/
ENV_INC=./inc/
TEST_COMMON=../../tests/common/
MBED_OS_DIR=../../submodules/mbed-os/

MBED_OS_TARGET_DIR = $(MBED_OS_DIR)/targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M4/device
MBED_OS_CMSIS = $(MBED_OS_DIR)/cmsis/CMSIS_5/CMSIS/TARGET_CORTEX_M/

ARCH_FLAGS += -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
LDSCRIPT = $(BUILD_DIR)/generated.M4.ld

SYSROOT := $(shell $(CC) --print-sysroot)

CFLAGS += \
-O3 \
-std=gnu99 \
--sysroot=$(SYSROOT) \
-Wall -Wextra -Wshadow -Werror \
-MMD \
-fno-common \
-I$(COMMON_INC) \
-I$(ENV_INC) \
-I$(SRC_DIR) \
-I$(TESTDIR) \
-I$(MBED_OS_CMSIS)/Include \
-I$(MBED_OS_TARGET_DIR) \
-I$(TEST_COMMON) \

CFLAGS += \
-DMPS2 -DMPS2_AN386 \
$(ARCH_FLAGS) \
--specs=nosys.specs

LDFLAGS += \
-Wl,--wrap=_sbrk \
-Wl,--wrap=_open \
-Wl,--wrap=_close \
-Wl,--wrap=_isatty \
-Wl,--wrap=_kill \
-Wl,--wrap=_lseek \
-Wl,--wrap=_read \
-Wl,--wrap=_write \
-Wl,--wrap=_fstat \
-Wl,--wrap=_getpid \
--specs=nosys.specs \
-T$(LDSCRIPT) \
$(ARCH_FLAGS)

all: $(TARGET)

HAL_SOURCES = ../common/src/hal-mps2.c
HAL_ASMS = $(MBED_OS_TARGET_DIR)/TOOLCHAIN_GCC_ARM/startup_MPS2.S
OBJECTS_HAL = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(HAL_SOURCES)))
OBJECTS_HAL += $(patsubst %.S, $(BUILD_DIR)/%.S.o, $(abspath $(HAL_ASMS)))
OBJECTS_SOURCES=$(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(SOURCES)))
OBJECTS_C = $(OBJECTS_SOURCES) $(OBJECTS_HAL) $(OBJECTS_TEST_COMMON)
OBJECTS_ASM = $(patsubst %.s, $(BUILD_DIR)/%.s.o, $(abspath $(ASMS)))

OBJECTS = $(OBJECTS_C) $(OBJECTS_ASM)

$(OBJECTS_C): $(BUILD_DIR)/%.o: %
mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<

$(OBJECTS_ASM): $(BUILD_DIR)/%.o: %
mkdir -p $(@D)
$(CC) -x assembler-with-cpp $(CFLAGS) -c -o $@ $<

$(TARGET): $(OBJECTS) $(LDSCRIPT)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)

.PHONY: build
build: $(TARGET)

run: $(TARGET)
qemu-system-arm -M mps2-an386 -nographic -semihosting -kernel $(TARGET)

check: $(TARGET)
qemu-system-arm -M mps2-an386 -nographic -semihosting -kernel $(TARGET) | tail -n 2 | grep "ALL GOOD!" || exit 1


$(LDSCRIPT): $(MBED_OS_TARGET_DIR)/TOOLCHAIN_GCC_ARM/MPS2.ld
[ -d $(@D) ] || $(Q)mkdir -p $(@D); \
$(CC) -x assembler-with-cpp -E -Wp,-P $(CFLAGS) $< -o $@
CFLAGS += -DMPS2 -DMPS2_AN386
QEMU_PLATFORM = mps2-an386

clean:
rm -f *.elf
rm -rf $(BUILD_DIR)
include ../common/mps2.mk
92 changes: 3 additions & 89 deletions envs/m7-an500/Makefile
Original file line number Diff line number Diff line change
@@ -1,96 +1,10 @@
# Makefile for images for AN500

CC = arm-none-eabi-gcc
LD := $(CC)

SRC_DIR=./src
BUILD_DIR=./build/$(TARGET)

COMMON_INC=../common/inc/
ENV_INC=./inc/
TEST_COMMON=../../tests/common/
MBED_OS_DIR=../../submodules/mbed-os/

MBED_OS_TARGET_DIR = $(MBED_OS_DIR)/targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M7/device
MBED_OS_CMSIS = $(MBED_OS_DIR)/cmsis/CMSIS_5/CMSIS/TARGET_CORTEX_M/

ARCH_FLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16
LDSCRIPT = $(BUILD_DIR)/generated.M7.ld
CFLAGS += -DMPS2 -DMPS2_AN500
QEMU_PLATFORM = mps2-an500

SYSROOT := $(shell $(CC) --print-sysroot)

CFLAGS += \
-O3 \
-std=gnu99 \
--sysroot=$(SYSROOT) \
-Wall -Wextra -Wshadow -Werror \
-MMD \
-fno-common \
-I$(COMMON_INC) \
-I$(ENV_INC) \
-I$(SRC_DIR) \
-I$(TESTDIR) \
-I$(MBED_OS_CMSIS)/Include \
-I$(MBED_OS_TARGET_DIR) \
-I$(TEST_COMMON) \

CFLAGS += \
-DMPS2 -DMPS2_AN500 \
$(ARCH_FLAGS) \
--specs=nosys.specs

LDFLAGS += \
-Wl,--wrap=_sbrk \
-Wl,--wrap=_open \
-Wl,--wrap=_close \
-Wl,--wrap=_isatty \
-Wl,--wrap=_kill \
-Wl,--wrap=_lseek \
-Wl,--wrap=_read \
-Wl,--wrap=_write \
-Wl,--wrap=_fstat \
-Wl,--wrap=_getpid \
--specs=nosys.specs \
-T$(LDSCRIPT) \
$(ARCH_FLAGS)

all: $(TARGET)

HAL_SOURCES = ../common/src/hal-mps2.c
HAL_ASMS = $(MBED_OS_TARGET_DIR)/TOOLCHAIN_GCC_ARM/startup_MPS2.S
OBJECTS_HAL = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(HAL_SOURCES)))
OBJECTS_HAL += $(patsubst %.S, $(BUILD_DIR)/%.S.o, $(abspath $(HAL_ASMS)))
OBJECTS_SOURCES=$(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(SOURCES)))
OBJECTS_C = $(OBJECTS_SOURCES) $(OBJECTS_HAL) $(OBJECTS_TEST_COMMON)
OBJECTS_ASM = $(patsubst %.s, $(BUILD_DIR)/%.s.o, $(abspath $(ASMS)))

OBJECTS = $(OBJECTS_C) $(OBJECTS_ASM)

$(OBJECTS_C): $(BUILD_DIR)/%.o: %
mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<

$(OBJECTS_ASM): $(BUILD_DIR)/%.o: %
mkdir -p $(@D)
$(CC) -x assembler-with-cpp $(CFLAGS) -c -o $@ $<

$(TARGET): $(OBJECTS) $(LDSCRIPT)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)

.PHONY: build
build: $(TARGET)

run: $(TARGET)
qemu-system-arm -M mps2-an500 -nographic -semihosting -kernel $(TARGET)

check: $(TARGET)
qemu-system-arm -M mps2-an500 -nographic -semihosting -kernel $(TARGET) | tail -n 2 | grep "ALL GOOD!" || exit 1


$(LDSCRIPT): $(MBED_OS_TARGET_DIR)/TOOLCHAIN_GCC_ARM/MPS2.ld
[ -d $(@D) ] || $(Q)mkdir -p $(@D); \
$(CC) -x assembler-with-cpp -E -Wp,-P $(CFLAGS) $< -o $@

clean:
rm -f *.elf
rm -rf $(BUILD_DIR)
include ../common/mps2.mk

0 comments on commit c19d212

Please sign in to comment.