Ubuntu 24.04 构建 openEuler Embedded 24.03 LTS (Phytium BSP)
参考链接:Phytium-OpenEuler-Embedded-BSP - Gitee
1 介绍
本文档介绍如何在Ubuntu 24.04上构建openEuler Embedded 24.03 LTS (Phytium BSP)。对计算机配置有要求。
2 脚本
将以下内容复制到新文件oe_phy.sh
,添加权限sudo chmod +x oe_phy.sh
,运行./oe_phy.sh
即可一键编译:
#!/bin/bash
# 安装oebuild
sudo apt install python3 python3-pip -y
sudo pip install oebuild --break-system-packages
# 在Ubuntu 24.04中,不加--break-system-packages会报错
# 安装docker
sudo apt install docker -y
sudo groupadd docker
sudo usermod -a -G docker $(whoami)
sudo systemctl reload docker
sudo systemctl restart docker
sudo chmod o+rw /var/run/docker.sock
# 初始化oebuild目录
oebuild init -b openEuler-24.03-LTS oe_phy
cd oe_phy && oebuild update
# 下载 openeuler-meta-phytium
rm -rf src/yocto-meta-openeuler/bsp/meta-phytium
git clone https://gitee.com/phytium_embedded/phytium-bsp-openeuler-embedded.git src/yocto-meta-openeuler/bsp/meta-phytium
cp src/yocto-meta-openeuler/bsp/meta-phytium/phytium.yaml src/yocto-meta-openeuler/.oebuild/platform/
# 支持编译SD卡镜像:在local.conf.sample 里添加变量
# vim src/yocto-meta-openeuler/.oebuild/local.conf.sample
# MACHINE_FEATURES += " sd"
# uboot 默认支持4G内存,如果支持2G内存修改如下变量
# vim recipes-bsp/phyuboot/phyuboot.bb
# RAMSIZE="2GB"
# 执行构建操作
oebuild generate -p phytium
cd ./build/phytium/
# 1. 正常编译:
# oebuild bitbake openeuler-image
# 或(两条指令二选一即可):
# oebuild bitbake phydisk
# 2. 带menuconfig的编译:
oebuild bitbake
# 配置menuconfig,比如找到Realtek devices,勾选所有
# 以下需要手动输入:
# bitbake -c menuconfig linux-openeuler
# 然后在图形界面中配置编译选项
# 继续手动输入指令:
# bitbake openeuler-image
注意,根据需求方面是否要配置menuconfig,脚本末尾部分(正常编译)和(带menuconfig的编译)二选一。具体而言:
- 若要正常编译,则开放openeuler-image或phydisk的注释,二选一。openEuler-image是编译出内核、设备树、文件系统,可以分别加载。phydisk是包含内核、设备树、文件系统的整体镜像。
- 若要在menuconfig中配置,则开放
oebuild bitbake
的注释。余下部分是在oebuild环境中,需要手动输入。以添加Realtek网卡驱动为例,需要勾选Device Drivers > Network device support > Ethernet driver support > Realtek devices下的各项:
3 在eMMC加载镜像
镜像输出位置:
kernel image和rootfs:
<work-directory>/build/phytium/output/xxxxx/
dtb file:
<work-directory>/build/phytium/tmp/deploy/images/phytium
通过SD卡加载镜像很简单,用读卡器插入SD卡烧录,插入开发板即可。下面讨论如何在eMMC加载镜像:
3.1 搭建TFTP环境
在与板子同一局域网下的Linux PC(以Ubuntu为例)上运行如下指令:
# 搭建TFTP服务器
sudo apt install tftp-hpa tftpd-hpa
sudo apt install xinetd
# 创建一个目录存放tftp文件并开放权限
# (使uboot可以从tftpboot中下载文件)
mkdir tftpboot
chmod 777 tftpboot
新建文件sudo vim /etc/xinetd.d/tftp
,输入如下内容:
server tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s ~/Work/7-2024/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
启动tftp服务:
sudo systemctl start tftpd-hpa
打开sudo vim /etc/default/tftpd-hpa
,修改为如下内容(TFTP_DIRECTORY
需为绝对路径):
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/xilong/Work/7-2024/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -c -s"
重启tftp服务器:
sudo systemctl restart tftpd-hpa
3.2 传输镜像Image和设备树dtb文件至开发板
将之前编译生成的Image和dtb文件拷贝到tftpboot文件夹中,并开放权限:
# cp复制各文件
cp Image ~/Work/9-2024/tftpboot
cp e2000q-hanwei-qcore.dtb ~/Work/9-2024/tftpboot
# 修改文件夹及所有文件权限(也可逐个修改)
sudo chmod 777 -R ./tftpboot
重启开发板,在uboot界面加载系统镜像和设备树文件:
# 通过TFTP将Image和dtb传输到DRAM中
tftp 90000000 192.168.0.10:Image
tftp 80800000 192.168.0.10:e2000q-hanwei-qcore.dtb
# 将Image和dtb从DRAM加载到eMMC中(持久存储)
# 其中e53200是Image的大小(十六进制,单位:字节)
fatwrite mmc 0:1 90000000 Image e53200
fatwrite mmc 0:1 80800000 e2000q-hanwei-qcore.dtb 6098
# 以后每次可以从mmc加载文件:
# fatload mmc 0:1 90000000 Image
# fatload mmc 0:1 80800000 e2000q-hanwei-qcore.dtb
# 启动
# booti <Image地址> <initrd地址> <dtb地址>
# 其中initrd地址可不指定,用"-"代替
booti 90000000 - 80800000
注意修改IP地址和dtb文件名。
3.3 加载rootfs(By LA)
-
openeuler通过TF卡启动。
-
把板载的emmc重新分区
- 通过fdisk删除/dev/mmcblk0的第二个分区/dev/mmcblk0p2 (mmcblk0p1现在存储了image和dtb,暂时保留了,如果mmcblk0p1足够大,分2个区就足够)
- 通过fdisk 在/dev/mmcblk0重新创建分区/dev/mmcblk0p2 大小为10G(只要能放下rootfs就行)
- 通过fdisk 在/dev/mmcblk0重新创建分区/dev/mmcblk0p3(大小为mmcblk0剩余的所有空间)
重新分区完成后效果如下:
phytium ~ # fdisk /dev/mmcblk0
The number of cylinders for this disk is set to 954240.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:- software that runs at boot time (e.g., old versions of LILO)
- booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/mmcblk0: 29 GB, 31268536320 bytes, 61071360 sectors
954240 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytesDevice Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk0p1 * 0,32,33 636,67,22 2048 6108975 6106928 2981M b Win95 FAT32
/dev/mmcblk0p2 1023,3,16 1023,3,16 6108976 27080495 20971520 10.0G 83 Linux
/dev/mmcblk0p3 1023,3,16 1023,3,16 27080496 61071359 33990864 16.2G 83 LinuxCommand (m for help):
-
格式化/dev/mmcblk0p2, /dev/mmcblk0p3
phytium ~ # mkfs.ext4 /dev/mmcblk0p2
phytium ~ # mkfs.ext4 /dev/mmcblk0p3 -
把rootfs存放到/dev/mmcblk0p2中
mkdir /home/disk2
mount -t ext4 /dev/mmcblk0p2 /home/disk2
scp 用户名@地址:rootfs路径 /home/disk2例如 scp [email protected]:/rootfs/openeuler-image-phytium-20240828023833.rootfs.ext4 /home/disk2
-
烧写rootfs到/dev/mmcblk0p3
dd if=rootfs路径 of=/dev/mmcblk0p3 bs=1M status=progress
sync例如 dd if=/home/disk2/openeuler-image-phytium-20240828023833.rootfs.ext4 of=/dev/mmcblk0p3 bs=1M status=progress
-
调整uboot 环境变量
setenv boot_linux “booti $kernel_addr - $kernel_fdt_addr“
setenv kernel_name Image
setenv distro_bootcmd "run load_kernel;run load_fdt;run boot_linux"
setenv dtb e2000q-hanwei-qcore.dtb
setenv kernel_fdt_addr 80800000
setenv kernel_fdt_name "$dtb"
saveenv当前的环境变量如下:
HANWEI_E2K#printenv
arch=arm
baudrate=115200
board=e2000
board_name=e2000
boot_linux=booti 0x90000000 - 80800000
boot_os=$boottype $kernel_addr -:- $kernel_fdt_addr
boot_sylixos=bootelf
bootargs=console=ttyAMA1,115200 audit=0 earlycon=pl011,0x2800d000 root=/dev/mmcblk0p3 rootwait rw
bootcmd=run distro_bootcmd
bootdelay=2
boottype=bootm
cpu=armv8
distro_bootcmd=run load_kernel;run load_fdt;run boot_linux
dtb=e2000q-hanwei-qcore.dtb
eth0addr=9c:69:b4:c0:44:fb
eth1addr=9c:69:b4:c0:44:fc
eth2addr=9c:69:b4:c0:44:fd
eth3addr=9c:69:b4:c0:44:fe
ethaddr=9c:69:b4:c0:dc:a0
fdtcontroladdr=f9c265b0
fileaddr=90000000
filesize=e01a00
gatewayip=192.168.1.1
ipaddr=192.168.1.101
kernel_addr=0x90000000
kernel_fdt_addr=80800000
kernel_fdt_name=e2000q-hanwei-qcore.dtb
kernel_name=Image
load_fdt=load $loadtype 0:1 $kernel_fdt_addr $kernel_fdt_name
load_kernel=load $loadtype 0:1 $kernel_addr $kernel_name
loadaddr=0x90000000
loadtype=mmc
netdev=eth0
netmask=255.255.255.0
serverip=192.168.1.7
show_pad_ver=1
usb_install=run usb_install_bootargs;usb start;fatload usb 0:1 0x91000000 Images/Image_initrd;fatload usb 0:1 0x90000000 dtbs/e2000q-hanwei-qcore.dtb;fatload usb 0:1 0x800000000
usb_install_bootargs=setenv bootargs "console=ttyAMA1,115200 quiet loglevel=0 audit=0 root=/dev/ram rw"
use_eeprom_mac=1
vendor=phytiumEnvironment size: 1367/4092 bytes
-
拔掉TF卡,板卡重新上电可自动进入系统。默认即root登录,首次登录设定密码。
注意:需要把Image和e2000q-hanwei-qcore.dtb提前放到/dev/mmcblk0p1中。
标签:LTS,kernel,Embedded,Phytium,sudo,dev,dtb,openeuler,phytium From: https://www.cnblogs.com/EndPoem-ZH/p/18146574