为瑞芯微设备手动创建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

全志A33修改默认调试串口

tools/pack/chips/sun8iw5p1/configs/default/env.cfg

Line5:

# swap to uart2 by tz61 25/02/14
console=ttyS2,115200

tools/pack/chips/sun8iw5p1/configs/vstar/sys_config.fex

Line112

; swap to uart2 debug by tz61. 25/02/14
[uart_para]
uart_debug_port = 2
;uart_debug_tx   = port:PF02<3><1><default><default>
;uart_debug_rx   = port:PF04<3><1><default><default>
uart_debug_tx    = port:PB00<2><1><default><default>
uart_debug_rx    = port:PB01<2><1><default><default>
[force_uart_para]
force_uart_port  = 2
;force_uart_tx    = port:PF02<3><1><default><default>
;force_uart_rx    = port:PF04<3><1><default><default>
force_uart_tx    = port:PB00<2><1><default><default>
force_uart_rx    = port:PB01<2><1><default><default>

FBTFT源码解析

文件结构

目录:drivers/staging/fbtft
其中文件分为核心驱动与面板驱动

  • 核心(通用件,共性):fbtft-core.c, fbtft-bus.c, fbtft-sysfs.c, fbtft-io.c, fbtft.h
  • 面板驱动(下级,特性):(e.g.) fb_st7789v.c

    fbtftops

    write_reg -> fbtftops.write_register
    fbtftops.write_register -> fbtft_write_reg8_bus8 -> fbtft_write_buf_dc -> fbtftops.write
    fbtft_update_display -> fbtftops.write_vmem -> fbtft_write_vmem16_bus8 -> fbtftops.write
    reg,value对本质上就是两个u8参数.

    fbtft_merge_fbtftops

    用于覆盖默认的ops

    fbtft_update_display

    这个是更新整个屏幕的核心函数,首先调用特定的display驱动的set_addr_win,来指定行列起始(x start/end; y start/end)
    在设置完起始后write_reg(par, MIPI_DCS_WRITE_MEMORY_START);来直接写入屏幕的VRAM
    流程图如下(MIPI_DCS_WRITE_MEMORY_START)(0x2C)(RAMWR)

    deferred_io 上层接口

    deferred_io 每次调用会回调fbtftops.update_display来更新屏幕. deferred_io 是整个驱动的上层接口
    见https://docs.kernel.org/fb/deferred_io.html

    dirty机制以及局部更新

    TBD

    注册流程 registration process

    TBD
    fbtft.h有一个FBTFT_REGISTER_DRIVER宏,在每个display驱动里面调用这个.

在Vitis HLS CSim中使用SDL2

用msvc编译后(之所以不用mingw是因为 HLS Csim用的是一个老的mingw,如果你用新的编译很麻烦)
编译完后dll丢进D:\Xilinx\Vitis_HLS\2022.2\tps\win64\msys64\mingw64\bin
然后HLS project里面设置Ldflags 为lib导入库SDL2d.lib还有SDL2maind.lib
如果不想用SDL_main(),在include SDL2.h之前设置

define SDL_MAIN_HANDLED

The Great Gig in the Sky

"And I am not frightened of dying, any time will do, I
don't mind. Why should I be frightened of dying?
There's no reason for it, you've gotta go sometime."

"I never said I was frightened of dying."