交叉工具链:arm-2009q3
环境:ubuntu+sourceInsight
目标板:CPU: S5PV210@1000MHz(OK)
APLL = 1000MHz, HclkMsys = 200MHz, PclkMsys = 100MHz
MPLL = 667MHz, EPLL = 80MHz
HclkDsys = 166MHz, PclkDsys = 83MHz
HclkPsys = 133MHz, PclkPsys = 66MHz
SCLKA2M = 200MHz
Serial = CLKUART
Board: SMDKV210
DRAM: 512 MB
Flash: 8 MB
SD/MMC: 1910MB
NAND: 256 MB
运行uboot命令help sdfuse 可知道:
sdfuse info - print primitive infomation.
sdfuse flashall - flash boot.img, system.img,
erase userdata, cache, and reboot.
sdfuse flash
[ ] - write a file to a partition.
sdfuse erase - erase (format) a partition.
sdfuse命令的源码在common/cmd_fastboot.c下实现。
命令的构造:
U_BOOT_CMD(
sdfuse, 4, 1, do_sdfuse,
"sdfuse - read images from FAT partition of SD card and write them to booting device.\n",
"info - print primitive infomation.\n"
"sdfuse flashall - flash boot.img, system.img,\n"
" erase userdata, cache, and reboot.\n"
"sdfuse flash [ ] - write a file to a partition.\n"
"sdfuse erase - erase (format) a partition.\n"
);
分析函数实现do_sdfuse:
-
/* SD Fusing : read images from FAT partition of SD Card, and write it to boot device.
-
*
-
* NOTE
-
* - sdfuse is not a original code of fastboot
-
* - Fusing image from SD Card is not a original part of Fastboot protocol.
-
* - This command implemented at this file to re-use an existing code of fastboot */
-
int do_sdfuse (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
-
{
-
int ret = 1;
-
int enable_reset = 0;
-
//1.寻找mmc设备
-
struct mmc *mmc = find_mmc_device(CFG_FASTBOOT_SDFUSE_MMCDEV);
-
-
//2.初始化mmc
-
if (mmc_init(mmc)) {
-
printf("sdmmc init is failed.\n");
-
}
-
-
//3.static struct cmd_fastboot_interface interface
-
interface.nand_block_size = CFG_FASTBOOT_PAGESIZE * 64;
-
interface.transfer_buffer = (unsigned char *) CFG_FASTBOOT_TRANSFER_BUFFER;
-
interface.transfer_buffer_size = CFG_FASTBOOT_TRANSFER_BUFFER_SIZE;
-
-
printf("[Fusing Image from SD Card.]\n");
-
-
//4.读取分区信息
-
if (set_partition_table())
-
return 1;
-
-
//5.help sdfuse 可以知道命令分为:
-
//sdfuse info
-
//sdfuse flashall
-
//sdfuse flash <partition> [ <filename> ]
-
//sdfuse erase <partition>
-
-
//执行sdfuse info命令
-
if ((argc == 2) && !strcmp(argv[1], "info"))
-
{
-
printf("sdfuse will read images from the followings:\n");
-
printf(" sd/mmc device : mmc %d:%d\n",
-
CFG_FASTBOOT_SDFUSE_MMCDEV, CFG_FASTBOOT_SDFUSE_MMCPART);
-
//images所在的目录CFG_FASTBOOT_SDFUSE_DIR
-
printf(" directory : %s\n", CFG_FASTBOOT_SDFUSE_DIR);
-
printf(" booting device : %s\n",
-
#if defined(CFG_FASTBOOT_ONENANDBSP)
-
"OneNAND"
-
#elif defined(CFG_FASTBOOT_NANDBSP)
-
"NAND"
-
#elif defined(CFG_FASTBOOT_SDMMCBSP)
-
"MoviNAND"
-
#else
-
#error "Unknown booting device!"
-
#endif
-
#if defined(CONFIG_FUSED)
-
" (on eFused Chip)"
-
#endif
-
);
-
return 0;
-
}
-
else if ((argc == 2) && !strcmp(argv[1], "flashall"))
-
//执行sdfuse flashall命令
-
{
-
//sdfuse flashhall -flash boot.img, system.img,erase userdata, cache, and reboot
-
LCD_turnon();
-
-
if (update_from_sd("boot", "boot.img"))
-
goto err_sdfuse;
-
if (update_from_sd("system", "system.img"))
-
goto err_sdfuse;
-
if (update_from_sd("userdata", NULL))
-
goto err_sdfuse;
-
if (update_from_sd("cache", NULL))
-
goto err_sdfuse;
-
-
enable_reset = 1;
-
ret = 0;
-
}
-
else if ((argc == 4) && !strcmp(argv[1], "flash"))
-
{
-
//执行sdfuse flash命令
-
LCD_turnon();
-
-
if (update_from_sd(argv[2], argv[3]))
-
goto err_sdfuse;
-
-
ret = 0;
-
}
-
else if ((argc == 3) && !strcmp(argv[1], "erase"))
-
{
-
-
//执行sdfuse erase命令
-
LCD_turnon();
-
-
if (update_from_sd(argv[2], NULL))
-
goto err_sdfuse;
-
-
ret = 0;
-
}
-
else
-
{
-
printf("Usage:\n%s\n", cmdtp->usage);
-
return 1;
-
}
-
-
-
-
err_sdfuse:
-
LCD_setfgcolor(0x000010);
-
LCD_setleftcolor(0x000010);
-
LCD_setprogress(100);
-
-
if (enable_reset)
-
do_reset (NULL, 0, 0, NULL);
-
-
return ret;
-
}
从源代码可知,do_sdfuse会调用set_partition_table获取分区信息:
-
....................
-
-
if (ptable_default_size >= sizeof(fastboot_ptentry))
-
{
-
printf("Fastboot: employ default partition information\n");
-
//memcpy(ptable, ptable_default, ptable_default_size);
-
//内存拷贝默认的分区信息到ptable
-
memcpy((void*)ptable, (void*)&ptable_default, ptable_default_size);
-
pcount = ptable_default_size / sizeof(fastboot_ptentry);
-
}
-
.......................
这里set_partition_table获取的是板的默认分区ptable_default,一个在cpu/s5pc11x/fastboot.c下定义为fastboot_ptentry类型的结构体数组
然后在当前函数下使用 fastboot_flash_dump_ptn();打印分区信息到串口
SD卡烧写的目标文件需要放在指定的目录下。在cmd_fastboot.c下有个宏:
//镜像所在目录
#define CFG_FASTBOOT_SDFUSE_DIR "/lucasSdfuse"
烧写的主要函数是update_from_sd (char *part, char *file),它接受两个字符串指针,分别是分区名称和目标文件名。烧写的过程是先从SD卡读取file,然后调用static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)烧写。具体的烧写动作如同nand erase 然后 nand write
通过do_sdfuse函数,我们就实现了sdfuse flash bootloader u-boot.bin这样的烧写过程。
------自定义一键烧写命令
在cmd_fastboot.c末尾添加一个自定义命令:
点击(此处)折叠或打开
-
U_BOOT_CMD(
-
alfred,1,1,do_Alfred_Sdfuse,
-
"alfred auto burning uboot kernel system \n",
-
"alfred auto burning uboot kernel system\n"
-
)
编写do_Alfred_Sdfuse函数:
-
int do_Alfred_Sdfuse (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
-
{
-
if(argc > 1){
-
//实现的效果是在uboot输入alfred这个命令就可以自动执行
-
//sdfuse flash bootloader u-boot.bin
-
//sdfuse flash kernel Kernel.img
-
//sdfuse flash system System.img
-
//所以只需要一个命令参数
-
return 1;
-
}
-
-
int ret = 1;
-
-
-
//1.寻找mmc设备
-
struct mmc *mmc = find_mmc_device(CFG_FASTBOOT_SDFUSE_MMCDEV);
-
-
//2.初始化mmc
-
if (mmc_init(mmc)) {
-
printf("sdmmc init is failed.\n");
-
}
-
-
//3.static struct cmd_fastboot_interface interface
-
interface.nand_block_size = CFG_FASTBOOT_PAGESIZE * 64;
-
interface.transfer_buffer = (unsigned char *) CFG_FASTBOOT_TRANSFER_BUFFER;
-
interface.transfer_buffer_size = CFG_FASTBOOT_TRANSFER_BUFFER_SIZE;
-
-
printf("[Fusing Image from SD Card.]\n");
-
-
//4.读取分区信息
-
if (set_partition_table())
-
return 1;
-
-
-
//sdfuse flash uboot filename
-
//sdfuse flash kernel filename
-
//sdfuse flash system filename
-
-
//char *des[] = {"bootloader","kernel","system"};
-
-
char *des[] = {ptable[0].name,ptable[2].name,ptable[4].name};//通过分区表ptable获取分区名
-
char *src[] = {"u-boot.bin","Kernel.img","System.img"};
-
-
int t = 0,count=sizeof(des)/sizeof(des[t]);
-
-
if(count != sizeof(src)/sizeof(src[t])){
-
return 1;
-
}
-
for(t=0; t < count; t++){//循环烧写目标文件
-
printf("des=%s*************src=%s\n",des[t],src[t]);
-
LCD_turnon();
-
-
if (update_from_sd(des[t], src[t])){
-
goto err_sdfuse;
-
}
-
printf("*******************************\n");
-
}
-
-
ret = 0;
-
-
err_sdfuse:
-
LCD_setfgcolor(0x000010);
-
LCD_setleftcolor(0x000010);
-
LCD_setprogress(100);
-
-
return ret;
-
}
重新烧写uboot,然后启动uboot,输入alfred
阅读(1756) | 评论(0) | 转发(0) |