Open quinnwencn opened 10 months ago
对于Image格式的kernel,可以使用以下命令手动压缩成gzip格式的kernel:
cat Image | gzip -n -f -9 > Image.gz
关于内核镜像的格式和制作,请看内核镜像的格式和制作
当然,我们也可以从FIT格式的镜像中提取对应的镜像,例如提取initramfs.cpio.gz:
dumpimage -T flat_dt -p 1 image.ub -o initramfs.cpio.gz
这里-p指的是在制作image.ub时initramfs的位置,-o是initramfs的名字,这是提取出来的名称,可以自己制定2,如果忘记了对应的位置,那么可以用以下命令查看:
dumpimage -l image.ub
上述将rootfs制作成initramfs.cpio.gz的操作会在initramfs.cpio.gz中多一份initramfs.cpio,可以采用以下方式制作更小的:
sudo find . -print | sudo cpio --create --format=newc | gzip -9 > ../initramfs.cpio.gz
1. 背景
由于NXP官方手册中并没有描述如何为Layerscape制作和使用initramfs,而initramfs在嵌入式设备中的使用又非常广泛和必要,例如,在基于ostree升级软件的方案中,就需要用initramfs去进行必要的ostree操作。因此,必须要为Layerscape制作initramfs。使用FIT格式启动的系统文件分布如下: 接下来,我将介绍如何制作Layerscape的initramfs,并打包FIT格式镜像,和从initramfs如何切换到正常的rootfs。
2. 制作FIT格式系统镜像
2.1 制作initramfs
由于initramfs需要对硬件做初始化工作,因此不具备通用性,必须在芯片厂商提供的initramfs上改造。但是,NXP没有提供制作initramfs的源文件,但是,我们可以基于NXP提供的Layerscape SDK中buildroot编出来,步骤如下:
configs/sdk.yml
里的仓库进行重新配置,因为一些仓库已经失效,目前已知的有:编译完成后,可以看到:
0 directories, 5 files
gunzip rootfs.cpio.gz
cpio -idmv < rootfs.cpio
$ tree . -L 1 . ├── bin ├── dev ├── etc ├── init ├── lib ├── lib64 -> lib ├── linuxrc -> bin/busybox ├── media ├── mnt ├── opt ├── proc ├── root ├── rootfs.cpio ├── run ├── sbin ├── sys ├── tmp ├── usr └── var
sudo find . | sudo cpio -H newc -o | gzip -9 > initramfs.cpio.gz
生成FIT格式的Image:
最终将生成一个
image.ub
文件,我们可以用dumpimage
来查看:可以看到确实是一个FIT格式的镜像了。
3 启动FIT格式的镜像
将SD卡进行分区,分区信息如下:
其中,分区1用于存放FIT格式的Image镜像,分区2用于存放真正的rootfs,现在该rootfs是一个ubuntu rootfs。
3.1 刷写文件
3.2 启动测试
为了成功从FIT格式的镜像启动,我们需要设置uboot环境变量:
这里,设置的uboot读取FIT格式的image的地址,不能和FIT格式里面的地址重叠
add_key: No su[ 3.666973] __wake_up_parent+0x0/0x30 ch device cat: [ 3.672100] el0_svc_common.constprop.0+0x78/0x1a0 can't open '/mnt[ 3.678269] do_el0_svc+0x24/0x90 /etc/encrypted_k[ 3.682961] el0_svc+0x14/0x20 ey.blob': No suc[ 3.687393] el0_sync_handler+0xb0/0xb8 h file or direct[ 3.692606] el0_sync+0x178/0x180 ory add_key: No[ 3.697302] SMP: stopping secondary CPUs such device /i[ 3.702604] Kernel Offset: disabled [ 3.707466] CPU features: 0x0240022,21002000 [ 3.711726] Memory Limit: none [ 3.714774] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100 ]---
sudo cpio -idmv < rootfs.cpio sudo chown -R root ./ sudo chgrp -R root ./ sudo find . | sudo cpio -H newc -o | gzip -9 > initramfs.cpio.gz
Hit any key to stop autoboot: 0 switch to partitions #0, OK mmc0 is current device 17708815 bytes read in 768 ms (22 MiB/s)
Loading kernel from FIT Image at b0000000 ...
Using 'standard' configuration Trying 'kernel' kernel subimage Description: kernel image Type: Kernel Image Compression: gzip compressed Data Start: 0xb00000c8 Data Size: 12277242 Bytes = 11.7 MiB Architecture: AArch64 OS: Linux Load Address: 0x94200000 Entry Point: 0x94200000 Hash algo: sha256 Hash value: c346c152ae2f4c792e7dfd5b6730111fc9e3d2ece39c3bbf57e150a671a7dbb0 Verifying Hash Integrity ... sha256+ OK
Loading ramdisk from FIT Image at b0000000 ...
Using 'standard' configuration Trying 'initrd' ramdisk subimage Description: initrd for arm64 Type: RAMDisk Image Compression: gzip compressed Data Start: 0xb0bb57d0 Data Size: 5388952 Bytes = 5.1 MiB
mount: mounting securityfs on /sys/kernel/security failed: No such file or directory partnum: 4[ 3.607799] mmc0: new ultra high speed SDR104 SDHC card at address 59b4
[ 3.608911] /dev/mmcblk0p4: Can't open blockdev [ 3.615336] mmcblk0: mmc0:59b4 SD3.0 30.3 GiB mount: mounting [ 3.625300] mmcblk0: p1 p2 /dev/mmcblk0p4 on /mnt failed: No such device or address Loadin[ 3.633742] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100 g blobs cat: ca[ 3.641543] CPU: 2 PID: 1 Comm: busybox Not tainted 5.10.35 #3 n't open '/mnt/e[ 3.648751] Hardware name: LS1046A RDB Board (DT) tc/secure_key.bl[ 3.654835] Call trace: ob': No such fil[ 3.658667] dump_backtrace+0x0/0x1a8 e or directory [ 3.663700] show_stack+0x18/0x68 add_key: No such[ 3.668393] dump_stack+0xd0/0x12c device cat: ca[ 3.673171] panic+0x16c/0x334 n't open '/mnt/e[ 3.677603] do_exit+0x9ec/0xa08 tc/encrypted_key[ 3.682208] do_group_exit+0x44/0xa0 .blob': No such [ 3.687161] __wake_up_parent+0x0/0x30 file or director[ 3.692289] el0_svc_common.constprop.0+0x78/0x1a0 y add_key: No s[ 3.698457] do_el0_svc+0x24/0x90 uch device /ini[ 3.703149] el0_svc+0x14/0x20 t: line 54: can'[ 3.707581] el0_sync_handler+0xb0/0xb8 t create /sys/ke[ 3.712796] el0_sync+0x178/0x180 rnel/security/ev[ 3.717490] SMP: stopping secondary CPUs m: nonexistent d[ 3.722793] Kernel Offset: disabled [ 3.727655] CPU features: 0x0240022,21002000 [ 3.731915] Memory Limit: none [ 3.734963] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100 ]---
[ OK ] Started Internet superserver. [ OK ] Started Weston Wayland Compositor (on tty7). [ OK ] Finished Set console scheme. [ OK ] Created slice system-getty.slice. [ OK ] Started Getty on tty1. [ OK ] Reached target Login Prompts. [FAILED] Failed to start Advanced I�…1X/WPA/WPA2/EAP Authenticator. See 'systemctl status hostapd.service' for details. [ OK ] Finished Set console font and keymap. [ OK ] Started Lighttpd Daemon. [ OK ] Started OpenBSD Secure Shell server. [ OK ] Created slice User Slice of UID 0. Starting User Runtime Directory /run/user/0... [ OK ] Finished Resize root files�…m to fit available disk space. [ OK ] Finished User Runtime Directory /run/user/0.
NXP LSDK 2108 main (custom based on ubuntu 20.04) forlinx login: