Skip to content

Commit 1619308

Browse files
committed
Arm backend: Update Zephyr example README.md
This move the sample part of the README to the actual sample folder. This will allow adding more example without bloating the main README Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com> Change-Id: Id8d28cf7cd5eb30949155f324a65d42c065dc6ff
1 parent 007f97e commit 1619308

4 files changed

Lines changed: 206 additions & 169 deletions

File tree

.ci/scripts/zephyr-utils.sh

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
# This source code is licensed under the BSD-style license found in the
77
# LICENSE file in the root directory of this source tree.
88

9-
# Run instruction from zephyr/README.md
9+
# Run instruction from a README.md file
1010
#
11-
# This contains some CI helper runtime functions to dig out and run commands
12-
# from zephyr/README.md
13-
# It also try to verify that zephyr/executorch.yaml is in sync and the snippets
14-
# in the README are sane with various regexps.
11+
# This contains CI helper runtime functions to dig out and run commands
12+
# from a README file.
1513
#
16-
# Main functions is run_command_block_from_zephyr_readme it will dig out the code between
14+
# Generic helper:
15+
# - run_command_block_from_readme
16+
#
17+
# Zephyr-specific validator:
18+
# - verify_zephyr_readme (checks zephyr/executorch.yaml snippet sync)
19+
#
20+
# Main function is run_command_block_from_readme. It digs out the code between
1721
# the two ''' after a blockheader text and run it
1822
#
1923
# .e.g. from this README.md snippet
@@ -26,7 +30,7 @@
2630
#
2731
# The blockheader is 'Install requirements' and the code block is 'pip install something ... \npip install something_else'
2832
# so if we run
29-
# run_command_block_from_zephyr_readme 'Install requirements'
33+
# run_command_block_from_readme path/to/README.md 'Install requirements'
3034
# it will run them one by one
3135

3236

@@ -56,10 +60,22 @@ _zephyr_utils_root_dir () {
5660
(cd "${script_dir}/../.." && pwd)
5761
}
5862

