Raspberry PI + cross compile & build kernel
先準備ubuntu 18 (64bit版)
2024版本
- 現在可以無人值守安裝了!! 不過用了這個反而會遇到奇怪的問題, 重新安裝 + 略過無人值守突然就好了
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
編譯檔案
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
2022版本
-
剪貼簿設定 (可以複製貼上指令)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
Install VirtualBox Guest Additions
- 重開機後, 再執行 Insert Guest Additional CD image
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Install Required Dependencies and Toolchain
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
- Install the 64-bit Toolchain for a 64-bit Kernel
sudo apt install crossbuild-essential-arm64
- Get the Kernel Sources
git clone --depth=1 https://github.com/raspberrypi/linux
-
Load 64-bit default configs (For Raspberry Pi 3, 3+, 4, 400 and Zero 2 W, and Raspberry Pi Compute Modules 3, 3+ and 4:)
-
Make image for all 64-bit Builds
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
-
把micro sd卡連接到虛擬機裡面, 然後掛載磁區
-
back up old kernel
cp -rf /media/xd/boot/* Desktop/boot_PI/
-
install the kernel modules onto the SD card (For 64-bit)
sudo env PATH=$PATH make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH=mnt/ext4 modules_install
- copy the kernel and Device Tree blobs onto the SD card
-
edit the sd/boot/config.txt file, add the following setting
kernel=kernel-madebyyou.img
-
remove SD card
- Insert SD card to PI and boot!!
上面的build kernel是使用default config, 可以用menuconfig來調整所需的功能
-
Preparing to make menuconfig
sudo apt install libncurses5-dev
-
cross-compiling a 64-bit kernel:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
- 重複上述的4-10步驟, 從 Make image for all 64-bit Builds 開始
以下是2021整理的資料
cross compile 環境
-
Install required dependencies and toolchain
sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev
-
Install the 32-bit toolchain for a 32-bit kernel (因為raspbian是32 bit)
sudo apt install crossbuild-essential-armhf
測試cross compile
- 準備一個c code
- 建立流程
- Cross compile, then copy it to PI and execute
準備Build kernel
Get sources (To download the minimal source tree for the current branch)
load default config and build (For Pi 3, Pi 3+ or Compute Module 3)
load default config and build (For Raspberry Pi 4)
Use custom config by menuconfig and build
ps. build的時間很長, 根據電腦的性能有所影響. 第一次build可以估30-60min.
複製檔案到SD卡
- copy the kernel and Device Tree blobs to your SD card
- check SD card state
- 在虛擬機掛載SD卡時, 通常會自動掛載
- 可以用df -h檢查 before/after 的變化
-
back up old kernel
cp -rf /media/xd/boot/* Desktop/boot_PI/
-
copy new kernel to SD card
-
install module in the filesystem (the second partition), ex: /media/username/rootfs
sudo env PATH=$PATH make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=sd/rootfs modules_install
-
edit the sd/boot/config.txt file, add the following setting
kernel=kernel-madebyyou.img
-
remove SD card
- Insert SD card to PI and boot!!
//以下是官網範例