论坛元老
- 积分
- 6379
- 金钱
- 6379
- 注册时间
- 2015-8-25
- 在线时间
- 1004 小时
|
发表于 2020-8-21 15:13:45
|
显示全部楼层
这个不清楚,你可以试试在imxdownload.c中加入烧录是否成功的检查
下面是我用的,烧录完再从SD卡读回来跟烧录的文件比较下看看是否成功并输出提示信息:
int main(int argc, char *argv[])
{
FILE *fp;
unsigned char *buf;
unsigned char *cmdbuf;
int nbytes, filelen;
int i = 0, j = 0;
int ddrsize = 0; /* 0为512MB,1为256MB,2为128MB...... */
int block_size = 0; /* 烧录的块数 */
int status = 0;
message_print();
if((argc != 3) && (argc != 4)){
printf("Error Usage! Reference Below:\r\n");
printf("sudo ./%s <-512m or -256m> <source_bin> <sd_device>\r\n", argv[0]);
return -1;
}
/* 查找参数,获取DDR容量 */
for(i = 0; i < argc; i++)
{
char *param = argv;
if(param[0] != '-')
continue;
if(strcmp(param, "-256m") == 0) /* 256MB */
ddrsize = 1;
else if(strcmp(param, "-512m") == 0) /* 512MB */
ddrsize = 0;
}
if(argc == 3) /* 三个参数,也就是不输入DDR容量的话默认为512MB */
ddrsize = 0;
/* 打开bin文件 */
fp = fopen(argv[1], "rb"); /* 以二进制只读方式打开bin文件 */
if(fp == NULL){
printf("Can't Open file %s\r\n", argv[1]);
return -1;
}
/* 获取bin文件长度 */
fseek(fp, 0L, SEEK_END);
filelen = ftell(fp);
fseek(fp, 0L, SEEK_SET);
printf("file %s size = %dBytes\r\n", argv[1], filelen);
/* 读取bin文件到缓冲区buf中 */
buf = malloc(filelen + BIN_OFFSET);
if(buf == NULL){
printf("Mem Malloc Failed!\r\n");
fclose(fp);
return -1;
}
memset(buf, 0, filelen + BIN_OFFSET); /* 清零 */
/* 读取bin源码文件 */
fread(buf + BIN_OFFSET, 1, filelen, fp);
/* 关闭文件 */
fclose(fp);
#if PRINT_TAB
printf("IVT DCD Table:\r\n");
for(i = 0; i < 1024/32; i++){
for(j = 0; j < 8; j++)
{
printf("0X%08X,",*(int *)(buf + BIN_OFFSET + (((i * 8) + j) * 4)));
}
printf("\r\n");
}
free(buf);
return 0;
#endif
/* 添加IVT DCD等表信息到bin文件里面 */
if(ddrsize == 0) { /* 512MB */
printf("Board DDR SIZE: 512MB\r\n");
memcpy(buf, imx6_512mb_ivtdcd_table, sizeof(imx6_512mb_ivtdcd_table));
}
else if (ddrsize == 1) { /* 256MB */
printf("Board DDR SIZE: 256MB\r\n");
memcpy(buf, imx6_256mb_ivtdcd_table, sizeof(imx6_256mb_ivtdcd_table));
}
/* 现在我们已经在buf中构建好了可以用于下载的bin文件,将buf中的数据保存到
* 到一个文件中,文件命名为load.imx
*/
printf("Delete Old load.imx\r\n");
system("rm -rf load.imx"); /* 先删除旧的load.imx文件 */
printf("Create New load.imx\r\n");
system("touch load.imx"); /* 创建新的load.imx文件 */
fp = fopen("load.imx", "wb"); /* 打开laod.imx */
if(fp == NULL){
printf("Cant't Open load.imx!!!\r\n");
free(buf);
return -1;
}
nbytes = fwrite(buf, 1, filelen + BIN_OFFSET, fp);
if(nbytes != (filelen + BIN_OFFSET)){
printf("File Write Error!\r\n");
free(buf);
fclose(fp);
return -1;
}
free(buf);
fclose(fp);
if(access((argv[2]), F_OK) == 0){
/* 构建烧写的shell命令 */
cmdbuf = malloc(SHELLCMD_LEN);
sprintf(cmdbuf, "sudo dd iflag=dsync oflag=dsync if=load.imx of=%s bs=512 seek=2",argv[2]);
printf("Download load.imx to %s ......\r\n", argv[2]);
/* 执行上面的shell命令 */
system(cmdbuf);
/* 检测bin文件是否正确烧录入SD卡 */
#ifndef SZC_CONFIRM
block_size = (filelen + BIN_OFFSET) / 512 + 1;
#else
block_size = ((filelen+BIN_OFFSET)%512)?((filelen+BIN_OFFSET)/512+1)(filelen+BIN_OFFSET)/512);
#endif
printf("\r\nCheck whether load.imx is burned correctly.....\r\n");
sprintf(cmdbuf, "sudo dd iflag=direct oflag=direct if=%s of=check.imx bs=512 count=%d skip=2",argv[2], block_size);
system(cmdbuf);
sprintf(cmdbuf, "sudo cmp -n %d check.imx load.imx", (filelen + BIN_OFFSET));
status = system(cmdbuf);
if (status == 0) {
printf ("load.imx is burned correclty.\r\n");
}else{
printf("load.imx is burned incorrectly.\r\n");
}
free(cmdbuf);
}else{
printf("%s is not found\r\n", argv[2]);
}
return 0;
} |
|