Skip to content

Commit 77e957b

Browse files
authored
Add mps2-an385 (Cortex-M3) and mps2-an500 (Cortex-M7) with embed-os (#41)
* import mbed-os for emulating with nix Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * build mps2-an386 with mbed-os Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * add support for mps2-an385 and mps2-an386 Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * include tests for mps2-an385/mps2-an500 in ci Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * cleanup makefile Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * add --list-platforms command Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * update README Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * refactor ci with xargs Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * cleanup Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * verbose output configurable for qemu emulation Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * add MPS2 macro Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> --------- Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com>
1 parent 02d6d9e commit 77e957b

25 files changed

+186
-7916
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,22 @@ jobs:
3535
echo "::endgroup::"
3636
}
3737
38-
make_platform stm32f4discovery
39-
make_platform nucleo-f767zi
40-
make_platform nucleo-f207zg
38+
export -f make_platform
39+
tests --list-platforms | grep -v "mps2" | xargs -I {} bash -c 'make_platform "$@"' _ {}
4140
42-
- name: Build for emulation on QEMU
43-
shell: nix develop .#ci -c bash -e {0}
44-
run: |
45-
output=$(make emulate) && true
46-
if [[ $? != 0 ]]; then
47-
echo "::error title={Build failed}::$output" 1>&2
48-
fi
4941
- name: Functional test
5042
id: func_test
5143
shell: nix develop .#ci -c bash -e {0}
5244
run: |
53-
tests func -v mps2-an386
45+
tests-qemu func
5446
- name: Speed test
5547
id: speed_test
5648
shell: nix develop .#ci -c bash -e {0}
5749
if: |
5850
success()
5951
|| steps.func_test.conclusion == 'failure'
6052
run: |
61-
tests speed -v mps2-an386
53+
tests-qemu speed
6254
- name: Stack test
6355
id: stack_test
6456
shell: nix develop .#ci -c bash -e {0}
@@ -67,7 +59,7 @@ jobs:
6759
|| steps.func_test.conclusion == 'failure'
6860
|| steps.speed_test.conclusion == 'failure'
6961
run: |
70-
tests stack -v mps2-an386
62+
tests-qemu stack
7163
- name: Nistkat test
7264
shell: nix develop .#ci -c bash -e {0}
7365
if: |
@@ -76,4 +68,4 @@ jobs:
7668
|| steps.speed_test.conclusion == 'failure'
7769
|| steps.stack_test.conclusion == 'failure'
7870
run: |
79-
tests nistkat -v mps2-an386
71+
tests-qemu nistkat

Makefile

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# temporary Makefile to be replaced by Arm cross-compilation
32

43
.PHONY: all
54

@@ -19,21 +18,9 @@ nistkat: $(foreach scheme,$(KEM_SCHEMES),$(scheme)-nistkat)
1918

2019
.PHONY: emulate clean
2120

22-
emulate%: PLATFORM = mps2-an386
23-
emulate%: NTESTS = 10
24-
emulate%: override RNG = NOTRAND
25-
26-
emulate\ nistkat: override RNG = NISTKAT
27-
28-
# emulate for test, speed, stack
29-
emulate%:
30-
$(Q)$(MAKE) PLATFORM=$(PLATFORM) NTESTS=$(NTESTS) RNG=$(RNG) $*
31-
32-
emulate\ run: PLATFORM=mps2-an386
33-
emulate\ run:
21+
emulate:
3422
$(Q)qemu-system-arm -machine $(PLATFORM) -nographic -semihosting -kernel $(ELF_FILE)
3523

36-
3724
clean:
3825
$(Q)rm -rf elf/
3926
$(Q)rm -rf bin/

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,17 @@ For further details, please refer to [scripts/README.md](scripts/README.md)
6767

6868
## Running tests and benchmarks
6969

70-
The build system compiles tests and benchmarks for each mlkem parameter set on specified platform, currently supported platform includes `stm32f4discovery` and `mps2-an386` (could be simulated with the `QEMU` simulator).
70+
The build system compiles tests and benchmarks for each mlkem parameter set on specified platform, supported platform can be found by running `tests --list-platforms`.
7171
The PLATFORM configuration is optional, with the default platform set to `stm32f4discovery`.
7272

