http://blog.csdn.net/yunfly163/article/details/7497160
=========================================
cmd_fastboot.c
命令格式:
sdfuse flash kernel zImage
sdfuse flash system system.ext3
=========================================
[cpp] view plain copy print ?
- int do_sdfuse (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
- {
- int ret = 1;
- int enable_reset = 0;
- struct mmc *mmc = find_mmc_device(CFG_FASTBOOT_SDFUSE_MMCDEV);
-
- if (mmc_init(mmc)) {
- printf("sdmmc init is failed.\n");
- }
-
- 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;
-
- #ifdef CONFIG_EMMC_INAND
- printf("[ Check emmc 0 MBR label..]\n");
- if(fdisk_emmc0_partition() == 0){
-
- format_part_ext3(2);
- format_part_ext3(3);
- format_part_ext3(4);
- }
- #endif
-
- printf("[Fusing Image from SD Card.]\n");
-
- if (set_partition_table())
- return 1;
- if ((argc == 2) && !strcmp(argv[1], "flashall"))
- {
-
-
-
-
-
-
- if (update_from_sd("bootloader", "u-boot_emmc.bin"))
- goto err_sdfuse;
-
- if (update_from_sd("kernel", "zImage"))
- goto err_sdfuse;
-
- if (update_from_sd("system", "system.ext3"))
- goto err_sdfuse;
-
- if (update_from_sd("userdata", NULL))
- goto err_sdfuse;
-
- if (update_from_sd("cache", NULL))
- goto err_sdfuse;
- delay1s();
- delay1s();
- delay1s();
- enable_reset = 1;
- ret = 0;
- }
- else if ((argc == 4) && !strcmp(argv[1], "flash"))
- {
- LCD_turnon();
-
- if (update_from_sd(argv[2], argv[3]))
- goto err_sdfuse;
-
- ret = 0;
- }
- else if ((argc == 3) && !strcmp(argv[1], "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;
- }
[cpp] view plain copy print ?
- static int update_from_sd (char *part, char *file)
- {
- int ret = 1;
-
-
- if (file != NULL)
- {
- long size;
- unsigned long offset;
- unsigned long count;
- char filename[32];
- block_dev_desc_t *dev_desc=NULL;
-
- printf("Partition: %s, File: %s/%s\n", part, CFG_FASTBOOT_SDFUSE_DIR, file);
-
-
- dev_desc = get_dev("mmc", CFG_FASTBOOT_SDFUSE_MMCDEV);
- if (dev_desc == NULL) {
- printf ("** Invalid boot device **\n");
- return 1;
- }
- if (fat_register_device(dev_desc, CFG_FASTBOOT_SDFUSE_MMCPART) != 0) {
- printf ("** Invalid partition **\n");
- return 1;
- }
- sprintf(filename, "%s/%s", CFG_FASTBOOT_SDFUSE_DIR, file);
- offset = CFG_FASTBOOT_TRANSFER_BUFFER;
- count = 0;
- size = file_fat_read (filename, (unsigned char *) offset, count);
-
- if (size == -1) {
- printf("Failed to read %s\n", filename);
- return 1;
- }
-
- download_size = 0;
- download_bytes = size;
-
- printf ("%ld (0x%08x) bytes read\n", size, size);
- }
- else {
- printf("Partition: %s\n", part);
-
- download_size = 0;
- download_bytes = 0;
- }
-
-
-
- {
- char command[32];
-
- if (download_bytes == 0)
- sprintf(command, "%s:%s", "erase", part);
- else
- sprintf(command, "%s:%s", "flash", part);
-
- ret = rx_handler(command, sizeof(command));
- }
-
- return ret;
- }
SD卡支持自动格式,分区emmc命令:
[cpp] view plain copy print ?
-
- #ifdef CONFIG_EMMC_INAND
-
- static void format_part_ext3(int dev_num)
- {
- char run_cmd[80];
- int status = 1;
- char response[65];
-
- sprintf(run_cmd, "ext3format mmc 0:%d",dev_num);
- status = run_command(run_cmd, 0);
- if (status)
- {
- sprintf(response,"FAILfailed to ext3format partition");
- }
- else
- {
-
- sprintf(response, "OKAY");
- }
-
- fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
-
- }
-
- static void format_part_dos ()
- {
- char run_cmd[80];
- int status = 1;
- char response[65];
-
- sprintf(run_cmd, "fatformat mmc 0:1");
- status = run_command(run_cmd, 0);
- if (status)
- {
- sprintf(response,"FAILfailed to fatformat partition");
- }
- else
- {
-
- sprintf(response, "OKAY");
- }
-
- fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
- }
-
-
- int fdisk_emmc0_partition()
- {
- unsigned char buffer[512];
- block_dev_desc_t *dev_desc=NULL;
- char run_cmd[80];
- int status = 1;
- char response[65];
- int ret =1;
-
- struct mmc *mmc = find_mmc_device(0);
-
- if (mmc_init(mmc)) {
- printf("emmc 0 init is failed.\n");
- }
-
- dev_desc = get_dev("mmc", 0);
- if (dev_desc == NULL) {
- printf ("** Invalid boot device : emmc 0 **\n");
- return ret;
- }
-
- if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1) ||
- (buffer[0x1fe] != 0x55 ||
- buffer[0x1ff] != 0xaa)) {
- printf ("bad MBR sector! so fdisk emmc 0 now\n");
-
- sprintf(run_cmd, "fdisk -c 0");
- status = run_command(run_cmd, 0);
- if (status)
- {
- sprintf(response,"FAILfailed to fdisk emmc 0");
- }
- else
- {
- printf("fdisk emmc 0 success! \n");
- sprintf(response, "OKAY");
- }
- ret =status;
- fastboot_tx_status(response, strlen(response), FASTBOOT_TX_ASYNC);
- }
- return ret;
- }
- #endif