安裝步驟 === ## PREEMPT_RT安裝 硬體:Raspberry Pi 3 Model B 作業系統:Raspbian PREEMPT_RT patch:Latest 4.4-rt Latest 4.6-rt linux kernel:https://github.com/raspberrypi/linux > 剛剛使用ubuntu mate kernel version 4.1.18 去執行 4.4.9 的 PREEMPT_RT > 應該是版本不同所致,或者 ubuntu mate 不支援 接著要使用 raspbian來編看看 > raspbian 成功了!! [name=阿Hua] > 要用 GitHub 上的版本,不要用 kernel.org FTP tarball,日後還要追蹤修改[name=jserv] > 好的,我們一開始就是使用 tarball,結果編譯都過不去 換使用 GitHub 後就沒事了[name=阿Hua] 1. 安裝必要套件: `$sudo apt-get install lib32stdc++6 lib32z1 lib32z1-dev` `$sudo apt-get install libncurses5-dev libncursesw5-dev` `$sudo apt-get install gcc-arm-linux-gnueabihf` > 這邊可能會有漏掉的,找不到的套件試著使用 apt-file search[name=阿Hua] 2. 下載 raspberrypi linux kernel `$git clone https://github.com/raspberrypi/linux.git` > 記得利用 git checkout (commit number) 下載跟 PREEMPT_RT patch 相同版本的核心[name=阿Hua] 3. 下載 raspberrypi compile toolchain `$git clone https://github.com/raspberrypi/tools` 4. `$cd linux` > 進入 kernel source 的目錄[name=阿Hua] 5. 下載核心patch檔 https://www.kernel.org/pub/linux/kernel/projects/rt/ > 要下載與 kernel 相同版本的![name=阿Hua] 6. 解壓縮下載來的 patch `$unxz patch-4.4.9-rt17.patch.xz` > 4.4.9 是我們使用的版本[name=阿Hua] 7. patch 進入 kernel source `$cat patch-4.4.9-rt17.patch | patch -p1` 8. 設定全域變數 `$vim ~/.bashrc` ``` export PATH=$PATH:/home/`your name`/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin ``` > 設定環境變數,在 make 時 Makefile會偵測路徑[name=阿Hua] 9. 在 kernel source 中產生預設 .config `$KERNEL=kernel7` `$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig` 10. 修改.config `$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- gconfig` `$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig` > 選一個執行,詳情請上[鳥哥](http://linux.vbird.org/linux_basic/0540kernel.php)爽一波[name=阿Hua] 在`Kernel Features` >> `Preemption Model` 選擇 `Full Preempt` > 只要比較 PREEMPT_NONE 與 PREEMPT_RT[name=jserv] > 好的~[name=阿Hua] > 是否打開下面兩項再測試一下?[name=jserv] > ``` > General setup >> Timer tick handling >> Full dynticks system (tickless) > General setup >> Timer tick handling >> Full dynticks system on all CPUs by default (except CPU 0) > ``` > [name=張立鑫] 11. 開始編譯 ``` $sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs ``` 12. 編譯模組 ``` sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=dist modules_install ``` 13. 接著將 build/arch/arm/boot/zImage 的 kernel image 複製到安裝好的樹莓派的目錄 /boot/ 之下,並改名為 zImage-4.4.9-rt17 14. 將 linux/dist/lib/modules/4.4.9-rt17+ 複製到 /lib/modules 之中,要使用 `cp -rp` 15. 最後將樹莓派中的 /boot/config.txt 中加入 kernel=zImage-4.4.9-rt17 16. reboot -> 完成!! ``` $uname -r 4.4.9-rt17-v7+ ``` > 請問一下,為何編譯出來的 initrd.img-4.4.12-rt19 約 294mb, 相較於 generic 的約 37mb 大很多? OS: Ubuntu16.04 > [name=CHIA-CHI H] > 你好!我們所使用的 OS 為 raspbian ,跟您使用的 distribution 在功能上差異很大( raspbian較為輕量化 ),因此編譯出來的 img 檔的大小會不同 > [name=阿Hua] 做實驗 - [x] sftp 跟 cp 的差別 (動態連結的問題) => 壓縮可以保存動態連結 - [x] device tree bulbs (dtbs) 覆蓋的影響 => dtb 會影響 kernel boot (不同 kernel 要搭配對應的 dtb ) ## Xenomai安裝 ipipe patch : https://xenomai.org/downloads/ipipe/ 參考:http://www.blaess.fr/christophe/2016/05/22/xenomai-3-sur-raspberry-pi-2/ ### Xenomai2.6 on Raspberry pi3 1. 下載 raspberrypi linux kernel `$git clone https://github.com/raspberrypi/linux.git` `$git checkout rpi-4.1.y` > 可以切到此 comment `e9e9ccf11ac5b6ee9b65416980900ababdd6c48c` > 或者使用`git clone https://github.com/raspberrypi/linux.git -b rpi-4.1.y --depth=1` 節省下載時間 2. 下載 xenomai-2.6 `$git clone git://git.xenomai.org/xenomai-2.6.git` 3. 下載 i-pipe patch ``` $wget https://xenomai.org/downloads/ipipe/v4.x/arm/ipipe-core-4.1.18-arm-7.patch ``` > 目前 i-pipe patch 最新版本為 ipipe-core-4.1.18-arm-7.patch > 如有更新請至https://xenomai.org/downloads/ipipe/v4.x/arm/ 尋找 [name=阿Hua] 4. 打入 i-pipe patch `cat ipipe-core-4.1.18-arm-7.patch | patch -p1` > 此步驟在 rpi-linux之中執行[name=阿Hua] 5. 將 Xenomai 放入 rpi-linux之中 > 此步驟在 xenomai-2.6 之中執行[name=阿Hua] `$scripts/prepare-kernel.sh --linux=../linux/ --arch=arm` 6. 修改(**重要,不然編譯會出問題**) `cd ~/linux/arch/arm/kernel` `vim smp.c` ``` static inline void ipi_timer(void) { #if defined(CONFIG_IPIPE_LEGACY) && !defined(CONFIG_IPIPE_ARM_KUSER_TSC) //__ipipe_mach_update_tsc(); #endif tick_receive_broadcast(); } ``` > 註解掉此行,此函式並沒有被定義,且後續的 kernel config 會讓此函式無效,如果沒註解掉,編譯時會出錯[name=阿Hua] 7. 載入組態檔 `$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig` `$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig` ``` CPU Power Management ---> CPU Frequency scaling ---> [ ] CPU Frequency scaling CPU idle ---> [ ] CPU idle PM support Kernel Features ---> [ ] Contiguous Memory Allocator [ ] Allow for memory compaction Kernel Hacking ---> [ ] KGDB: kernel debugger ---> Boot options ---> Kernel command line type ---> (X) Extend bootloader kernel arguments ``` 8. 編譯核心 ``` $make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs ``` > -j num 利用平行運算編譯加速,num 幾個 threads > 如果加入 sudo 的 prefix 會導致,在編譯時會讀取 root 的環境變數,而使得設定在 user 中的環境變數無效 (`~/.bashrc`) > [name=阿Hua] 9. 輸出編譯完的模組 ``` $make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=dist modules_install ``` 10. 複製 zImage `$cp arch/arm/boot/zImage /media/${USER}/boot` 11. 複製 device tree * 備份(optional) `$mv /media/$(USER)/boot/overlays /media/$(USER)/boot/overlays_bak` * 移除舊 device tree 及複製 device tree `$rm /media/$(USER)/boot/overlays/*` `$cp arch/arm/boot/dts/overlays/*.dtb /media/$(USER)/boot/overlays` `$cp arch/arm/boot/dts/bcm2709-pi-2-b.dtb /media/${USER}/boot` ``` config.txt修改如下 kernel=${zImage name} device_tree=bcm2710-rpi-3-b.dtb ``` 12. 複製模組 `$sudo cp -r linux/dist/lib/modules/* /media/${USER}/${ROOT}/lib/modules` `$sync` 13. Xenomai2.6 參數設定 ``` $./configure CFLAGS="-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ffast-math" --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --enable-smp ``` > ./scripts時,如果遇到 perl 的問題: > http://dev.sopili.net/2014/07/ubuntu-perl-language-lcall-unset.html > ./configure CFLAGS下的參數必須配合SoC的版本 > rp2 bcm2709 -> armv7 -> enable smp > http://xenomai.org/installing-xenomai-3-x/ > [name=阿Hua] 14. 編譯 Xenomai2.6 `$make DESTDIR=${PWD}/target install` 15. 將 Xenoami2.6 複製進 rpi3 中 `$sudo cp -a target/* /media/${USER}/${ROOTFS}/` 16. 完成! ### ROS on Raspberry Pi3 1. 修改 source.list `$cd /etc/apt` `$vim source.list` 在最後加上 ``` deb-src http://free.nchc.org.tw/raspbian/raspbian jessie main contrib non-free rpi deb http://free.nchc.org.tw/raspbian/raspbian jessie main contrib non-free rpi deb http://free.nchc.org.tw/ubuntu-ports/ trusty main universe ``` > 前面兩個是把 raspbain 的鏡像站改成國網中心的伺服器 後面就是把 ubuntu 的套件庫加進去 > [name=阿Hua] 2. 後續照著官方 ubuntu armhf 的教學: http://wiki.ros.org/indigo/Installation/UbuntuARM > 在 sudo apt-get update 可能會遇到錯誤 此時就輸入 sudo apt-get install ros- 在 tab 兩次 如果回應 `Display all 2825 possibilities? (y or n)` 那就代表成功抓到套件,就可忽略錯誤繼續執行! > [name=阿Hua] ### OROCOS + Xenomai2.6 on Pi3 > 目前尚未完成 > [name=阿Hua] http://rtt-lwr.readthedocs.io/en/latest/install/install.html > 安裝 orocos2.9 (build from source) > [name=阿Hua] native build : kdltypekit At `~/orocos-2.9_ws/src/orocos_toolchain/rtt/config/` 修改 `export OROCOS_TARGET=xenomai` `export XENOMAI_ROOT_DIR=/home/hua/target/usr/xenomai` `export XENOMAI_INCLUDE_DIR=/home/hua/target/usr/xenomai/include` `export XENOMAI_NATIVE_LIBRARY=/home/hua/target/usr/xenomai/include/native` mkdir -p ~/orocos-2.9_ws/src cd ~/orocos-2.9_ws/src wstool init wstool merge https://raw.githubusercontent.com/kuka-isir/rtt_lwr/rtt_lwr-2.0/lwr_utils/config/orocos_toolchain-2.9.rosinstall wstool update -j2 cd orocos_toolchain git submodule foreach git checkout toolchain-2.9 git submodule foreach git pull cd ~/orocos-2.9_ws/ catkin init catkin config --install --extend /opt/ros/indigo/ catkin config --cmake-args -DCMAKE_BUILD_TYPE=Release `catkin build --cmake-args -DCMAKE_TOOLCHAIN_FILE=/opt/ros/indigo/share/ros/rostoolchain.cmake` test( maybe not correct ) /usr/lib/arm-linux-gnueabihf/librt.so ( 必須重新導向 ) 修改 /home/hua/orocos-2.9_ws/src/orocos_toolchain/utilrb/CMakeLists.txt ++ set(RUBY_ARCH_DIR /home/hua/root/usr/lib/ruby/1.9.1/arm-linux-eabihf) ++ set(RUBY_RUBY_LIB_PATH /home/hua/root/usr/lib/ruby/1.9.1) 修改 /home/hua/orocos-2.9_ws/src/orocos_toolchain/typelib/CMakeLists.txt ++ set(LibXML_FOUND true) 修改/home/hua/orocos-2.9_ws/src/orocos_toolchain/typelib/cmake/RubyExtensions.cmake ++ set(RUBY_ARCH_DIR /home/hua/root/usr/lib/ruby/1.9.1/arm-linux-eabihf) ++ set(RUBY_RUBY_LIB_PATH /home/hua/root/usr/lib/ruby/1.9.1) ++ set(RUBY_VERSION 1.9.1) ++ set(RUBY_CFLAGS -O2 -march=armv7-a) 修改/home/hua/orocos-2.9_ws/src/orocos_toolchain/typelib/bindings/ruby/CMakeLists.txt -- if (RUBY_VERSION_MAJOR EQUAL 1 AND RUBY_VERSION_MINOR LESS 9) -- message(FATAL_ERROR "typelib required Ruby version 1.9.3 or later") -- endif() ### Xenomai3 on Raspberry pi2 1. 下載 raspberrypi linux kernel `$git clone https://github.com/raspberrypi/linux.git` `$git checkout rpi-4.1.y` > 配合 xenomai 所支援的最新版本 > [name=阿Hua] 2. 下載 xenomai3 `$git clone http://git.xenomai.org/xenomai-3.git/` `$git checkout v3.0.2` > 因為目前的 master 中,沒有 ipipe-4.1.18-arm-4.patch,所以要切換至 v3.0.2 的分支。[name=阿Hua] > 切換到 xenomai-3 的 "next" branch,然後 ipipe patch 額外指定 [name=jserv] > 老師,這麼做的原因是因為 next 是目前最新的版本嗎? > 在 https://xenomai.org/getting-the-xenomai-code/ 中提到 > the next branch tracks the latest commits pending merge into the master branch, it contains the most bleeding edge work. This branch may be rebased until it gets merged into the master branch eventually. > [name=阿Hua] > 因為要準備對 upstream 做出貢獻 > [name=jserv] 3. 下載 xenomai3 on bcm2709 patch ``` $wget http://www.blaess.fr/christophe/files/article-2016-05-22/patch-xenomai-3-on-bcm-2709.patch ``` ``` diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 5b894d6..d9a61ca 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -348,6 +348,7 @@ config ARCH_BCM2709 select MACH_BCM2709 select VC4 select FIQ + select IPIPE_ARM_KUSER_TSC if IPIPE help This enables support for Broadcom BCM2709 boards. ``` > 這個 patch 解決了編譯上的問題及補足函式庫[name=阿Hua] 4. Patch Xenomai 到 Linux kernel 中: ``` $scripts/prepare-kernel.sh --linux=../linux/ --ipipe=kernel/cobalt/arch/arm/patches/ipipe-core-4.1.18-arm-4.patch --arch=arm ``` > 在xenomai3目錄裡進行 [name=shengwen] 5. 打入 patch `$cat patch-xenomai-3-on-bcm-2709.patch| patch -p1` > 鍵盤預設 | patch -p1 打不出來要改鍵盤配製http://blog.csdn.net/c80486/article/details/8460271 > [name=YUENCHU] 6. 載入組態檔 `$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig` `$make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig` ``` CPU Power Management ---> CPU Frequency scaling ---> [ ] CPU Frequency scaling CPU idle ---> [ ] CPU idle PM support Kernel Features ---> [ ] Contiguous Memory Allocator [ ] Allow for memory compaction Kernel Hacking ---> [ ] KGDB: kernel debugger ---> Boot options ---> Kernel command line type ---> (X) Extend bootloader kernel arguments ``` > 可以關掉一些音訊影像設定,降低外部中斷的影響,通常都在device driver的選項中,實測之後再補上[name=阿Hua] 7. 編譯核心 ``` $make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs ``` > -j num 利用平行運算編譯加速,num 幾個 threads[name=阿Hua] > `$make -j 5 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs`[name=shengwen] > 如果加入 sudo 的 prefix 會導致,在編譯時會讀取 root 的環境變數,而使得設定在 user 中的環境變數無效 (`~/.bashrc`)[name=阿Hua] 8. 輸出編譯完的模組 ``` $make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=dist modules_install ``` 9. 複製 zImage `$cp arch/arm/boot/zImage /media/${USER}/boot` 10. 複製 device tree * 備份(optional) `$cp -r /media/$(USER)/boot/overlays /media/$(USER)/boot/overlays_bak` * 移除舊 device tree 及複製 device tree `$rm /media/$(USER)/boot/overlays/*` `$cp arch/arm/boot/dts/overlays/*.dtb /media/$(USER)/boot/overlays` `$cp arch/arm/boot/dts/bcm2709-rpi-2-b.dtb /media/${USER}/boot` ``` config.txt修改如下 kernel=${zImage name} device_tree=bcm2709-rpi-2-b.dtb ``` > kernel變數決定開機的kernel映像[name=shengwen] 11. 複製模組 ``` $sudo cp -r linux/dist/lib/modules/* /media/${USER}/${ROOT}/lib/modules ``` > 複製到pi根目錄下的lib/modules目錄中( /lib/modules )[name=shengwen] 12. cobalt kernel 參數設定 > 下面這個應該在xenomai-3下執行才對[name=shengwen] > 嗯嗯,謝謝提醒![name=阿Hua] ``` $./scripts/bootstrap --with-core=cobalt –enable-debug=partial $./configure CFLAGS="-march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ffast-math" --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --enable-smp ``` > $./scripts時,如果遇到 perl 的問題: > http://dev.sopili.net/2014/07/ubuntu-perl-language-lcall-unset.html > $./configure CFLAGS下的參數必須配合SoC的版本 rp2 bcm2709 -> armv7 -> enable smp > http://xenomai.org/installing-xenomai-3-x/ > [name=阿Hua] 13. 開始編譯 `$make DESTDIR=${PWD}/target install` > pwd環境變數要大寫否則會失敗[name=shengwen] 14. 將 cobalt kernel 複製進 pi 中 `$sudo cp -a target/* /media/${USER}/${ROOTFS}/` 15. 完成! ### Xenomai3 on Raspberry pi3 > 利用跟pi2一樣的方法後,pi3可以成功開機! > device_tree換成bcm2710-rpi-3-b.dtb > 會導致UART無法輸入訊息Q_Q > 但會正常輸出 dmesg,看起來是 Rx 沒有運作 > 將device_tree換成bcm2709-rpi-2-b.dtb後就可以運作啦! > 耶耶耶耶~ > 不過這應該是pi3有向下相容的緣故 > 將device_tree切換回bcm2710-rpi-3-b.dtb > 用ssh登入即可![name=阿Hua] > good job![name=YUEHCHU] > 這個沒有說清楚意思,是先使用bcm2709-rpi-2-b.dtb,> 然後再替換成bcm2710-rpi-3-b.dtb?[name=jserv] > 不用 直接改用2710的dtb就好![name=workfunction] ### Xenomai3 on Beaglebone Black Usage:http://elinux.org/BeagleBoardUbuntu#Method_1:_Download_a_Complete_Pre-Configured_Image Default username/password: * username: ubuntu * password: temppwd `git clone https://github.com/RobertCNelson/bb-kernel` `git checkout 4.1.26-bone22` `./bulid_kernel.sh` > bulid_kernel.sh在幫忙檢查安裝所需套件,某些 linux distribution 會讀不到[name=阿Hua]
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up