7373
For example,
74-
- `make [PLATFORM=<PLATFORM_NAME>] bin/mlkem768-test.hex` assembles the `mlkem768` binary performing functional tests.
75-
- `make [PLATFORM=<PLATFORM_NAME>] bin/mlkem1024-speed.hex` assembles the `mlkem-1024` speed benchmark binary.
76-
- `make [PLATFORM=<PLATFORM_NAME>] test` assembles all binaries for functional tests.
77-
- `make [PLATFORM=<PLATFORM_NAME>] speed` assembles all binaries for speed benchmarking
78-
- `make [PLATFORM=<PLATFORM_NAME>] stack` assembles all binaries for stack benchmarking
74+
- `make [PLATFORM=<PLATFORM_NAME>] [RNG=HAL|NOTRAND] test` assembles all binaries for functional tests.
75+
- `make [PLATFORM=<PLATFORM_NAME>] [RNG=HAL|NOTRAND] speed` assembles all binaries for speed benchmarking
76+
- `make [PLATFORM=<PLATFORM_NAME>] [RNG=HAL|NOTRAND] stack` assembles all binaries for stack benchmarking
7977
- `make [PLATFORM=<PLATFORM_NAME>] RNG=NISTKAT nistkat` assembles all binaries for nistkat
8078
- `make [PLATFORM=<PLATFORM_NAME>] (all)` assembles all the above targets for all parameter sets.
8179

82-
- `make emulate` build binaries for emulating `mps2-an386` on `QEMU` of test, speed, stack
83-
- `make "emulate [test|speed|stack|nistkat]"` build binaries of test, speed, stack or nistkat for emulating `mps2-an386` on `QEMU`
84-
- `make "emulate run" ELF_FILE=<ELF_FILE_NAME>` run emulatation for the file on `QEMU`
80+
- `make emulate` run emulatation for the binary file on `QEMU`
8581
- `make clean` cleans up intermediate artifacts
8682

8783
### Manual testing on board
@@ -104,6 +100,7 @@ Make sure to run `make clean` between running tests on QEMU or on board or runni
104100
Usage: tests [OPTIONS] COMMAND [ARGS]...
105101
106102
Options:
103+
--list-platforms List the supported platforms
107104
--help Show this message and exit.
108105
109106
Commands:
@@ -119,13 +116,14 @@ func/speed tests depends on the iteration parameter, which is passed to the test
119116

120117
```
121118
▶ tests func --help
122-
Usage: tests func [OPTIONS]
119+
Usage: tests func [OPTIONS] {stm32f4discovery|mps2-an386|nucleo-f767zi|mps2-an
120+
500|nucleo-f207zg|mps2-an385}
123121
124122
Options:
125-
-cfg, --platform-cfg PATH Configuration file of the specified platform
126-
[default: hal/stm32f4discovery.cfg]
127-
-v, --verbose Show verbose output or not
128-
-e, --emulate Emulate on the QEMU or not
129-
-i, --iterations INTEGER Number of tests [default: 1]
130-
--help Show this message and exit.
123+
-v, --verbose Show verbose output or not
124+
-u, --uart PATH TTY serial device for UART, default to the 1st
125+
serial device connected to your board or an empty
126+
string
127+
-i, --iterations INTEGER Number of tests [default: 1]
128+
--help Show this message and exit.
131129
```

flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
libopencm3 = pkgs.callPackage ./libopencm3.nix {
2222
targets = [ "stm32/f2" "stm32/f4" "stm32/f7" ];
2323
};
24+
mbed-os = pkgs.callPackage ./mbed-os.nix {
25+
targets = [ "TARGET_MPS2_M3" "TARGET_MPS2_M4" "TARGET_MPS2_M7" ];
26+
};
2427
core = builtins.attrValues {
2528
libopencm3 = libopencm3;
29+
mbed-os = mbed-os;
2630

2731
inherit (pkgs)
2832
# formatter & linters
@@ -56,6 +60,7 @@
5660

5761
shellHook = ''
5862
export OPENCM3_DIR=${libopencm3}
63+
export MBED_OS_DIR=${mbed-os}
5964
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
6065
eval "$(_TESTS_COMPLETE=bash_source tests)"
6166
'';
@@ -66,6 +71,7 @@
6671

6772
shellHook = ''
6873
export OPENCM3_DIR=${libopencm3}
74+
export MBED_OS_DIR=${mbed-os}
6975
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
7076
'';
7177
};

hal/hal-mps2.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
#include <hal.h>
3+
#if defined(MPS2_AN385)
4+
#include <CMSDK_CM3.h>
5+
#elif defined(MPS2_AN386)
36
#include <CMSDK_CM4.h>
7+
#elif defined(MPS2_AN500)
8+
#include <CMSDK_CM7.h>
9+
#else
10+
#error Unsupported mps2 board
11+
#endif
412

513
#define BAUD 38400
614

hal/hal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <stdint.h>
66
#include <stdlib.h>
77

8-
#if !defined(MPS2_AN386)
8+
#if !defined(MPS2)
99
#define SERIAL_MARKER() {\
1010
hal_send_str("$");\
1111
}

0 commit comments

Comments
 (0)