TQ210的u-boot应放在第49个扇区(按首扇区从0开始算),BL1放在扇区1,大小可以取8K,取16K也可以,只要能运行到搬运代码即可。
u-boot需要添加16字节的头信息,网上有个mkv210_image.c,还有zjh写的addheader.c,都差不多,由于TQ210的u-boot头部已经填充了16字节,所以需要该一下源码。
mktq210spl.c :
-
#include <stdio.h>
-
#include <string.h>
-
#include <stdlib.h>
-
-
#define IMG_SIZE (8 * 1024)//BL1=8K
-
#define HEADER_SIZE 16 //16字节
-
#define DATA_OFFSET 16 //16字节
-
#define UBOOT_SIZE (512* 1024)
-
-
/*
-
* Requirement:
-
* IROM code reads first 14K bytes from boot device.
-
* It then calculates the checksum of 14K-4 bytes and compare with data at
-
* 14K-4 offset.
-
*
-
* This function takes two filenames:
-
* IN "u-boot-spl.bin" and
-
* OUT "u-boot-mmc-spl.bin" as filenames.
-
* 1. 开辟缓冲区buffer
-
* 2. 读取输入文件到缓冲区u-boot-spl.bin
-
* 3. 计算校验和,存放头信息到buffer的前面16个字节
-
* 4. 保存buffer到输出文件u-boot-mmc-spl.bin
-
*/
-
-
int main (int argc, char *argv[])
-
{
-
FILE *fp;
-
unsigned char *buffer;
-
int bufferLen;
-
int nbytes, fileLen;
-
unsigned int checksum, count;
-
int i;
-
-
if (argc != 3)
-
{
-
printf("Usage: %s , argv[0]);
-
return -1;
-
}
-
-
/* 分配16KByte的buffer,BL1最大为16KByte,并初始化为0 */
-
buffer = calloc(1, UBOOT_SIZE);
-
if (!buffer)
-
{
-
perror("Alloc buffer failed!");
-
return -1;
-
}
-
-
/* 打开源bin文件 */
-
fp = fopen(argv[1], "rb");
-
if( fp == NULL)
-
{
-
perror("source file open error");
-
free(buffer);
-
return -1;
-
}
-
-
/* 获取源bin文件的长度 */
-
fseek(fp, 0L, SEEK_END);//指针定位到文件末尾
-
fileLen = ftell(fp);//计算当前指针到相对于文件首的偏移字节数,即文件长度
-
fseek(fp, 0L, SEEK_SET);
-
/* 源bin文件不得超过512KByte */
-
if (fileLen > UBOOT_SIZE)
-
{
-
fprintf(stderr, "Source file is too big(> 16KByte)\n");
-
free(buffer);
-
fclose(fp);
-
return 0;
-
}
-
if (fileLen > IMG_SIZE)
-
{
-
fileLen = IMG_SIZE;
-
}
-
/* 计算校验和 */
-
i = 0;
-
checksum = 0;
-
fseek(fp, DATA_OFFSET, SEEK_SET);//指针指向数据起始位置,即spl的第16字节
-
/* 从buffer[HEADER_SIZE]开始,复制bl1的(8K-16)字节 */
-
for (i = 0; i < (fileLen - DATA_OFFSET); i++)
-
{
-
fread(buffer + HEADER_SIZE + i, 1, 1, fp);
-
checksum += buffer[HEADER_SIZE + i];
-
}
-
printf("\ni = %d ", i);
-
printf("checksum = 0x%x\n", checksum );
-
fclose(fp);
-
-
/* 计算BL1的大小(BL1的大小包括BL1的头信息),并保存到buffer[0~3]中 */
-
fileLen -= DATA_OFFSET;
-
printf("Length of BL1 = %d\n", fileLen );
-
-
//保存BL1的长度(包含头信息)到buffer的最前面4个字节。
-
memcpy(buffer, &fileLen, 4);
-
-
// 将校验和保存在buffer[8~15]
-
memcpy(buffer + 8, &checksum, 4);
-
-
/* 打开目标文件 */
-
fp = fopen(argv[2], "wb");
-
if (fp == NULL)
-
{
-
perror("destination file open error");
-
free(buffer);
-
return -1;
-
}
-
// 将buffer拷贝到目标bin文件中
-
nbytes = fwrite(buffer, 1, fileLen, fp);
-
if (nbytes != fileLen)
-
{
-
perror("destination file write error");
-
free(buffer);
-
fclose(fp);
-
return -1;
-
}
-
-
free(buffer);
-
fclose(fp);
-
-
return 0;
-
}
使用addheader的烧写脚本:
#!/bin/sh
dd bs=1 count=8176 if=u-boot.bin of=spl.bin skip=16
./addheader spl.bin bl1.bin
dd bs=512 iflag=dsync oflag=dsync if=bl1.bin of=/dev/sdb seek=1
dd bs=512 iflag=dsync oflag=dsync if=u-boot.bin of=/dev/sdb seek=49
或者使用修改后的mktq210spl:
#!/bin/sh
./mktq210spl u-boot.bin bl1.bin
dd bs=512 iflag=dsync oflag=dsync if=bl1.bin of=/dev/sdb seek=1
dd bs=512 iflag=dsync oflag=dsync if=u-boot.bin of=/dev/sdb seek=49
阅读(1951) | 评论(0) | 转发(0) |