为瑞芯微设备手动创建emmc镜像

Device description

设备:rk3566
emmc:8GB/32GB Sandisk emmc
Host: Ubuntu22.04(24.04's qemu has problem when creating ubuntu base rootfs, so skip it)
参考: 【每周学习摘要06(23/10/27-23/11/10)】

制作过程

编译组件

DDR+SPL loader

U-boot

Kernel

Image, ko and dtb files,TBD

制作boot.img

boot.img包含kernel以及设备树等,以及uboot保存的env(saveenv)
预留63M空间足以(未压缩的Image最大50MiB), 如果要更大,请修改parameter.txt以防止烧录时干涉rootfs分区

touch boot.img
dd if=/dev/zero of=boot.img bs=1M count=63
sync
mkfs.fat boot.img
sync
sudo mount boot.img /mnt
sudo cp -a -r boot/* /mnt
sync
sudo umount /mnt

制作Ubuntu 2204 rootfs

下载Ubuntu base 2204

地址:https://cdimage.ubuntu.com/ubuntu-base/releases/jammy/release/

wget https://cdimage.ubuntu.com/ubuntu-base/releases/jammy/release/ubuntu-base-22.04.5-base-arm64.tar.gz
mkdir rootfs && tar --same-owner -xf ubuntu-base-22.04.5-base-arm64.tar.gz -C rootfs

Note you shall
添加dns解析

echo nameserver 114.114.114.114 > rootfs/etc/resolv.conf

以及apt源(vim rootfs/etc/apt/source.list)

deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy universe
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates universe
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy multiverse
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy-updates multiverse
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy-security universe
deb [trusted=yes] http://mirrors.aliyun.com/ubuntu-ports/ jammy-security multiverse

进入环境后更新apt 源并且下载必要包

sudo chroot rootfs
apt update
apt upgrade
apt install vim sudo kmod net-tools ethtool ifupdown language-pack-en-base rsyslog htop iputils-ping udev systemd network-manager -y

change passwd for root

passwd root

create user meta

adduser meta

add meta to sudoers
chmod +w /etc/sudoers
vim /etc/sudoers
on line 44

# User privilege specification
root    ALL=(ALL:ALL) ALL
meta    ALL=(ALL:ALL) ALL

Finally pack it
return to the father of rootfs directory.
Create a rootfs.img buffer with 1G size
shrink its size by e2fsck and resize2fs

touch rootfs.img
dd if=/dev/zero of=rootfs.img bs=1M count=900
sync
mkfs.ext4 rootfs.img
sudo mount rootfs.img /mnt
sudo cp -a -r rootfs/* /mnt
sync
sudo umount /mnt
e2fsck -f -p rootfs.img
resize2fs -M rootfs.img

You can adjust count in the second command by check fs usage by mounting it to /mnt and then check df -h. To achieve a smaller image size, better make the Available space to be less than 50M.
example:

➜  my-emmc-image df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           6.3G  2.2M  6.3G   1% /run
/dev/nvme1n1p3   60G   31G   27G  54% /
tmpfs            32G  148M   32G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
efivarfs        268K  144K  120K  55% /sys/firmware/efi/efivars
/dev/nvme0n1p1  256M   49M  208M  19% /boot/efi
tmpfs           6.3G   64K  6.3G   1% /run/user/1000
/dev/nvme0n1p5  480G  405G   51G  89% /media/ztn/4ca5df7c-065c-4b2b-b868-bab13a2816b0
/dev/loop10     868M  783M   24M  98% /mnt

拷贝网卡驱动

TBD, both kernel and user space

拷贝Mali GPU 显卡驱动

TBD, only mali so libs

zju weblogin script

if you want to accesss net after connecting to ZJUWLAN but lacks of a webbrowser to authenticate, you can use
https://github.com/Mythologyli/zju-web-login

First install python3

apt install python3

then follow https://pip.pypa.io/en/stable/installation/ to install pip
By using host's system's wget, we can get rid of downloading wget and its dependency.

su meta
cd ~
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

In order to shrink the rootfs size, don't install git but rather clone by downloading.
Again, by using host's system's wget, to avoid downloading wget and its dependency. Then unzip it.

wget https://github.com/Mythologyli/zju-web-login/archive/refs/heads/master.zip
unzip master.zip
cd master
pip3 install -r requirements.txt

Leave a Reply

Your email address will not be published. Required fields are marked *