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)
reader_type1="/dev/sdb"
reader_type2="/dev/mmcblk0"
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
echo "make sd card partition"
echo "./sd_fdisk $1"
./sd_fdisk $1
dd iflag=dsync oflag=dsync if=sd_mbr.dat of=$1
rm sd_mbr.dat
umount $partition1 2> /dev/null
umount $partition2 2> /dev/null
umount $partition3 2> /dev/null
umount $partition4 2> /dev/null
echo "mkfs.vfat -F 32 $partition1"
mkfs.vfat -F 32 $partition1
bl1_position=1
uboot_position=49
echo "BL1 fusing"
./mkbl1 ../u-boot.bin SD-bl1-8k.bin 8192
dd iflag=dsync oflag=dsync if=SD-bl1-8k.bin of=$1 seek=$bl1_position
rm SD-bl1-8k.bin
echo "u-boot fusing"
dd iflag=dsync oflag=dsync if=../u-boot.bin of=$1 seek=$uboot_position
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;
}