int update_nand_info(void *gpio_info)
{
	script_gpio_set_t   gpio_set[32];
    normal_gpio_cfg    *gpio;
	int  i;

	gpio = (normal_gpio_cfg *)gpio_info;
	if(!script_parser_mainkey_get_gpio_cfg("nand_para", gpio_set, 32))
	{
		for(i=0;i<32;i++)
		{
			if(!gpio_set[i].port)
			{
				break;
			}
			gpio[i].port      = gpio_set[i].port;
			gpio[i].port_num  = gpio_set[i].port_num;
			gpio[i].mul_sel   = gpio_set[i].mul_sel;
			gpio[i].pull      = gpio_set[i].pull;
			gpio[i].drv_level = gpio_set[i].drv_level;
		}
	}

	return 0;
}
Exemple #2
0
static int __init aw_pin_test_init(void)
{
	int ret;
	u32 gpio_handle;
	printk("aw_pin_test_init: enter\n");

	ret = script_parser_mainkey_get_gpio_cfg("uart_para", (void *)gpio_set, 38);
	if(!ret) {
		gpio_handle = sunxi_gpio_request_array(gpio_set, 38);
		printk("gpio_handle=0x%08x, ret=%d\n", gpio_handle,ret);

		ret = gpio_release(gpio_handle, 2);
		printk("gpio_Release: ret=%d\n", ret);
	}
	else {
		printk("ERR: script_parser_mainkey_get_gpio_cfg\n");
	}

	return 0;
}
int update_for_boot0(char *boot0_name, int storage_type)
{
	FILE *boot0_file = NULL;
	boot0_file_head_t  *boot0_head;
	char *boot0_buf = NULL;
	int   length = 0;
	int   i;
	int   ret = -1;
	int   value[8];
    script_gpio_set_t   gpio_set[32];

	boot0_file = fopen(boot0_name, "rb+");
	if(boot0_file == NULL)
	{
		printf("update:unable to open boot0 file\n");
		goto _err_boot0_out;
	}
	fseek(boot0_file, 0, SEEK_END);
	length = ftell(boot0_file);
	fseek(boot0_file, 0, SEEK_SET);
	if(!length)
	{
		goto _err_boot0_out;
	}
	boot0_buf = (char *)malloc(length);
	if(!boot0_buf)
	{
		goto _err_boot0_out;
	}
	fread(boot0_buf, length, 1, boot0_file);
	rewind(boot0_file);

	boot0_head = (boot0_file_head_t *)boot0_buf;
	//检查boot0的数据结构是否完整
    ret = check_file( (unsigned int *)boot0_buf, boot0_head->boot_head.length, BOOT0_MAGIC );
    if( ret != CHECK_IS_CORRECT )
    {
		goto _err_boot0_out;
	}
	//取出数据进行修正,DRAM参数
	if(script_parser_sunkey_all("dram_para", (void *)boot0_head->prvt_head.dram_para))
	{
		printf("script fetch dram para failed\n");
		goto _err_boot0_out;
	}
	//取出数据进行修正,UART参数
	if(!script_parser_fetch("uart_para", "uart_debug_port", value))
	{
		boot0_head->prvt_head.uart_port = value[0];
	}
	if(!script_parser_mainkey_get_gpio_cfg("uart_para", gpio_set, 32))
	{
		for(i=0;i<32;i++)
		{
			if(!gpio_set[i].port)
			{
				break;
			}
			boot0_head->prvt_head.uart_ctrl[i].port      = gpio_set[i].port;
			boot0_head->prvt_head.uart_ctrl[i].port_num  = gpio_set[i].port_num;
			boot0_head->prvt_head.uart_ctrl[i].mul_sel   = gpio_set[i].mul_sel;
			boot0_head->prvt_head.uart_ctrl[i].pull      = gpio_set[i].pull;
			boot0_head->prvt_head.uart_ctrl[i].drv_level = gpio_set[i].drv_level;
			boot0_head->prvt_head.uart_ctrl[i].data      = gpio_set[i].data;
		}
	}
	//取出数据进行修正,debugenable参数
	if(!script_parser_fetch("jtag_para", "jtag_enable", value))
	{
		boot0_head->prvt_head.enable_jtag = value[0];
	}
	if(!script_parser_mainkey_get_gpio_cfg("jtag_para", gpio_set, 32))
	{
		for(i=0;i<32;i++)
		{
			if(!gpio_set[i].port)
			{
				break;
			}
			boot0_head->prvt_head.jtag_gpio[i].port      = gpio_set[i].port;
			boot0_head->prvt_head.jtag_gpio[i].port_num  = gpio_set[i].port_num;
			boot0_head->prvt_head.jtag_gpio[i].mul_sel   = gpio_set[i].mul_sel;
			boot0_head->prvt_head.jtag_gpio[i].pull      = gpio_set[i].pull;
			boot0_head->prvt_head.jtag_gpio[i].drv_level = gpio_set[i].drv_level;
			boot0_head->prvt_head.jtag_gpio[i].data      = gpio_set[i].data;
		}
	}
	//取出数据进行修正,NAND参数
	if(!storage_type)
	{
		if(!script_parser_mainkey_get_gpio_cfg("nand_para", gpio_set, 32))
		{
			for(i=0;i<32;i++)
			{
				if(!gpio_set[i].port)
				{
					break;
				}
				boot0_head->prvt_head.storage_gpio[i].port      = gpio_set[i].port;
				boot0_head->prvt_head.storage_gpio[i].port_num  = gpio_set[i].port_num;
				boot0_head->prvt_head.storage_gpio[i].mul_sel   = gpio_set[i].mul_sel;
				boot0_head->prvt_head.storage_gpio[i].pull      = gpio_set[i].pull;
				boot0_head->prvt_head.storage_gpio[i].drv_level = gpio_set[i].drv_level;
				boot0_head->prvt_head.storage_gpio[i].data      = gpio_set[i].data;
			}
		}
	}
	else if(1 == storage_type) //取得卡参赛
	{
		if(update_sdcard_info((char *)boot0_head->prvt_head.storage_gpio))
		{
			goto _err_boot0_out;
		}
	}
	else if(2 == storage_type)
	{
		if(!script_parser_mainkey_get_gpio_cfg("spi0_para", gpio_set, 32))
		{
			for(i=0;i<32;i++)
			{
				if(!gpio_set[i].port)
				{
					break;
				}
				boot0_head->prvt_head.storage_gpio[i].port      = gpio_set[i].port;
				boot0_head->prvt_head.storage_gpio[i].port_num  = gpio_set[i].port_num;
				boot0_head->prvt_head.storage_gpio[i].mul_sel   = gpio_set[i].mul_sel;
				boot0_head->prvt_head.storage_gpio[i].pull      = gpio_set[i].pull;
				boot0_head->prvt_head.storage_gpio[i].drv_level = gpio_set[i].drv_level;
				boot0_head->prvt_head.storage_gpio[i].data      = gpio_set[i].data;
			}
		}
	}
	//数据修正完毕
	//重新计算校验和
	gen_check_sum( (void *)boot0_buf );
	//再检查一次
    ret = check_file( (unsigned int *)boot0_buf, boot0_head->boot_head.length, BOOT0_MAGIC );
    if( ret != CHECK_IS_CORRECT )
    {
		goto _err_boot0_out;
	}
	fwrite(boot0_buf, length, 1, boot0_file);

_err_boot0_out:
	if(boot0_buf)
	{
		free(boot0_buf);
	}
	if(boot0_file)
	{
		fclose(boot0_file);
	}

	return ret;
}
int update_for_uboot(char *uboot_name)
{
	FILE *uboot_file = NULL;
	struct spare_boot_head_t  *uboot_head;
	char *uboot_buf = NULL;
	int   length = 0;
	int   i;
	int   ret = -1;
	int   value[8];
	script_gpio_set_t   gpio_set[32];

	uboot_file = fopen(uboot_name, "rb+");
	if(uboot_file == NULL)
	{
		printf("update uboot error : unable to open uboot file\n");
		goto _err_uboot_out;
	}
	fseek(uboot_file, 0, SEEK_END);
	length = ftell(uboot_file);
	fseek(uboot_file, 0, SEEK_SET);
	if(!length)
	{
		printf("update uboot error : uboot length is zero\n");
		goto _err_uboot_out;
	}
	uboot_buf = (char *)malloc(length);
	if(!uboot_buf)
	{
		printf("update uboot error : fail to malloc memory for uboot\n");
		goto _err_uboot_out;
	}
	fread(uboot_buf, length, 1, uboot_file);
	rewind(uboot_file);
	uboot_head = (struct spare_boot_head_t *)uboot_buf;
	//检查uboot的数据结构是否完整
	align_size = uboot_head->boot_head.align_size;
	//增加判断:是否是原始uboot
	if((uboot_head->boot_head.length == uboot_head->boot_head.uboot_length))
	{
		//uboot长度和原始整体长度一致,表示是原始uboot
		uboot_head->boot_head.length = length;
		uboot_head->boot_head.uboot_length = length;
	}
	//否则,不需要修改文件长度
	//printf("size=%d, magic=%s\n", uboot_head->boot_head.length, UBOOT_MAGIC);
    //ret = check_file( (unsigned int *)uboot_buf, uboot_head->boot_head.length, UBOOT_MAGIC );
    ret = check_magic( (unsigned int *)uboot_buf, UBOOT_MAGIC );
    if( ret != CHECK_IS_CORRECT )
    {
    	printf("update uboot error : uboot pre checksum error\n");
		goto _err_uboot_out;
	}
	//取出数据进行修正,UART参数
	if(!script_parser_fetch("uart_para", "uart_debug_port", value))
	{
		uboot_head->boot_data.uart_port = value[0];
	}
	if(!script_parser_mainkey_get_gpio_cfg("uart_para", gpio_set, 32))
	{
		for(i=0;i<2;i++)
		{
			if(!gpio_set[i].port)
			{
				break;
			}
			uboot_head->boot_data.uart_gpio[i].port      = gpio_set[i].port;
			uboot_head->boot_data.uart_gpio[i].port_num  = gpio_set[i].port_num;
			uboot_head->boot_data.uart_gpio[i].mul_sel   = gpio_set[i].mul_sel;
			uboot_head->boot_data.uart_gpio[i].pull      = gpio_set[i].pull;
			uboot_head->boot_data.uart_gpio[i].drv_level = gpio_set[i].drv_level;
			uboot_head->boot_data.uart_gpio[i].data      = gpio_set[i].data;
		}
	}
	//取出数据进行修正,TWI参数
	if(!script_parser_fetch("twi_para", "twi_port", value))
	{
		uboot_head->boot_data.twi_port = value[0];
	}
	if(!script_parser_mainkey_get_gpio_cfg("twi_para", gpio_set, 32))
	{
		for(i=0;i<2;i++)
		{
			if(!gpio_set[i].port)
			{
				break;
			}
			uboot_head->boot_data.twi_gpio[i].port      = gpio_set[i].port;
			uboot_head->boot_data.twi_gpio[i].port_num  = gpio_set[i].port_num;
			uboot_head->boot_data.twi_gpio[i].mul_sel   = gpio_set[i].mul_sel;
			uboot_head->boot_data.twi_gpio[i].pull      = gpio_set[i].pull;
			uboot_head->boot_data.twi_gpio[i].drv_level = gpio_set[i].drv_level;
			uboot_head->boot_data.twi_gpio[i].data      = gpio_set[i].data;
		}
	}
	//根据数据进行修正,修正target参数
	if(!script_parser_fetch("target", "boot_clock", value))
	{
		uboot_head->boot_data.run_clock = value[0];
	}
	if(!script_parser_fetch("target", "dcdc3_vol", value))
	{
		uboot_head->boot_data.run_core_vol = value[0];
	}
	//修正存储设备信息
	if(update_sdcard_info((void *)uboot_head->boot_data.sdcard_gpio, (void *)uboot_head->boot_data.sdcard_spare_data))
	{
		goto _err_uboot_out;
	}
	update_nand_info((void *)uboot_head->boot_data.nand_gpio);
	//数据修正完毕
	//重新计算校验和
	gen_check_sum( (void *)uboot_buf );

    //再检查一次
    //printf("size=%d, magic=%s\n", uboot_head->boot_head.length, UBOOT_MAGIC);
    ret = check_file( (unsigned int *)uboot_buf, uboot_head->boot_head.length, UBOOT_MAGIC );
    if( ret != CHECK_IS_CORRECT )
    {
    	printf("update uboot error : uboot after checksum error\n");
		goto _err_uboot_out;
	}
	fwrite(uboot_buf, length, 1, uboot_file);

_err_uboot_out:
	if(uboot_buf)
	{
		free(uboot_buf);
	}
	if(uboot_file)
	{
		fclose(uboot_file);
	}

	return ret;
}
int update_for_fes1(char *fes1_name, int storage_type)
{
	FILE *fes1_file = NULL;
	boot0_file_head_t  *fes1_head;
	char *fes1_buf = NULL;
	int   length = 0;
	int   i;
	int   ret = -1;
	int   value[8];
    script_gpio_set_t   gpio_set[32];

	fes1_file = fopen(fes1_name, "rb+");
	if(fes1_file == NULL)
	{
		printf("update:unable to open fes1 file\n");
		goto _err_fes1_out;
	}
	fseek(fes1_file, 0, SEEK_END);
	length = ftell(fes1_file);
	fseek(fes1_file, 0, SEEK_SET);
	if(!length)
	{
		printf("fes1 file size is 0\n");
		goto _err_fes1_out;
	}
	fes1_buf = (char *)malloc(length);
	if(!fes1_buf)
	{
		printf("unable to malloc for fes1 update\n");
		goto _err_fes1_out;
	}
	fread(fes1_buf, length, 1, fes1_file);
	rewind(fes1_file);
	fes1_head = (boot0_file_head_t *)fes1_buf;
	//检查fes1的数据结构是否完整
    ret = check_file( (unsigned int *)fes1_buf, fes1_head->boot_head.length, BOOT0_MAGIC );
    if( ret != CHECK_IS_CORRECT )
    {
    	printf("stage1 check file is error\n");
		goto _err_fes1_out;
	}
	//取出数据进行修正,DRAM参数
	if(script_parser_sunkey_all("dram_para", (void *)fes1_head->prvt_head.dram_para))
	{
		printf("script fetch dram para failed\n");
		goto _err_fes1_out;
	}
	//取出数据进行修正,UART参数
	if(!script_parser_fetch("uart_para", "uart_debug_port", value))
	{
		fes1_head->prvt_head.uart_port = value[0];
	}
	if(!script_parser_mainkey_get_gpio_cfg("uart_para", gpio_set, 32))
	{
		for(i=0;i<32;i++)
		{
			if(!gpio_set[i].port)
			{
				break;
			}
			fes1_head->prvt_head.uart_ctrl[i].port      = gpio_set[i].port;
			fes1_head->prvt_head.uart_ctrl[i].port_num  = gpio_set[i].port_num;
			fes1_head->prvt_head.uart_ctrl[i].mul_sel   = gpio_set[i].mul_sel;
			fes1_head->prvt_head.uart_ctrl[i].pull      = gpio_set[i].pull;
			fes1_head->prvt_head.uart_ctrl[i].drv_level = gpio_set[i].drv_level;
			fes1_head->prvt_head.uart_ctrl[i].data      = gpio_set[i].data;
		}
	}
	//取出数据进行修正,debugenable参数
	if(!script_parser_fetch("jtag_para", "jtag_enable", value))
	{
		fes1_head->prvt_head.enable_jtag = value[0];
	}
	if(!script_parser_mainkey_get_gpio_cfg("jtag_para", gpio_set, 32))
	{
		for(i=0;i<32;i++)
		{
			if(!gpio_set[i].port)
			{
				break;
			}
			fes1_head->prvt_head.jtag_gpio[i].port      = gpio_set[i].port;
			fes1_head->prvt_head.jtag_gpio[i].port_num  = gpio_set[i].port_num;
			fes1_head->prvt_head.jtag_gpio[i].mul_sel   = gpio_set[i].mul_sel;
			fes1_head->prvt_head.jtag_gpio[i].pull      = gpio_set[i].pull;
			fes1_head->prvt_head.jtag_gpio[i].drv_level = gpio_set[i].drv_level;
			fes1_head->prvt_head.jtag_gpio[i].data      = gpio_set[i].data;
		}
	}
	//数据修正完毕
	//重新计算校验和
	gen_check_sum( (void *)fes1_buf );
	//再检查一次
    ret = check_file( (unsigned int *)fes1_buf, fes1_head->boot_head.length, BOOT0_MAGIC );
    if( ret != CHECK_IS_CORRECT )
    {
    	printf("stage2 check file is error\n");
		goto _err_fes1_out;
	}
	fwrite(fes1_buf, length, 1, fes1_file);

_err_fes1_out:
	if(fes1_buf)
	{
		free(fes1_buf);
	}
	if(fes1_file)
	{
		fclose(fes1_file);
	}

	return ret;
}