示例#1
0
int main(void) {
	printf("Hello World !!!\n\r");

	//init ocsdc driver
	struct mmc * drv = ocsdc_mmc_init(0x9e000000, 50000000);
	if (!drv) {
		printf("ocsdc_mmc_init failed\n\r");
		return -1;
	}
	printf("ocsdc_mmc_init success\n\r");

	drv->has_init = 0;
	int err = mmc_init(drv);
	if (err != 0 || drv->has_init == 0) {
		printf("mmc_init failed\n\r");
		return -1;
	}
	printf("mmc_init success\n\r");

	print_mmcinfo(drv);

	//read 1 block
	printf("attempting to read 1 block\n\r");
	if (mmc_bread(drv, 0, 1, buff) == 0) {
		printf("mmc_bread failed\n\r");
		return -1;
	}
	printf("mmc_bread success\n\r");

	printHex(buff, BLKSIZE);

	return EXIT_SUCCESS;
}
示例#2
0
int do_mmc_read (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int device_num = 1;
	ulong dev_id = 0;
	ulong addr,block_num,bytes,blk_cnt;
	ulong ret;
		
	if (argc < 4) {
		printf("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}
	
	/*get device id*/
	dev_id = simple_strtoul(argv[1], NULL, 16);
	if (dev_id == 0 || dev_id == 1 || dev_id == 2 || dev_id == 3) //add dev_id == 3 by eason 2012/3/27
		device_num = dev_id;
	else {
		printf("dev_id Invalid\n");
		return 1;
	}

	/*get memory address*/
	addr = simple_strtoul (argv[2], NULL, 16);
	if (addr < 0) {
		printf("addr Invalid\n");
		return 1;
	}

	/*get card block address*/
	block_num = simple_strtoul (argv[3], NULL, 16);
	if (block_num < 0) {
		printf("block_num Invalid\n");
		return 1;
	}

	/*get transfer size is bytes*/
	bytes = simple_strtoul (argv[4], NULL, 16);
	if (bytes < 0) {
		printf("bytes Invalid\n");
		return 1;
	}

	if (bytes == 0)
		return 0;

	/*calculate transfer block count*/
	blk_cnt = (bytes / 512);
	if (bytes % 512)
		blk_cnt++;
	
	//printf("device_num = %x block_num = %x addr =  %x bytes = %x blk_cnt =%x\n",device_num,block_num,addr,bytes,blk_cnt);

	ret = mmc_bread(device_num,block_num,blk_cnt,(ulong *)addr);

	if (ret != blk_cnt) {
		printf("Read Data Fail\n");
		return 1;
	} else {
		printf("Read Data Success\n");
	}
		

	return 0;
}
示例#3
0
int do_mmc_read_img (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int device_num = 1;
	int dev_id = 0;
	ulong kernel_addr,ramdisk_addr;
	ulong blk_cnt_kenel, blk_cnt_ramdisk, page_cnt_kenel, page_cnt_ramdisk;
	ulong ret;
	static unsigned char data[512];
	block_dev_desc_t *dev_desc=NULL;
	int dev=0;
	ulong part=1;
	char *ep;
	unsigned int  page_size, kernel_size, ramdisk_size, total_size;
	
	char var[64], val[32];
	char *setenv[4]  = { "setenv", NULL, NULL, NULL, };
	char *saveenv[2] = { "setenv", NULL, };
	setenv[1] = var;
	setenv[2] = val;


	/*printf("%s\n", __FUNCTION__);*/

	if (argc < 4) {
		printf("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}
	/*get device id*/
	dev_id = (int)simple_strtoul (argv[2], &ep, 16);
	if (dev_id == 0 || dev_id == 1 || dev_id == 2 || dev_id == 3) 
		device_num = dev_id;
	else {
		printf("dev_id Invalid\n");
		return 1;
	}
	/*get mmc dev descriptor*/
	dev_desc=get_dev(argv[1], dev_id);
	if (dev_desc==NULL) {
		puts ("\n** Invalid boot device **\n");
		return 1;
	}
	if (*ep) {
		if (*ep != ':') {
			puts ("\n** Invalid boot device, use `dev[:part]' **\n");
			return 1;
		}
		part = (int)simple_strtoul(++ep, NULL, 16);
	}


	/*printf("dev_id:%x,part:%x\n",dev_id,part);*/
	/* init mmc controller */	
	if (mmc_init(1, device_num)) {
		printf("mmc init failed?\n");
		return 1;
	}
	if (mmc_register_device(dev_desc, part) != 0) {
		printf ("\n** Unable to use %s %d:%d for fatload **\n", argv[1], dev_id, part);
		return 1;
	}

	/*get kernel memory address*/
	kernel_addr = simple_strtoul (argv[3], NULL, 16);
	if (kernel_addr < 0) {
		printf("kernel addr Invalid\n");
		return 1;
	}

	/*get ramdisk memory address*/
	ramdisk_addr = simple_strtoul (argv[4], NULL, 16);
	if (ramdisk_addr < 0) {
		printf("ramdisk addr  Invalid\n");
		return 1;
	}
	/*mmc block read partition offset sectors*/
	ret = mmc_bread(device_num, mmc_part_offset, 1,  (void *)data);
	if (ret == -1  ) {
		printf("Read Data Fail\n");
		return 1;
	} else {
		printf("Read Data Success\n");
	}

	/*memdump ((void *) data, 512);*/
	struct fastboot_boot_img_hdr *fb_hdr = (struct fastboot_boot_img_hdr *)data;
	
	if (memcmp(data, "ANDROID!", 8)) {
		printf(" boot.img  partition table not found\n");
		return -1;
	}
	/*kernel size change to sectors*/
	kernel_size = fb_hdr->kernel_size ;
	ramdisk_size = fb_hdr->ramdisk_size;
	page_size = fb_hdr->page_size ; 
	total_size = 1*page_size + kernel_size + ramdisk_size;

	/* calculate transfer block count */
	blk_cnt_kenel= (fb_hdr->kernel_size / 512);
	if (fb_hdr->kernel_size % 512)
		blk_cnt_kenel++;
	
	page_cnt_kenel= (fb_hdr->kernel_size / page_size);
	if (fb_hdr->kernel_size % page_size)
		page_cnt_kenel++;

	/* load kernel image from mmc boot image to kernel_addr */
	/*printf(" mmc_part_offset + page_size:0x%x, fb_hdr->kernel_size:0x%x, mem kernel_addr:0x%x\n", 
		mmc_part_offset + page_size / 512, fb_hdr->kernel_size, kernel_addr);*/
    	ret = mmc_bread(device_num, mmc_part_offset + page_size / 512, blk_cnt_kenel, kernel_addr);
	if (ret == -1  ) {
		printf("Read Kernel Data Fail\n");
		return 1;
	} else {
		printf("Read Kernel Data Success\n");
	}
	blk_cnt_ramdisk= (fb_hdr->ramdisk_size / 512);
	if (fb_hdr->ramdisk_size % 512)
		blk_cnt_ramdisk++;
	
	page_cnt_ramdisk= (fb_hdr->kernel_size / page_size);
	if (fb_hdr->kernel_size % page_size)
		page_cnt_ramdisk++;

	/* load ramdisk image from mmc boot image to ramdisk_addr */
	/*printf("mmc_part_offset + page_size + blk_cnt_kenel:0x%x, fb_hdr->ramdisk_size:0x%x, mem ramdisk_addr:0x%x\n",
			mmc_part_offset + page_size /512 + page_cnt_kenel *(page_size/512), fb_hdr->ramdisk_size, ramdisk_addr);*/
    	ret = mmc_bread(device_num, mmc_part_offset + page_size /512 + page_cnt_kenel *(page_size /512), blk_cnt_ramdisk, ramdisk_addr);
	if (ret == -1  ) {
		printf("Read Ramdisk Data Fail\n");
		return 1;
	} else {
		printf("Read Ramdisk Data Success\n");
	}
	
	/*save ramdisk size to env argv[4]*/
	sprintf (var, "%s", argv[5]);
	sprintf (val, "%x", fb_hdr->ramdisk_size);
	do_setenv (NULL, 0, 3, setenv);

	printf("%s %s %s\n", setenv[0], setenv[1], setenv[2]);
	/*do_saveenv (NULL, 0, 1, saveenv);*/

	return 0;
}
示例#4
0
/*******************************************************************************
*函数名称: load_boot1_from_sdmmc
*函数原型:int32 load_boot1_from_sdmmc( __u8 card_no )
*函数功能: 将一份好的Boot1从sdmmc flash中载入到SRAM中。
*入口参数: void
*返 回 值: OK                         载入并校验成功
*          ERROR                      载入并校验失败
*备    注:
*******************************************************************************/
__s32 load_boot1_from_sdmmc( char *buf)
{
    __u32  length;
    __s32  card_no, i;
	struct spare_boot_head_t  *bfh = (struct spare_boot_head_t *) CONFIG_SYS_TEXT_BASE;;
	boot_sdcard_info_t  *sdcard_info = (boot_sdcard_info_t *)buf;

	i = BT0_head.boot_head.platform[0];
	printf("card boot number = %d\n", i);

	//for(i=0;i<4;i++)
	{
		/* open sdmmc */
		card_no = i;
		printf("card no is %d\n", card_no);
		if(card_no < 0)
		{
			printf("bad card number %d in card boot\n", card_no);

			goto __card_op_fail__;
		}
		printf("sdcard %d line count %d\n", card_no, sdcard_info->line_count[i] );
		if(!sdcard_info->line_count[i])
		{
			sdcard_info->line_count[i] = 4;
		}
		if( sunxi_mmc_init( card_no, sdcard_info->line_count[i], BT0_head.prvt_head.storage_gpio, 16 ) == -1)   //高速卡,4线配置
		{
			printf("Fail in Init sdmmc.\n");
			goto __card_op_fail__;
		}
		printf("sdcard %d init ok\n", card_no);
#ifndef CONFIG_SUNXI_SECURE_SYSTEM
		/* load 1k uboot head */
	    if( mmc_bread( card_no, UBOOT_START_SECTOR_IN_SDMMC, 1024/512, (void *)CONFIG_SYS_TEXT_BASE ) != (1024/512))
		{
			printf("Fail in reading uboot head.\n");
			goto __card_op_fail__;
		}
		/* check head */
		if( check_magic( (__u32 *)CONFIG_SYS_TEXT_BASE, UBOOT_MAGIC ) != 0 )
		{
			printf("ERROR! NOT find the head of uboot.\n");
			goto __card_op_fail__;
		}
		/* check length */
	    length =  bfh->boot_head.length;
		printf("The size of uboot is %x.\n", length );
	    if( ( length & ( 8 * 1024 - 1 ) ) != 0 )
	    {
	    	printf("boot0 length is NOT align.\n");
	    	goto __card_op_fail__;
	    }
	    if( mmc_bread( card_no, UBOOT_START_SECTOR_IN_SDMMC, length/512, (void *)CONFIG_SYS_TEXT_BASE )!= (length/512))
		{
			printf("Fail in reading uboot head.\n");
			goto __card_op_fail__;
		}
		/* 检查校验和 */
	    if( check_sum( (__u32 *)CONFIG_SYS_TEXT_BASE, length ) != 0 )
	    {
	        printf("Fail in checking uboot.\n");
	       	goto __card_op_fail__;
	    }
#else
		uint start_sector = UBOOT_START_SECTOR_IN_SDMMC - (UBOOT_START_SECTOR_PRE_IN_SDMMC - UBOOT_START_SECTOR_IN_SDMMC);

		do
		{
			start_sector += UBOOT_START_SECTOR_PRE_IN_SDMMC - UBOOT_START_SECTOR_IN_SDMMC;

			if(start_sector > UBOOT_START_SECTOR_PRE_IN_SDMMC)
			{
				printf("read all u-boot blk failed\n");

				goto __card_op_fail__;
			}
			/* load 1k uboot head */
		    if( mmc_bread( card_no, start_sector, 1024/512, (void *)CONFIG_SYS_TEXT_BASE ) != (1024/512))
			{
				printf("Fail in reading uboot head.\n");
				continue;
			}
			/* check head */
			if( check_magic( (__u32 *)CONFIG_SYS_TEXT_BASE, UBOOT_MAGIC ) != 0 )
			{
				printf("ERROR! NOT find the head of uboot.\n");
				continue;
			}
			/* check length */
		    length =  bfh->boot_head.length;
			printf("The size of uboot is %x.\n", length );
		    if( ( length & ( 8 * 1024 - 1 ) ) != 0 )
		    {
		    	printf("boot0 length is NOT align.\n");
		    	continue;
		    }
		    if( mmc_bread( card_no, start_sector, length/512, (void *)CONFIG_SYS_TEXT_BASE )!= (length/512))
			{
				printf("Fail in reading uboot head.\n");
				continue;
			}
			/* 检查校验和 */
		    if( check_sum( (__u32 *)CONFIG_SYS_TEXT_BASE, length ) != 0 )
		    {
		        printf("Fail in checking uboot.\n");
		       	continue;
		    }
		    break;
		}
		while(1);
#endif
		if(i == 0)
		{
			bfh->boot_data.storage_type = 1;
		}
		else
		{
			bfh->boot_data.storage_type = 2;
			set_mmc_para(2,(void *)&BT0_head.prvt_head.storage_data);
		}
		printf("Succeed in loading uboot from sdmmc flash.\n");

		sunxi_mmc_exit( card_no, BT0_head.prvt_head.storage_gpio, 16 );

		return 0;

__card_op_fail__:
		sunxi_mmc_exit(card_no, BT0_head.prvt_head.storage_gpio, 16 );
	}

	return -1;
}
示例#5
0
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int sunxi_flash_init(int boot_type)
{
    int ret;

    if((boot_type == BOOT_FROM_SD0) || (boot_type == BOOT_FROM_SD2))
    {
        u8  *tmp_buff = (u8 *)CONFIG_TOC1_STORE_IN_DRAM_BASE;
        uint head_size;
        sbrom_toc1_head_info_t  *toc1_head;
        int  sunxi_flash_mmc_card_no;

        if(boot_type == BOOT_FROM_SD0)
        {
            sunxi_flash_mmc_card_no = 0;
        }
        else
        {
            sunxi_flash_mmc_card_no = 2;
        }
        ret = sunxi_mmc_init(sunxi_flash_mmc_card_no, 4, toc0_config->storage_gpio + 24, 8);
        if(ret <= 0)
        {
            printf("sunxi_flash_init err: sunxi_mmc_init failed\n");

            return -1;
        }
        //一次读取64k数据
        ret = mmc_bread(sunxi_flash_mmc_card_no, UBOOT_START_SECTOR_IN_SDMMC, 64, tmp_buff);
        if(!ret)
        {
            printf("PANIC : sunxi_flash_init() error --1--\n");
            return -1;
        }
        toc1_head = (struct sbrom_toc1_head_info *)tmp_buff;
        if(toc1_head->magic != TOC_MAIN_INFO_MAGIC)
        {
            printf("PANIC : sunxi_flash_init() error --2--,toc1 magic error\n");
            return -1;
        }
        head_size = toc1_head->valid_len;
        if(head_size > 64 * 512)
        {
            tmp_buff += 64*512;
            ret = mmc_bread(sunxi_flash_mmc_card_no, UBOOT_START_SECTOR_IN_SDMMC + 64, (head_size - 64*512 + 511)/512, tmp_buff);
            if(!ret)
            {
                printf("PANIC : sunxi_flash_init() error --3--\n");

                return -1;
            }
        }

        return 0;
    }
    else if(boot_type == BOOT_FROM_NFC)
    {
        if(load_toc1_from_nand())
        {
            printf("sunxi_flash_init err: nand init failed\n");

            return -1;
        }

        return 0;
    }
    else if(boot_type == BOOT_FROM_SPI)
    {
        printf("PANIC:NVM_init() : spi not support now\n");
        return -1;
    }
    else
    {
        printf("PANIC:NVM_init() : nvm_id = %d not support now\n",boot_type);

        return -1;
    }
}