先明确:/dev/mmcblk0p1是SD卡的FAT区,/dev/mmcblk0p2是SD卡的EXT4,
/dev/mmcblk1是未进行分区的EMMC;一会下面会讲到要讲把EMMC分为 /dev/mmcblk1p1和 /dev/mmcblk1p2。
1,vivado硬件配置,要选择EMMC代表的SD1;
2,编译petalinux:执行petalinux-config。
(1)选择Subsystem AUTO Hardware Setting
-> Advanced bootable images storage settings
->boot image settings;
选择primary flash,这里是将BOOT.bin设置为从qspi flash启动
(2)选择Subsystem AUTO Hardware Setting
-> Advanced bootable images storage settings
->kernel image settings;
选择primary sd,进入后我们看到这里实际就是设置image.ub的存放区域。
(3)选择Image Packaging Configuration,设置启动启动文件系统所在位置;
在设置启动方式的时候,如下两张图这样设置读取根文件系统的位置/dev/mmcblk1p2。
(4)设置你的驱动然后编译,依次执行:petalinux-config -c kernel;petalinux-config -c rootfs;
petalinux-build;petalinux-package --boot --fsbl ./images/linux/zynq_fsbl.elf --fpga --u-boot --force;
3,做之前先分区(把EMMC分区),先做一个SD卡启动的petalinux文件,
petalinux系统在zynq上面启动起来以后就进行如下分区:即是mmcblk1分为mmcblk1p1和mmcblk1p2
具体步骤如下:
(1) 把EMMC进行分区,执行命令: fdisk /dev/mmcblk1
(2)使用n命令,添加一个新的分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
选择p,添加主分区
,(3)选择分区号,选择1,
Partition number (1-4): 1 // 选择分区号
First cylinder (1-238592, default 1): Using default value 1 // 选择分区的第一个柱面,选择1
Last cylinder or +size or +sizeM or +sizeK (1-238592, default 238592): Using default value 238592 // 选择最后一个柱面
注意:1-238592,first要选第一个数,last要选择的比238592小,其中1024就是表示1M
(4)使用t命令,设置分区格式
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (Win95 FAT32)
(5)使用w命令,保存配置,必须保存配置
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
(6)使用对应文件系统工具对分析进行格式化(只能在debian里面才能识别命令)
mkfs.fat /dev/mmcblk1p1 设置为fat32格式
mkfs.ext4 /dev/mmcblk1p2设置为ext4格式
注意:执行完w命令然后才算分区成功,执行完mkfs命令才算格设置内存属性成功。
以上分区完成后,可以使用p命令,显示分区信息;也可以使用用d命令表示删除分区
Command (m for help): p
Disk /dev/mmcblk0: 7818 MB, 7818182656 bytes
4 heads, 16 sectors/track, 238592 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 1 238592 7634936 83 Linux
(7)执行这句:mkdosfs -F 32 /dev/mmcblk0p1
当然,可以重复上述步骤,多分几个区,用来存放不同的状态:
FLASH要要用来存放BOOT.bin
第一个分区用来存放image.ub或者设备树(比如uImage和devicetree.dtb)等文件;--可以设置为128MB
第二个分区用来存放用户数据(比如可执行程序);可以设置为2048MB
第三个分区用来存放程序执行需要的库文件(opencv的库,qtcreator库,相机库,视频编码解码库等);剩余的1个多GB
4,把系统同步到ext4里面
先把sd卡里面系统挂载进来 :mount /dev/mmcblk0p2 /mnt
再把刚刚弄好的系统挂进来: mount /dev/mmcblk1p2 /tmp , 然后cd /mnt
然后进入把SD卡里面的系统同步到emmc里面:rsync -av ./* /tmp ,时间有点久,直到结束为止。
(要是不用SD卡也可以挂载U盘,解压,然后进行系统同步到EMMC所挂载的地方/tmp)
5,然后将BOOT.BIN和image.ub烧录到QSPI-FLASH中
首先擦除QSPI-FLASH:flash_erashall /dev/mtd0
存放BOOT.bin到flash : flashcp BOOT.bin /dev/mtd0
此处若是将image.ub写入emmc的FAT分区中(不存放到flash中),先使用mount挂载eMMC的FAT分区,
然后将image.ub使用cp指令拷贝进 /mnt/mmcFat即可,也就是把uImage 拷贝到 /dev/mmcblk1p1;
进入uImage所在目录,然后执行 cp uImage /tmp;也就是把uImage存放到了 /dev/mmcblk1p1里面。
6,最后断电拔出SD卡,将拨码开关设置为flash启动,就能看到petalinux启动起来;
7,报错及其解决办法
(1)在 project-spec/meta-user/recipes-bsp/u-boot/files/platform-top.h 文件中修改为
#include
#define CONFIG_SYS_BOOTM_LEN 0xF000000
/*Required for uartless designs */
#ifndef CONFIG_BAUDRATE
#define CONFIG_BAUDRATE 115200
#ifdef CONFIG_DEBUG_UART
#undef CONFIG_DEBUG_UART
#endif
#endif
#ifdef CONFIG_BOOTCOMMAND
#undef CONFIG_BOOTCOMMAND
#define CONFIG_BOOTCOMMAND "mmc dev ${sdbootdev}; run default_bootcmd"
#endif
(2)
/*
* This file is auto-generated by PetaLinux SDK
* DO NOT MODIFY this file, the modification will not persist
*/
#ifndef __PLNX_CONFIG_H
#define __PLNX_CONFIG_H
/* Board oscillator frequency */
#define CONFIG_ZYNQ_PS_CLK_FREQ 33333333UL
/* The following table includes the supported baudrates */
#define CONFIG_SYS_BAUDRATE_TABLE {9600, 19200, 38400, 57600, 115200, 230400}
/* use serial multi for all serial devices */
#define CONFIG_SERIAL_MULTI
#define CONFIG_SYS_CONSOLE_IS_IN_ENV 1
/* Board name */
/* processor - ps7_cortexa9_0 */
#define CONFIG_CPU_FREQ_HZ 666666687
#define CONFIG_CLOCKS
#define CONFIG_CMD_CLK
#define CONFIG_SYS_CACHELINE_SIZE 32
#define CONFIG_SYS_LDSCRIPT "arch/arm/mach-zynq/u-boot.lds"
/* main_memory - ps7_ddr_0 */
/* uart - ps7_uart_1 */
#define CONFIG_ZYNQ_SERIAL
#define PSSERIAL0 "psserial0=setenv stdout ttyPS0;setenv stdin ttyPS0\0"
#define SERIAL_MULTI "serial=setenv stdout serial;setenv stdin serial\0"
#define CONSOLE_ARG "console=console=ttyPS0,115200\0"
#define SERIAL_MULTI "serial=setenv stdout serial;setenv stdin serial\0"
#define CONFIG_BAUDRATE 115200
/* ethernet - ps7_ethernet_0 */
#define CONFIG_SYS_FAULT_ECHO_LINK_DOWN
#define CONFIG_PHY_XILINX
#define CONFIG_MII
#define CONFIG_PHY_GIGE
#define CONFIG_PHY_MARVELL
#define CONFIG_PHY_NATSEMI
#define CONFIG_NET_MULTI
#define CONFIG_NETCONSOLE 1
#define CONFIG_SERVERIP 192.168.231.129
#define CONFIG_IPADDR
/* spi_flash - ps7_qspi_0 */
#define XILINX_PS7_QSPI_CLK_FREQ_HZ 200000000
#define CONFIG_SF_DEFAULT_SPEED (XILINX_PS7_QSPI_CLK_FREQ_HZ / 4)
#define CONFIG_SF_DUAL_FLASH
#define CONFIG_SYS_NO_FLASH
/* sdio - ps7_sd_1 */
#define CONFIG_ZYNQ_SDHCI1
#define CONFIG_MMC
#define CONFIG_GENERIC_MMC
#define CONFIG_SUPPORT_VFAT
#define CONFIG_DOS_PARTITION
#define CONFIG_FAT_WRITE
#define CONFIG_ZYNQ_SDHCI_MAX_FREQ 52000000
/* devcfg - ps7_dev_cfg_0 */
#define CONFIG_FPGA
#define CONFIG_FPGA_XILINX
#define CONFIG_FPGA_ZYNQPL
#define CONFIG_CMD_FPGA_LOADFS
/* ps7_scutimer_0 */
#define ZYNQ_SCUTIMER_BASEADDR 0xF8F00600
#define CONFIG_SYS_TIMER_COUNTS_DOWN
#define CONFIG_SYS_TIMERBASE ZYNQ_SCUTIMER_BASEADDR
#define CONFIG_SYS_TIMER_COUNTER (CONFIG_SYS_TIMERBASE + 0x4)
/* FPGA */
/* Memory testing handling */
#define CONFIG_SYS_MEMTEST_START 0x0
#define CONFIG_SYS_MEMTEST_END (0x0 + 0x1000)
#define CONFIG_SYS_LOAD_ADDR 0x0 /* default load address */
#define CONFIG_NR_DRAM_BANKS 1
/* Size of malloc() pool */
#define SIZE 0xC00000
#define CONFIG_SYS_MALLOC_LEN SIZE
/* Physical Memory Map */
#define CONFIG_SYS_INIT_RAM_ADDR 0xFFFF0000
#define CONFIG_SYS_INIT_RAM_SIZE 0x1000
#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \
CONFIG_SYS_INIT_RAM_SIZE - \
GENERATED_GBL_DATA_SIZE)
/* BOOTP options */
#define CONFIG_BOOTP_SERVERIP
#define CONFIG_BOOTP_BOOTFILESIZE
#define CONFIG_BOOTP_BOOTPATH
#define CONFIG_BOOTP_GATEWAY
#define CONFIG_BOOTP_HOSTNAME
#define CONFIG_BOOTP_MAY_FAIL
/*Command line configuration.*/
#define CONFIG_CMDLINE_EDITING
#define CONFIG_CMD_SAVES
/* Miscellaneous configurable options */
#define CONFIG_SYS_CBSIZE 2048/* Console I/O Buffer Size */
#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
/* Boot Argument Buffer Size */
#define CONFIG_SYS_MAXARGS 32 /* max number of command args */
#define CONFIG_SYS_LONGHELP
/* architecture dependent code */
#define CONFIG_SYS_USR_EXCEP /* user exception */
#define CONFIG_SYS_HZ 1000
/* Use the HUSH parser */
#define CONFIG_SYS_PROMPT_HUSH_PS2 "> "
/* Don't define BOOTARGS, we get it from the DTB chosen fragment */
#undef CONFIG_BOOTARGS
#define CONFIG_ENV_OVERWRITE /* Allow to overwrite the u-boot environment variables */
#define CONFIG_LMB
/* Initial memory map for Linux */
#define CONFIG_SYS_BOOTMAPSZ 0x08000000
/* Environment settings*/
#define CONFIG_ENV_IS_IN_SPI_FLASH
#define CONFIG_ENV_SPI_MAX_HZ 30000000
#define CONFIG_ENV_OFFSET 0x500000
#define CONFIG_ENV_SIZE 0x20000
#define CONFIG_ENV_SECT_SIZE 0x20000
/* PREBOOT */
#define CONFIG_PREBOOT "echo U-BOOT for emmc;setenv preboot; echo; dhcp"
/* Extra U-Boot Env settings */
#define CONFIG_EXTRA_ENV_SETTINGS \
SERIAL_MULTI \
CONSOLE_ARG \
PSSERIAL0 \
"nc=setenv stdout nc;setenv stdin nc;\0" \
"ethaddr=00:0a:35:00:1e:53\0" \
"sdbootdev=1\0" \
"bootenv=uEnv.txt\0" \
"importbootenv=echo \"Importing environment from SD ...\"; " \
"env import -t ${loadbootenv_addr} $filesize\0" \
"loadbootenv=load mmc $sdbootdev:$partid ${loadbootenv_addr} ${bootenv}\0" \
"sd_uEnvtxt_existence_test=test -e mmc $sdbootdev:$partid /uEnv.txt\0" \
"uenvboot=" \
"if run sd_uEnvtxt_existence_test; then " \
"run loadbootenv; " \
"echo Loaded environment from ${bootenv}; " \
"run importbootenv; " \
"fi; " \
"if test -n $uenvcmd; then " \
"echo Running uenvcmd ...; " \
"run uenvcmd; " \
"fi\0" \
"autoload=no\0" \
"clobstart=0x10000000\0" \
"netstart=0x10000000\0" \
"dtbnetstart=0x11800000\0" \
"loadaddr=0x10000000\0" \
"bootsize=0x500000\0" \
"bootstart=0x0\0" \
"boot_img=BOOT.BIN\0" \
"load_boot=tftpboot ${clobstart} ${boot_img}\0" \
"update_boot=setenv img boot; setenv psize ${bootsize}; setenv installcmd \"install_boot\"; run load_boot test_img; setenv img; setenv psize; setenv installcmd\0" \
"sd_update_boot=echo Updating boot from SD; mmcinfo && fatload mmc ${sdbootdev}:1 ${clobstart} ${boot_img} && run install_boot\0" \
"install_boot=sf probe 0 && sf erase ${bootstart} ${bootsize} && " \
"sf write ${clobstart} ${bootstart} ${filesize}\0" \
"bootenvsize=0x20000\0" \
"bootenvstart=0x500000\0" \
"eraseenv=sf probe 0 && sf erase ${bootenvstart} ${bootenvsize}\0" \
"jffs2_img=rootfs.jffs2\0" \
"load_jffs2=tftpboot ${clobstart} ${jffs2_img}\0" \
"update_jffs2=setenv img jffs2; setenv psize ${jffs2size}; setenv installcmd \"install_jffs2\"; run load_jffs2 test_img; setenv img; setenv psize; setenv installcmd\0" \
"sd_update_jffs2=echo Updating jffs2 from SD; mmcinfo && fatload mmc ${sdbootdev}:1 ${clobstart} ${jffs2_img} && run install_jffs2\0" \
"install_jffs2=sf probe 0 && sf erase ${jffs2start} ${jffs2size} && " \
"sf write ${clobstart} ${jffs2start} ${filesize}\0" \
"kernel_img=image.ub\0" \
"load_kernel=tftpboot ${clobstart} ${kernel_img}\0" \
"update_kernel=setenv img kernel; setenv psize ${kernelsize}; setenv installcmd \"install_kernel\"; run load_kernel ${installcmd}; setenv img; setenv psize; setenv installcmd\0" \
"install_kernel=mmcinfo && fatwrite mmc 0 ${clobstart} ${kernel_img} ${filesize}\0" \
"cp_kernel2ram=mmcinfo && fatload mmc ${sdbootdev} ${netstart} ${kernel_img}\0" \
"dtb_img=system.dtb\0" \
"load_dtb=tftpboot ${clobstart} ${dtb_img}\0" \
"update_dtb=setenv img dtb; setenv psize ${dtbsize}; setenv installcmd \"install_dtb\"; run load_dtb test_img; setenv img; setenv psize; setenv installcmd\0" \
"sd_update_dtb=echo Updating dtb from SD; mmcinfo && fatload mmc ${sdbootdev}:1 ${clobstart} ${dtb_img} && run install_dtb\0" \
"loadbootenv_addr=0x00100000\0" \
"fault=echo ${img} image size is greater than allocated place - partition ${img} is NOT UPDATED\0" \
"test_crc=if imi ${clobstart}; then run test_img; else echo ${img} Bad CRC - ${img} is NOT UPDATED; fi\0" \
"test_img=setenv var \"if test ${filesize} -gt ${psize}\\; then run fault\\; else run ${installcmd}\\; fi\"; run var; setenv var\0" \
"netboot=tftpboot ${netstart} ${kernel_img} && bootm\0" \
"default_bootcmd=run uenvboot; run cp_kernel2ram && bootm ${netstart}\0" \
""
/* BOOTCOMMAND */
#define CONFIG_BOOTCOMMAND "run default_bootcmd"
#endif /* __PLNX_CONFIG_H */
8,修改后,启动成功