RK3328 LINUX開發者指南
一、編譯 Linux 固件
1.在Ubuntu 16.04 amd64系統中安裝以下包:
sudo apt-get install bc bison build-essential curl device-tree-compiler dosfstools flex gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gdisk git gnupg gperf libc6-dev libncurses5-dev libpython-dev libssl-dev libssl1.0.0 lzop mtools parted repo swig tar zip
2.創建工作目錄:
mkdir ~/proj/roc-rk3328-cccd ~/proj/roc-rk3328-cc
3.下載 Linux SDK:
# U-Bootgit clone -b roc-rk3328-cc https://github.com/FireflyTeam/u-boot# Kernelgit clone -b roc-rk3328-cc https://github.com/FireflyTeam/kernel --depth=1# Buildgit clone -b debian https://github.com/FireflyTeam/build# Rkbingit clone -b master https://github.com/FireflyTeam/rkbin
4.編譯 U-Boot:
./build/mk-uboot.sh roc-rk3328-cc
編譯完後輸出:
out/u-boot/
├── idbloader.img├── rk3328_loader_ddr786_v1.06.243.bin├── trust.img└── uboot.img其中,
idbloader.img
: DDR 初始化與 miniloader 結合的文件。- rk3328_loader_ddr786_v1.06.243.bin: DDR 初始化文件。
trust.img
: ARM trusted 固件。uboot.img
: U-Boot映像文件。
可以配置U-BOOT:
configs/roc-rk3328-cc_defconfig
5.編譯 kernel:
相關文件:
arch/arm64/configs/fireflyrk3328_linux_defconfig: 默認內核配置。
arch/arm64/boot/dts/rockchip/rk3328-roc-cc.dts
: 開發板設備樹描述。arch/arm64/boot/dts/rockchip/rk3328.dtsi
: CPU 設備樹描述。
內核配置和更新默認配置:
# 這非常重要!export ARCH=arm64cd kernel# 首先使用默認配置make fireflyrk3328_linux_defconfig# 自定義你的 kernel 配置make menuconfig# 保存為默認配置make savedefconfigcp defconfig arch/arm64/configs/fireflyrk3328_linux_defconfig
特別說明:
Device Drivers > Network device support > Wireless LAN > Rockchip Wireless LAN support
> Rockchip Wireless LAN support 下的除「*」其他都去掉
Device Drivers > Network device support > Wireless LAN > Realtek rtlwifi family of devices
> Realtek rtlwifi family of devices 下的都去掉
配置好後即可編譯整個kernel(腳本文件內部設置使用-j4來編譯):
./build/mk-kernel.sh roc-rk3328-cc
編譯完後輸出:
out/
├── boot.img└── kernel
├── Image └── rk3328-roc-cc.dtb其中,
boot.img
: 包含Image
andrk3328-roc-cc.dtb
的映像文件, 為 fat32 文件系統格式。Image
: 內核映像。rk3328-roc-cc.dtb
: 設備樹。
二、製作根文件系統
1.安裝依賴包
sudo apt-get install qemu qemu-user-static binfmt-support debootstrap
2.下載 Ubuntu core
wget -c http://cdimage.ubuntu.com/ubuntu-base/releases/16.04.1/release/ubuntu-base-16.04.1-base-arm64.tar.gz
3.創建一個大小為 2G的根文件系統映像文件,將ubuntu core解壓到該映像中:
cd /mnt/h/projsudo fallocate -l 2000M rootfs.imgsudo mkfs.ext4 rootfs.imgsudo mkdir /mnt/tempsudo mount rootfs.img /mnt/temp sudo tar -xzvf ubuntu-base-16.04.1-base-arm64.tar.gz -C mnt/
4.複製qemu:
sudo cp -a /usr/bin/qemu-aarch64-static mnt/usr/bin/
5.複製主機DNS:
sudo cp -b /etc/resolv.conf mnt/etc/resolv.conf
6.增加有效的更新源:
vim mnt/etc/apt/sources.list
將以下源複製到sources.list中:
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to# newer versions of the distribution.deb http://ports.ubuntu.com/ubuntu-ports/ xenial main restricteddeb-src http://ports.ubuntu.com/ubuntu-ports/ xenial main restricted## Major bug fix updates produced after the final release of the## distribution.deb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricteddeb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates main restricted## Uncomment the following two lines to add software from the universe## repository.## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu## team. Also, please note that software in universe WILL NOT receive any## review or updates from the Ubuntu security team.deb http://ports.ubuntu.com/ubuntu-ports/ xenial universedeb-src http://ports.ubuntu.com/ubuntu-ports/ xenial universedeb http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universedeb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-updates universe## N.B. software from this repository may not have been tested as## extensively as that contained in the main release, although it includes## newer versions of some applications which may provide useful features.## Also, please note that software in backports WILL NOT receive any review## or updates from the Ubuntu security team.deb http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricteddeb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-backports main restricteddeb http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricteddeb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security main restricted#deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe#deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security universe#deb http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiverse#deb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-security multiversedeb http://ports.ubuntu.com/ubuntu-ports/ xenial-proposed main restricteddeb-src http://ports.ubuntu.com/ubuntu-ports/ xenial-proposed main restricted
7.chroot 到新的文件系統中:
sudo chroot mnt/
在rootfs的root用戶下設置:
# 這裡可以修改設置USER=dolphinHOST=dolphin# 創建用戶useradd -G sudo -m -s /bin/bash $USERpasswd $USER# 輸入密碼# 使能串口# 15000mbpsln -s /lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service# 安裝包apt-get updateapt-get install lightdm vim gitapt-get install ifupdown net-tools network-manager
退出
exit
8.卸載文件系統:
sudo umount rootfs/
三、打包固件
1.把Linux 根文件系統映像文件rootfs放在 out/
下:
out
目錄應包含以下文件:
$ tree out
out
├── boot.img├── kernel
│ ├── Image│ └── rk3328-roc-cc.dtb├── rootfs.img└── u-boot ├── idbloader.img ├── rk3328_loader_ddr786_v1.06.243.bin ├── trust.img └── uboot.img2.打包固件:
./build/mk-image.sh -c rk3328 -t system -r out/rootfs.img
這條命令根據《存儲映射》所描述的布局,將分區映像文件寫到指定位置,最終打包成out/system.img
。
四、燒寫
插入SD卡,如果被文件管理器自動掛載,則先將其卸載。
安裝 pv:
sudo apt-get install pv
通過檢查內核的日誌查找 SD 卡的設備文件:
dmesg | tail
如果設備文件為 /dev/
sdb,使用 dd
命令去燒錄:
pv -tpreb /path/to/your/raw/firmware | sudo dd of=/dev/sdb conv=notrunc
也可以運行以下命令將分區鏡像寫入到 SD 卡中:
sudo dd if=./out/u-boot/idbloader.img of=/dev/sdb seek=64 conv=sync,fsync
sudo dd if=./out/u-boot/uboot.img of=/dev/sdb seek=16384 conv=sync,fsync
sudo dd if=./out/u-boot/trust.img of=/dev/sdb seek=24576 conv=sync,fsync
sudo dd if=./out/boot.img of=/dev/sdb seek=32768 conv=sync,fsync
sudo dd if=./out/rootfs.img of=/dev/sdb seek=262144 conv=sync,fsync
也可以運行下面指令,將生成的統一固件 system.img 寫入到 SD 卡中:
build/flash_tool.sh -c rk3328 -d /dev/sdb -p system -i out/system.img
推薦閱讀: