OSHW-DEIMOS/SOFTWARE/A64-TERES/sunxi-pack-tools/update_uboot/script.c

289 lines
7.2 KiB
C
Raw Permalink Normal View History

2017-10-13 13:08:52 +02:00
/*
**********************************************************************************************************************
* eGon
* the Embedded System
* script parser sub-system
*
* Copyright(C), 2006-2010, SoftWinners Microelectronic Co., Ltd.
* All Rights Reserved
*
* File : script.c
*
* By : Jerry
*
* Version : V2.00
*
* Date :
*
* Descript:
**********************************************************************************************************************
*/
#include "script.h"
#include "string.h"
static char *script_mod_buf = NULL; //ָ<><D6B8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static int script_main_key_count = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>
static int _test_str_length(char *str)
{
int length = 0;
while(str[length++])
{
if(length > 32)
{
length = 32;
break;
}
}
return length;
}
/*
************************************************************************************************************
*
* script_parser_init
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>script_buf: <EFBFBD>ű<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD>
*
* ˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
*
*
************************************************************************************************************
*/
int script_parser_init(char *script_buf)
{
script_head_t *script_head;
if(script_buf)
{
script_mod_buf = script_buf;
script_head = (script_head_t *)script_mod_buf;
script_main_key_count = script_head->main_key_count;
return SCRIPT_PARSER_OK;
}
else
{
return SCRIPT_PARSER_EMPTY_BUFFER;
}
}
/*
************************************************************************************************************
*
* script_parser_exit
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>NULL
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD>
*
* ˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
*
*
************************************************************************************************************
*/
int script_parser_exit(void)
{
script_mod_buf = NULL;
script_main_key_count = 0;
return SCRIPT_PARSER_OK;
}
/*
************************************************************************************************************
*
* script_parser_fetch
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD>
*
* ˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ö<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
*
*
************************************************************************************************************
*/
int script_parser_fetch(char *main_name, char *sub_name, int value[])
{
char main_char[32], sub_char[32];
script_main_key_t *main_key;
script_sub_key_t *sub_key;
int i, j;
int pattern, word_count;
script_gpio_set_t *user_gpio_cfg;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD>buffer<65>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if(!script_mod_buf)
{
return SCRIPT_PARSER_EMPTY_BUFFER;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺ<EFBFBD><C6BA>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
if((main_name == NULL) || (sub_name == NULL))
{
return SCRIPT_PARSER_KEYNAME_NULL;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>buffer<65>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
if(value == NULL)
{
return SCRIPT_PARSER_DATA_VALUE_NULL;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺ<EFBFBD><C6BA>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<31>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>ȡ16<31>ֽ<EFBFBD>
memset(main_char, 0, sizeof(main_char));
memset(sub_char, 0, sizeof(sub_char));
if(_test_str_length(main_name) <= 32)
{
strcpy(main_char, main_name);
}
else
{
strncpy(main_char, main_name, 31);
}
if(_test_str_length(sub_name) <= 32)
{
strcpy(sub_char, sub_name);
}
else
{
strncpy(sub_char, sub_name, 31);
}
for(i=0;i<script_main_key_count;i++)
{
main_key = (script_main_key_t *)(script_mod_buf + (sizeof(script_head_t)) + i * sizeof(script_main_key_t));
if(strcmp(main_key->main_name, main_char)) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD>䣬Ѱ<E4A3AC><D1B0><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
continue;
}
//<2F><><EFBFBD><EFBFBD>ƥ<EFBFBD>䣬Ѱ<E4A3AC><D1B0><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>
for(j=0;j<main_key->lenth;j++)
{
sub_key = (script_sub_key_t *)(script_mod_buf + (main_key->offset<<2) + (j * sizeof(script_sub_key_t)));
if(strcmp(sub_key->sub_name, sub_char)) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD>䣬Ѱ<E4A3AC><D1B0><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
continue;
}
pattern = (sub_key->pattern>>16) & 0xffff; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD>
word_count = (sub_key->pattern>> 0) & 0xffff; //<2F><>ȡ<EFBFBD><C8A1>ռ<EFBFBD>õ<EFBFBD>word<72><64><EFBFBD><EFBFBD>
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
switch(pattern)
{
case DATA_TYPE_SINGLE_WORD: //<2F><>word<72><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
value[0] = *(int *)(script_mod_buf + (sub_key->offset<<2));
break;
case DATA_TYPE_STRING: //<2F>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
memcpy((char *)value, script_mod_buf + (sub_key->offset<<2), word_count << 2);
break;
case DATA_TYPE_GPIO_WORD: //<2F><>word<72><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
user_gpio_cfg = (script_gpio_set_t *)value;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIO<49><4F><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><E3B9BB><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
strcpy( user_gpio_cfg->gpio_name, sub_char);
memcpy(&user_gpio_cfg->port, script_mod_buf + (sub_key->offset<<2), sizeof(script_gpio_set_t) - 32);
break;
}
return SCRIPT_PARSER_OK;
}
}
return SCRIPT_PARSER_KEY_NOT_FIND;
}
/*
************************************************************************************************************
*
* script_parser_mainkey_get_gpio_cfg
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD>
*
* ˵<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIO<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
*
*
************************************************************************************************************
*/
int script_parser_mainkey_get_gpio_cfg(char *main_name, void *gpio_cfg, int gpio_count)
{
char main_bkname[32];
char *main_char;
script_main_key_t *main_key = NULL;
script_sub_key_t *sub_key = NULL;
script_gpio_set_t *user_gpio_cfg = (script_gpio_set_t *)gpio_cfg;
int i, j;
int pattern, user_index;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD>buffer<65>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if(!script_mod_buf)
{
return SCRIPT_PARSER_EMPTY_BUFFER;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺ<EFBFBD><C6BA>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
if(main_name == NULL)
{
return SCRIPT_PARSER_KEYNAME_NULL;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>buffer
memset(user_gpio_cfg, 0, sizeof(script_gpio_set_t) * gpio_count);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺ<EFBFBD><C6BA>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>31<33>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>ȡ31<33>ֽ<EFBFBD>
main_char = main_name;
if(_test_str_length(main_name) > 31)
{
memset(main_bkname, 0, 32);
strncpy(main_bkname, main_name, 31);
main_char = main_bkname;
}
for(i=0;i<script_main_key_count;i++)
{
main_key = (script_main_key_t *)(script_mod_buf + (sizeof(script_head_t)) + i * sizeof(script_main_key_t));
if(strcmp(main_key->main_name, main_char)) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD>䣬Ѱ<E4A3AC><D1B0><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
continue;
}
//<2F><><EFBFBD><EFBFBD>ƥ<EFBFBD>䣬Ѱ<E4A3AC><D1B0><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5>
user_index = 0;
for(j=0;j<main_key->lenth;j++)
{
sub_key = (script_sub_key_t *)(script_mod_buf + (main_key->offset<<2) + (j * sizeof(script_sub_key_t)));
pattern = (sub_key->pattern>>16) & 0xffff; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD>
//ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(DATA_TYPE_GPIO_WORD == pattern)
{
strcpy( user_gpio_cfg[user_index].gpio_name, sub_key->sub_name);
memcpy(&user_gpio_cfg[user_index].port, script_mod_buf + (sub_key->offset<<2), sizeof(script_gpio_set_t) - 32);
user_index++;
if(user_index >= gpio_count)
{
break;
}
}
}
return SCRIPT_PARSER_OK;
}
return SCRIPT_PARSER_KEY_NOT_FIND;
}