Biên dịch và porting Linux Kernel cho BeagleBone Black (Phần 3)
Cross-compile và porting Linux kernel cho BeagleBone Black, cấu hình ARM cross-compile và boot kernel từ U-Boot.
1. Tải source code
Clone Linux repository:
1
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux
Repository này khoảng 2.5GB, hãy kiên nhẫn chờ đợi.
Thêm stable repository và fetch:
1
2
3
cd linux
git remote add stable https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux
git fetch stable
Checkout phiên bản stable mới nhất:
1
git checkout remotes/stable/linux-6.1.y
2. Cross-compile kernel
Thiết lập biến môi trường:
1
2
export ARCH=arm
export CROSS_COMPILE=arm-linux-
Cấu hình kernel cho BeagleBone Black:
1
make omap2plus_defconfig # hoặc multi_v7_defconfig
Mở menu cấu hình và tắt CONFIG_GCC_PLUGINS
:
1
make menuconfig
Trong menu, tìm và disable CONFIG_GCC_PLUGINS
(dùng /
để search).
Menu cấu hình kernel Linux với các tùy chọn build
Biên dịch kernel:
1
make -j$(nproc)
Quá trình này sẽ mất một thời gian tùy thuộc vào CPU.
Quá trình build kernel hoàn tất thành công
Copy các file cần thiết vào thẻ SD:
1
2
cp arch/arm/boot/zImage /media/$USER/boot/
cp arch/arm/boot/dts/am335x-boneblack.dtb /media/$USER/boot/
3. Boot kernel
Khởi động minicom:
1
minicom -D /dev/ttyUSB0 -b 115200
Boot BeagleBone từ SD card (giữ nút Reset button khi cấp nguồn).
Tại prompt U-Boot =>
, thiết lập boot arguments:
1
2
=> setenv bootargs console=ttyS0,115200n8
=> saveenv
Load kernel và device tree vào memory:
1
2
=> fatload mmc 0:1 0x80200000 zImage
=> fatload mmc 0:1 0x80f00000 am335x-boneblack.dtb
Boot kernel:
1
=> bootz 0x80200000 - 0x80f00000
Bạn sẽ thấy kernel boot và cuối cùng gặp kernel panic về việc không tìm thấy root filesystem. Điều này là bình thường vì chúng ta chưa tạo root filesystem.
Tự động hóa quá trình boot:
1
2
=> setenv bootcmd 'fatload mmc 0:1 0x80200000 zImage; fatload mmc 0:1 0x80f00000 am335x-boneblack.dtb; bootz 0x80200000 - 0x80f00000'
=> saveenv
Chúc mừng! Bạn đã thành công biên dịch và boot Linux kernel trên BeagleBone Black.