Skip to content

Commit d7dcf73

Browse files
committed
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 --no-auto 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). Signed-off-by: willieyz <[email protected]>
1 parent c559c8e commit d7dcf73

File tree

2 files changed

+110
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)