Skip to content

Commit 4ced977

Browse files
authored
Enhance build scripts, logging, and documentation for Zephyr and Linux targets; refactor state machine handling and improve error reporting in core functions. (#81)
Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
1 parent 5181deb commit 4ced977

18 files changed

Lines changed: 237 additions & 125 deletions

File tree

.github/workflows/build.yml

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,60 +33,71 @@ jobs:
3333

3434
- name: Build native_sim
3535
run: |
36-
west build --pristine -b native_sim ./application -d build -- -DMODULE_EXT_ROOT=$(pwd)/application
36+
west build --pristine -b native_sim ./application -d build -- -DMODULE_EXT_ROOT=$(pwd)/application | tee zephyr_build_native_sim.log
3737
38-
- name: Upload build native_sim artifact
38+
- name: Upload native_sim build artifact
3939
if: job.status == 'success'
4040
uses: actions/upload-artifact@v4
4141
with:
42-
name: zephyr-build-native-sim
43-
path: build/
42+
name: ocre-zephyr-native_sim-app #TODO: modify when matrix will added
43+
path: build/zephyr/zephyr.exe
44+
45+
- name: Upload native_sim build log
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: zephyr_build_native_sim_log
49+
path: zephyr_build_native_sim.log
4450

4551
- name: Build b_u585i_iot02a
46-
if: runner.environment == 'self-hosted'
4752
run: |
48-
west build --pristine -b b_u585i_iot02a ./application -d build -- -DMODULE_EXT_ROOT=$(pwd)/application
49-
50-
- name: Upload firmware artifact
51-
if: runner.environment == 'self-hosted' && job.status == 'success'
53+
west build --pristine -b b_u585i_iot02a ./application -d build -- -DMODULE_EXT_ROOT=$(pwd)/application | tee zephyr_build_b_u585.log
54+
55+
- name: Upload b_u585 build artifact
56+
if: job.status == 'success'
5257
uses: actions/upload-artifact@v4
5358
with:
54-
name: firmware
59+
name: ocre-zephyr-b_u585-app #TODO: modify when matrix will added
5560
path: build/zephyr/zephyr.bin
5661

62+
- name: Upload b_u585 build log
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: zephyr_build_b_u585_log
66+
path: zephyr_build_b_u585.log
67+
5768
run-zephyr-native-sim:
5869
runs-on: zephyr-xlarge-runner
5970
needs: build-zephyr
6071
container:
6172
image: ghcr.io/zephyrproject-rtos/ci:v0.26-branch
6273
options: --user root
6374
steps:
64-
- name: Download Zephyr build artifacts
75+
- name: Download Zephyr build artifact (native_sim)
6576
uses: actions/download-artifact@v4
6677
with:
67-
name: zephyr-build-native-sim
78+
name: ocre-zephyr-native_sim-app
6879
path: build/
6980

7081
- name: Run Zephyr binary and check output
71-
working-directory: build/zephyr/
82+
working-directory: build
7283
run: |
7384
EXPECTED_LOG="Hello World from Ocre!"
7485
echo "Running Zephyr (native_sim)..."
7586
chmod +x zephyr.exe
76-
stdbuf -oL -eL timeout 20s ./zephyr.exe | tee zephyr_app.log
87+
stdbuf -oL -eL timeout 20s ./zephyr.exe | tee zephyr_run_native_sim.log
7788
echo "===== Checking for expected log ====="
78-
if grep -q "$EXPECTED_LOG" zephyr_app.log; then
89+
if grep -q "$EXPECTED_LOG" zephyr_run_native_sim.log; then
7990
echo "[OK] Found expected log: $EXPECTED_LOG"
8091
else
8192
echo "[ERROR] Expected log not found: $EXPECTED_LOG"
8293
exit 1
8394
fi
8495
85-
- name: Upload app logs
96+
- name: Upload run app logs
8697
uses: actions/upload-artifact@v4
8798
with:
88-
name: zephyr-app-log
89-
path: build/zephyr/zephyr_app.log
99+
name: zephyr_run_native_sim_log
100+
path: build/zephyr_run_native_sim.log
90101

91102
build-linux:
92103
runs-on: ubuntu-latest
@@ -101,36 +112,45 @@ jobs:
101112
cd application
102113
git submodule update --init --recursive
103114
104-
- name: Build Linux
115+
- name: Build Linux x86_64
105116
run: |
106117
cd application
107-
./build.sh -t l
118+
./build.sh -t l | tee linux_build.log
108119
109-
- name: Upload build artifacts
120+
- name: Upload Linux build log
110121
uses: actions/upload-artifact@v4
111122
with:
112-
name: linux-build
113-
path: application/build/
123+
name: linux_build_log
124+
path: application/linux_build.log
125+
126+
- name: Upload x86_64 build artifact
127+
uses: actions/upload-artifact@v4
128+
with:
129+
name: ocre-ubuntu-x86_64-app
130+
path: |
131+
application/build/app
132+
application/build/src
114133
115134
run-linux:
116135
runs-on: ubuntu-latest
117136
needs: build-linux
118137
steps:
119-
- name: Download Linux build artifacts
138+
- name: Download Linux build artifact
120139
uses: actions/download-artifact@v4
121140
with:
122-
name: linux-build
141+
name: ocre-ubuntu-x86_64-app
123142
path: application/build/
124143

125144
- name: Run Linux binary and check output
126145
working-directory: application/build
127146
run: |
147+
ls -l
128148
EXPECTED_LOG="Hello World from Ocre!"
129149
chmod +x app
130150
echo "Running application..."
131-
stdbuf -oL -eL timeout 20s ./app | tee linux_app.log
151+
stdbuf -oL -eL timeout 20s ./app | tee linux_run.log
132152
echo "===== Checking for expected log ====="
133-
if grep -q "$EXPECTED_LOG" linux_app.log; then
153+
if grep -q "$EXPECTED_LOG" linux_run.log; then
134154
echo "[OK] Found expected log: $EXPECTED_LOG"
135155
else
136156
echo "[ERROR] Expected log not found: $EXPECTED_LOG"
@@ -140,18 +160,18 @@ jobs:
140160
- name: Upload app logs
141161
uses: actions/upload-artifact@v4
142162
with:
143-
name: linux-app-log
144-
path: application/build/linux_app.log
163+
name: linux_run_log
164+
path: application/build/linux_run.log
145165

146166
flash:
147167
needs: build-zephyr
148168
runs-on: zephyr-xlarge-runner
149169
steps:
150-
- name: Download firmware
170+
- name: Download Zephyr build artifact(b_u585i_iot02a)
151171
if: runner.environment == 'self-hosted'
152172
uses: actions/download-artifact@v4
153173
with:
154-
name: firmware
174+
name: ocre-zephyr-b_u585-app
155175

156176
- name: Flash b_u585i_iot02a
157177
if: runner.environment == 'self-hosted'

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ cd ocre-runtime
103103
git submodule update --init --recursive
104104
```
105105

106-
---
107-
108106
## Building and Running
109107

110108
### Using the `build.sh` Script (Recommended)
@@ -114,13 +112,16 @@ Ocre provides a convenient `build.sh` script to simplify building and running fo
114112
#### Usage
115113

116114
```sh
117-
./build.sh -t <target> [-r] [-f <file1> [file2 ...]] [-b] [-h]
115+
./build.sh -t <target> [-r] [-f <file1> [file2 ...]] [-b] <board> [-h]
118116
```
119117
120118
- `-t <target>`: **Required**. `z` for Zephyr, `l` for Linux.
121119
- `-r`: Run after build (optional).
122120
- `-f <file(s)>`: Specify one or more input files (optional).
123-
- `-b`: (Zephyr only) Build for `b_u585i_iot02a` board instead of `native_sim`.
121+
- `-b <board>`: (Zephyr only) Select a zephyr board instead of the default `native_sim`:
122+
- `uw` -> b_u585i_iot02a + W5500
123+
- `ue` -> b_u585i_iot02a + ENC28J60
124+
- `your_option` -> any Zephyr-supported board
124125
- `-h`: Show help.
125126
126127
#### Examples
@@ -179,7 +180,34 @@ make
179180
- The script checks build success and only runs the application if the build completes successfully.
180181
- The `mini-samples` directory contains a "Hello World" container, which is hardcoded as a C array. When Ocre is run without input file arguments, it executes this sample container by default. If an input file is provided, Zephyr will convert that file into a C array at build time and run it as a container. On Linux, this conversion does not occur — instead, Ocre simply opens and reads the provided file(s) directly from the filesystem.
181182
182-
---
183+
## Sample Output
184+
185+
#### Zephyr (b_u585i_iot02a)
186+
```sh
187+
./build.sh -t z -r -b ue
188+
```
189+
190+
##### Output
191+
```sh
192+
Target is: Zephyr
193+
Building for b_u585i_iot02a with ENC28J60 support
194+
Linking C executable zephyr/zephyr.elf
195+
Ocre runtime started
196+
Hello World from Ocre!
197+
```
198+
199+
#### Linux
200+
```sh
201+
./build.sh -t l -r
202+
```
203+
204+
##### Output
205+
```sh
206+
Target is: Linux
207+
[100%] Built target app
208+
Ocre runtime started
209+
Hello World from Ocre!
210+
```
183211
184212
## License
185213

boards/native_sim.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE=y
2-
CONFIG_NATIVE_UART_0_ON_STDINOUT=y
3-
CONFIG_UART_NATIVE_POSIX=y
1+
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
2+
CONFIG_UART_NATIVE_PTY=y
43
CONFIG_FLASH_SIMULATOR=y
54
CONFIG_ENTROPY_GENERATOR=y
65
CONFIG_TEST_RANDOM_GENERATOR=y

build.sh

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ show_help() {
66
echo " -t <target> (Required) Specify the target. z for Zephyr and l for Linux"
77
echo " -r (Optional) Specify whether run after the build"
88
echo " -f <file(s)> (Optional) Specify one or more input files"
9-
echo " -b (Optional) Only Zephyr: build for b_u585i_iot02a instead of native_sim"
10-
echo " -h Display help"
9+
echo " -b <board> (Optional, Zephyr only) Select board:"
10+
echo " uw -> b_u585i_iot02a + W5500"
11+
echo " ue -> b_u585i_iot02a + ENC28J60"
12+
echo " note: when no board is selected, native_sim is the default target for Zephyr"
13+
echo " -h Display help"
1114
exit 0
1215
}
1316

1417
RUN_MODE=false # Default: Run mode disabled
1518
INPUT_FILES=()
16-
ZEPHYR_BOARD="native_sim"
19+
BOARD_ARG="native_sim"
1720

1821
# resolve absolute paths (portable, no readlink -f)
1922
abs_path() {
@@ -29,6 +32,10 @@ abs_path() {
2932
while [[ $# -gt 0 ]]; do
3033
case "$1" in
3134
-t)
35+
if [[ -z "$2" || "$2" =~ ^- ]]; then
36+
echo "Error: -t requires a value (z or l)" >&2
37+
exit 1
38+
fi
3239
TARGET="$2"
3340
shift 2
3441
;;
@@ -44,8 +51,12 @@ while [[ $# -gt 0 ]]; do
4451
done
4552
;;
4653
-b)
47-
ZEPHYR_BOARD=b_u585i_iot02a
48-
shift
54+
if [[ -z "$2" || "$2" =~ ^- ]]; then
55+
echo "Error: -b requires a board argument" >&2
56+
exit 1
57+
fi
58+
BOARD_ARG="$2"
59+
shift 2
4960
;;
5061
-h)
5162
show_help
@@ -66,21 +77,39 @@ fi
6677

6778
# Check if required argument is provided
6879
if [[ "$TARGET" == "z" ]]; then
69-
echo "Target is: Zephyr's $ZEPHYR_BOARD"
80+
echo "Target is: Zephyr"
7081
cd ..
82+
case "$BOARD_ARG" in
83+
uw)
84+
ZEPHYR_BOARD="b_u585i_iot02a"
85+
CONF_EXTRA=""
86+
echo "Building for b_u585i_iot02a with W5500 support"
87+
;;
88+
ue)
89+
ZEPHYR_BOARD="b_u585i_iot02a"
90+
CONF_EXTRA="-DCONF_FILE=prj.conf\;boards/${ZEPHYR_BOARD}.conf\;boards/enc28j60.conf \
91+
-DDTC_OVERLAY_FILE=boards/${ZEPHYR_BOARD}.overlay\;boards/enc28j60.overlay"
92+
echo "Building for b_u585i_iot02a with ENC28J60 support"
93+
;;
94+
*)
95+
ZEPHYR_BOARD="$BOARD_ARG"
96+
CONF_EXTRA=""
97+
echo "Building for board: $ZEPHYR_BOARD"
98+
;;
99+
esac
100+
71101
if [[ ${#INPUT_FILES[@]} -gt 0 ]]; then
72102
echo "Input files provided: ${INPUT_FILES[*]}"
73-
rm flash.bin
103+
rm flash.bin
74104
west build -p -b $ZEPHYR_BOARD ./application -d build -- \
75-
-DMODULE_EXT_ROOT=`pwd`/application -DOCRE_INPUT_FILE="${INPUT_FILES[0]}" -DTARGET_PLATFORM_NAME=Zephyr || exit 1
76-
# Note: Only the first file is passed to OCRE_INPUT_FILE, adapt as needed for multiple files
105+
-DMODULE_EXT_ROOT=`pwd`/application -DOCRE_INPUT_FILE="${INPUT_FILES[0]}" -DTARGET_PLATFORM_NAME=Zephyr $CONF_EXTRA || exit 1
77106
else
78107
rm flash.bin
79-
west build -p -b $ZEPHYR_BOARD ./application -d build -- \
80-
-DMODULE_EXT_ROOT=`pwd`/application -DTARGET_PLATFORM_NAME=Zephyr || exit 1
108+
west build -p -b $ZEPHYR_BOARD ./application -d build -- \
109+
-DMODULE_EXT_ROOT=`pwd`/application -DTARGET_PLATFORM_NAME=Zephyr $CONF_EXTRA || exit 1
81110
fi
82111
elif [[ "$TARGET" == "l" ]]; then
83-
echo "Target is: Linux x86_64"
112+
echo "Target is: Linux"
84113
if [[ ! -d "build" ]]; then
85114
echo "build folder does not exist. Creating: build"
86115
mkdir -p "build"

src/ocre/api/ocre_api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

8+
#ifndef _GNU_SOURCE
89
#define _GNU_SOURCE
10+
#endif
911

1012
#include <stdio.h>
1113
#include <sys/utsname.h>

src/ocre/api/ocre_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef OCRE_API_H
1111
#define OCRE_API_H
1212

13-
#define OCRE_API_POSIX_BUF_SIZE 75
13+
#define OCRE_API_POSIX_BUF_SIZE 80
1414

1515
#ifndef OCRE_SYSTEM_NAME
1616
#define OCRE_SYSTEM_NAME "Project Ocre"
@@ -29,4 +29,4 @@ int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name
2929

3030
extern NativeSymbol ocre_api_table[];
3131
extern int ocre_api_table_size;
32-
#endif
32+
#endif

0 commit comments

Comments
 (0)