Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: zephyr: Revive Zephyr's sample #29

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ceolin
Copy link

@ceolin ceolin commented Sep 15, 2023

Small fixes to use upstream Zephyr. The major change is removing instructions to fetch Zephyr and its tools since it is barely reproducible. Lets just assume that the host is capable of building a Zephyr application.

Flavio Ceolin added 5 commits September 15, 2023 15:42
Lets assume that Zephyr repository and needed tools
are available and properly setup. Trying to fetch
and setup everything is very fragile and don't work
in different environments.

Signed-off-by: Flavio Ceolin <[email protected]>
Use find_package() instead of manually including
deprecated boilerplate.cmake

Signed-off-by: Flavio Ceolin <[email protected]>
Zephyr headers are in zephyr/*

Signed-off-by: Flavio Ceolin <[email protected]>
It seems that icount does not play well with kvm. Just disabling it.

Signed-off-by: Flavio Ceolin <[email protected]>
Use west tool to build Zephyr and simplify the build logic.

Signed-off-by: Flavio Ceolin <[email protected]>
@Wenzel
Copy link
Contributor

Wenzel commented Sep 23, 2023

Thanks for this PR and reviving the Zephyr target @ceolin !

I tried to repro your work, but I'm unlucky so far.
First I wanted to use the official Zephyr Docker image (which it turns out, contains all the dependencies + the SDK, but not Zephyr itself), so I build my own Dockerfile:

FROM zephyrprojectrtos/zephyr-build

ARG ZEPHYR_VER=v3.4.0
ENV ZEPHYR_BASE=/opt
ENV ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-0.16.3-rc1
USER root
# setup Zephyr
RUN west init --mr ${ZEPHYR_VER} $ZEPHYR_BASE
WORKDIR /workdir
RUN west update

And I ran it inside the zephyr_x86_32 directory:
docker run -ti --rm -v $PWD:/workdir zephyr_test

And I tried to build the test app:

$ ./run.sh build TEST
# Detected Zephyr environment:
ZEPHYR_BASE=/opt
ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-0.16.3-rc1
ZEPHYR_TOOLCHAIN_VARIANT=zephyr
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
CMake Error at /opt/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include):
  include could not find requested file:

    zephyr_default
Call Stack (most recent call first):
  /opt/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
  CMakeLists.txt:5 (find_package)


-- The C compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:8 (set_property):
  set_property could not find TARGET app.  Perhaps it has not yet been
  created.


CMake Error at CMakeLists.txt:10 (target_sources):
  Cannot specify sources for target "app" which is not built by this project.


CMake Error at CMakeLists.txt:13 (target_sources_ifdef):
  Unknown CMake command "target_sources_ifdef".


-- Configuring incomplete, errors occurred!
See also "/workdir/build/CMakeFiles/CMakeOutput.log".
FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/workdir/build -GNinja -DBOARD=qemu_x86 -DKAFL_TEST=y -S/workdir

But I'm getting cmake errors.

Anything I'm doing wrong ?

Poke @il-steffen, if you know better how to setup Zephyr for these examples !

Thanks

@Wenzel
Copy link
Contributor

Wenzel commented Oct 6, 2023

I added a couple of fixes plus the Dockerfile image to compile the targets inside Docker, and avoid installing Zephyr locally.

cd zephyr_x86_64
docker build -t kafl_zephyr .
docker run -ti --rm -v $PWD:/workdir -v $PWD/../nyx_api.h:/usr/local/include/nyx_api.h kafl_zephyr
./run.sh build TEST
# CTRL-D (exit container)
./run.sh fuzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants