tiny4412核心板用到了三星exynos4412芯片。
2020版的uboot支持spl, spl使得uboot可以编译出一个比较小巧的uboot_spl.bin的镜像文件,叫做辅助引导程序。可以加载到芯片SoC里面的ram上进行运行。
在为tiny4412编译uboot时,烧录的时候用到三星提供的sd_fuse程序。
烧录程序时,uboot_spl.bin小于14KB,我打算把uboot_spl.bin变为bl2.bin,烧录到sd卡的bl2分区上。
运行脚本sudo ./sd_fusing.sh /dev/sdd
发现类似如下的提示:
/dev/sdd reader is identified.
Usage: unsupported size
---------------------------------------
BL1 fusing
16+0 records in
16+0 records out
8192 bytes (8.2 kB, 8.0 KiB) copied, 0.0789386 s, 104 kB/s
---------------------------------------
BL2 fusing
28+0 records in
28+0 records out
14336 bytes (14 kB, 14 KiB) copied, 0.0987058 s, 145 kB/s
---------------------------------------
u-boot fusing
679+1 records in
679+1 records out
347883 bytes (348 kB, 340 KiB) copied, 1.57829 s, 220 kB/s
---------------------------------------
TrustZone S/W fusing
184+0 records in
184+0 records out
94208 bytes (94 kB, 92 KiB) copied, 0.402006 s, 234 kB/s
---------------------------------------
U-boot image is fused successfully.
Eject SD card and insert it again.
明显有这个错误,Usage: unsupported size,uboot_spl.bin并未变为bl2.bin。
Usage: unsupported size 来自V310-EVT1-mkbl2.c
V310-EVT1-mkbl2.c编译为mkbl2,主要作用是把要烧录到bl2分区的镜像处理成SoC能够识别的镜像。
比如可以执行 ./mkbl2 uboot_spl.bin bl2.bin 14336
意思是把boot_spl.bin的前14KB通过mkbl2变成bl2.bin,以便SoC芯片能够处理这个镜像。
打开V310-EVT1-mkbl2.c文件,发现只要
if ( BufLen > fileLen )
{
printf("Usage: unsupported size\n");
free(Buf);
fclose(fp);
return -1;
}
因为boot_spl.bin小于14KB,所以报错,并为执行转换。
所以我把V310-EVT1-mkbl2.c这个文件修改如下:(去掉长度的限制)
/*
* Copyright (c) 2010 Samsung Electronics Co., Ltd.
* http://www.samsung.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
FILE *fp;
unsigned char src;
char *Buf, *a;
int BufLen;
int nbytes, fileLen;
unsigned int checksum = 0;
int i;
if (argc != 4)
{
printf("Usage: mkbl1 <source file> <destination file> <size> \n");
return -1;
}
BufLen = atoi(argv[3]);
Buf = (char *)malloc(BufLen);
memset(Buf, 0x00, BufLen);
fp = fopen(argv[1], "rb");
if( fp == NULL)
{
printf("source file open error\n");
free(Buf);
return -1;
}
fseek(fp, 0L, SEEK_END);
fileLen = ftell(fp);
fseek(fp, 0L, SEEK_SET);
if (fileLen > BufLen)
fileLen = BufLen;
nbytes = fread(Buf, 1, BufLen, fp);
if ( nbytes != fileLen )
{
printf("source file read error\n");
free(Buf);
fclose(fp);
return -1;
}
fclose(fp);
for(i = 0;i < (14 * 1024) - 4;i++)
{
checksum += (unsigned char)(Buf[i]);
}
*(unsigned int*)(Buf+i) = checksum;
fp = fopen(argv[2], "wb");
if (fp == NULL)
{
printf("destination file open error\n");
free(Buf);
return -1;
}
a = Buf;
nbytes = fwrite( a, 1, BufLen, fp);
if ( nbytes != BufLen )
{
printf("destination file write error\n");
free(Buf);
fclose(fp);
return -1;
}
free(Buf);
fclose(fp);
return 0;
}
与原来文件的差别如下:
--- V310-EVT1-mkbl2_old.c 2020-10-11 10:52:51.502287669 +0800
+++ V310-EVT1-mkbl2.c 2020-10-15 16:58:48.595410174 +0800
@@ -43,17 +43,11 @@
fileLen = ftell(fp);
fseek(fp, 0L, SEEK_SET);
- if ( BufLen > fileLen )
- {
- printf("Usage: unsupported size\n");
- free(Buf);
- fclose(fp);
- return -1;
- }
+ if (fileLen > BufLen)
+ fileLen = BufLen;
nbytes = fread(Buf, 1, BufLen, fp);
-
- if ( nbytes != BufLen )
+ if ( nbytes != fileLen )
{
printf("source file read error\n");
free(Buf);