作者:付汉杰 hankf@amd.com,文章来源:博客园
工具
Vitis 2022.1
PetaLinux 2022.1
文档
建议重点查看 DS988 Kria KR260 Robotics Starter Kit Data Sheet
和 UG1092 - Kria KR260 Robotics Starter Kit User Guide.
启动设备
KR260首先从QSPI加载BOOT.BIN启动U-BOOT,U-BOOT再从SD(TF)卡的第1个分区(sda1)启动Linux内核,Linux内核再把SD(TF)卡的第2个分区(sda2)加载为根文件系统。BOOT.BIN包含FSBL、U-BOOT。Linux的启动文件包括boot.scr,Image,ramdisk.cpio.gz.u-boot,system.dtb,system-zynqmp-sck-kr-g-revB.dtb等。
官方文档描述如下:
KR260 has a primary and secondary boot device.
The primary boot device is a QSPI memory located on the SOM
The secondary boot device is an SD card interface on the carrier card.
By default, the KR260 sets the XCK26 boot mode to QSPI32.
The SOM boots up to U-Boot using the QSPI contents
and then U-Boot does a hand-off to the secondary boot device.
Linux根文件系统
如上所述,默认情况下,KR260使用从SD(TF)卡的第2个分区(sda2)作为根文件系统。可以查看系统日志中的相关信息、使用df查看系统的文件系统信息来确认。
xilinx-kr260-starterkit-20221:/home/petalinux# dmesg | grep sda
[ 7.203335] sd 0:0:0:0: [sda] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[ 7.211483] sd 0:0:0:0: [sda] Write Protect is off
[ 7.216272] sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
[ 7.216897] sd 0:0:0:0: [sda] No Caching mode page found
[ 7.222207] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 7.235477] sda: sda1 sda2
[ 7.240160] sd 0:0:0:0: [sda] Attached SCSI removable disk
[ 8.663905] EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
[ 10.872703] EXT4-fs (sda2): re-mounted. Opts: (null). Quota mode: none.
xilinx-kr260-starterkit-20221:/home/petalinux# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.5G 4.0K 1.5G 1% /dev
/dev/sda2 3.8G 809M 2.8G 23% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 787M 9.9M 777M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
tmpfs 2.0G 0 2.0G 0% /tmp
tmpfs 2.0G 184K 2.0G 1% /var/volatile
/dev/sda1 2.0G 44M 2.0G 3% /boot
tmpfs 394M 0 394M 0% /run/user/1000
升级BOOT.BIN
应用开发人员,主要升级Linux和开发应用程序,一般不更改BOOT.BIN。特殊情况下,如果需要更改,需要使用xilinx的工具xmutil来做BOOT.BIN的升级。注意,仅把BOOT.BIN复制到SD(TF)卡的第1个分区(sda1),并不能起作用。
xmutil的详细信息可以参考Xilinx文档。升级BOOT.BIN的简要流程如下:
将BOOT.BIN复制到单板上,比如通过SFTP等。
使用命令“sudo xmutil bootfw_update
升级成功后,硬件复位单板或者掉电重启动。
新的BOOT.BIN启动成功后, “sudo xmutil bootfw_update -v” ,标记新的BOOT.BIN可用,后续启动一直使用它。
另外,可以使用命令“sudo xmutil bootfw_status”查看启动映像的使用情况。注意带上命令“sudo”或者root用户,否则会报告错误“Open Qspi MTD partition failed”。
普通用户执行情况。
xilinx-kr260-starterkit-20221:~$ xmutil bootfw_status
Open Qspi MTD partition failed
Reading persistent registers backup
Open Qspi MTD partition failed
xilinx-kr260-starterkit-20221:~$ xmutil bootfw_update -p
Open Qspi MTD partition failed
Reading persistent registers backup
Open Qspi MTD partition failed
root用户执行情况。
xilinx-kr260-starterkit-20221:/home/petalinux# xmutil bootfw_update -p
Image A: Bootable
Image B: Bootable
Requested Boot Image: Image B
Last Booted Image: Image B
XilinxSom_QspiImage_v2.0_03240013
ImageA Revision Info: XilinxSOM_BootFW_20220323
ImageB Revision Info: Not defined
启动映像
AMD Xilinx 提供了多个KR260启动映像。
在Kria K26 SOM中,提供了Kria Starter Kit 2022.1 Image。下载后,得到文件“petalinux-sdimage_xilinx-k26-starterkit.wic.xz”。
Xilinx Downloads 中,提供了 Kria KR260 Starter Kit 2022.1 BSP。使用BSP文件,创建petalinux工程后,在目录“pre-built/linux/images”中有所有启动相关的文件,包括wic Image文件petalinux-sdimage.wic的压缩版本“petalinux-sdimage.wic.xz”。
hankf@XSZGS4:kr260-221-bsp-orig-peta$ ls pre-built/linux/images/ -l
total 2853440
-rw-r--r-- 1 hankf hankf 3595720 May 14 16:36 BOOT.BIN
-rw-r--r-- 1 hankf hankf 394 May 14 16:47 bootgen.bif
-rw-r--r-- 1 hankf hankf 2777 May 14 16:11 boot.scr
-rw-r--r-- 1 hankf hankf 22401536 May 14 16:26 Image
-rw-r--r-- 1 hankf hankf 9678824 May 14 16:21 Image.gz
-rw-r--r-- 1 hankf hankf 33001984 May 14 16:21 image.ub
-rw-r--r-- 1 hankf hankf 173143748 May 14 16:41 petalinux-sdimage.wic.xz
-rw-r--r-- 1 hankf hankf 23215496 May 14 16:20 ramdisk.cpio.gz
-rw-r--r-- 1 hankf hankf 23215560 May 14 16:20 ramdisk.cpio.gz.u-boot
-rw-r--r-- 1 hankf hankf 5340 May 14 16:20 ramdisk.manifest
-rw-r--r-- 1 hankf hankf 23511703 May 14 16:20 ramdisk.tar.gz
-rw-r--r-- 1 hankf hankf 240271201 May 14 16:23 rootfs.cpio.gz
-rw-r--r-- 1 hankf hankf 240271265 May 14 16:23 rootfs.cpio.gz.u-boot
-rw-r--r-- 1 hankf hankf 50142 May 14 16:22 rootfs.manifest
-rw-r--r-- 1 hankf hankf 242846085 May 14 16:23 rootfs.tar.gz
-rw-r--r-- 1 hankf hankf 51 May 14 16:36 som_build_info.txt
-rw-r--r-- 1 hankf hankf 1861099 May 14 16:06 system.bit
lrwxrwxrwx 1 hankf hankf 31 May 14 16:13 system.dtb -> system-zynqmp-sck-kr-g-revB.dtb
-rw-r--r-- 1 hankf hankf 46945 May 14 16:13 system-zynqmp-sck-kr-g-revB.dtb
...........
hankf@XSZGS4:kr260-221-bsp-orig-peta$ cd pre-built/linux/images/
hankf@XSZGS4:images$ pwd
/proj/hankf/hankf/kr260/v221/kr260-221-bsp-orig-peta/pre-built/linux/images
hankf@XSZGS4:images$ xz -d petalinux-sdimage.wic.xz
hankf@XSZGS4:images$ wic ls petalinux-sdimage.wic
Num Start End Size Fstype
1 4096 2147487743 2147483648 fat32
2 2147487744 6442455039 4294967296 ext4
hankf@XSZGS4:images$ wic ls petalinux-sdimage.wic:1
Volume in drive : is boot
Volume Serial Number is D247-3B5E
Directory for ::/
boot scr 2777 2022-05-14 8:40
IMAGE 22401536 2022-05-14 8:40 Image
RAMDIS~1 U-B 23215560 2022-05-14 8:40 ramdisk.cpio.gz.u-boot
system dtb 46945 2022-05-14 8:40
SYSTEM~1 DTB 46945 2022-05-14 8:40 system-zynqmp-sck-kr-g-revB.dtb
5 files 45 713 763 bytes
2 097 545 216 bytes free
hankf@XSZGS4:images$ wic ls petalinux-sdimage.wic:2
debugfs 1.44.1 (24-Mar-2018)
2 40755 (2) 0 0 4096 14-May-2022 16:40 .
2 40755 (2) 0 0 4096 14-May-2022 16:40 ..
11 40700 (2) 0 0 16384 14-May-2022 16:40 lost+found
12 40755 (2) 0 0 4096 9-Mar-2018 20:34 bin
169 40755 (2) 0 0 4096 9-Mar-2018 20:34 boot
174 40755 (2) 0 0 4096 9-Mar-2018 20:34 dev
175 40755 (2) 0 0 4096 9-Mar-2018 20:34 etc
969 40755 (2) 0 0 4096 9-Mar-2018 20:34 home
974 40755 (2) 0 0 4096 9-Mar-2018 20:34 lib
1813 40755 (2) 0 0 4096 9-Mar-2018 20:34 media
1814 40755 (2) 0 0 4096 9-Mar-2018 20:34 mnt
1815 40555 (2) 0 0 4096 9-Mar-2018 20:34 proc
1816 40755 (2) 0 0 4096 9-Mar-2018 20:34 run
1817 40755 (2) 0 0 4096 9-Mar-2018 20:34 sbin
1942 40755 (2) 0 0 4096 9-Mar-2018 20:34 srv
1943 40555 (2) 0 0 4096 9-Mar-2018 20:34 sys
1944 41777 (2) 0 0 4096 9-Mar-2018 20:34 tmp
1945 40755 (2) 0 0 4096 9-Mar-2018 20:34 usr
38765 40755 (2) 0 0 4096 9-Mar-2018 20:34 var
Install Ubuntu on Xilinx 的 “Ubuntu for Kria SOMs” 提供了 Ubuntu的映像,“iot-limerick-kria-classic-desktop-2204-x06-20220614-78.img.xz”。Ubnuntu的更多信息,可以参考
Getting Started with Ubuntu 20.04 LTS for Xilinx Devices 。
使用工具,比如7zip,解压上述的wic文件的压缩版本,再使用Win32DiskImager或者类似工具,将wic文件写入TF卡,插入KR260,即可启动。
包含逻辑设计到BOOT.BIN
Xilinx建议使用KR260的客户,使用DFX进行逻辑设计,使用dfx-mgr加载新的DFX逻辑设计。如果使用DFX流程,在PetaLinux工程中,建议选择“DTG Settings”中的“Devicetree overlay”和“Remove PL from devicetree”。
很多客户还是习惯传统流程。传统流程中,Linux内核启动时会加载PL的驱动程序,所以要在启动阶段加载逻辑设计,必须在BOOT.BIN中包含逻辑设计的bit文件。请使用命令“petalinux-package --boot --u-boot --fpga --force”制作BOOT.BIN,再按前面的方法升级BOOT.BIN。
hankf@XSZGS4:kr260-221-bsp-i2c-peta$ petalinux-package --boot --u-boot --fpga --force
[INFO] Sourcing buildtools
INFO: Getting system flash information...
INFO: File in BOOT BIN: "/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/zynqmp_fsbl.elf"
INFO: File in BOOT BIN: "/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/pmufw.elf"
INFO: File in BOOT BIN: "/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/project-spec/hw-description/kr260_starter_kit_pl_bram_timer.bit"
INFO: File in BOOT BIN: "/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/bl31.elf"
INFO: File in BOOT BIN: "/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/system-zynqmp-sck-kr-g-revB.dtb"
INFO: File in BOOT BIN: "/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/u-boot.elf"
INFO: Generating zynqmp binary package BOOT.BIN...
****** Xilinx Bootgen v2022.1
**** Build date : Mar 30 2022-09:29:13
** Copyright 1986-2022 Xilinx, Inc. All Rights Reserved.
[WARNING]: Partition zynqmp_fsbl.elf.0 range is overlapped with partition bl31.elf.0 memory range
[INFO] : Bootimage generated successfully
INFO: Binary is ready.
hankf@XSZGS4:kr260-221-bsp-i2c-peta$ cat images/linux/bootgen.bif
the_ROM_image:
{
[bootloader, destination_cpu=a53-0] /proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/zynqmp_fsbl.elf
[pmufw_image] /proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/pmufw.elf
[destination_device=pl] /proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/project-spec/hw-description/kr260_starter_kit_pl_bram_timer.bit
[destination_cpu=a53-0, exception_level=el-3, trustzone] /proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/bl31.elf
[destination_cpu=a53-0, load=0x00100000] /proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/system-zynqmp-sck-kr-g-revB.dtb
[destination_cpu=a53-0, exception_level=el-2] /proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux/u-boot.elf
}
如果在启动阶段没有加载逻辑设计,Linux内核加载PL的驱动程序时会被卡死。如果怀疑Linux启动失败时这个原因,可以再U-Boot启动时按键停止U-Boot的自动启动,在U-Boot的命令行中输入“md.l <pl_device_base_addrss>”读取PL的寄存器。如果也卡死,说明PL没有被加载,需要检查单板目前使用的BOOT.BIN。
从image.ub加载最终的根文件系统
如前所述,KR260的Linux默认使用SD(TF)卡的第2个分区(sda2)作为根文件系统(rootfs)。如果更改设计,需要烧写大约6GB的wic文件,耗时较长。实际上,文件系统rootfs.cpio大约只有800MB,压缩后的rootfs.cpio.gz大约只有200MB。使用传统的带根文件系统的image.ub启动Linux,更加方便。但是默认的KR260的PetaLinux工程中,image.ub只包含一个临时的小的根文件系统,不包含最终的根文件系统。
默认设置
检查文件"project-spec/configs/config",可以发现默认的设置如下:
hankf@XSZGS4:project-spec$ pwd
/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/project-spec
hankf@XSZGS4:project-spec$ cat configs/config | grep -A 10 -B 3 CONFIG_SUBSYSTEM_ROOTFS_INITRD
# Image Packaging Configuration
# CONFIG_SUBSYSTEM_ROOTFS_INITRAMFS is not set
CONFIG_SUBSYSTEM_ROOTFS_INITRD=y
CONFIG_SUBSYSTEM_INITRD_RAMDISK_LOADADDR=0x0
CONFIG_SUBSYSTEM_INITRAMFS_IMAGE_NAME="petalinux-initramfs-image"
CONFIG_SUBSYSTEM_UIMAGE_NAME="image.ub"
CONFIG_SUBSYSTEM_RFS_FORMATS="cpio cpio.gz cpio.gz.u-boot ext4 tar.gz jffs2
使用默认配置,编译后得到的Linux文件信息如下:
hankf@XSZGS4:linux$ pwd
/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux
hankf@XSZGS4:images$ ls -l -h
total 2.8G
-rw-r--r-- 1 hankf hankf 22M May 14 16:26 Image
-rw-r--r-- 1 hankf hankf 9.3M May 14 16:21 Image.gz
-rw-r--r-- 1 hankf hankf 32M May 14 16:21 image.ub
-rw-r--r-- 1 hankf hankf 23M May 14 16:20 ramdisk.cpio.gz
-rw-r--r-- 1 hankf hankf 23M May 14 16:20 ramdisk.cpio.gz.u-boot
-rw-r--r-- 1 hankf hankf 5.3K May 14 16:20 ramdisk.manifest
-rw-r--r-- 1 hankf hankf 23M May 14 16:20 ramdisk.tar.gz
-rw-r--r-- 1 hankf hankf 230M May 14 16:23 rootfs.cpio.gz
-rw-r--r-- 1 hankf hankf 230M May 14 16:23 rootfs.cpio.gz.u-boot
-rw-r--r-- 1 hankf hankf 1.2G May 14 16:23 rootfs.ext4
-rw-r--r-- 1 hankf hankf 317M May 14 16:23 rootfs.jffs2
-rw-r--r-- 1 hankf hankf 49K May 14 16:22 rootfs.manifest
-rw-r--r-- 1 hankf hankf 232M May 14 16:23 rootfs.tar.gz
...............
hankf@XSZGS4:images$ dumpimage -l image.ub
FIT description: Kernel fitImage for PetaLinux/5.15.19+gitAUTOINC+5ead03b6e6/xilinx-k26-kr
Created: Thu May 12 17:05:30 2022
Image 0 (kernel-1)
Description: Linux kernel
Created: Thu May 12 17:05:30 2022
Type: Kernel Image
Compression: gzip compressed
Data Size: 9682192 Bytes = 9455.27 KiB = 9.23 MiB
Architecture: AArch64
OS: Linux
Load Address: 0x00200000
Entry Point: 0x00200000
Hash algo: sha256
Hash value: 28338e2a871c889ab8d2569571307a0281eda7d916c97dc4f44cd64af2d6d849
Image 1 (fdt-system-top.dtb)
Description: Flattened Device Tree blob
Created: Thu May 12 17:05:30 2022
Type: Flat Device Tree
Compression: uncompressed
Data Size: 45034 Bytes = 43.98 KiB = 0.04 MiB
Architecture: AArch64
Hash algo: sha256
Hash value: 40cc4ba1fb9736b13d9d10d103d813d207ab529672114fc9022900b2e868abf1
...........................................
Image 4 (ramdisk-1)
Description: petalinux-initramfs-image
Created: Thu May 12 17:05:30 2022
Type: RAMDisk Image
Compression: uncompressed
Data Size: 23215496 Bytes = 22671.38 KiB = 22.14 MiB
Architecture: AArch64
OS: Linux
Load Address: unavailable
Entry Point: unavailable
Hash algo: sha256
Hash value: 5d5b3c289b6afda7a87e56f324afb00ee25bdeb175ea6c89312a6e4212d3bf12
Default Configuration: 'conf-system-top.dtb'
Configuration 0 (conf-system-top.dtb)
Description: 1 Linux kernel, FDT blob, ramdisk
Kernel: kernel-1
Init Ramdisk: ramdisk-1
FDT: fdt-system-top.dtb
Hash algo: sha256
Hash value: unavailable
..................
从上面可以看到,image.ub只有32MB左右,包含的文件系统只有22MB左右。Linux只是临时使用这个文件系统。
image.ub含根文件系统的设置
在PetaLinux的工程里,把ROOTFS从INITRD改为INITRAMFS,把INITRAMFS_IMAGE_NAME从petalinux-initramfs-image改为"petalinux-image-minimal",编译后的image.ub的包含最终的根文件系统。
更改后的设置如下:
hankf@XSZGS4:project-spec$ pwd
/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/project-spec
hankf@XSZGS4:project-spec$ cat configs/config | grep -A 10 -B 2 CONFIG_SUBSYSTEM_ROOTFS_INITRAMFS
# Image Packaging Configuration
#
CONFIG_SUBSYSTEM_ROOTFS_INITRAMFS=y
# CONFIG_SUBSYSTEM_ROOTFS_INITRD is not set
......
CONFIG_SUBSYSTEM_INITRAMFS_IMAGE_NAME="petalinux-image-minimal"
CONFIG_SUBSYSTEM_UIMAGE_NAME="image.ub"
CONFIG_SUBSYSTEM_RFS_FORMATS="cpio cpio.gz cpio.gz.u-boot ext4 tar.gz jffs2"
使用新配置,编译后得到的Linux的文件信息如下:
hankf@XSZGS4:linux$ pwd
/proj/hankf/hankf/kr260/v221/kr260-221-bsp-i2c-peta/images/linux
hankf@XSZGS4:linux$ ls -l -h
total 6.0G
-rw-r--r-- 1 hankf hankf 740M Sep 14 16:06 Image
-rw-r--r-- 1 hankf hankf 237M Sep 14 16:06 Image.gz
-rw-r--r-- 1 hankf hankf 239M Sep 14 16:06 image.ub
-rw-r--r-- 1 hankf hankf 23M Sep 14 15:00 ramdisk.cpio.gz
-rw-r--r-- 1 hankf hankf 23M Sep 14 15:00 ramdisk.cpio.gz.u-boot
-rw-r--r-- 1 hankf hankf 5.3K Sep 13 17:49 ramdisk.manifest
-rw-r--r-- 1 hankf hankf 23M Sep 14 15:00 ramdisk.tar.gz
-rw-r--r-- 1 hankf hankf 718M Sep 14 16:01 rootfs.cpio
-rw-r--r-- 1 hankf hankf 229M Sep 14 16:01 rootfs.cpio.gz
-rw-r--r-- 1 hankf hankf 229M Sep 14 16:01 rootfs.cpio.gz.u-boot
-rw-r--r-- 1 hankf hankf 1.2G Sep 14 16:01 rootfs.ext4
-rw-r--r-- 1 hankf hankf 316M Sep 14 16:01 rootfs.jffs2
-rw-r--r-- 1 hankf hankf 49K Sep 14 16:00 rootfs.manifest
-rw-r--r-- 1 hankf hankf 232M Sep 14 16:01 rootfs.tar.gz
..............
hankf@XSZGS4:linux$ dumpimage -l image.ub
FIT description: Kernel fitImage for PetaLinux/5.15.19+gitAUTOINC+b0c1be301e/xilinx-k26-kr
Created: Tue Apr 12 01:52:14 2022
Image 0 (kernel-1)
Description: Linux kernel
Created: Tue Apr 12 01:52:14 2022
Type: Kernel Image
Compression: gzip compressed
Data Size: 9681872 Bytes = 9454.95 KiB = 9.23 MiB
Architecture: AArch64
OS: Linux
Load Address: 0x00200000
Entry Point: 0x00200000
Hash algo: sha256
Hash value: 969233c18dce2dfc5d3f63398c2610c5c9bb9215579c3cef57ddfa95d06fe5af
Image 1 (fdt-system-top.dtb)
Description: Flattened Device Tree blob
Created: Tue Apr 12 01:52:14 2022
Type: Flat Device Tree
Compression: uncompressed
Data Size: 46754 Bytes = 45.66 KiB = 0.04 MiB
Architecture: AArch64
Hash algo: sha256
Hash value: 29cea877670408077e8a53d989e42db2ef06818ed425502fa51bc11c3ab9afe3
.................
Image 4 (ramdisk-1)
Description: petalinux-image-minimal
Created: Tue Apr 12 01:52:14 2022
Type: RAMDisk Image
Compression: uncompressed
Data Size: 239828082 Bytes = 234207.11 KiB = 228.72 MiB
Architecture: AArch64
OS: Linux
Load Address: unavailable
Entry Point: unavailable
Hash algo: sha256
Hash value: 8065d42c7c2f4460b03a1b94655245645445c5a7b5c72353fc9fbed9919d1419
Default Configuration: 'conf-system-top.dtb'
Configuration 0 (conf-system-top.dtb)
Description: 1 Linux kernel, FDT blob, ramdisk
Kernel: kernel-1
Init Ramdisk: ramdisk-1
FDT: fdt-system-top.dtb
Hash algo: sha256
Hash value: unavailable
.................
从上面可以看到,新的image.ub有239MB,包含的文件系统已经变大为228MB。启动后,可以看到sda2被加载到“/run/media/sda2”,不再是根目录。
xilinx-kr260-starterkit-20221:/home/petalinux# dmesg | grep sda
[ 10.215647] sd 0:0:0:0: [sda] 31116288 512-byte logical blocks: (15.9 GB/14.8 GiB)
[ 10.224745] sd 0:0:0:0: [sda] Write Protect is off
[ 10.229556] sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
[ 10.235198] sd 0:0:0:0: [sda] No Caching mode page found
[ 10.245733] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 10.259460] sda: sda1 sda2
[ 10.264831] sd 0:0:0:0: [sda] Attached SCSI removable disk
[ 13.202278] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[ 13.334297] EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
xilinx-kr260-starterkit-20221:/home/petalinux# df -h
Filesystem Size Used Available Use% Mounted on
devtmpfs 4.0M 4.0K 4.0M 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 786.1M 9.8M 776.3M 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
tmpfs 1.9G 0 1.9G 0% /tmp
tmpfs 1.9G 12.0K 1.9G 0% /var/volatile
/dev/sda1 2.0G 107.8M 1.9G 5% /run/media/sda1
/dev/sda2 3.8G 807.1M 2.8G 22% /run/media/sda2
tmpfs 393.1M 0 393.1M 0% /run/user/1000
xilinx-kr260-starterkit-20221:/home/petalinux# free
total used free shared buff/cache available
Mem: 4024936 84916 3601200 318300 338820 3536020
Swap: 0 0 0
INITRAMFS和petalinux-initramfs-image
注意,不能同时使用配置“ROOTFS_INITRAMFS”,和把INITRAMFS_IMAGE_NAME设置成“petalinux-initramfs-image”,否则会遇到错误“Could not find any petalinux-initramfs-image-xilinx-k26-kr.cpio{.gz|.lz4|.lzo|.lzma|.xz|.zst) for bundling; ”。
这时的配置如下:
# Image Packaging Configuration
CONFIG_SUBSYSTEM_ROOTFS_INITRAMFS=y
# CONFIG_SUBSYSTEM_ROOTFS_INITRD is not set
CONFIG_SUBSYSTEM_INITRAMFS_IMAGE_NAME="petalinux-initramfs-image"
CONFIG_SUBSYSTEM_UIMAGE_NAME="image.ub"
CONFIG_SUBSYSTEM_RFS_FORMATS="cpio cpio.gz cpio.gz.u-boot ext4 tar.gz"
更多错误信息如下:
Initialising tasks: 100% |#####################################################################################################################################################| Time: 0:00:08
Checking sstate mirror object availability: 100% |#############################################################################################################################| Time: 0:00:04
Sstate summary: Wanted 1089 Local 21 Network 647 Missed 421 Current 2635 (61% match, 88% complete)
Removing 27 stale sstate objects for arch xilinx_k26_kr: 100% |################################################################################################################| Time: 0:00:00
NOTE: Executing Tasks
ERROR: linux-xlnx-5.15.19+gitAUTOINC+b0c1be301e-r0 do_bundle_initramfs:
Could not find any /home/hankf/proj/kr260/v221/kr260-221-bsp-peta/build/tmp/deploy/images/xilinx-k26-kr/
petalinux-initramfs-image-xilinx-k26-kr.cpio{.gz|.lz4|.lzo|.lzma|.xz|.zst) for bundling;
INITRAMFS_IMAGE_NAME might be wrong.
减小image.ub大小
分析文件大小
上述的image.ub很大。解压文件系统的压缩文件,使用du命令“du --max-depth=2 -h | grep [0-9]M ”分析文件夹的大小。
hankf@XSZGS4:rootfs$ du --max-depth=3 -h | grep [0-9][0-9]M
18M./lib/udev
44M./lib
440M./usr/lib/python3.9
512M./usr/lib
106M./usr/bin
26M./usr/libexec/gcc
28M./usr/libexec
17M./usr/share/jupyter
17M./usr/share/cmake-3.21
78M./usr/share
733M./usr
13M./var/lib/rpm
18M./var/lib
18M./var
810M.
可以看到主要是文件夹“/usr/lib”和“/usr/bin”占用了很多空间。其中python的库就占用了440MB。
PetaLinux的文件系统的配置保存在文件project-spec/configs/rootfs_config,分析后输出到build/conf/plnxtool.conf。
分析文件project-spec/configs/rootfs_config,通过下面字段,可以发现packagegroup-core-full-cmdline、packagegroup-petalinux-jupyter和packagegroup-petalinux-som被使能。
CONFIG_packagegroup-core-full-cmdline=y
CONFIG_packagegroup-petalinux-jupyter=y
CONFIG_packagegroup-petalinux-som=y
重点分析packagegroup-petalinux-som,检查它的定义文件packagegroup-petalinux-som.bb,可以发现它使能了python、jupyter等软件包。
SOM_PACKAGES = " \
packagegroup-core-full-cmdline \
packagegroup-core-tools-debug \
packagegroup-core-ssh-dropbear \
packagegroup-petalinux-jupyter \
packagegroup-petalinux-networking-stack \
packagegroup-petalinux-python-modules \
packagegroup-petalinux-tpm \
packagegroup-petalinux-utils \
packagegroup-petalinux \
archconfig \
fru-print \
image-update \
ldd \
ntp \
resize-part \
tree \
tzdata \
xmutil \
som-dashboard \
k26-starter-kits \
lmsensors-fancontrol \
"
RDEPENDS:${PN} = "${SOM_PACKAGES}"
使用命令“petalinux-config -c rootfs”配置文件系统,禁止上述模块。再编译petalinux工程,可以发现rootfs.cpio和image.ub的大小都大大减小。
hankf@XSZGS4:kr260-221-bsp-i2c-peta$ ls images/linux/ -l -h
total 2.3G
-rw-r--r-- 1 hankf hankf 305M Sep 15 16:55 Image
-rw-r--r-- 1 hankf hankf 103M Sep 15 16:55 Image.gz
-rw-r--r-- 1 hankf hankf 104M Sep 15 16:55 image.ub
-rw-r--r-- 1 hankf hankf 284M Sep 15 16:50 rootfs.cpio
-rw-r--r-- 1 hankf hankf 95M Sep 15 16:50 rootfs.cpio.gz
-rw-r--r-- 1 hankf hankf 95M Sep 15 16:50 rootfs.cpio.gz.u-boot
-rw-r--r-- 1 hankf hankf 500M Sep 15 16:50 rootfs.ext4
-rw-r--r-- 1 hankf hankf 128M Sep 15 16:50 rootfs.jffs2
-rw-r--r-- 1 hankf hankf 39K Sep 15 16:50 rootfs.manifest
-rw-r--r-- 1 hankf hankf 95M Sep 15 16:50 rootfs.tar.gz
继续分析文件系统,还可以进一步减小系统的大小。
分析PetaLinux配置
也可以正向分析来减少软件包。
PetaLinux编译的目标是petalinux-image-minimal。分析petalinux-image-minimal的定义文件petalinux-image-minimal.bb和petalinux-image-minimal.bbappend,可以发现它包含的软件包。
hankf@XSZGS4:kr260-221-bsp-peta$ find -name "petalinux-image-minimal*.bb*"
./components/yocto/layers/meta-petalinux/recipes-core/images/petalinux-image-minimal.bb
./components/yocto/layers/meta-som/dynamic-layers/petalinux/recipes-core/images/petalinux-image-minimal.bbappend
petalinux-image-minimal.bb只包含了petalinux-image-common-som.inc。 petalinux-image-common.inc中通过定义IMAGE_INSTALL、IMAGE_FEATURES,增加了各种软件包。主要内容如下:
IMAGE_FEATURES += "${COMMON_FEATURES}
COMMON_FEATURES = " \
ssh-server-dropbear \
hwcodecs \
"
IMAGE_INSTALL = " \
packagegroup-core-boot \
${COMMON_INSTALL} \
${CORE_IMAGE_EXTRA_INSTALL} \
"
COMMON_INSTALL = " \
tcf-agent \
mtd-utils \
bridge-utils \
can-utils \
pciutils \
kernel-modules \
nfs-utils \
nfs-utils-client \
"
COMMON_INSTALL:append:zynqmp = " ${INSTALL_ZYNQ_ZYNQMP_VERSAL} hellopm ${LIBDFX_RECIPE}"
INSTALL_ZYNQ_ZYNQMP_VERSAL = " haveged htop iperf3 meson u-boot-tools"
CORE_IMAGE_EXTRA_INSTALL:append:ultra96 = " packagegroup-base-extended"
上面的内容,为了便于理解,调整了各个变量的顺序。
petalinux-image-minimal.bbappend包含了petalinux-image-common-som.inc, 后者增加了软件包packagegroup-petalinux-som。
其它
PetaLinux的用户名和密码
PetaLinux 2022.1 为了提升系统安全性,第一次启动时,需要设置用户密码。默认用户名是petalinux。第一次使用sudo时,也需要设置密码。
PetaLinux 2022.1_release_S04190222 xilinx-kr260-starterkit-20221 ttyPS1
xilinx-kr260-starterkit-20221 login: petalinux
You are required to change your password immediately (administrator enforced).
New password:
Retype new password:
[ 25.175711] audit: type=1006 audit(1637342384.772:2): pid=753 uid=0 old-auid=4294967295 auid=1000 tty=(none) old-ses=4294967295 ses=1 res=1
[ 25.188338] audit: type=1300 audit(1637342384.772:2): arch=c00000b7 syscall=64 success=yes exit=4 a0=8 a1=fffffd5ff460 a2=4 a3=ffffa94d66b0 items=0 ppid=1 pid=753 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=1 comm="(systemd)" exe="/lib/systemd/systemd" key=(null)
[ 25.214878] audit: type=1327 audit(1637342384.772:2): proctitle="(systemd)"
xilinx-kr260-starterkit-20221:~$ sudo su
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
Password: