📄 skyeye_options.c
字号:
/* skyeye_options.c - skyeye config file options' functions Copyright (C) 2003 Skyeye Develop Group for help please send mail to <skyeye-developer@lists.sf.linuxforum.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* 08/20/2003 add log option function chenyu 4/02/2003 add net option function * walimis <walimi@peoplemail.com.cn> * 3/22/2003 add cpu, mem_num, mem_bank, arch, dummy option function * walimis <walimi@peoplemail.com.cn> * 10/24/2005 add dbct test speed function * teawater <c7code-uc@yahoo.com.cn> * */#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "skyeye_options.h"#include "skyeye_arch.h"#include "skyeye_config.h"#include "skyeye_arch.h"#include "skyeye_config.h"extern FILE *skyeye_logfd;intsplit_param (const char *param, char *name, char *value){ const char *src = param; char *dst = name; while (*src && (*src != '=')) *dst++ = *src++; *dst = '\0'; if (*src == '\0') { value = '\0'; return -1; } strcpy (value, src + 1); return 0;}/* we need init some options before read the option file. * now put them here. * *///chy 2004-12-05 for eclipse//#define SKYEYE4ECLIPSE#ifdef SKYEYE4ECLIPSEextern char *inferior_io_terminal;int nouart;#endif//------------------------------intskyeye_option_init (skyeye_config_t * config){//chy 2004-12-05 for eclipse#ifdef SKYEYE4ECLIPSE int fd;#endif//------------------------------ config->uart.fd_in = 0; /*stdin */ config->uart.fd_out = 1; /*stdout */ /*ywc 2005-04-01 */ config->no_dbct = 1; /*default, dbct is off */ //teawater add for new tb manage function 2005.07.10---------------------------- config->tb_tbt_size = 0; config->tb_tbp_size = TB_TBP_DEFAULT;//chy 2004-12-05 for eclipse#ifdef SKYEYE4ECLIPSE nouart = 0; if (inferior_io_terminal != NULL) { nouart = 1; printf ("SKYEYE: inferior_io_terminal is %s \n", inferior_io_terminal); if ((fd = open (inferior_io_terminal, O_RDWR)) == -1) SKYEYE_DBG ("Error when open device %s", inferior_io_terminal); skyeye_config.uart.fd_in = fd; skyeye_config.uart.fd_out = fd; }#endif//------------------------------ }intdo_dummy_option (skyeye_option_t * this_option, int num_params, const char *params[]){ return 0;};/* parse "int" parameters. e.g. int=16:17*/intget_interrupts (char value[], u32 * interrupts){ char *cur = value; char *next = value; int i = 0, end = 0; while ((*next != ':') && (*next != 0)) next++; while (*cur != 0) { if (*next != 0) { *next = '\0'; } else end = 1; interrupts[i] = strtoul (cur, NULL, 0); //printf("%s:%s\n", __FUNCTION__, cur); i++; if ((i > 4) || end == 1) return 0; cur = ++next; while ((*next != ':') && (*next != 0)) next++; } return 0;}/* setup device option. * all device options may have common parameters. Here we handle these common parameters. * */intsetup_device_option (char *option_name, void *dev_option, int num_params, const char *params[]){ char name[MAX_PARAM_NAME], value[MAX_PARAM_NAME]; struct common_config conf; int i; memset (&conf, 0, sizeof (conf)); conf.type = NULL; conf.name = NULL; for (i = 0; i < num_params; i++) { if (split_param (params[i], name, value) < 0) SKYEYE_ERR ("Error: \"%s\" has wrong parameter \"%s\".\n", option_name, name); if (!strncmp ("type", name, strlen (name))) { conf.type = strdup (value); } else if (!strncmp ("name", name, strlen (name))) { conf.name = strdup (value); } else if (!strncmp ("base", name, strlen (name))) { conf.base = strtoul (value, NULL, 0); } else if (!strncmp ("size", name, strlen (name))) { conf.size = strtoul (value, NULL, 0); } else if (!strncmp ("int", name, strlen (name))) { get_interrupts (value, conf.interrupts); } } setup_device (option_name, &conf, dev_option, skyeye_config.mach); if (conf.type) free (conf.type); if (conf.name) free (conf.name); return 0;}/*defined in skyeye_arch.c*/extern arch_config_t *skyeye_archs[];intdo_arch_option (skyeye_option_t * this_option, int num_params, const char *params[]){ int i; arch_config_t *arch = skyeye_config.arch; char *default_arch = "arm"; for (i = 0; i < MAX_SUPP_ARCH; i++) { if (skyeye_archs[i] == NULL) continue; if (!strncmp (params[0], skyeye_archs[i]->arch_name, MAX_PARAM_NAME)) { skyeye_config.arch = skyeye_archs[i]; SKYEYE_INFO ("arch: %s\n", skyeye_archs[i]->arch_name); return 0; } } SKYEYE_ERR ("Error: Unknowm architecture name \"%s\" or you use low version of skyeye?\n", params[0]); return -1;}intdo_cpu_option (skyeye_option_t * this_option, int num_params, const char *params[]){ int ret; if (skyeye_config.arch == NULL) { /* If we don't set arch, we use "arm" as default. */ char *default_arch = "arm"; int i; for (i = 0; i < MAX_SUPP_ARCH; i++) { if (skyeye_archs[i] == NULL) continue; if (!strncmp (default_arch, skyeye_archs[i]->arch_name, MAX_PARAM_NAME)) { skyeye_config.arch = skyeye_archs[i]; SKYEYE_INFO ("arch: %s\n", skyeye_archs[i]->arch_name); } } if (skyeye_config.arch == NULL) { SKYEYE_ERR ("ERROR: No arch option found! Maybe you use low version of skyeye?\n"); skyeye_exit (-1); } } ret = skyeye_config.arch->parse_cpu (params); if (ret < 0) SKYEYE_ERR ("Error: Unkonw cpu name \"%s\"\n", params[0]); return ret;}intdo_mach_option (skyeye_option_t * this_option, int num_params, const char *params[]){ int ret; machine_config_t *mach = skyeye_config.mach; ret = skyeye_config.arch->parse_mach (mach, params); if (ret < 0) { SKYEYE_ERR ("Error: Unkonw mach name \"%s\"\n", params[0]); } return ret;}intdo_mem_bank_option (skyeye_option_t * this_option, int num_params, const char *params[]){ int ret; ret = skyeye_config.arch->parse_mem (num_params, params); if (ret < 0) { SKYEYE_ERR ("Error: Unkonw mem bank name \"%s\"\n", params[0]); } return ret;}intdo_net_option (skyeye_option_t * this_option, int num_params, const char *params[]){ char name[MAX_PARAM_NAME], value[MAX_PARAM_NAME]; int i; struct net_option net_opt; unsigned char mac_addr[6]; unsigned char hip[4]; unsigned char *maddr, *ip; for (i = 0; i < num_params; i++) { if (split_param (params[i], name, value) < 0) { SKYEYE_ERR ("Error: %s has wrong parameter \"%s\".\n", this_option->name, name); return -1; } if (!strncmp ("mac", name, strlen (name))) { sscanf (value, "%x:%x:%x:%x:%x:%x", &mac_addr[0], &mac_addr[1], &mac_addr[2], &mac_addr[3], &mac_addr[4], &mac_addr[5]); memcpy (net_opt.macaddr, mac_addr, 6); } else if (!strncmp ("hostip", name, strlen (name))) { /* FIXME: security problem, don't use sscanf later */ sscanf (value, "%d.%d.%d.%d", &hip[0], &hip[1], &hip[2], &hip[3]); memcpy (net_opt.hostip, hip, 4); } else if (!strncmp ("ethmod", name, strlen (name))) { if (!strncmp ("linux", value, strlen (value))) { net_opt.ethmod = NET_MOD_LINUX; } else if (!strncmp ("tuntap", value, strlen (value))) { net_opt.ethmod = NET_MOD_TUNTAP; } else if (!strncmp ("win", value, strlen (value))) { net_opt.ethmod = NET_MOD_WIN; } else if (!strncmp ("vnet", value, strlen (value))) { net_opt.ethmod = NET_MOD_VNET; } } } maddr = net_opt.macaddr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -