以往飞腾相关文章:
真诚感谢MK分享此篇文档
本文讲解了,如何设置uboot环境变量和编译linux内核,实现将uboot和系统同时放置到SD卡或eMMC后,从SD或者eMMC启动uboot,引导系统启动的过程。
同时使用E2000Q-demo,演示了从SD卡启动和从eMMC启动的过程。
1、制作MMC(eMMC/SD卡)启动镜像文件
1.1、重新编译u-boot.bin,实现U-boot环境变量存储在MMC(eMMC/SD卡)
进入E2000打包工具image-fix目录,更新bl33_new.bin指向重新make得到的u-boot.bin,然后执行脚本打包得到新的BIOS固件文件fip-all.bin。
1.2、重新编译linux内核,实现bootargs传递分区信息
E2000配置从MMC(eMMC/SD卡)启动的模式,上电启动需要从MMC设备(eMMC/SD卡)起始地址加载BIOS固件,BIOS固件会覆盖分区表信息,因此需要开启“u-boot通过bootargs重新传递分区表”的功能。
在交叉编译环境(Ubuntu20.04_X86虚拟机),进入linux kernel源码目录,运行make menuconfig开启command line partition support,然后重新make得到内核镜像Image.gz。
第1步:在交叉编译环境(Ubuntu20.04_X86虚拟机),使用命令 mkimage将当前目录下的内核Image.gz、设备树e2000q-demo-board.dtb进行打包,得到启动镜像文件uImage.itd。
mkimage -f ./ demo.its ./uImage.itd
/dts-v1/;
/ {
description = "Image with single Linux kernel and compressed FDT blobs";
#address-cells = <1>;
images {
kernel {
description = "Linux kernel";
data = /incbin/("./Image.gz");
type = "kernel";
arch = "arm64";
os = "linux";
compression = "gzip";
load = <0x80080000>;
entry = <0x80080000>;
hash-1 {
algo = "crc32";
};
hash-2 {
algo = "sha1";
};
};
fdt@ demo{
description = "e2000q demo board";
data = /incbin/("./e2000q-demo-board.dtb");
type = "flat_dt";
arch = "arm64";
compression = "none";
hash-1 {
algo = "crc32";
};
hash-2 {
algo = "sha1";
};
};
};
configurations {
default = "e2k@demo";
e2k@demo{
description = "Boot Linux kernel with FDT demo";
kernel = "kernel";
fdt = "fdt@demo";
};
};
};
第2步:然后,使用dd 命令将fip-all.bin、uImage.itd封装在一起(偏移地址0x400000,可根据情况修改),封装合并后文件为BIOS固件fip-all.bin,这里把fip-all.bin重命名为mmc-boot.bin,支持eMMC/SD卡的MMC启动镜像文件就制作完成了。
dd if=./uImage.itd of=./fip-all.bin bs=1M seek=4
sync
mv -f fip-all.bin mmc-boot.bin
sync
第1步:在交叉编译环境(Ubuntu20.04_X86虚拟机)连接SD卡设备,使用fdisk 对SD卡进行分区,第一个分区起始地址要避开前64MB地址(First sector (2048-62333951,default 2048): 131072),空间0~64MB将用来存放fip-all.bin、kernel和设备树,64MB及之后空间是Linux根目录存放分区,下图为分区过程。
sudo dd if=mmc-boot.bin of=/dev/sdb
sync
到这里,SD系统盘就安装制作完成了。
2.2、在E20000Q-DEMO参考板上加载SD系统盘
setenv bootcmd "mmc dev 1;mmc read 0x90000000 0x2000 0x10000;bootm 0x90000000#e2k@demo"
setenv bootargs 'console=ttyAMA1,115200 earlycon=pl011,0x2800d000 root=/dev/mmcblk1p2 rootfstype=ext4 rootwait rw cma=128m blkdevparts=mmcblk1:64M(boot),-(userdata);'
saveenv
boot
系统加载过程,SD启动log如下:
…….
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc1 is current device
MMC read: dev # 1, block # 8192, count 65536 ... 65536 blocks read: OK
## Loading kernel from FIT Image at 90000000 ...
Using 'e2k@demo' configuration
Trying 'kernel' kernel subimage
Description: Linux kernel
Type: Kernel Image
Compression: gzip compressed
Data Start: 0x900000e4
Data Size: 7363002 Bytes = 7 MiB
Architecture: AArch64
OS: Linux
Load Address: 0x80080000
Entry Point: 0x80080000
Hash algo: crc32
Hash value: aad68492
Hash algo: sha1
Hash value: 3a0551d751553ecf011b3ca4ff585ba5e6e37cb8
Verifying Hash Integrity ... crc32+ sha1+ OK
## Loading fdt from FIT Image at 90000000 ...
Using 'e2k@demo' configuration
Trying 'fdt@demo' fdt subimage
Description: e2000q demo borad
Type: Flat Device Tree
Compression: uncompressed
Data Start: 0x90705bc8
Data Size: 23372 Bytes = 22.8 KiB
Architecture: AArch64
Hash algo: crc32
Hash value: 9a360ce7
Hash algo: sha1
Hash value: 7bf7a0fea3ecfe809ddddfe9863bb36340e1d9d5
Verifying Hash Integrity ... crc32+ sha1+ OK
Booting using the fdt blob at 0x90705bc8
Uncompressing Kernel Image
Loading Device Tree to 00000000f9c2f000, end 00000000f9c37b4b ... OK
run in ft_board_setup
fdt_addr 00000000f9c2f000
N: Phytium System Service Call: 0xc2000005
mb_count = 0x2
mb_blocks[0].mb_size = 0x7c000000
mb_blocks[1].mb_size = 0x180000000
fdt : can not find /memory@01 node
fdt : add node memory@01
fdt : dram size 0x200000000 update successfully
Starting kernel ...
/ {
compatible = "phytium,e2000q";
…….
dd if=mmc-boot.bin of=/dev/mmcblk0 sync |
setenv bootcmd "mmc dev 1;mmc read 0x90000000 0x2000 0x10000;bootm 0x90000000#e2k@demo"
setenv bootargs 'console=ttyAMA1,115200 earlycon=pl011,0x2800d000 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait rw cma=128m blkdevparts=mmcblk0:64M(boot),-(userdata);'
saveenv
boot
…….
Hit any key to stop autoboot: 0
Card did not respond to voltage select! : -110
MMC read: dev # 0, block # 8192, count 65536 ... 65536 blocks read: OK
## Loading kernel from FIT Image at 90000000 ...
Using 'e2k@demo' configuration
Trying 'kernel' kernel subimage
Description: Linux kernel
Type: Kernel Image
Compression: gzip compressed
Data Start: 0x900000e4
Data Size: 7363002 Bytes = 7 MiB
Architecture: AArch64
OS: Linux
Load Address: 0x80080000
Entry Point: 0x80080000
Hash algo: crc32
Hash value: aad68492
Hash algo: sha1
Hash value: 3a0551d751553ecf011b3ca4ff585ba5e6e37cb8
Verifying Hash Integrity ... crc32+ sha1+ OK
## Loading fdt from FIT Image at 90000000 ...
Using 'e2k@demo' configuration
Trying 'fdt@demo' fdt subimage
Description: e2000q demo borad
Type: Flat Device Tree
Compression: uncompressed
Data Start: 0x90705bc8
Data Size: 23372 Bytes = 22.8 KiB
Architecture: AArch64
Hash algo: crc32
Hash value: 9a360ce7
Hash algo: sha1
Hash value: 7bf7a0fea3ecfe809ddddfe9863bb36340e1d9d5
Verifying Hash Integrity ... crc32+ sha1+ OK
…….
The Phytium Distribution e2000 ttyAMA1
Phytium SDK (Phy Reference Distro) 3.3.2 - Kernel \r
e2000 login: root
root@e2000:~#