tiny4412 基础(一)启动过程

主要参考《Android_Exynos4212_iROM_Secure_Booting_Guide_Ver.1.00.00.pdf》,其启动方式和4412是类似的。

1.IROM CODE


This application note explains the way to build the secure BL1(1st Bootloader) and BL2(2nd Bootloader) images in
the booting environment of Exynos4212. iROM code(iROM Bootloader) of Exynos4212 confirms to download the
BL1 image with checksum, verifies the integrity of the secure BL1 image, decrypts the secure BL1 image, and
then iROM goes to BL1
IROM CODE是三星提供的程序包,不开源,我们拿到的是一个bin文件,后面会描述烧写位置。

tiny4412 基础(一)启动过程_第1张图片

 

The booting device can be selected by OM pins.
 

tiny4412 基础(一)启动过程_第2张图片

 

2.BL1 AND BL2 CODE
 

首先看BL1,BL1 code copies the BL2 image to internal RAM.
tiny4412 基础(一)启动过程_第3张图片

再看BL2:

BL2 code copies the OS image(BL3) to external DRAM area and checks the integrity of OS code
 

tiny4412 基础(一)启动过程_第4张图片

3.memory map

 

tiny4412 基础(一)启动过程_第5张图片

并详细说明了:

The size of the secure BL1 is8192B

In order to execute iROM properly, 5KB should be reserved at the start of internal memory. The secure
context for BL1 code should be located at 0x0202_3000 of internal memory. The size of BL2 code can be user
defined and depends on BL1 code. However, in S.LSI‟s reference code of BL1, the valid size of BL2 code would
be less than 14332B 14KB-4B, 4B is the checksum
) and if the size of BL2 code is less than 14332B, the rest area
up to 14332B should be filled with zeros. The signature for BL2 should be located 0x0202_6C00 of internal
memory and the checksum for BL2 should be at 0x0202_6BFC in S.LSI‟s reference code.
由上可知:

BL1 大小最大8K,

BL2为14K-4

这点和s5p210有区别的。

 

4.SD启动

 

tiny4412 基础(一)启动过程_第6张图片

BL1位于SD卡里面的偏移地址 512 字节处,可知IROM会把8K的BL1复制到0x02021400里面。

BL2 位于 SD 卡偏移地址(512+8K)字节处,BL1 从这个位置读入 14K 字节的数据,存在 iRAM地址 0x02023400
处。 BL2 不能大于(14K – 4)字节,最后 4 字节用于存放较验码
 

如果我们的程序大于(14K – 4)字节,那么需要截取前面(14K – 4)字节用来制作 BL2 并烧入 SD 卡偏移
地址 16K 字节处。当 BL2 启动后,由它来将存放在 SD 卡另外位置的、完整的程序读入内存。
板子一上电,首先执行 iROM, iROM 依次尝试从第 1 个 SD 卡、 NAND Flash、第 2 个 SD 卡、 SPI Nor Flash
上把程序读入内存中,一旦从某个设备上成功读出程序就会去启动它。
 

5.烧写过程

 

dd iflag=dsync oflag=dsync if=/work/4412/tools/E4412_N.bl1.bin of=$1 seek=1
dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=17

第 1 行的命令用于将 E4412_N.bl1.bin 烧写到 SD 卡的第 1 个扇区(扇区从 0 编号);
第 2 行的命令用于将 bl2.bin 烧写到 SD 卡的第 17 个扇区;
 

E4412_N.bl1.bin(BL1)是由三星原厂提供,没有源码, 它的作用在前面稍有介绍;
bl2.bin 是通过 mkbl2 工具处理源文件得到,具体实现如下
 

./mkbl2 xxx.bin bl2.bin 14336

mkbl2 是 用 来 生 成 bl2.bin 的 工 具 , 通 过 编 译 V310-EVT1-mkbl2.c 文 件
 

gcc -o mkbl2 V310-EVT1-mkbl2.c

通过分析 V310-EVT1-mkbl2.c 源码,我们可以知道,它主要做了这些工作:
1).从源文件中读取 14K 的数据到 Buf 当中;
2).处理 Buf 中前 14332 字节的数据,得到 4 字节的 checksum;
3).组装 Buf 中前 14332 字节的数据和 4 字节的 checksum,得到一个新的 14K 的 Buf 数据;
4).将 3)中构建的 Buf 数据写到 bl2.bin 文件中
 

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 
#include 
#include 

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    \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 ( BufLen > fileLen )
	{
		printf("Usage: unsupported size\n");
		free(Buf);
		fclose(fp);
		return -1;
	}
*/
	//nbytes = fread(Buf, 1, BufLen, fp);
	if(BufLen > fileLen)
		nbytes = fread(Buf, 1, fileLen, fp);
	else
		nbytes = fread(Buf, 1, BufLen, fp);
/*
	if ( nbytes != BufLen )
	{
		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;
}

 

你可能感兴趣的:(tiny4412,tiny4412)