CHZhan
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Xenomai 3 --- cobalt & mercury contributed by <`RainboeEye0486` 、 `fdfdd12345628`> ###### tags: `面試` ## PREEMPT RT (Mercury core) ### 硬體: Jetson nano #### 規格 ```shell $ uname -a Linux haha-desktop 4.9.201-rt134 #1 SMP PREEMPT RT Sun May 9 05:27:57 CST 2021 aarch64 aarch64 aarch64 GNU/Linux ``` #### 環境設定 我們在 pc 上面 cross compile 。 #### 編譯 PREEMPT RT 的作業系統 由於 Jetson nano 的系統是 nvidia 提供程式碼,因此需要使用他們的原始碼來修改。 [原始討論串](https://forums.developer.nvidia.com/t/preempt-rt-patches-for-jetson-nano/72941) ``` # Install required packages sudo apt-get update sudo apt-get install libncurses5-dev sudo apt-get install build-essential bc sudo apt-get install lbzip2 sudo apt-get install qemu-user-static # Create build folder mkdir $HOME/jetson_nano cd $HOME/jetson_nano # Download the following files in the jetson_nano folder: # L4T Jetson Driver Package https://developer.nvidia.com/embedded/dlc/r32-3-1_Release_v1.0/t210ref_release_aarch64/Tegra210_Linux_R32.3.1_aarch64.tbz2 # L4T Sample Root File System https://developer.nvidia.com/embedded/dlc/r32-3-1_Release_v1.0/t210ref_release_aarch64/Tegra_Linux_Sample-Root-Filesystem_R32.3.1_aarch64.tbz2 # L4T Sources: https://developer.nvidia.com/embedded/dlc/r32-3-1_Release_v1.0/Sources/T210/public_sources.tbz2 # GCC Tool Chain for 64-bit BSP https://developer.nvidia.com/embedded/dlc/l4t-gcc-7-3-1-toolchain-64-bit # Extract files sudo tar xpf Tegra210_Linux_R32.3.1_aarch64.tbz2 cd Linux_for_Tegra/rootfs/ sudo tar xpf ../../Tegra_Linux_Sample-Root-Filesystem_R32.3.1_aarch64.tbz2 cd ../../ tar -xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz sudo tar -xjf public_sources.tbz2 tar -xjf Linux_for_Tegra/source/public/kernel_src.tbz2 # Apply PREEMPT-RT patches cd kernel/kernel-4.9/ ./scripts/rt-patch.sh apply-patches # Compile kernel TEGRA_KERNEL_OUT=jetson_nano_kernel mkdir $TEGRA_KERNEL_OUT export CROSS_COMPILE=$HOME/jetson_nano/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- make ARCH=arm64 O=$TEGRA_KERNEL_OUT tegra_defconfig make ARCH=arm64 O=$TEGRA_KERNEL_OUT menuconfig # This option should already be selected: Kernel Features -> Preemption Model: Fully Preemptible Kernel (RT) # You can modify other options for your kernel, like the timer frequency (or anything you need): Kernel Features -> Timer frequency: 1000 HZ # After saving the configuration and exiting, start the kernel compilation make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j4 # Copy results sudo cp jetson_nano_kernel/arch/arm64/boot/Image $HOME/jetson_nano/Linux_for_Tegra/kernel/Image sudo cp -r jetson_nano_kernel/arch/arm64/boot/dts/* $HOME/jetson_nano/Linux_for_Tegra/kernel/dtb/ sudo make ARCH=arm64 O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$HOME/jetson_nano/Linux_for_Tegra/rootfs/ cd $HOME/jetson_nano/Linux_for_Tegra/rootfs/ sudo tar --owner root --group root -cjf kernel_supplements.tbz2 lib/modules sudo mv kernel_supplements.tbz2 ../kernel/ # Apply binaries cd .. sudo ./apply_binaries.sh # Generate Jetson Nano image cd tools sudo ./jetson-disk-image-creator.sh -o jetson_nano.img -s 14G -b jetson-nano -r 100 ``` #### 安裝 xenomai (PREEMPT_RT 版本) 當我們把 PREEMPT_RT 成功開起來之後,接下來要能夠安裝 Xenomai 提供的第二個核心以及 執行 ```shell $ uname -r 4.9.201-rt134 ``` 我們當前的 linux kernel 版本是4.9,並且已經做 RT 的處理。 這裡參考[Xenomai 3 官方安裝說明](https://xenomai.org/documentation/xenomai-3/html/README.INSTALL/index.html) ```shell $ curl -O https://xenomai.org/downloads/xenomai/stable/xenomai-3.1.tar.bz2 $ tar -xvf xenomai-3.1.tar.bz2 $ cd xenomai-3.1 ~/xenomai-3.1 $ ./configure --with-core=mercury --enable-smp --enable-pshared ~/xenomai-3.1 $ sudo make install ``` 之後會安裝在 `/usr/xenomai` 底下。 #### 測試 ##### CyclicTest 首先取得相依套件 ```shell $ sudo apt-get install build-essential libnuma-dev ``` 安裝 ```shell $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git $ cd rt-tests $ make all $ sudo cp ./cyclictest /usr/bin/ ``` 安裝完畢之後,執行 ```shell $ sudo cyclictest -p80 -n -D 60 ``` 設定 thread priority 最高為80,測試時間持續60s ,並且使用 `stress --cpu 4` x來讓系統滿載,輸出結果如下 ``` # /dev/cpu_dma_latency set to 0us policy: fifo: loadavg: 3.81 2.59 1.68 6/557 1265 T: 0 ( 1265) P:80 I:1000 C: 59994 Min: 6 Act: 12 Avg: 9 Max: 37 ``` 在系統空載時執行結果如下 ``` # /dev/cpu_dma_latency set to 0us policy: fifo: loadavg: 2.15 2.81 1.95 2/551 1286 T: 0 ( 1276) P:80 I:1000 C: 59997 Min: 5 Act: 8 Avg: 9 Max: 41 ``` 或是也可以使用 xenomai 自帶的 cyclictest ,路徑為 `/usr/xenomai/demo/cyclictest` 執行結果如下 ![](https://i.imgur.com/cUoUTqX.png) ``` T: 0 ( 1081) P:99 I:1000 C: 118912 Min: 15 Act: 28 Avg: 28 Max: 1066 ``` :::info Jetson Nano 後面沒有繼續開發下去了,原因是我們發現在 Nvidia 發布的 kernel 版本當中並沒有對 real time linux 支援,並且 kernel 的版本也跟 xenomai 支援的版本相差太大,只能等 Nvidia 官方更新版本 ::: ### 硬體: Raspberry pi 在官方 git 中尋找有 `rt` 的 branch (例如 `rpi-4.19.y-rt`)就可以直接編譯出有 PREEMPT RT 的 kernel ,接個開機後再去編譯 Xenomai 3.1 即可。 ## Xenomai 3 (cobalt) ### 硬體: Raspberry zero, 3, 4 不同 rpi 的差異之處會在下面標明,無標明表示通用 ==**前人成果與先前嘗試**== 因為在之前[成大資工 Wiki](http://wiki.csie.ncku.edu.tw/embedded/xenomai) 使用的版本比較舊了,所以在這邊更新相關的指令跟版本 在 [xenomai.org](https://xenomai.org/downloads/) 提供下載的版本中,可以選擇 downloads/xenomai/stable 中的 3.1 版本下載,但是如果想要完成 xenomai 提供的 Cobalt 組態,必須安裝 ipipe patch ,注意 ipipe patch 的版本需要與 kernel 的版本一致,並且 subversion 相差盡量在個位數以內,不然會無法安裝成功,例如一開始我使用 4.9.80 版本,出現了這樣的 error message : ```shell prepare-kernel.sh: Unable to patch kernel 4.9.80 with ipipe-core-4.19.144-arm-10.patch. ``` 執行 ```shell $ git clone https://github.com/raspberrypi/linux.git ``` 需要花上一段時間 clone ,接著進入資料夾並檢查 branch ```shell $ cd linux $ git checkout rpi-4.19.y $ git branch * rpi-4.19.y rpi-5.10.y ``` 從 [raspberrypi/linux](https://github.com/raspberrypi/linux) 對照 [ipipe patch](https://xenomai.org/downloads/ipipe/v4.x/arm/) 後選擇了 4.19.124 這個版本,但是因為目前的版本是 4.9.80 (在 Makefile 中會提供版本資訊) ,因此需要透過檢查之前的 commit 找到[ 4.19.124 版本](https://github.com/raspberrypi/linux/tree/1bab61d3e8cd96f2badf515dcb06e4e1029bc017) 執行 ```shell $ git reset 1bac61d3e8 ``` 回復到 4.19.124 版本。之後進入下載下來的 xenomai-3.1 資料夾,執行 ```shell $ cd srcipts $ ./prepare-kernel.sh --linux=[route]/linux --ipipe=../kernel/ipipe/ipipe-core-4.19.124-cip27-arm-09.patch --arch=arm ``` 這邊路徑我是使用了絕對路徑,指定我們剛剛下載下來的 raspberrypi linux ,並指定 patch 為載下來的 ipipe-core-4.19.124-cip27-arm-09.patch ,4.19.124 版本,這個版本連 subversion 都能吻合,所以使用這個版本。 > - General setup >> Preemption Model >> Fully Preemptible Kernel(RT) > - General setup >> Timers subsystem >> Timer tick handling >> Idle dynticks system (tickless idle) > - Kernel Features >> Symmetric Multi-Processing :::info :bulb: **失敗版本** 以下是我們嘗試過的版本,同時能夠在 raspberry pi 以及 xenomai ipipe patch 找到一樣的版本,並且 patch 能夠成功被安裝,但是在 make 並產生映像檔的時候會出現錯誤,錯誤內容包括未定義的變數(但是在檔案中根本沒有出現過這個變數)、找不到 header file (所有的 linux kernel 版本都沒有出現過這個 header file )等等, ipipe patch 穩定的版本真的很難找。 - 4.4.43 - 4.14.85 - 4.19.128 - 4.19.124-rt53 - 4.19.124 ::: > 之前的問題多數無法單獨被解決。原因可能是 Xenomai 的 patch 本身版本就比較少,並且缺乏維護,加上 raspberry pi 提供的 linux kernel 版本跟 Xenomai 參考的 linux 版本可能有所出入,所以就算 patch 成功安裝,可能還是會導致打包成映像檔的時候失敗。經過多方嘗試之後,我們終於發現一個穩定的版本可以使用。 #### 安裝 Xenomai 環境設定 需要先滿足[官方提供的硬體規格](https://source.denx.de/Xenomai/xenomai/-/wikis/Supported_Hardware) **==安裝環境==** 電腦 : `5.4.0-73-generic #82~18.04.1-Ubuntu SMP Fri Apr 16 15:10:02 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux` **Raspberry zero w** : 安裝 [2018-04-18-raspbian-stretch](https://downloads.raspberrypi.org/raspbian/images/raspbian-2018-04-19/) ,因為與等等要安裝的 kernel 版本最近,而且也可以成功開機。 #### 安裝過程 ==**STEP0:必要環境套件**== 接下來的環境預設是在 PC 上,因為用 cross compile 比在 rpi 上編譯快不少。 在 PC 執行下列指令安裝必須套件: ```shell $ sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev ``` 接著安裝 cross-compile 用的 gcc ```shell sudo apt install crossbuild-essential-armhf ``` ==**STEP1:檔案配置**== 首先透過以下指令完成檔案的配置,在 /home 執行 ```shell ~$ mkdir ~/rpi-kernel ~$ cd ~/rpi-kernel ~rpi-kernel$ mkdir rt-kernel ``` 其中 rt-kernel 是用來放置我們編譯完的檔案,現在我們暫時不用理會它 ==**STEP2:下載核心**== 在 rpi-kernel 底下下載 linux kernel 及相關工具。執行 ```shell ~/rpi-kernel$ git clone https://github.com/raspberrypi/linux.git ~/rpi-kernel$ git clone https://github.com/raspberrypi/tools.git --depth 3 ``` 然後需要等一陣子,下載整個核心本來就需要一定的時間(或是看一下 STEP4 ,可以只複製指定的 commit)。 ==**STEP3: xenomai 下載**== 在 [xenomai.org](https://xenomai.org/downloads/) 提供下載的版本中,選擇 downloads/xenomai/stable 中的 3.1 版本下載並解壓縮,放置在 rpi-kernel 目錄底下。 ```shell curl -O https://xenomai.org/downloads/xenomai/stable/xenomai-3.1.tar.bz2 tar -xf xenomai-3.1.tar.bz2 ``` 並且下載關於 xenomai 雙核心系統必要的 patch ,提供我們在 Adeos 中的 ipipe ```shell ~/rpi-kernel$ wget https://xenomai.org/downloads/ipipe/v4.x/arm/ipipe-core-4.14.36-arm-1.patch ``` ==**STEP4:同步版本**== ```shell ~/rpi-kernel$ cd linux ~/rpi-kernel/linux$ git reset --hard 719df11c ~/rpi-kernel/linux$ git merge d6949f48093c2d862d9bc39a7a89f2825c55edc4 ``` 當我們使用 xenomai patch 去修補 lernel 的時候,必須確保兩者版本一致,但是我們現有的版本屬於 4.14.91 ,因此需要回溯到 4.14.36 版本。 也可以不用 clone 整個 kernel 下來,可以直接去 [https://github.com/raspberrypi/linux/tree/d6949f48093c2d862d9bc39a7a89f2825c55edc4](https://github.com/raspberrypi/linux/tree/d6949f48093c2d862d9bc39a7a89f2825c55edc4) 下載指定 commit 。 ==**STEP5:修補 kernel**== 執行 ```shell ~/rpi-kernel/xenomai-3.1/scripts$ ./prepare-kernel.sh --linux=linux/ --arch=arm --ipipe=ipipe-core-4.14.36-arm-1.patch ``` 會顯示 `Unable to patch kernel 4.14.36/7 with ipipe-core-4.14.36/7-arm-1.patch.` 看紀錄可以看出以下兩個檔案不能 patch ``` linux/drivers/irqchip/irq-bcm2835.c linux/drivers/irqchip/irq-bcm2836.c ``` 這時候只要將[這裡的兩個檔案](https://github.com/lemariva/RT-Tools-RPi/tree/master/xenomai/v3.0.7)放入`linux/drivers/irqchip`並且覆蓋原檔案即可。 接著再執行一次 patch : ```shell ~/rpi-kernel/xenomai-3.1$ ./scripts/prepare-kernel.sh --linux=linux/ --arch=arm --ipipe=ipipe-core-4.14.36-arm-1.patch --verbose [ ... ] I-pipe core/arm #1 installed. Links installed. Build system ready. ``` 沒有出現任何錯誤,代表我們的 patch 成功安裝。 ==**STEP6:工具以及環境參數設置**== ```shell ~/rpi-kernel$ export ARCH=arm ~/rpi-kernel$ export CROSS_COMPILE=arm-linux-gnueabihf- ~/rpi-kernel$ export INSTALL_MOD_PATH=~/rpi-kernel/rt-kernel ~/rpi-kernel$ export INSTALL_DTBS_PATH=~/rpi-kernel/rt-kernel ``` 可以使用 `$echo $INSTALL_MOD_PATH` 來檢查包含的變數,注意 `=` 的前後不要加空格。 - `ARCH` : 系統架構,以 rpi 來說是 `arm` 。 - `CROSS_COMPILE` : tool-chain 路徑。 - `INSTALL_MOD_PATH` : 安裝編譯 kernel module 的路徑。 - `INSTALL_DTBS_PATH` : 安裝編譯 DTB (Device Tree Blob) 路徑。 ==**STEP7: kernel 配置**== 1. Raspberry zero 執行 ```shell ~/rpi-kernel$ export KERNEL=kernel ~/rpi-kernel$ cd ~/rpi-kernel/linux/ ~/rpi-kernel/linux/$ make bcmrpi_defconfig ``` 2. Raspberry 3 執行 ```shell ~/rpi-kernel$ export KERNEL=kernel7 ~/rpi-kernel$ cd ~/rpi-kernel/linux/ ~/rpi-kernel/linux/$ make bcm2709_defconfig ``` 3. Raspberry 4 執行 ```shell ~/rpi-kernel$ export KERNEL=kernel7l ~/rpi-kernel$ cd ~/rpi-kernel/linux/ ~/rpi-kernel/linux/$ make bcm2711_defconfig ``` 並打開 kernel 的選項配置 ```shell ~/rpi-kernel/linux/$ make menuconfig ``` >- **Disable** CPU Frequency scaling: CPU Power Management → CPU Frequency scaling → CPU Frequency scaling >- **Disable** Allow for memory compaction: Kernel Features → Contiguous Memory Allocator >- **Disable** Contiguous Memory Allocator: Kernel Features → Allow for memory compaction >- **Disable** KGDB: kernel debugger: KGDB: kernel debugger → Kernel Hacking 視情況修改`LOCALVERSION`以防止自己的 kernel 被系統更新蓋掉。 ==**STEP8: 編譯 kernel**== ```shell ~/rpi-kernel/linux$ make -j4 zImage ~/rpi-kernel/linux$ make -j4 modules ~/rpi-kernel/linux$ make -j4 dtbs ~/rpi-kernel/linux$ make -j4 modules_install ~/rpi-kernel/linux$ make -j4 dtbs_install ``` 預計能夠在 `make -j4 modules_install` 跑完後看到 `DEPMOD 4.14.37-v7+` 最後執行 ```shell ~/rpi-kernel/linux$ mkdir $INSTALL_MOD_PATH/boot ~/rpi-kernel/linux$ cp ./arch/arm/boot/zImage $INSTALL_MOD_PATH/boot/$KERNEL.img ~/rpi-kernel/linux$ cp INSTALL_DTBS_PATH ~/rpi-kernel/linux$ cp arch/arm/boot/dts/*.dtb $INSTALL_DTBS_PATH/boot/ ~/rpi-kernel/linux$ mkdir $INSTALL_MOD_PATH/boot/overlay ~/rpi-kernel/linux$ cp arch/arm/boot/dts/overlays/*.dtb* $INSTALL_MOD_PATH/boot/overlays/ ~/rpi-kernel/linux$ cp arch/arm/boot/dts/overlays/README $INSTALL_MOD_PATH/boot/overlays/ ``` 打包完成 ==**STEP9: 將 kernel 搬移至 rpi 上**== ```shell ~/rpi-kernel/linux$ cd $INSTALL_MOD_PATH ~/rpi-kernel/rt-kernel$ tar czf ../xenomai-kernel.tgz * ~/rpi-kernel/rt-kernel$ cd .. ~/rpi-kernel$ scp xenomai-kernel.tgz pi@<ipaddress>:/tmp ``` 這裡的 `ipaddress` 放置 rpi 的 IP , ==**STEP10: 進入 rpi 系統**== 在 rpi 內,將剛剛複製的檔案安裝進系統 ```shell ~$ cd /tmp /tmp$ tar xzf xenomai-kernel.tgz /tmp$ cd boot /tmp/boot$ sudo cp *.dtb /boot/ /tmp/boot$ sudo cp -rd * /boot/ /tmp/boot$ cd ../lib /tmp/lib$ sudo cp -dr * /lib/ /tmp/lib$ cd ../boot/overlays /tmp/boot/overlays$ sudo cp -d * /boot/overlays /tmp/boot/overlays$ cd ../boot /tmp$ sudo cp -d bcm* /boot/ ``` 並且需要修改 `/boot/config.txt` ,確保系統開機進入我們的 kernel 1. Raspberry zero ``` # 加上這行 kernel=kernel.img ``` 2. Raspberry 3 ``` # 加上這行 kernel=kernel7.img ``` 3. Raspberry 4 ``` # 加上這行 kernel=kernel7l.img ``` 重新開機,等待好一段時間後(等LED燈不再閃爍時),就可以成功看到 `dmesg` 出現 I-pipe 的訊息了: ```shell $ dmesg | grep -i xenomai I-pipe: head domain Xenomai registered. [Xenomai] Cobalt vX.Y.Z enabled ``` 就可以繼續安裝 xenomai 了,呼~(擦汗):wink: #### 參考資料: 1. [Xenomai 3 官方安裝說明](https://xenomai.org/documentation/xenomai-3/html/README.INSTALL/index.html) 2. [Raspberry Pi: Real Time System - Xenomai Patching Tutorial for Kernel 4.14.y](https://lemariva.com/blog/2018/07/raspberry-pi-xenomai-patching-tutorial-for-kernel-4-14-y) > [name=詹承翰]我是用kernel=7,需要重新編一個image檔嗎 > OK > [name=fdfdd12345628]不用,這個只是最後 kernel.img 的檔名,可以隨意命名,不過如果在 `/boot/config.txt` 沒有特別指定,他會針對不同的硬體選預設的 kernel.img ,所以有指定就沒差,隨便命名。 > [Raspberry Pi: Real Time System - Preempt-RT Patching Tutorial for Kernel 4.14.y](https://lemariva.com/blog/2018/07/raspberry-pi-preempt-rt-patching-tutorial-for-kernel-4-14-y) > 這個 > 是不是也可以先編起來放啊 > rpi4 版本的 > [name=fdfdd12345628] 可以,不過他已經有編好的,有點想要直接用 #### 實驗 ##### latency ###### CyclicTest ![](https://i.imgur.com/M1pTTc7.png) :::info 因為這個版本比較老舊,針對此版本的實驗暫時擱置,嘗試用比較新的版本重新編譯 ::: --- ==**rpi kernel 5.4**== 目前在實做的版本當中成功的是 4.19 kernel 搭配 3.1 xenomai 這個組合 ,但是由於 4.19 的版本已經是四年前提出的版本,太過老舊以至於失去討論意義,我們觀察了由 xenomai 官方提供的 ipipe 版本,發現 5.4.93 的版本是最符合 Rasberry pi linux 的版本,而在 Rasberry pi linux 的版本當中與之最接近的是 5.4.83 同時也是 5.4.y 版本的最新 release ,但是因為版本號不一樣,所以在 patch 的時候會發現有許多地方沒辦法直接安裝,因此選擇執行 ```shell $ patch -p1 -N --ignore-whitespace --fuzz 3 < ../ipipe-core-5.4.93-arm-0.patch| ``` 指令來取代原本的 ```shell $ ./prepare-kernel.sh --linux=../../linux --arch=arm --ipipe=ipipe-core-5.4.93-arm-0.patch --verbose ``` 指令,原因是有些檔案之所以沒辦法 patch 過的原因是因為 patch 檔案當中的變更被認定為危險或是非法的,所以被拒絕 apply 這些變更並且中止, 或者是可以去嘗試找到一個方式去使得 patch 以較少變動去 apply 進 kernel 裡 > from [linux kernel Documentation](https://android.googlesource.com/kernel/common/+/android-3.18/Documentation/applying-patches.txt) : > If patch encounters something that doesn't look quite right it has two options. It can either refuse to apply the changes and abort or it can try to find a way to make the patch apply with a few minor changes. 可能行數的 bias 不同,也就是以某行當作基準往下加的行數不同,也有可能是變更之後會使某些 API 的連接出現問題,而在 patch 的過程中我們可以透過參數 `--fuzz` 來使放寬限制,這樣做的好處是會模糊掉一部分的 patch 規則,畢竟版本如果不完全相容的話檔案可能會有蠻多地方會有出入的,但是這樣做是有風險的,有時候雖然 patch 過了在編譯 kernel 的時候會發生一些意想不到的錯誤或是直接不能開機。 另一個可以嘗試的辦法是閱讀相關的 `.rej` 檔並且嘗試修改,因為每個 patch 過不了的檔案都會留下一個 `.rej` 檔,上面會紀錄舊版跟新版之間的差異。 最後在在執行完 patch 的指令並且模糊化規則後只剩下關於 `arch/arm/kernel/entry-header.S` 的錯誤 ```shell arch/arm/kernel/entry-header.S: Assembler messages: arch/arm/kernel/entry-header.S:470: Error: Macro `slow_restore_user_regs' was already defined scripts/Makefile.build:348: recipe for target 'arch/arm/kernel/entry-common.o' failed make[1]: *** [arch/arm/kernel/entry-common.o] Error 1 Makefile:1732: recipe for target 'arch/arm/kernel' failed ``` 以及 `drivers/irqchip/irq-bcm2835.c` ,與上面相似的報錯。 我們的解決方式是用相同版本(5.4.83 kernel)的檔案 [entry-header.S](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/arm/kernel/entry-header.S) 以及 [irq-bcm2835.c](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/irqchip/irq-bcm2835.c) 替代,在 patch 的階段便不會報錯。 接著在編譯 kernel 的時候,執行 ```shell $ make -j4 modules ``` 時,出現以下錯誤 ```shell In file included from include/xenomai/cobalt/kernel/thread.h:26:0, from include/xenomai/cobalt/kernel/sched.h:24, from kernel/xenomai/intr.c:24: kernel/xenomai/intr.c: In function ‘inc_irqstats’: include/xenomai/cobalt/kernel/stat.h:61:49: error: passing argument 1 of ‘atomic_long_xchg’ from incompatible pointer type [-Werror=incompatible-pointer-types] __prev = (xnstat_exectime_t *)atomic_long_xchg(&(sched)->current_account, (long)(new_account)); \ ^ include/xenomai/cobalt/kernel/stat.h:147:2: note: in expansion of macro ‘xnstat_exectime_set_current’ xnstat_exectime_set_current(sched, new_account); \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~ kernel/xenomai/intr.c:123:2: note: in expansion of macro ‘xnstat_exectime_lazy_switch’ xnstat_exectime_lazy_switch(sched, &statp->account, start); ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` > 我們遇到的這個問題,之前在編譯 4.19 版本的時候不曾出現過, 5.4 版本的時候才有這個錯誤。 :::info Xenomai 將逐步拋棄 ipipe,改用 ==[EVL](https://evlproject.org/)== (成為 Xenomai 4 的基礎),針對較新的 Linux 核心,請見 [ports](https://evlproject.org/ports/) :notes: jserv ::: --- :::warning 將上方 Xenomai 相關記錄移動到另外一個共筆頁面,使得 EVL 相關進度更顯著。 :notes: jserv ::: ## Reference 1. [Linux 核心設計: PREEMPT_RT 作為邁向硬即時作業系統的機制](https://hackmd.io/@sysprog/preempt-rt) 2. [The Real-Time Linux Kernel: A Survey on PREEMPT_RT](https://dl.acm.org/doi/fullHtml/10.1145/3297714) 3. [Xenomai](https://stackoverflow.com/questions/65163745/is-rtos-effective-for-cloud-edge-computing) 4. [xenomai3 install on raspberrypi 4](http://www.simplerobot.net/2019/12/xenomai-3-for-raspberry-pi-4.html) 5. [Raspberry Pi: Real Time System - Xenomai Patching Tutorial for Kernel 4.14.y](https://lemariva.com/blog/2018/07/raspberry-pi-xenomai-patching-tutorial-for-kernel-4-14-y?fbclid=IwAR0k-dXYQM9jnrjavWHf7z8ITnhqYIcrQPPrvRtlCg63q2_WAbgNokzmnbc) ###### tags: `linux2021`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    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

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully