瑞芯微Rockchip开发者社区
直播中

李涛

7年用户 1392经验值
私信 关注
[问答]

怎样在RK3399平台上去制作一种linux系统呢

怎样在RK3399平台上去制作一种linux系统呢?有哪些制作步骤?

回帖(1)

段朝思

2022-3-7 17:22:32
1.VM虚拟机安装和PC端ubuntu系统安装


我的配置:


修改源:


安装vmwaretool:先点击虚拟机的安装VNwaretool,然后将压缩文件复制到home目录下解压:

sudo tar -x*** VMwareTools-10.0.0-2977863.tar.gz
sudo ./vmware-install.pl
sudo apt-get remove vim-common  #更新vi编辑器
sudo apt-get install vim
sudo apt-get install git

安装vscode(以后驱动编写用):

sudo dpkg -i code_1.47.3-1595520028_amd64.deb

输入code命令即可启动VScode程序

安装交叉编译器




#安装交叉编译器:
sudo mkdir /usr/local/arm
sudo cp gcc-linaro-7.5.0-2019.12-i686_aarch64-linux-gnu.tar /usr/local/arm/ -f
sudo tar -vxf gcc-linaro-7.5.0-2019.12-i686_aarch64-linux-gnu.tar
sudo vi /etc/profile
#复制这行到文本最后一行:export PATH=$PATH:/usr/local/arm/gcc-linaro-7.5.0-2019.12-i686_aarch64-linux-gnu/bin
#安装依赖库:
sudo apt-get install l***-core lib32stdc++6

安装ARM-software:

安装rkbin

安装rkdeveloptool

sudo apt-get install libudev-dev libu***-1.0-0-dev dh-autoreconf
autoreconf -i
./configure
make
sudo make install

2.u-boot

系统分区地址表:可通过gdisk命令对分区做相应的设置



sudo git clone
-b stable-4.4-rk3399-linux #下载u-boot源码
cd u-boot #进入u-boot
sudo apt install python-pip
pip install pyelftools
make clean      #清理工程
#这里使用的firefly的开发板,所以选择firefly-rk3399_defconfi
make firefly-rk3399_defconfig ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- #编译生成.config文件,注意arch为arm而非arm64。
make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- # 编译源码

获得idbloader的命令:

#将/rkbin/bin/rk33/rk3399_ddr_800MHz_v1.24.bin复制到u-boot目录下
cd ..
cp ./rkbin/bin/rk33/rk3399_ddr_800MHz_v1.24.bin ./u-boot/
cp ./rkbin/bin/rk33/rk3399_miniloader_v1.19.bin ./u-boot/
cd u-boot
tools/mkimage -n rk3399 -T rksd -d rk3399_ddr_800MHz_v1.24.bin idbloader.img
cat rk3399_miniloader_v1.19.bin >> idbloader.img

获得rk3399_loader_v1.24.126.bin的方法:

cd ..
cd rkbin
./tools/boot_merger ./RKBOOT/RK3399MINIALL.ini

获得trust.img的方法:

cd rkbin
./tools/trust_merger  ./RKTRUST/RK3399TRUST.ini

获得uboot.img:

cd u-boot #进入u-boot目录
tools/loaderimage --pack --uboot u-boot.bin uboot.img

选项①:向eMMC烧录u-boot:

将RK3399的OTG接口与电脑相连,并使其进入Loader模式或则maskrom模式。

cp ./rkbin/trust.img ./u-boot/
cd u-boot
sudo rkdeveloptool db rk3399_loader_v1.24.126.bin
sudo rkdeveloptool ul rk3399_loader_v1.24.126.bin
sudo rkdeveloptool wl 0x4000 uboot.img
sudo rkdeveloptool wl 0x6000 trust.img
sudo rkdeveloptool rd

选项②:向sd卡烧录u-boot:

将内存卡插入读卡器,将读卡器插上电脑。

cp ./rkbin/trust.img ./u-boot/
cd u-boot
sudo dd if=idbloader.img of=/dev/sdb seek=64
sudo dd if=uboot.img of=/dev/sdb seek=16384
sudo dd if=trust.img of=/dev/sdb seek=24576


3.内核


#下载源码:
sudo git clone
-b stable-4.4-rk3399-linux
sudo apt-get install libssl-dev
sudo apt-get install genext2fs

将源码arch/arm64/boot/dts/rockchip/rk3399-linux.dtsi中的

chosen {
   bootargs = "earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 console=ttyFIQ0 rw root=PARTUUID=614e0000-0000 rootfstype=ext4 rootwait";
};

