1.1 S5PV210 的启动过程
文档S5PV210_iROM_ApplicationNote_Preliminary_20091126.pdf(以下简称启动文档)详细描述了S5PV210的启动过程,基本过程如下图所示,详细过程和内容请见启动文档。
1.2 BL1的 Header information
从1.1节可知,S5PV210可以从eSSD,NAND,one NAND,NORFlash,SD/MMC和UART/USB多种介质启动,但启动文档2.4.2节指出,UART/USB启动时,BL1不需要Header information,其他启动方式则需要Header
information,原文如下(原文有错误,这里将0xd002_0010和0xd002_0000做了对调)。
As BL1 doesn’t need header information through UART/USB boot mode, BL1’s code base address is 0xd002_0010. In other cases except UART/USB boot mode, BL1 should have header information and It’s code base address is 0xd0020000. (refer chapter 2.9)
|
启动文档2.9节指出,BL1的Header information用于从启动介质把代码copy到intenal SRAM时的校验,具体内容如下图,因此程序员需要在代码编译时制作Header information,在此以友善之臂+朱有鹏老师的mkv210_image.c为例,详细解析BL1的 Header information制作过程。
2.9 Header information data for Boot Code description
The BL1 must have header data. The header data is used for being copied to internal SRAM by iROM code.The header data has two information. One is size of BL1 and Another is checksum data of BL1.
When loading BL1, iROM check size of BL1 in header data and copy BL1 to internal SRAM.After coping BL1, iROM sum data of copied BL1 and compare it to checksum data in header data of BL1.If it is success, BL1 start. otherwise iROM will try second boot(4-bit SD/MMC) from SDMMC channel 2 port.
|
1.3
代码解析
-
/*
-
* mkv210_image.c的作用是为BL1添加header information(包括BL1 size和Checksum)
-
*
-
* 本文件来自于友善之臂+朱有鹏的裸机教程。
-
*/
-
/* 在BL0阶段,iROM内固化的代码读取启动介质eSSD,NAND,one NAND,NORFlash或SD/MMC前16K的内容,
-
* 并比对前16字节中的校验和是否正确,正确则继续,错误则停止;UART/USB启动不需要BL1的header information。
-
*/
-
#include <stdio.h>
-
#include <string.h>
-
#include <stdlib.h>
-
-
#define BUFSIZE (16*1024)
-
#define IMG_SIZE (16*1024)
-
#define SPL_HEADER_SIZE 16
-
//#define SPL_HEADER "S5PC110 HEADER "
-
#define SPL_HEADER "****************"
-
-
int main (int argc, char *argv[]) //从外面传递参数到main函数
-
{
-
FILE *fp;
-
char *Buf, *a;
-
int BufLen;
-
int nbytes, fileLen;
-
unsigned int checksum, count;
-
int i;
-
-
// 1. 3个参数
-
if (argc != 3)
-
{
-
printf("Usage: %s \n", argv[0]);
-
return -1;
-
}
-
-
// 2. 分配16K的buffer
-
BufLen = BUFSIZE;
-
Buf = (char *)malloc(BufLen);
-
if (!Buf)
-
{
-
printf("Alloc buffer failed!\n");
-
return -1;
-
}
-
-
memset(Buf, 0x00, BufLen);
-
-
// 3. 读源bin到buffer
-
// 3.1 打开源bin
-
fp = fopen(argv[1], "rb");
-
if( fp == NULL)
-
{
-
printf("source file open error\n");
-
free(Buf);
-
return -1;
-
}
-
// 3.2 获取源bin长度
-
fseek(fp, 0L, SEEK_END); // 定位到文件尾
-
fileLen = ftell(fp); // 得到文件长度
-
fseek(fp, 0L, SEEK_SET); // 再次定位到文件头
-
// 3.3 源bin长度不得超过16K-16byte
-
count = (fileLen < (IMG_SIZE - SPL_HEADER_SIZE))
-
? fileLen : (IMG_SIZE - SPL_HEADER_SIZE);
-
// 3.4 buffer[0~15]存放"S5PC110 HEADER "
-
memcpy(&Buf[0], SPL_HEADER, SPL_HEADER_SIZE);
-
// 3.5 读源bin到buffer[16]
-
nbytes = fread(Buf + SPL_HEADER_SIZE, 1, count, fp);
-
if ( nbytes != count )
-
{
-
printf("source file read error\n");
-
free(Buf);
-
fclose(fp);
-
return -1;
-
}
-
fclose(fp);
-
-
// 4. 计算校验和
-
// 4.1 从第16byte开始计算,把buffer中所有的字节数据加和起来得到的结果
-
a = Buf + SPL_HEADER_SIZE;
-
for(i = 0, checksum = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++)
-
checksum += (0x000000FF) & *a++;
-
// 4.2 将校验和保存在buffer[8~15]
-
a = Buf + 8;
-
*( (unsigned int *)a ) = checksum;
-
-
// 5. 拷贝buffer中的内容到目的bin
-
// 5.1 打开目的bin
-
fp = fopen(argv[2], "wb");
-
if (fp == NULL)
-
{
-
printf("destination file open error\n");
-
free(Buf);
-
return -1;
-
}
-
// 5.2 将16k的buffer拷贝到目的bin中
-
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;
-
}
阅读(1595) | 评论(0) | 转发(0) |