Chinaunix首页 | 论坛 | 博客
  • 博客访问: 129139
  • 博文数量: 38
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 191
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-16 11:31
个人简介

嵌入式新人

文章分类

全部博文(38)

文章存档

2016年(38)

我的朋友

分类: 嵌入式

2016-05-11 08:27:12

1.1 S5PV210 的启动过程

文档S5PV210_iROM_ApplicationNote_Preliminary_20091126.pdf(以下简称启动文档)详细描述了S5PV210的启动过程,基本过程如下图所示,详细过程和内容请见启动文档。

 

1.2 BL1Header information

1.1节可知,S5PV210可以从eSSDNANDone NANDNORFlashSD/MMCUART/USB多种介质启动,但启动文档2.4.2节指出,UART/USB启动时,BL1不需要Header information,其他启动方式则需要Header information,原文如下(原文有错误,这里将0xd002_00100xd002_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节指出,BL1Header information用于从启动介质把代码copyintenal SRAM时的校验,具体内容如下图,因此程序员需要在代码编译时制作Header information,在此以友善之臂+朱有鹏老师的mkv210_image.c为例,详细解析BL1Header 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 代码解析


点击(此处)折叠或打开

  1. /*
  2.  * mkv210_image.c的作用是为BL1添加header information(包括BL1 size和Checksum)
  3.  *
  4.  * 本文件来自于友善之臂+朱有鹏的裸机教程。
  5.  */
  6. /* 在BL0阶段,iROM内固化的代码读取启动介质eSSD,NAND,one NAND,NORFlash或SD/MMC前16K的内容,
  7.  * 并比对前16字节中的校验和是否正确,正确则继续,错误则停止;UART/USB启动不需要BL1的header information。
  8.  */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>

  12. #define BUFSIZE (16*1024)
  13. #define IMG_SIZE (16*1024)
  14. #define SPL_HEADER_SIZE 16
  15. //#define SPL_HEADER "S5PC110 HEADER "
  16. #define SPL_HEADER "****************"

  17. int main (int argc, char *argv[]) //从外面传递参数到main函数
  18. {
  19.     FILE        *fp;
  20.     char        *Buf, *a;
  21.     int        BufLen;
  22.     int        nbytes, fileLen;
  23.     unsigned int    checksum, count;
  24.     int        i;
  25.     
  26.     // 1. 3个参数
  27.     if (argc != 3)
  28.     {
  29.         printf("Usage: %s \n", argv[0]);
  30.         return -1;
  31.     }

  32.     // 2. 分配16K的buffer
  33.     BufLen = BUFSIZE;
  34.     Buf = (char *)malloc(BufLen);
  35.     if (!Buf)
  36.     {
  37.         printf("Alloc buffer failed!\n");
  38.         return -1;
  39.     }

  40.     memset(Buf, 0x00, BufLen);

  41.     // 3. 读源bin到buffer
  42.     // 3.1 打开源bin
  43.     fp = fopen(argv[1], "rb");
  44.     if( fp == NULL)
  45.     {
  46.         printf("source file open error\n");
  47.         free(Buf);
  48.         return -1;
  49.     }
  50.     // 3.2 获取源bin长度
  51.     fseek(fp, 0L, SEEK_END);                                // 定位到文件尾
  52.     fileLen = ftell(fp);                                    // 得到文件长度
  53.     fseek(fp, 0L, SEEK_SET);                                // 再次定位到文件头
  54.     // 3.3 源bin长度不得超过16K-16byte
  55.     count = (fileLen < (IMG_SIZE - SPL_HEADER_SIZE))
  56.         ? fileLen : (IMG_SIZE - SPL_HEADER_SIZE);
  57.     // 3.4 buffer[0~15]存放"S5PC110 HEADER "
  58.     memcpy(&Buf[0], SPL_HEADER, SPL_HEADER_SIZE);
  59.     // 3.5 读源bin到buffer[16]
  60.     nbytes = fread(Buf + SPL_HEADER_SIZE, 1, count, fp);
  61.     if ( nbytes != count )
  62.     {
  63.         printf("source file read error\n");
  64.         free(Buf);
  65.         fclose(fp);
  66.         return -1;
  67.     }
  68.     fclose(fp);

  69.     // 4. 计算校验和
  70.      // 4.1 从第16byte开始计算,把buffer中所有的字节数据加和起来得到的结果
  71.     a = Buf + SPL_HEADER_SIZE;
  72.     for(i = 0, checksum = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++)
  73.         checksum += (0x000000FF) & *a++;
  74.     // 4.2 将校验和保存在buffer[8~15]
  75.     a = Buf + 8;                            
  76.     *( (unsigned int *)a ) = checksum;

  77.     // 5. 拷贝buffer中的内容到目的bin
  78.     // 5.1 打开目的bin
  79.     fp = fopen(argv[2], "wb");
  80.     if (fp == NULL)
  81.     {
  82.         printf("destination file open error\n");
  83.         free(Buf);
  84.         return -1;
  85.     }
  86.     // 5.2 将16k的buffer拷贝到目的bin中
  87.     a = Buf;
  88.     nbytes    = fwrite( a, 1, BufLen, fp);
  89.     if ( nbytes != BufLen )
  90.     {
  91.         printf("destination file write error\n");
  92.         free(Buf);
  93.         fclose(fp);
  94.         return -1;
  95.     }

  96.     free(Buf);
  97.     fclose(fp);

  98.     return 0;
  99. }
阅读(1506) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~