0
点赞
收藏
分享

微信扫一扫

S5PV210的烧录脚本目录(sd_fusing)完整解析

有点d伤 2022-04-13 阅读 96

1、从SD卡启动的逻辑分析

2、制作启动SD卡

2.1、文件分析

	sd_fusing
	├── C110-EVT1-mkbl1.c
	├── c110.signedBL1_bin
	├── Makefile
	├── mkbl1
	├── sd_fdisk
	├── sd_fdisk.c
	├── sd_fusing2.sh
	└── sd_fusing.sh

2.2、编译指令

3、烧录脚本分析(sd_fusing.sh)

#SD卡或者mmc卡的设备文件
reader_type1="/dev/sdb"
reader_type2="/dev/mmcblk0"

#判断传入的$1是否为空
if [ -z $1 ]
then
    echo "usage: ./sd_fusing.sh [/dev/sdb | /dev/mmcblk0]"
    exit 0
fi

if [ $1 = $reader_type1 ]
then 
    partition1="$11"
    partition2="$12"
    partition3="$13"
    partition4="$14"

elif [ $1 = $reader_type2 ]
then 
    partition1="$1p1"
    partition2="$1p2"
    partition3="$1p3"
    partition4="$1p4"

else
    echo "Unsupported SD reader"
    exit 0
fi

#文件存在且为块设备文件
if [ -b $1 ]
then
    echo "$1 reader is identified."
else
    echo "$1 is NOT identified."
    exit 0
fi

####################################
# make partition
echo "make sd card partition"
echo "./sd_fdisk $1" 

#构建SD卡的MBR(主引导记录区),写入到0号扇区
./sd_fdisk $1 
dd iflag=dsync oflag=dsync if=sd_mbr.dat of=$1 
rm sd_mbr.dat
 
####################################
# format
umount $partition1 2> /dev/null
umount $partition2 2> /dev/null
umount $partition3 2> /dev/null
umount $partition4 2> /dev/null

#将SD卡格式化成vfat格式
echo "mkfs.vfat -F 32 $partition1"
mkfs.vfat -F 32 $partition1

#<BL1 fusing>
bl1_position=1
uboot_position=49

#截取uboot.bin的前8kb做成BL1
echo "BL1 fusing"
./mkbl1 ../u-boot.bin SD-bl1-8k.bin 8192

#将SD-bl1-8k.bin写入到SD卡的1扇区开始的地方。(扇区是编号从0开始的)
dd iflag=dsync oflag=dsync if=SD-bl1-8k.bin of=$1 seek=$bl1_position
rm SD-bl1-8k.bin

####################################
#<u-boot fusing>
echo "u-boot fusing"

# 将整个uboot写入到SD卡49扇区开始的地方,当做BL2
dd iflag=dsync oflag=dsync if=../u-boot.bin of=$1 seek=$uboot_position

####################################
#<Message Display>
echo "U-boot image is fused successfully."
echo "Eject SD card and insert it again."

4、制作BL1的代码分析(C110-EVT1-mkbl1.c)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main (int argc, char *argv[])
{
	FILE		*fp;
	char		*Buf, *a;
	int		BufLen;
	int		nbytes, fileLen;
	unsigned int	checksum;
	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 ( BufLen > fileLen )
	{
		printf("Usage: unsupported size\n");
		free(Buf);
		fclose(fp);
		return -1;
	}
	nbytes = fread(Buf, 1, BufLen, fp);

	if ( nbytes != BufLen )
	{
		printf("source file read error\n");
		free(Buf);
		fclose(fp);
		return -1;
	}
	fclose(fp);
	//计算校验和
	a = Buf + 16;
	for(i = 0, checksum = 0; i < BufLen - 16; i++)
		checksum += (0x000000FF) & *a++;

	//保存校验和
	a = Buf + 8;	
	*( (unsigned int *)a ) = 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;
}

5、BL1和BL2在SD中的分布

6、S5PV210对从SD卡启动的要求

在这里插入图片描述在这里插入图片描述在这里插入图片描述

7、uboot启动过程中读取BL2

7.1、函数调用关系

	start.S
		movi_bl2_copy()
			copy_bl2()

7.2、movi_bl2_copy函数分析

void movi_bl2_copy(void)
{
	ulong ch;
	
	ch = *(volatile u32 *)(0xD0037488);
	copy_sd_mmc_to_mem copy_bl2 =
	    (copy_sd_mmc_to_mem) (*(u32 *) (0xD0037F98));

	u32 ret;
	if (ch == 0xEB000000) {
		ret = copy_bl2(0, MOVI_BL2_POS, MOVI_BL2_BLKCNT,
			CFG_PHY_UBOOT_BASE, 0);
	}
	else if (ch == 0xEB200000) {
		ret = copy_bl2(2, MOVI_BL2_POS, MOVI_BL2_BLKCNT,
			CFG_PHY_UBOOT_BASE, 0);
	}
	else
		return;

	if (ret == 0)
		while (1)
			;
	else
		return;
}
举报

相关推荐

0 条评论