Skip to content

Commit 45eb852

Browse files
Baremetal: Add support for MPS3 AN547 (Cortex-M55) builds
This adds support for testing on the MPS3 AN547 platform in qemu. Tests can be excuted using EXTRA_MAKEFILE=test/baremetal/platform/m55-an547/platform.mk tests all Platform sources (hal, ld script, semihosting) are taken from pqmx. baremetal/platform/m55-an547/platform.mk sets the required flags and other build configuration. test/baremetal/platform/m55-an547/exec_wrapper.py handles passing inputs to the tests (e.g., required for the ACVP tests). Co-authored-by: Brendan Moran <[email protected]> Signed-off-by: Matthias J. Kannwischer <[email protected]>
1 parent fa42091 commit 45eb852

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) The mldsa-native project authors
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4+
5+
import struct as st
6+
import sys
7+
import subprocess
8+
import tempfile
9+
import os
10+
11+
12+
def err(msg, **kwargs):
13+
print(msg, file=sys.stderr, **kwargs)
14+
15+
16+
binpath = sys.argv[1]
17+
args = sys.argv[1:]
18+
cmdline_offset = 0x70000
19+
20+
arg0_offset = cmdline_offset + 4 + len(args) * 4
21+
22+
arg_offsets = [sum(map(len, args[:i])) + i + arg0_offset for i in range(len(args))]
23+
24+
binargs = st.pack(
25+
f"<{1+len(args)}I" + "".join(f"{len(a)+1}s" for a in args),
26+
len(args),
27+
*arg_offsets,
28+
*map(lambda x: x.encode("utf-8"), args),
29+
)
30+
31+
with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".bin") as fd:
32+
args_file = fd.name
33+
fd.write(binargs)
34+
35+
try:
36+
qemu_cmd = f"qemu-system-arm -M mps3-an547 -nographic -semihosting -kernel {binpath} -device loader,file={args_file},addr=0x{cmdline_offset:x}".split()
37+
result = subprocess.run(qemu_cmd, encoding="utf-8", capture_output=True)
38+
finally:
39+
os.unlink(args_file)
40+
if result.returncode != 0:
41+
err("FAIL!")
42+
err(f"{qemu_cmd} failed with error code {result.returncode}")
43+
err(result.stderr)
44+
exit(1)
45+
46+
for line in result.stdout.splitlines():
47+
print(line)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) The mldsa-native project authors
2+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
PLATFORM_PATH:=test/baremetal/platform/m55-an547
5+
6+
CROSS_PREFIX=arm-none-eabi-
7+
CC=gcc
8+
9+
CFLAGS += \
10+
-O3 \
11+
-Wall -Wextra -Wshadow \
12+
-Wno-pedantic \
13+
-Wno-redundant-decls \
14+
-Wno-missing-prototypes \
15+
-fno-common \
16+
-ffunction-sections \
17+
-fdata-sections \
18+
--sysroot=$(SYSROOT) \
19+
-DDEVICE=an547 \
20+
-I$(M55_AN547_PATH) \
21+
-DARMCM55 \
22+
-DSEMIHOSTING
23+
24+
ARCH_FLAGS += \
25+
-march=armv8.1-m.main+mve.fp \
26+
-mcpu=cortex-m55 \
27+
-mthumb \
28+
-mfloat-abi=hard -mfpu=fpv4-sp-d16
29+
30+
CFLAGS += \
31+
$(ARCH_FLAGS) \
32+
--specs=nosys.specs
33+
34+
CFLAGS += $(CFLAGS_EXTRA)
35+
36+
LDSCRIPT = $(M55_AN547_PATH)/mps3.ld
37+
38+
LDFLAGS += \
39+
-Wl,--gc-sections \
40+
-Wl,--no-warn-rwx-segments \
41+
-L.
42+
43+
LDFLAGS += \
44+
--specs=nosys.specs \
45+
-Wl,--wrap=_open \
46+
-Wl,--wrap=_close \
47+
-Wl,--wrap=_read \
48+
-Wl,--wrap=_write \
49+
-Wl,--wrap=_fstat \
50+
-Wl,--wrap=_getpid \
51+
-Wl,--wrap=_isatty \
52+
-Wl,--wrap=_kill \
53+
-Wl,--wrap=_lseek \
54+
-Wl,--wrap=main \
55+
-ffreestanding \
56+
-T$(LDSCRIPT) \
57+
$(ARCH_FLAGS)
58+
59+
# Extra sources to be included in test binaries
60+
EXTRA_SOURCES = $(wildcard $(M55_AN547_PATH)/*.c)
61+
EXEC_WRAPPER := $(realpath $(PLATFORM_PATH)/exec_wrapper.py)

0 commit comments

Comments
 (0)