修改为

chosen {
   bootargs = "earlycon=uart8250,mmio32,0xff1a0000 swiotlb=1 console=ttyFIQ0 rw root=PARTUUID=B921B045-1D rootfstype=ext4 rootwait";
};



编译内核:

make clean
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- rockchip_linux_defconfig
#编译内核,这个过程需要很久,而且期间电脑较卡
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j2

生成boot.img

mkdir boot
cp arch/arm64/boot/dts/rockchip/rk3399-firefly-linux.dtb boot/rk3399.dtb
cp arch/arm64/boot/Image boot/
mkdir boot/extlinux
vi boot/extlinux/extlinux.conf
#在文档中写如:
label rockchip-kernel-4.4
    kernel /Image
    fdt /rk3399.dtb
    append earlycon=uart8250,mmio32,0xff1a0000 root=PARTUUID=B921B045-1D rootwait rootfstype=ext4 init=/***in/init
#执行下面命令生成boot_rk3399.img
genext2fs -b 32768 -B $((32*1024*1024/32768)) -d boot/ -i 8192 -U boot_rk3399.img

烧写内核:

sudo dd if=boot_rk3399.img of=/dev/sdb seek=32768
sync

启动u-boot进入命令模式:

gpt write mmc 0 $partitions  #此处根据启动方式修改0或1
gpt verify mmc 0 $partitions

4.根文件系统

下载        
ubuntu-base-16.04.6-base-arm64.tar.gz
mkdir raw-rootfs
sudo tar -xpf ubuntu-base-16.04.6-base-arm64.tar.gz -C raw-rootfs/
sudo apt-get install qemu-user-static
sudo cp /usr/bin/qemu-aarch64-static ./raw-rootfs/usr/bin/
sudo cp /etc/resolv.conf raw-rootfs/etc/resolv.conf

修改源./raw-rootfs/etc/apt/sources.list为:

编写挂载脚本:

touch mount.sh
sudo chmod +x mount.sh

#!/bin/bash
mnt() {
        echo "MOUNTING"
        sudo mount -t proc /proc ${2}proc
        sudo mount -t sysfs /sys ${2}sys
        sudo mount -o bind /dev ${2}dev
        sudo mount -o bind /dev/pts ${2}dev/pts
        sudo chroot ${2}
}
umnt() {
        echo "UNMOUNTING"
        sudo umount ${2}proc
        sudo umount ${2}sys
        sudo umount ${2}dev/pts
        sudo umount ${2}dev
}

if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
        mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
        umnt $1 $2
else
        echo ""
        echo "Either 1'st, 2'nd or both parameters were missing"
        echo ""
        echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
        echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
        echo ""
        echo "For example: ch-mount -m /media/sdcard/"
        echo ""
        echo 1st parameter : ${1}
        echo 2nd parameter : ${2}
fi

挂载系统:

source mount.sh -m raw-rootfs/

卸载系统:首先退出系统

exit
source mount.sh -u raw-rootfs/

挂载系统后:

source mount.sh -m raw-rootfs/
apt upgrade
apt install sudo language-pack-en-base ssh net-tools ethtool ifupdown iputils-ping htop vim kmod network-manager xorg make udhcpc gcc g++ sudo

安装ftp服务:

sudo apt-get install vsftpd
sudo vi /etc/vsftpd.conf

local_enable=YES
write_enable=YES

sudo /etc/init.d/vsftpd restart

用户设置:

chmod +w /etc/sudoers #在root用户下添加权限
vi /etc/sudoers



添加用户:

useradd -s '/bin/bash' -m -G adm,sudo tgm
passwd tgm  #给新用户设置密码
passwd root #给root用户设置密码
exit
source mount.sh -u raw-rootfs/

制作根文件系统映像:

dd if=/dev/zero of=linuxroot.img bs=1M count=1024  #根据自己的根文件系统大小分配
sudo mkfs.ext4 linuxroot.img
mkdir  rootfs
sudo mount linuxroot.img rootfs/
sudo cp -rfp raw-rootfs/*  rootfs/
sudo umount rootfs/
e2fsck -p -f linuxroot.img
resize2fs  -M linuxroot.img

烧录根文件系统:

sudo dd if=linuxroot.img of=/dev/sdb seek=262144

在系统正确加载后执行扩展文件系统命令:

sudo resize2fs /dev/sdb5

SD卡启动效果


u-boot:



内核:



根文件系统:

举报

更多回帖

发帖
×
20
完善资料,
赚取积分