文章目录
- 硬件配置及代码存放说明
- 操作步骤
- 注意事项:
硬件配置及代码存放说明
- QSPI连接一个16MB的Flash
- SD1接口接emmc
- 将zynq_fsbl.elf+fpga.bit +u-boot.elf组成的BOOT.BIN放在QSPI flash中
- 将emmc分成两个区,第一个区FAT32格式,用来存放iamge.ub。第二个区ext4格式,用来存放文件系统。
操作步骤
- 创建工程
petalinux-create --type project --template zynq --name emmc_prj
- 添加硬件平台描述信息
petalinux-config --get-hw-description ./xsa
- 配置从emmc加载image
petalinux-config -> sybsystem AUTO Hardware Settings -> Advanced bootable images storage Settings
boot image settings ---> image storage media (primary flash) //uboot放在QSPI Flash中
u-boot env partition settings ---> image storage media (primary flash) //环境变量放在QSPI Flash中
kernel image settings ---> image storage media (primary sd) //image放在emmc中
jffs2 rootfs image settings ---> image storage media (primary flash)
dtb image settings ---> image storage media (from boot image)
- 先配置一个initramfs的系统,用来给emmc分区。
petalinux-config -> Image Packaging Configuration -> Root filesystem type (INITRAMFS)
- 编译
petalinux-build
- 生成BOOT.BIN
petalinux-package --boot --fsbl --u-boot --fpga --force
- 将BOOT.BIN下载到QSPI Flash中
我是利用vitis软件新建一个工程,然后xillinx -> program flash时将BOOT.BIN替换成我们上面一步生成的。 - 进入uboot,使用tftpboot命令加载initramfs格式的文件系统到内存中,然后从内存启动。
- 删除emmc里的所有分区,然后重新创建两个分区。
第一个分区是primary分区,FAT32格式。
第二个分区也是primary分区,EXT4格式。
/* 查看emmc设备 */
root@2-emmc:~# ls /dev
...
mmcblk0 ram13 tty2 tty47 vcsu1
mmcblk0boot0 ram14 tty20 tty48 vga_arbiter
mmcblk0boot1 ram15 tty21 tty49 watchdog
mmcblk0p1 ram2 tty22 tty5 watchdog0
mmcblk0p2 ram3 tty23 tty50 zero
/* 查看emmc当前的分区是否有挂载点 */
root@2-emmc:~# mount
rootfs on / type rootfs (rw,size=503156k,nr_inodes=125789)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=503156k,nr_inodes=125789,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /var/volatile type tmpfs (rw,relatime)
/dev/mmcblk0p2 on /run/media/mmcblk0p2 type ext4 (rw,relatime) //第一个分区有挂载点
/dev/mmcblk0p1 on /run/media/mmcblk0p1 type vfat (rw,relatime,gid=6,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) //第二个分区也有挂载点
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
/* 如果有挂载点需要先取消挂载,否则重新分区会出问题 */
root@2-emmc:~# umount /dev/mmcblk0p1
root@2-emmc:~# umount /dev/mmcblk0p2
/* 对emmc进行重新分区 */
root@2-emmc:~# fdisk /dev/mmcblk0
The number of cylinders for this disk is set to 1942528.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/mmcblk0: 59 GB, 63652757504 bytes, 124321792 sectors
1942528 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk0p1 0,1,1 1023,3,16 16 2097167 2097152 1024M 83 Linux
/dev/mmcblk0p2 1023,3,16 1023,3,16 2097168 123731983 121634816 58.0G 5 Extended
Command (m for help): d
Partition number (1-5): 1
Command (m for help): d
Selected partition 2
Command (m for help): p
Disk /dev/mmcblk0: 59 GB, 63652757504 bytes, 124321792 sectors
1942528 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
Command (m for help): n
Partition type
p primary partition (1-4)
e extended
p
Partition number (1-4): 1
First sector (16-124321791, default 16):
Using default value 16
Last sector or +size{,K,M,G,T} (16-124321791, default 124321791): +1G //主分区1G,用来存放image.ub
Command (m for help): n
Partition type
p primary partition (1-4)
e extended
e
Partition number (1-4): 2
First sector (2097168-124321791, default 2097168):
Using default value 2097168
Last sector or +size{,K,M,G,T} (2097168-124321791, default 124321791)://剩下的所有空间都给扩展分区,用来做文件系统
Using default value 124321791
Command (m for help): p
Disk /dev/mmcblk0: 59 GB, 63652757504 bytes, 124321792 sectors
1942528 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk0p1 0,1,1 1023,3,16 16 2097167 2097152 1024M 83 Linux
/dev/mmcblk0p2 1023,3,16 1023,3,16 2097168 124321791 122224624 58.2G 5 Extended
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
mmcblk0: p1 p2 < >
mmcblk0: p1 p2 < >
root@2-emmc:~#
11.格式化分区
如果没有mkfs.ext4命令,请参考我的另外一篇博客:《zynq7000学习笔记》
root@2-emmc:~# mkfs.vfat /dev/mmcblk0p1
root@2-emmc:~# mkfs.ext4 /dev/mmcblk0p2
mke2fs 1.44.3 (10-July-2018)
Found a dos partition table in /dev/mmcblk0p2
Proceed anyway? (y,N) y
64-bit filesystem support is not enabled. The larger fields afforded by this feature enable full-strength checksumming. Pass -O 64bit to rectify.
Discarding device blocks: done
Creating filesystem with 10485760 4k blocks and 2621440 inodes
Filesystem UUID: 81ea86ef-96b6-4e39-8b52-78940a5ef335
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done
- 挂载emmc的两个分区 。
root@2-emmc:~# cd /mnt/
root@2-emmc:/mnt# mkdir mmcp1
root@2-emmc:/mnt# mkdir mmcp2
root@2-emmc:/mnt# mount /dev/mmcblk0p1 /mnt/mmcp1/
root@2-emmc:/mnt# mount /dev/mmcblk0p2 /mnt/mmcp2/
- 重新编译一个ext4文件系统的image
petalinux-config -> Image Packaging Configuration ---> Root filesystem type (EXT (SD/eMMC/QSPI/SATA/USB))
petalinux-build
//假设重新编译的image叫做emmc_image.ub,为了和刚才的image区分。
image/linux/image.ub是内核镜像(重命名为emmc_image.ub)
image/linux/rootfs.tar.gz是文件系统- 在目标机上利用tftp命令获取emmc_image.ub到mmcblk0p1,将rootfs.tar.gz解压到mmcblk0p2上
root@2-emmc:~# cd /mnt/mmcp1/
root@2-emmc:/mnt/mmcp1# tftp -g -r emmc/image.ub 192.168.1.50
root@2-emmc:/mnt/mmcp1# ls
image.ub
root@2-emmc:/mnt/mmcp1# cd /mnt/mmcp2/
root@2-emmc:/mnt/mmcp2# tftp -g -r emmc/rootfs.tar.gz 192.168.1.50
root@2-emmc:/mnt/mmcp2# tar -zxvpf rootfs.tar.gz
./
./usr/
./usr/lib/
./usr/lib/libelf-0.175.so
./usr/lib/libssl.so.1.1
...
root@2-emmc:/mnt/mmcp2# ls
bin emmcpe lib mmcp2 run usr
boot etc lost+found mnt sbin var
dev home media proc sys
emmcp2 image.ub mmcp1 rootfs.tar.gz tmp
root@2-emmc:/mnt/mmcp2# rm -rf rootfs.tar.gz
root@2-emmc:/mnt/mmcp2# ls
bin emmcp2 home lost+found mmcp2 run tmp
boot emmcpe image.ub media mnt sbin usr
dev etc lib mmcp1 proc sys var
root@2-emmc:/mnt/mmcp2#
- 重启目标机就可以了。
注意事项:
- 挂载
/dev/mmcblk0p2
失败
root@2-emmc:~# mount /dev/mmcblk0p2 /mnt
EXT4-fs (mmcblk0p2): unable to read superblock
EXT4-fs (mmcblk0p2): unable to read superblock
EXT4-fs (mmcblk0p2): unable to read superblock
EXT4-fs (mmcblk0p2): unable to read superblock
EXT4-fs (mmcblk0p2): unable to read superblock
EXT4-fs (mmcblk0p2): unable to read superblock
mount: mounting /dev/mmcblk0p2 on /mnt failed: Invalid argument
这个是因为mkfs.ext4 /dev/mmcblk0p2
失败导致的,出现如下打印才是格式化成功。格式化需要几十秒钟。
root@2-emmc:~# mkfs.ext4 /dev/mmcblk0p2
mke2fs 1.44.3 (10-July-2018)
Found a dos partition table in /dev/mmcblk0p2
Proceed anyway? (y,N) y
64-bit filesystem support is not enabled. The larger fields afforded by this feature enable full-strength checksumming. Pass -O 64bit to rectify.
Discarding device blocks: done
Creating filesystem with 10485760 4k blocks and 2621440 inodes
Filesystem UUID: 81ea86ef-96b6-4e39-8b52-78940a5ef335
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done
- 如果出现fdisk修改分区之后,分区表写不进去的情况,可以多尝试几次写操作。
Command (m for help): w
The partition table has been altered.
Failed to add partition 1 to system: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
root@2-emmc:~# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): w
The partition table has been altered.
Syncing disks.