Skip to content

Commit cae940d

Browse files
committed
zephyr: app: board: add native_sim board target
Add native_sim board configuration and support in the build script. This allows building and running tests on the host using Zephyr's native_sim target. native_sim leverages the POSIX architecture, but the libfuzzer support specifically requires CONFIG_ARCH_POSIX_LIBFUZZER to be set. Therefore, this wraps fuzzer-specific code in ipc.c and the build of fuzz.c behind this config to allow clean compilation on the standard native_sim board. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 87d2e63 commit cae940d

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

app/boards/native_sim.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_ZEPHYR_POSIX=y
2+
CONFIG_SYS_HEAP_BIG_ONLY=y
3+
CONFIG_ZEPHYR_NATIVE_DRIVERS=y
4+
CONFIG_ZEPHYR_LOG=y

scripts/xtensa-build-zephyr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ class PlatformConfig:
235235
"zephyr", "qemu_xtensa/dc233c/mmu",
236236
"", "", "zephyr"
237237
),
238+
"native_sim" : PlatformConfig(
239+
"zephyr", "native_sim",
240+
"", "", "zephyr"
241+
),
238242
}
239243

240244
platform_configs = platform_configs_all.copy()

src/platform/posix/ipc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SOF_DEFINE_REG_UUID(ipc_task_posix);
1414

1515
static struct ipc *global_ipc;
1616

17+
#ifdef CONFIG_ARCH_POSIX_LIBFUZZER
1718
// Not an ISR, called from the native_posix fuzz interrupt. Left
1819
// alone for general hygiene. This is how a IPC interrupt would look
1920
// if we had one.
@@ -131,6 +132,7 @@ static void fuzz_isr(const void *arg)
131132

132133
posix_ipc_isr(NULL);
133134
}
135+
#endif
134136

135137
// This API is... confounded by its history. With IPC3, the job of
136138
// this function is to get a newly-received IPC message header (!)
@@ -172,12 +174,14 @@ int ipc_platform_compact_read_msg(struct ipc_cmd_hdr *hdr, int words)
172174
// Re-raise the interrupt if there's still fuzz data to process
173175
void ipc_platform_complete_cmd(struct ipc *ipc)
174176
{
177+
#ifdef CONFIG_ARCH_POSIX_LIBFUZZER
175178
extern void posix_sw_set_pending_IRQ(unsigned int IRQn);
176179

177180
if (fuzz_in_sz > 0) {
178181
posix_fuzz_sz = 0;
179182
posix_sw_set_pending_IRQ(CONFIG_ZEPHYR_POSIX_FUZZ_IRQ);
180183
}
184+
#endif
181185
}
182186

183187
int ipc_platform_send_msg(const struct ipc_msg *msg)
@@ -200,8 +204,10 @@ void ipc_platform_send_msg_direct(const struct ipc_msg *msg)
200204

201205
int platform_ipc_init(struct ipc *ipc)
202206
{
207+
#ifdef CONFIG_ARCH_POSIX_LIBFUZZER
203208
IRQ_CONNECT(CONFIG_ZEPHYR_POSIX_FUZZ_IRQ, 0, fuzz_isr, NULL, 0);
204209
irq_enable(CONFIG_ZEPHYR_POSIX_FUZZ_IRQ);
210+
#endif
205211

206212
global_ipc = ipc;
207213
schedule_task_init_edf(&ipc->ipc_task, SOF_UUID(ipc_task_posix_uuid),

zephyr/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ zephyr_library_sources_ifdef(CONFIG_ZEPHYR_POSIX
484484
${SOF_PLATFORM_PATH}/posix/dai.c
485485
${SOF_PLATFORM_PATH}/posix/ipc.c
486486
${SOF_PLATFORM_PATH}/posix/posix.c
487+
)
488+
489+
zephyr_library_sources_ifdef(CONFIG_ARCH_POSIX_LIBFUZZER
487490
${SOF_PLATFORM_PATH}/posix/fuzz.c
488491
)
489492

0 commit comments

Comments
 (0)