5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[メモ] VagrantにてZephyr(RTOS)の開発環境を作って試す

Last updated at Posted at 2018-09-19

概要

環境

  • Windows 10 Pro (1803) 64bit
  • VirtualBox v5.2.18 + Extension Pack
  • Vagrant v2.1.5
    • Boxベース: 'ubuntu/bionic64' (v20180919.0.0) for 'virtualbox'
  • Zephyr: v1.13.0

Vagrantfile

Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# https://qiita.com/mt08/items/9014862d81282f4e04f0
#
# Reference(s):
#   https://docs.zephyrproject.org/1.13.0/getting_started/installation_linux.html
#
# vagrant up && vagrant reload

VM_NAME="u1804-zephyr"
VM_MEMORY=2048
VM_CORES=2

Vagrant.configure("2") do |config|
	config.vm.box = "ubuntu/bionic64"
	config.vbguest.auto_update = false
	#config.vm.network "public_network"
	config.vm.network "forwarded_port", guest: 22, host: 2322, id: "ssh"
	config.vm.provider "virtualbox" do |vb|
		vb.name = VM_NAME
		vb.cpus = VM_CORES
		vb.memory = VM_MEMORY
	end

	config.vm.provision "shell", inline: <<-SHELL
		# Allow ssh with PasswordAuthentication
		sed -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
		systemctl restart ssh
		# apt-cache-server 
		#echo 'Acquire::http::Proxy "http://apt-cache-server:3142";' | tee /etc/apt/apt.conf.d/02proxy
		#
		export DEBIAN_FRONTEND=noninteractive
		echo apt update & upgrade
		apt-get -qq update && apt-get -qq upgrade 
		echo Installing Requirements and Dependencies
		apt-get -qq install -y --no-install-recommends git cmake ninja-build gperf ccache doxygen dfu-util device-tree-compiler python3-ply python3-pip python3-setuptools python3-wheel xz-utils file make gcc-multilib autoconf automake libtool librsvg2-bin texlive-latex-base texlive-latex-extra latexmk texlive-fonts-recommended
		#
		echo zephyr-sdk
        wget --quiet --continue https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/0.9.3/zephyr-sdk-0.9.3-setup.run -O /vagrant/zephyr-sdk-0.9.3-setup.run
		echo "/opt/zephyr-sdk" | /bin/sh /vagrant/zephyr-sdk-0.9.3-setup.run --quiet
	SHELL

	config.vm.provision "shell", privileged: false, inline: <<-SHELL
		cd ${HOME}
		echo git clone 
		git clone https://github.com/zephyrproject-rtos/zephyr.git
		cd zephyr
		git checkout zephyr-v1.13.0

		# 
		echo "export ZEPHYR_BASE=$(pwd)"         >> ${HOME}/.profile
		echo 'source $ZEPHYR_BASE/zephyr-env.sh' >> ${HOME}/.profile
		cd ${HOME}

		echo 'export ZEPHYR_TOOLCHAIN_VARIANT=zephyr'        >  ${HOME}/.zephyrrc
		echo 'export ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk' >> ${HOME}/.zephyrrc
		
		# 
		source ${HOME}/.profile
		echo Install additional packages required for development with Zephyr:
		pip3 install --quiet --user -r $ZEPHYR_BASE/scripts/requirements.txt
	SHELL
end

手順

開発環境セットアップ

  1. VirtualBoxとVagrantをインストールして、使えるようにする
  2. 適当なフォルダを作って、↑のVagrantfile作成
  3. vagrant up && vagrant reload
  4. 待つ (20分~)

サンプルアプリのビルド(Hello World)

qemu_cortex_m3環境にて

  1. vagrant ssh
    にてログイン

  2. 以下実行

    cd $ZEPHYR_BASE/samples/hello_world
    mkdir build && cd build
    # cmakeを使ってNinjaベースのビルドシステムを設定:
    cmake -GNinja -DBOARD=qemu_cortex_m3 ..
    # 生成されたビルドシステムにて、ninjaを実行:
    ninja
    ninja run
    
  3. Hello World! armが表示される. CTRL-A, x にてqemuを抜ける

    実行例
    vagrant@ubuntu-bionic:~/zephyr/samples/hello_world/build$ ninja run
    [0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: cortex-m3
    ***** Booting Zephyr OS zephyr-v1.13.0 *****
    Hello World! arm
    QEMU: Terminated
    vagrant@ubuntu-bionic:~/zephyr/samples/hello_world/build$
    
    

hello_worldのソースコード

  • main.c

    zephyr/samples/hello_world/src/main.c
     /*
      * Copyright (c) 2012-2014 Wind River Systems, Inc.
      *
      * SPDX-License-Identifier: Apache-2.0
      */
    
     #include <zephyr.h>
     #include <misc/printk.h>
    
     void main(void)
     {
     		printk("Hello World! %s\n", CONFIG_ARCH);
     }
    
    
    
    

その他

  • Apache系のmynewtってのもあったな..
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?