默认情况下QSPI拷贝文件到DDR中需要时间很长,15M左右大小的bin文件约30s左右。在某些产品中无法满足需求。
经排查发现u-boot代码中有对速度进行配置的地方,位于zynq-common.h中。
默认值为30000000,也就是30M,而QSPI主频最多可达到100M,所以应该可以通过修改该值提升QSPI读写速度。
但是从30M提升到50M后发现速度依然不变,怀疑代码中根本没有配置该值,于是对u-boot代码进行了检查。
排查发现在u-boot在/common/cmd_sf.c中用到了速度配置,函数如下:
static int do_spi_flash_probe(int argc,char * const argv[])
{
unsignedint bus = CONFIG_SF_DEFAULT_BUS;
unsignedint cs = CONFIG_SF_DEFAULT_CS;
unsigned int speed =CONFIG_SF_DEFAULT_SPEED;
unsigned int mode =CONFIG_SF_DEFAULT_MODE;
char*endp;
structspi_flash *new;
if (argc >= 2) {
cs = simple_strtoul(argv[1], &endp, 0);
if (*argv[1] == 0 || (*endp != 0 && *endp!= ':'))
return -1;
if (*endp == ':') {
if (endp[1] == 0)
return -1;
bus = cs;
cs = simple_strtoul(endp + 1, &endp,0);
if (*endp != 0)
return -1;
}
}
if (argc >= 3) {
speed = simple_strtoul(argv[2], &endp, 0);
if (*argv[2] == 0 || *endp != 0)
return -1;
}
if (argc >= 4) {
mode = simple_strtoul(argv[3], &endp, 16);
if (*argv[3] == 0 || *endp != 0)
return -1;
}
new = spi_flash_probe(bus, cs,speed, mode);
if(!new) {
printf("Failedto initialize SPI flash at %u:%u\n", bus, cs);
return1;
}
if(flash)
spi_flash_free(flash);
flash= new;
return0;
}
函数中的speed和mode决定了QSPI的访问速度和模式。打桩发现speed和mode一开始是被正确赋值的,但却在函数中被修改为了0,导致提升CONFIG_SF_DEFAULT_SPEED时speed值并没有改变。错误原因在于传入参数argv[]均为0
而argv[]参数应该在U_BOOT_CMD中进行配置,通常情况下用户不会主动去修改:
U_BOOT_CMD(
sf, 5, 1, do_spi_flash,
"SPIflash sub-system",
"probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n"
" and chip select\n"
"sfread addr offset len - read `len' bytesstarting at\n"
" `offset' to memory at `addr'\n"
"sfwrite addr offset len - write `len' bytesfrom memory\n"
" at `addr'to flash at `offset'\n"
"sferase offset [+]len - erase`len' bytes from `offset'\n"
" `+len' round up `len' to block size\n"
"sfupdate addr offset len - erase andwrite `len' bytes from memory\n"
" at `addr' to flash at `offset'"
SF_TEST_HELP
);
最简单的解决方法是将下面一段代码进行注释
static int do_spi_flash_probe(int argc,char * const argv[])
{
unsignedint bus = CONFIG_SF_DEFAULT_BUS;
unsignedint cs = CONFIG_SF_DEFAULT_CS;
unsignedint speed = CONFIG_SF_DEFAULT_SPEED;
unsignedint mode = CONFIG_SF_DEFAULT_MODE;
char*endp;
structspi_flash *new;
/*
if (argc >= 2) {
cs = simple_strtoul(argv[1], &endp, 0);
if (*argv[1] == 0 || (*endp != 0 && *endp!= ':'))
return -1;
if (*endp == ':') {
if (endp[1] == 0)
return -1;
bus = cs;
cs = simple_strtoul(endp + 1, &endp,0);
if (*endp != 0)
return -1;
}
}
if (argc >= 3) {
speed = simple_strtoul(argv[2], &endp, 0);
if (*argv[2] == 0 || *endp != 0)
return -1;
}
if (argc >= 4) {
mode = simple_strtoul(argv[3], &endp, 16);
if (*argv[3] == 0 || *endp != 0)
return -1;
}
*/
new= spi_flash_probe(bus, cs, speed, mode);
if(!new) {
printf("Failedto initialize SPI flash at %u:%u\n", bus, cs);
return1;
}
if(flash)
spi_flash_free(flash);
flash= new;
return0;
}
修改完成后QSPI到DDR内存的拷贝时间可以忽略不计。
需要注意的是如果拷贝速度太快可能会出错,所以设置speed在30M-50M之间就能满足要求了,不需要配置到100M。