59-
_zephyr_utils_readme_path () {
63+
_utils_path_from_root () {
64+
local path="$1"
6065
local root_dir
66+
67+
if [[ -z "${path}" || "${path}" == "." ]]; then
68+
echo "ERROR: Path argument must be a non-empty file path" >&2
69+
return 1
70+
fi
71+
72+
if [[ "${path}" = /* ]]; then
73+
printf '%s\n' "${path}"
74+
return 0
75+
fi
76+
6177
root_dir="$(_zephyr_utils_root_dir)"
62-
printf '%s/zephyr/README.md\n' "${root_dir}"
78+
printf '%s/%s\n' "${root_dir}" "${path}"
6379
}
6480

6581
_zephyr_utils_ensure_file () {
@@ -117,28 +133,37 @@ _zephyr_utils_run_simple_commands () {
117133
return 0
118134
}
119135

120-
run_command_block_from_zephyr_readme () {
121-
local blockheader="$1"
136+
run_command_block_from_readme () {
137+
local readme_path="$1"
138+
local blockheader="$2"
139+
local block
140+
141+
if [[ -z "${readme_path}" || -z "${blockheader}" ]]; then
142+
echo "ERROR: Usage: run_command_block_from_readme <readme_path> <block_header_regex>" >&2
143+
return 1
144+
fi
145+
146+
readme_path="$(_utils_path_from_root "${readme_path}")" || return 1
122147

123-
echo "Run block '${blockheader}' from zephyr/README.md"
148+
echo "Run block '${blockheader}' from ${readme_path}"
124149

125-
readme_path="$(_zephyr_utils_readme_path)"
126150
_zephyr_utils_ensure_file "${readme_path}" "README.md" || return 1
127151

128152
block="$(_zephyr_utils_extract_block "${readme_path}" "${blockheader}")"
129-
130-
if [[ -z "${block}" ]]; then
131-
echo "ERROR: Failed to locate ${blockheader} block in ${readme_path}" >&2
132-
return 1
153+
if [[ -n "${block}" ]]; then
154+
_zephyr_utils_run_simple_commands "${block}" "${blockheader}"
155+
return $?
133156
fi
134-
_zephyr_utils_run_simple_commands "${block}" "${blockheader}"
157+
158+
echo "ERROR: Failed to locate ${blockheader} block in ${readme_path}" >&2
159+
return 1
135160
}
136161

137162
# Check that zephyr/executorch.yaml match zephyr/README.md
138163
verify_zephyr_readme () {
139164
local readme_path manifest_path snippet
140165

141-
readme_path="$(_zephyr_utils_readme_path)"
166+
readme_path="$(_utils_path_from_root "zephyr/README.md")" || return 1
142167
manifest_path="$(_zephyr_utils_root_dir)/zephyr/executorch.yaml"
143168

144169
_zephyr_utils_ensure_file "${readme_path}" "README" || return 1

.github/workflows/trunk.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ jobs:
8585
fi
8686
8787
export EXECUTORCH_PROJ_ROOT=$(realpath $(pwd))
88+
ZEPHYR_README_PATH="zephyr/README.md"
89+
ZEPHYR_SAMPLES_README_PATH="zephyr/samples/hello-executorch/README.md"
8890
8991
# Source utility scripts
9092
. .ci/scripts/utils.sh
@@ -93,9 +95,9 @@ jobs:
9395
# check that zephyr/README.md and zephyr/executorch.yaml are in sync
9496
verify_zephyr_readme
9597
96-
# Based on instruction in zephyr/README.md
98+
# Based on instructions in zephyr/README.md and zephyr/samples/hello-executorch/README.md
9799
98-
run_command_block_from_zephyr_readme "<!-- RUN install_reqs -->"
100+
run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN install_reqs -->"
99101
100102
# Make sure to backup the zephyr_scratch folder if it exists to allow for local
101103
# testing that does not lose code/data
@@ -128,11 +130,11 @@ jobs:
128130
129131
cd ${ZEPHYR_PROJ_ROOT}
130132
131-
run_command_block_from_zephyr_readme "<!-- RUN west_init -->"
133+
run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN west_init -->"
132134
133135
cp ${EXECUTORCH_PROJ_ROOT}/zephyr/executorch.yaml zephyr/submanifests/
134136
135-
run_command_block_from_zephyr_readme "<!-- RUN west_config -->"
137+
run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN west_config -->"
136138
137139
# Switch to executorch in this PR e.g. replace modules/lib/executorch with the root folder of this repo
138140
# instead of doing a re-checkout and figure out the correct commit hash etc
@@ -148,9 +150,9 @@ jobs:
148150
git config --global user.email "github_executorch@arm.com"
149151
fi
150152
151-
run_command_block_from_zephyr_readme "<!-- RUN install_executorch -->"
153+
run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN install_executorch -->"
152154
153-
run_command_block_from_zephyr_readme "<!-- RUN install_arm_tools -->"
155+
run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN install_arm_tools -->"
154156
155157
for TARGET in "${TARGETS[@]}"; do
156158
TARGET="$(echo "$TARGET" | xargs)" # trim whitespace
@@ -168,13 +170,13 @@ jobs:
168170
fi
169171
170172
echo "---- ${TARGET} Board ${BOARD} FVP setup ----"
171-
run_command_block_from_zephyr_readme "<!-- RUN setup_${BOARD}_fvp -->"
173+
run_command_block_from_readme "${ZEPHYR_SAMPLES_README_PATH}" "<!-- RUN setup_${BOARD}_fvp -->"
172174
173175
echo "---- ${TARGET} Create PTE ----"
174-
run_command_block_from_zephyr_readme "<!-- RUN test_${TARGET}_generate_pte -->"
176+
run_command_block_from_readme "${ZEPHYR_SAMPLES_README_PATH}" "<!-- RUN test_${TARGET}_generate_pte -->"
175177
176178
echo "---- ${TARGET} Build and run ----"
177-
run_command_block_from_zephyr_readme "<!-- RUN test_${TARGET}_build_and_run -->"
179+
run_command_block_from_readme "${ZEPHYR_SAMPLES_README_PATH}" "<!-- RUN test_${TARGET}_build_and_run -->"
178180
done
179181
180182
test-models-linux-aarch64:

zephyr/README.md

Lines changed: 6 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ git submodule update --init --recursive
7171
cd ../../..
7272
```
7373

74-
## Prepare Ethos&trade;-U tools like Vela compiler and Corstone&trade; 300/320 FVP
74+
## Prepare Ethos-U tools like Vela compiler and Corstone 300/320 FVP
7575

76-
This is needed to convert python models to PTE files for Ethos&trade;-Ux5 and also installs Corstone&trade; 300/320 FVP so you can run and test.
76+
This is needed to convert python models to PTE files for Ethos-Ux5 and also installs Corstone 300/320 FVP so you can run and test.
7777

78-
Make sure to read and agree to the Corstone&trade; eula
78+
Make sure to read and agree to the Corstone eula
7979

8080
Install TOSA, vela and FVPs
8181
<!-- RUN install_arm_tools -->
@@ -84,145 +84,10 @@ modules/lib/executorch/examples/arm/setup.sh --i-agree-to-the-contained-eula
8484
. modules/lib/executorch/examples/arm/arm-scratch/setup_path.sh
8585
```
8686

87-
# Running a sample application
87+
# Running sample applications
8888

89-
To run you need to point of the path to the installed Corstone&trade; FVP and you can then use west to build and run. You point out the model PTE file you want to run with -DET_PTE_FILE_PATH= see below.
90-
91-
The magic to include and use Ethos-U backend is to set
92-
CONFIG_ETHOS_U=y/n
93-
This is done in the example depending on the board you build for so it you build for a different board then the ones below you might want to add a board config file, or add this line to the prj.conf
94-
95-
## Corstone&trade; 300 FVP (Ethos&trade;-U55)
96-
97-
### Setup FVP paths
98-
99-
Set up FVP paths and macs used, this will also set shutdown_on_eot so the FVP auto stops after it has run the example.
100-
101-
Config Zephyr Corstone300 FVP
102-
<!-- RUN setup_corstone300_fvp -->
103-
```
104-
export FVP_ROOT=$PWD/modules/lib/executorch/examples/arm/arm-scratch/FVP-corstone300
105-
export ARMFVP_BIN_PATH=${FVP_ROOT}/models/Linux64_GCC-9.3
106-
export ARMFVP_EXTRA_FLAGS="-C mps3_board.uart0.shutdown_on_eot=1 -C ethosu.num_macs=128"
107-
```
108-
109-
### Ethos-U55
110-
111-
#### Prepare a PTE model file
112-
113-
Prepare the Ethos-U55 PTE model
114-
<!-- RUN test_ethos-u55_generate_pte -->
115-
```
116-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --delegate --target=ethos-u55-128 --output=add_u55_128.pte
117-
```
118-
119-
`--delegate` tells the aot_arm_compiler to use Ethos-U backend and `-t ethos-u55-128` specify the used Ethos-U variant and numbers of macs used, this must match you hardware or FVP config.
120-
121-
#### Build and run
122-
123-
Run the Ethos-U55 PTE model
124-
<!-- RUN test_ethos-u55_build_and_run -->
125-
```
126-
west build -b mps3/corstone300/fvp modules/lib/executorch/zephyr/samples/hello-executorch -t run -- -DET_PTE_FILE_PATH=add_u55_128.pte
127-
```
128-
129-
### Cortex-M55
130-
131-
#### Prepare a PTE model file
132-
133-
Prepare the Cortex-M55 PTE model
134-
<!-- RUN test_cortex-m55_generate_pte -->
135-
```
136-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --target=cortex-m55+int8 --output=add_m55.pte
137-
```
138-
139-
`--target=cortex-m55+int8` selects the Cortex-M/CMSIS-NN portable kernel path (no NPU delegation). This produces a `.pte` optimised for Cortex-M55 with INT8 quantisation.
140-
141-
#### Build and run
142-
143-
Run the Cortex-M55 PTE model
144-
<!-- RUN test_cortex-m55_build_and_run -->
145-
```
146-
west build -b mps3/corstone300/fvp modules/lib/executorch/zephyr/samples/hello-executorch -t run -- -DET_PTE_FILE_PATH=add_m55.pte
147-
```
148-
149-
## Corstone&trade; 320 FVP (Ethos&trade;-U85)
150-
151-
### Setup FVP paths
152-
153-
Set up FVP paths, libs and macs used, this will also set shutdown_on_eot so the FVP auto stops after it has run the example.
154-
155-
Config Zephyr Corstone320 FVP
156-
<!-- RUN setup_corstone320_fvp -->
157-
```
158-
export FVP_ROOT=$PWD/modules/lib/executorch/examples/arm/arm-scratch/FVP-corstone320
159-
export ARMFVP_BIN_PATH=${FVP_ROOT}/models/Linux64_GCC-9.3
160-
export LD_LIBRARY_PATH=${FVP_ROOT}/python/lib:${ARMFVP_BIN_PATH}:${LD_LIBRARY_PATH}
161-
export ARMFVP_EXTRA_FLAGS="-C mps4_board.uart0.shutdown_on_eot=1 -C mps4_board.subsystem.ethosu.num_macs=256"
162-
```
163-
164-
### Ethos-U85
165-
166-
#### Prepare a PTE model file
167-
168-
Prepare the Ethos-U85 PTE model
169-
<!-- RUN test_ethos-u85_generate_pte -->
170-
```
171-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --delegate --target=ethos-u85-256 --output=add_u85_256.pte
172-
```
173-
174-
`--delegate` tells the aot_arm_compiler to use Ethos-U backend and `-t ethos-u85-256` specify the used Ethos-U variant and numbers of macs used, this must match you hardware or FVP config.
175-
176-
#### Build and run
177-
178-
Run the Ethos-U85 PTE model
179-
<!-- RUN test_ethos-u85_build_and_run -->
180-
```
181-
west build -b mps4/corstone320/fvp modules/lib/executorch/zephyr/samples/hello-executorch -t run -- -DET_PTE_FILE_PATH=add_u85_256.pte
182-
```
183-
184-
## STM Nucleo n657x0_q
185-
186-
### Run west config and update:
187-
188-
You need to add hal_stm32 driver to Zephyr
189-
```
190-
west config manifest.project-filter -- -.*,+zephyr,+executorch,+cmsis,+cmsis_6,+cmsis-nn,+hal_stm32
191-
west update
192-
```
193-
194-
### Setup tools
195-
196-
Follow and make sure tools are setup according to this:
197-
198-
https://docs.zephyrproject.org/latest/boards/st/nucleo_n657x0_q/doc/index.html
199-
200-
Test the samples/hello_world in that guide to make sure all tools work.
201-
202-
Please note that the ZephyrOS made a fix for the signing tool version v2.21.0 after the v4.3 release in 20 Nov 2025. Make sure to use a later version of ZephyrOS that contains it.
203-
Also note that the signing tool must be in your path for it to auto sign your elf.
204-
205-
```
206-
export PATH=$PATH:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
207-
```
208-
209-
### Prepare a PTE model file
210-
211-
Prepare the Cortex-M55 PTE model
212-
```
213-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --target=cortex-m55+int8 --output=add_m55.pte
214-
```
215-
216-
`--target=cortex-m55+int8` selects the Cortex-M/CMSIS-NN portable kernel path (no NPU delegation).
217-
218-
#### Build and run
219-
220-
Run the Cortex-M55 PTE model
221-
```
222-
west build -b nucleo_n657x0_q modules/lib/executorch/zephyr/samples/hello-executorch -- -DET_PTE_FILE_PATH=add_m55.pte
223-
west flash
224-
```
225-
This will run the simple add model on your hardware one and print the output on the serial consol.
89+
Build and run instructions for simple Zephyr minimal example setup is documented in
90+
[`zephyr/samples/hello-executorch/README.md`](samples/hello-executorch/README.md).
22691

22792
## Notable files
22893

0 commit comments

Comments
 (0)