-
Notifications
You must be signed in to change notification settings - Fork 11
QEMU and Zephyr
This wiki probably belongs to Zephyr wiki page, but for the time that ARC support for QEMU is being developed, I leave it here.
Make sure you are using the latest ARC-QEMU.
On different GNU/Linux distributions, some packages are needed. I list them here, but for a recent one consult the original documentation page.
sudo pacman -S git cmake ninja gperf ccache dfu-util dtc wget \
python-pip python-setuptools python-wheel xz file make
sudo dnf group install "Development Tools" "C Development Tools and Libraries"
dnf install git cmake ninja-build gperf ccache dfu-util dtc wget \
python3-pip xz file glibc-devel.i686 libstdc++-devel.i686
sudo apt-get install --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-pip python3-setuptools python3-wheel \
xz-utils file make gcc gcc-multilib
sudo xbps-install git cmake ninja gperf ccache dfu-util dtc wget \
python3-pip python3-setuptools python3-wheel xz \
file make
-
Get the latest code base:
git clone --depth 10 https://github.com/zephyrproject-rtos/zephyrInstead, it is strongly recommended to use our fork of Zephyr, because it enjoys the latest updates. Later, you can also skip applying the patch.
git clone --single-branch --branch qemu_arc https://github.com/foss-for-synopsys-dwc-arc-processors/zephyr.git -
Install Python dependencies:
pip3 install --user -r zephyr/scripts/requirements.txt -
Prep the SDK for compiling and simulating different targets:
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.2/zephyr-sdk-0.11.2-setup.run sh zephyr-sdk-0.11.2-setup.runThis will extract all the binaries in
/opt/zephyr-sdkby default, unless during the execution you provide another path. You can check for the latest SDK releases here. To instruct Zephyr to use this SDK you must have the following variables set in your environment:export ZEPHYR_TOOLCHAIN_VARIANT=zephyr export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>Be aware that the ARC compiler provided in this SDK makes use of floating point instructions. Later, I will show a way to use our own compiler for ARC targets. Nevertheless, the provided environments should make things easier.
If you cloned from our Zephyr, you can skip to Hello World project. That is actually recommended, because the patch below is just a proof of concept and rather old.
-
Create an ASCII file with provided context:
cat > add_qemu_archs_board_to_zephyr.tar.gz.b64 << EOF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j1tkzOT6lEQsS6LBHYxk+HhANzwFQ9afS1zBmkVJLDr11d4MOlDOA1uDVGT QAOLxFdd/cueHpOxA5bl6iHuaV+1niiosqfNfMLugHraMYDKXbkodkWuK6ZSean3mRLR79ztWw/v 3k7sXG1ISHtYkMj1oboxvaSOIesqpfCsGaAZwo77sFwU59kzFAjymsGxa3K9Xq6auc0gKhFLAjlp 6D4gI2wjj9xDed0ZG4iTJjP5UOJdHgSAGxBAZp2WPH3hVqejM4I1bl3eb7GaYTwrCmIvUwiLSflZ 7nbvFl/B6XeQJSLZlww90Qbtu62w/XUAzH3SwXprrGVOqj3RdW0wxsZI0zq55LHNnCmq17rUerlE pLtzv5X43tUhe/Me/APSAhuFDndxb4+Ln4tizw2+kajo2dnhtUHnvphQp7JaazimnDeCtyrE+K2n 8Qtlxgf0sxeiKGHPdSW63g/rW49PMxKQyIyJjdkeSy6z5ucihbmMQ5ZpODh1STeAdL60eCvU9qAH 9VYw/eXCg6a3z7t4dNRtt/vHaGpSgtLrD2SCJ9mNB5/FOlQMvdXHxhgihZdqLC44KHvbJdTdXzW0 S81AyfR25g4O4J64V7ceOH82XAC0L91xVN4wkSuNqlVVms1m3jBJxAshUq49GSKN/1uIlD4kPBdT KPUcdMn/qpCcOMsoaYJ904pCynthOGiSwyfVNJ67FM2JaZMoMRR8LilERxwiuiCW66x4NNiEWpE7 hV6EyZd4CucCTEYVJ8LjOUGxGc1IXBQi2AFzO4gX7PgGbyNkCxEjwXepVVrGrieGcXpEtqHDRpB6 6E5cslzEezcZ7R9KLYNBeYqhLp5HjAVKq6f1qPLOgltGv9caXE9a19pTS9zCIzB06JfYo6ymy99M ALK/NmhdQrnGjJE9/jySH9KYVtCnT6hxvE8ANMxjyPPGIwFHDd4TvOWVFwLD/0dcxdqjG+zagwzx b//h7XW8jtfxOl7H63gdr+N1vI5/YfwP1FvbegAoAAA= EOF -
Decode and extract it:
base64 -d add_qemu_archs_board_to_zephyr.tar.gz.b64 > \ add_qemu_archs_board_to_zephyr.tar.gz tar xf add_qemu_archs_board_to_zephyr.tar.gz -
Apply the patch to your Zephyr repo:
git apply add_qemu_archs_board_to_zephyr.patch
-
Go to
hello_worldproject and make a build directory:cd zephyr/samples/hello_world mkdir build cd build -
Set the following variables or use the environment provided (
zephyr/arc):export ZEPHYR_BASE=/data/work/repos/zephyrproject/zephyr export QEMU_BIN_PATH=/data/work/install/qemu/bin unset ZEPHYR_SDK_INSTALL_DIR export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile # use $CROSS_COMPILE export CROSS_COMPILE=/data/work/install/arcgnu/bin/arc-elf32- # Our compiler -
Configure, build, and run:
cmake -G "Unix Makefiles" -DBOARD=qemu_archs -S $ZEPHYR_BASE/samples/hello_world make make run -
You must see an output like:
***** Booting Zephyr OS v1.14.0-rc1-26-g8d86773d6b ***** Hello World! qemu_archsYou can terminate it with
ctrl-a x. -
You may
cleanwith:make pristine
It helps a lot to have the following environments in place and switch between them. Adapt the paths according to your set-up.
#%Module1.0################################################################
##
## Zephyr qemu module file
##
set ModulesVersion "zephyr-arc-1.0"
proc ModulesHelp {} {
global version
puts stderr " This module loads the Zephyr ARC"
puts stderr ""
}
module-whatis "Use Zephyr with custom ARC compiler"
setenv ZEPHYR_BASE /data/work/repos/zephyrproject/zephyr
setenv QEMU_BIN_PATH /data/work/install/qemu/bin
unsetenv ZEPHYR_SDK_INSTALL_DIR
setenv ZEPHYR_TOOLCHAIN_VARIANT cross-compile
setenv CROSS_COMPILE /data/work/install/arcgnu/bin/arc-elf32-
#%Module1.0################################################################
##
## Zephyr qemu module file
##
set ModulesVersion "zephyr-sdk-1.0"
proc ModulesHelp {} {
global version
puts stderr " This module loads the Zephyr SDK"
puts stderr " located in /opt/zephyr-sdk"
puts stderr ""
}
module-whatis "Sets environment as such to use Zephyr SDK"
setenv ZEPHYR_TOOLCHAIN_VARIANT zephyr
setenv ZEPHYR_SDK_INSTALL_DIR /opt/zephyr-sdk
setenv ZEPHYR_BASE /data/work/repos/zephyrproject/zephyr