Initialize
[sdk/emulator/qemu.git] / tizen / src / configuration.c
1 /*
2  * Emulator
3  *
4  * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  * DoHyung Hong <don.hong@samsung.com>
8  * SeokYeon Hwang <syeon.hwang@samsung.com>
9  * Hyunjun Son <hj79.son@samsung.com>
10  * SangJin Kim <sangjin3.kim@samsung.com>
11  * MunKyu Im <munkyu.im@samsung.com>
12  * KiTae Kim <kt920.kim@samsung.com>
13  * JinHyung Jo <jinhyung.jo@samsung.com>
14  * SungMin Ha <sungmin82.ha@samsung.com>
15  * JiHye Kim <jihye1128.kim@samsung.com>
16  * GiWoong Kim <giwoong.kim@samsung.com>
17  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
18  * DongKyun Yun <dk77.yun@samsung.com>
19  *
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License
22  * as published by the Free Software Foundation; either version 2
23  * of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
33  *
34  * Contributors:
35  * - S-Core Co., Ltd
36  *
37  */
38
39 #include <assert.h>
40 #include "configuration.h"
41 #include "debug_ch.h"
42 #include "sdb.h"
43
44 //DEFAULT_DEBUG_CHANNEL(tizen);
45 MULTI_DEBUG_CHANNEL(tizen, configuration);
46
47 #define EMUL_PIXELFORMAT_YUV422P           1
48 #define EMUL_PIXELFORMAT_YUV420P           2
49
50 #define RESOLUTION_COUNT                   4
51 #define BUTTON_TYPE_COUNT               4
52 /*
53  *
54  * *** config *** (target_path)
55  *
56  * If emulator.conf exists & target name is created by user, check platform config and so (set ld config and script path)
57  * Else if emulator.conf exist & target is create by installer, read emulator.conf, nothing do by platform.conf
58  * Else if emulator.conf no exist
59  *    release type of platform exist ->
60  *    release type of platform no exist -> default X2 -> create popup -> by select, change configuration & systeminfo
61  *
62  * A. configuration (char *)
63  * init  (configuration.c init_structure - alloc) int init_configuration();
64  * copy (sprintf, strcpy, pointer, strdup); -> sprintf
65  * reload (by target path & skin path) (sprintf, strcpy, pointer, strdup) -> sprintf
66  * destroy (configuration.c destroy_structure - free) destroy_structure(); -> remove
67  *
68  * B. systeminfo (platform_type - char *)
69  * init
70  * copy
71  * reload -> X
72  * destroy
73  *
74  * */
75
76
77 /**
78  * @brief   set information to default init configuration structure
79  * @param   status: CONF_INIT_MODE, CONF_DEFAULT_MODE, CONF_EXIST_STARTUP_MODE
80  * @return  success(0)
81  * @date    Nov 18. 2008
82  * */
83
84 int fill_configuration(int status)
85 {
86     int default_telnet_port = 1200;
87     const gchar *data_path = get_data_path();
88
89     /* 1. startup option parsing */
90
91     /* 1.3 target setting */
92
93     if (strlen(startup_option.disk) > 0) {
94         configuration.qemu_configuration.diskimg_type = 1;
95         if(strcmp(SYSTEMINFO.virtual_target_name, "default") == 0)
96             strcpy(configuration.qemu_configuration.diskimg_path, startup_option.disk);
97     }
98
99     else {
100 #ifdef ENABLE_LIMO
101         snprintf(configuration.qemu_configuration.diskimg_path, MAXBUF, "%s/coronado-simulator.img",data_path);
102 #else // inhouse
103         snprintf(configuration.qemu_configuration.diskimg_path, MAXBUF, "%s/protector-simulator.img",data_path);
104 #endif
105     }
106
107     /* 2. CONF_INIT_MODE / CONF_EXIST_STARTUP_MODE*/
108
109     if (status == CONF_INIT_MODE) {
110
111         configuration.always_on_top = 0;
112         /* 2.1 emulator config initial */
113 #ifndef _WIN32
114         configuration.enable_shell = 1;
115 #else
116         configuration.enable_shell = 0;
117 #endif
118         configuration.enable_telephony_emulator = 0;
119         configuration.enable_gpsd = 0;
120         configuration.enable_compass = 0;
121
122         configuration.main_x = 100;
123         configuration.main_y = 100;
124
125         /* 2.2 qemu config initial */
126
127         configuration.qemu_configuration.use_host_http_proxy = 1;
128         configuration.qemu_configuration.use_host_dns_server = 1;
129 //      snprintf(configuration.qemu_configuration.sdcard_path, MAXBUF, "%s/sdcard.img",data_path);
130
131 //      configuration.qemu_configuration.sdcard_type = 0;
132         configuration.qemu_configuration.telnet_type = 1;
133
134         if(ENABLE_MULTI)
135         {
136             while(check_port(LOCALHOST, default_telnet_port) == 0 )
137                 default_telnet_port += 3;
138         }
139         snprintf(configuration.qemu_configuration.telnet_port, MAXBUF, "%d", default_telnet_port);
140
141         /* serial console command ==> start */
142         configuration.qemu_configuration.serial_console_command_type = 0;
143         snprintf(configuration.qemu_configuration.serial_console_command, MAXBUF, "/usr/bin/putty -telnet -P %s localhost",configuration.qemu_configuration.telnet_port);
144
145 //      configuration.qemu_configuration.snapshot_saved = 0;
146 /* end */
147         return 0;
148     }
149
150     else if (status == CONF_EXIST_STARTUP_MODE) {
151         return 0;
152     }
153     else
154         INFO( "Configuration Structure fill error !\n");
155
156     return 0;
157 }
158
159
160 /**
161  * @brief   get config value list from emulator.conf file
162  * @param   filename: configuration file path, group: EMULATOR_GROUP, field: RUNAPP_RECENT_LIST_KEY, CONFIGURATION
163  * @return  fail(0), success(value)
164  * @date    Nov 17. 2008
165  * */
166 PROGRAMNAME *get_config_value_list(gchar *filepath, const gchar *group, const gchar *field)
167 {
168     GKeyFile *keyfile;
169     GError *error = NULL;
170     gchar **value = NULL;
171     gsize length;
172     int i;
173
174     static PROGRAMNAME runapp_info[5];
175
176     keyfile = g_key_file_new();
177
178     if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &error)) {
179         INFO("loading key file form %s is failed\n", filepath );
180         g_error("%s", error->message);
181         return NULL;
182     }
183
184     value = g_key_file_get_string_list(keyfile, group, field,  &length, &error);
185
186     if ( value != NULL) {
187         for (i = 0; i < (length / 2); i++) {
188             runapp_info[i].nDate = atoi(*(value + (i * 2)));
189             g_strlcpy(runapp_info[i].arName, *(value + (i * 2) + 1), sizeof runapp_info[i].arName);
190         }
191         g_free(value);
192     }
193
194     g_key_file_free(keyfile);
195
196     return runapp_info;
197 }
198
199 /**
200  * @brief   create configuration file if it doesn't exist and each field of configuration file sets default value
201  * @param   filename : configuration file path (ex: /opt/xo-sim/conf/emulator.conf, emulator0.conf)
202  * @return  success(0)
203  * @date    Nov 17. 2008
204  * */
205 int create_config_file(gchar* filepath)
206 {
207     FILE *fp = g_fopen(filepath, "w+");
208
209     if (fp != NULL) {
210         g_fprintf (fp, "[%s]\n", COMMON_GROUP);
211         g_fprintf (fp, "%s=\n",ALWAYS_ON_TOP_KEY);
212
213         g_fprintf (fp, "\n[%s]\n", EMULATOR_GROUP);
214         g_fprintf (fp, "%s=\n",TERMINAL_TYPE_KEY );
215         g_fprintf (fp, "%s=\n", ENABLE_SHELL_KEY);
216         g_fprintf (fp, "%s=\n", ENABLE_TELEPHONY_EMULATOR_KEY);
217         g_fprintf (fp, "%s=\n", ENABLE_GPSD_KEY);
218         g_fprintf (fp, "%s=\n", ENABLE_COMPASS_KEY);
219         g_fprintf (fp, "%s=\n", CMD_TYPE_KEY);
220
221         g_fprintf (fp, "%s=\n", MAIN_X_KEY);
222         g_fprintf (fp, "%s=\n", MAIN_Y_KEY);
223         g_fprintf (fp, "%s=\n", SCALE_KEY);
224
225         g_fprintf (fp, "\n[%s]\n", QEMU_GROUP);
226         g_fprintf (fp, "%s=\n", HTTP_PROXY_KEY);
227         g_fprintf (fp, "%s=\n", DNS_SERVER_KEY);
228         g_fprintf (fp, "%s=\n", TELNET_TYPE_KEY);
229         g_fprintf (fp, "%s=\n", TELNET_PORT_KEY);
230         g_fprintf (fp, "%s=\n", TELNET_CONSOLE_COMMAND_TYPE_KEY);
231         g_fprintf (fp, "%s=\n", TELNET_CONSOLE_COMMAND_KEY);
232 //      g_fprintf (fp, "%s=\n", SDCARD_TYPE_KEY);
233 //      g_fprintf (fp, "%s=\n", SDCARD_PATH_KEY);
234 //      g_fprintf (fp, "%s=\n", DISK_TYPE_KEY);
235 //      g_fprintf (fp, "%s=\n", DISK_PATH_KEY);
236         g_fprintf (fp, "%s=1\n", SAVEVM_KEY);
237 //      g_fprintf (fp, "%s=\n", SNAPSHOT_SAVED_KEY);
238 //      g_fprintf (fp, "%s=\n", SNAPSHOT_SAVED_DATE_KEY);
239
240         fclose(fp);
241     }
242     else {
243         ERR( "Can't open file path. (%s)\n", filepath);
244         return -1;
245     }
246
247     g_chmod(filepath, 0666);
248
249     return 0;
250 }
251
252
253 /**
254  * @brief   write configuration structure value in conf file (emulator.conf)
255  * @param   filename : configuration file path (ex: /opt/xo-sim/conf/emulator.conf), CONFIGURATION
256  * @return  success(0)
257  * @date    Nov 17. 2008
258  * */
259 int write_config_file(gchar *filepath, CONFIGURATION *pconfiguration)
260 {
261     set_config_type(filepath, COMMON_GROUP, ALWAYS_ON_TOP_KEY, pconfiguration->always_on_top);
262     set_config_type(filepath, EMULATOR_GROUP, ENABLE_SHELL_KEY, pconfiguration->enable_shell);
263     set_config_type(filepath, EMULATOR_GROUP, ENABLE_TELEPHONY_EMULATOR_KEY, pconfiguration->enable_telephony_emulator);
264     set_config_type(filepath, EMULATOR_GROUP, ENABLE_GPSD_KEY, pconfiguration->enable_gpsd);
265     set_config_type(filepath, EMULATOR_GROUP, ENABLE_COMPASS_KEY, pconfiguration->enable_compass);
266     set_config_type(filepath, EMULATOR_GROUP, CMD_TYPE_KEY, pconfiguration->cmd_type);
267     set_config_type(filepath, EMULATOR_GROUP, MAIN_X_KEY, pconfiguration->main_x);
268     set_config_type(filepath, EMULATOR_GROUP, MAIN_Y_KEY, pconfiguration->main_y);
269     set_config_type(filepath, EMULATOR_GROUP, SCALE_KEY, pconfiguration->scale);
270
271     /*  QEMU option (09.05.26)*/
272
273     set_config_type(filepath, QEMU_GROUP, HTTP_PROXY_KEY, pconfiguration->qemu_configuration.use_host_http_proxy);
274     set_config_type(filepath, QEMU_GROUP, DNS_SERVER_KEY, pconfiguration->qemu_configuration.use_host_dns_server);
275     set_config_type(filepath, QEMU_GROUP, TELNET_TYPE_KEY, pconfiguration->qemu_configuration.telnet_type);
276     set_config_value(filepath, QEMU_GROUP, TELNET_PORT_KEY, pconfiguration->qemu_configuration.telnet_port);
277
278     set_config_type(filepath, QEMU_GROUP, TELNET_CONSOLE_COMMAND_TYPE_KEY, pconfiguration->qemu_configuration.serial_console_command_type);
279     set_config_value(filepath, QEMU_GROUP, TELNET_CONSOLE_COMMAND_KEY, pconfiguration->qemu_configuration.serial_console_command);
280
281 //  set_config_type(filepath, QEMU_GROUP, SDCARD_TYPE_KEY, pconfiguration->qemu_configuration.sdcard_type);
282 //  set_config_value(filepath, QEMU_GROUP, SDCARD_PATH_KEY, pconfiguration->qemu_configuration.sdcard_path);
283     set_config_type(filepath, QEMU_GROUP, SAVEVM_KEY, pconfiguration->qemu_configuration.save_emulator_state);
284 //  set_config_type(filepath, QEMU_GROUP, SNAPSHOT_SAVED_KEY, pconfiguration->qemu_configuration.snapshot_saved);
285 //  set_config_value(filepath, QEMU_GROUP, SNAPSHOT_SAVED_DATE_KEY, pconfiguration->qemu_configuration.snapshot_saved_date);
286
287     return 0;
288 }
289
290
291 /**
292  * @brief   read conf value and save in configuration structure from config file (emulator.conf)
293  * @param   filename : configuration file path, CONFIGURATION
294  * @return  fail(-1), success(0)
295  * @date    Nov 17. 2008
296  * */
297 int read_config_file(gchar *filepath, CONFIGURATION *pconfiguration)
298 {
299     char *buf = NULL;
300     int status = 0;
301
302     pconfiguration->always_on_top = get_config_type(filepath, COMMON_GROUP, ALWAYS_ON_TOP_KEY);
303
304     pconfiguration->qemu_configuration.use_host_http_proxy = get_config_type(filepath, QEMU_GROUP, HTTP_PROXY_KEY);
305     pconfiguration->qemu_configuration.use_host_dns_server = get_config_type(filepath, QEMU_GROUP, DNS_SERVER_KEY);
306
307     /* option menu config parsed */
308     gchar *sdb_path = get_sdb_path();
309     if (access(sdb_path, 0) == 0) {
310         pconfiguration->enable_shell = get_config_type(filepath, EMULATOR_GROUP, ENABLE_SHELL_KEY);
311     }
312     g_free(sdb_path);
313
314     pconfiguration->enable_telephony_emulator = get_config_type(filepath, EMULATOR_GROUP, ENABLE_TELEPHONY_EMULATOR_KEY);
315     pconfiguration->enable_gpsd = get_config_type(filepath, EMULATOR_GROUP, ENABLE_GPSD_KEY);
316     pconfiguration->enable_compass = get_config_type(filepath, EMULATOR_GROUP, ENABLE_COMPASS_KEY);
317     pconfiguration->cmd_type = get_config_type(filepath, EMULATOR_GROUP, CMD_TYPE_KEY);
318
319     pconfiguration->main_x = get_config_type(filepath, EMULATOR_GROUP, MAIN_X_KEY);
320     pconfiguration->main_y = get_config_type(filepath, EMULATOR_GROUP, MAIN_Y_KEY);
321     pconfiguration->scale = get_config_type(filepath, EMULATOR_GROUP, SCALE_KEY);
322
323     int telnet_port;
324     buf = get_config_value(filepath, QEMU_GROUP, TELNET_PORT_KEY);
325     if (buf != NULL) {
326         telnet_port = atoi(buf);
327         if(ENABLE_MULTI) {
328             while(check_port(LOCALHOST, telnet_port) == 0)
329                 telnet_port += 3;
330         }
331         snprintf(pconfiguration->qemu_configuration.telnet_port, MAXBUF, "%d", telnet_port);
332     }
333     g_free(buf);
334
335     pconfiguration->qemu_configuration.telnet_type = get_config_type(filepath, QEMU_GROUP, TELNET_TYPE_KEY);
336
337     pconfiguration->qemu_configuration.serial_console_command_type = get_config_type(filepath, QEMU_GROUP, TELNET_CONSOLE_COMMAND_TYPE_KEY);
338
339     buf = get_config_value(filepath, QEMU_GROUP, TELNET_CONSOLE_COMMAND_KEY);
340
341     if (buf != NULL)
342         snprintf(pconfiguration->qemu_configuration.serial_console_command, MAXBUF, "%s", buf);
343
344     g_free(buf);
345
346 /*  pconfiguration->qemu_configuration.sdcard_type = get_config_type(filepath, QEMU_GROUP, SDCARD_TYPE_KEY);
347
348     buf = get_config_value(filepath, QEMU_GROUP, SDCARD_PATH_KEY);
349     if (buf != NULL)
350         snprintf(pconfiguration->qemu_configuration.sdcard_path, MAXBUF, "%s", buf);
351     g_free(buf); */
352
353     pconfiguration->qemu_configuration.save_emulator_state = get_config_type(filepath, QEMU_GROUP, SAVEVM_KEY);
354
355 /*  pconfiguration->qemu_configuration.snapshot_saved = get_config_type(filepath, QEMU_GROUP, SNAPSHOT_SAVED_KEY);
356
357     buf = get_config_value(filepath, QEMU_GROUP, SNAPSHOT_SAVED_DATE_KEY);
358     if (buf != NULL)
359         snprintf(pconfiguration->qemu_configuration.snapshot_saved_date, MAXBUF, "%s", buf);
360     g_free(buf); */
361
362     return status;
363 }
364
365
366 int read_virtual_target_info_file(gchar *virtual_target_name, VIRTUALTARGETINFO *pvirtual_target_info)
367 {
368     int status = 0;
369     int info_file_status;
370     char *virtual_target_path;
371     char *info_file;
372     char *buf = NULL;
373
374     virtual_target_path = get_virtual_target_path(virtual_target_name);
375     info_file = g_strdup_printf("%sconfig.ini", virtual_target_path);
376     info_file_status = is_exist_file(info_file);
377
378     if(info_file_status == -1 || info_file_status == FILE_NOT_EXISTS)
379     {
380         ERR( "target info file not exists : %s\n", virtual_target_name);
381         return -1;
382     }
383
384     snprintf(pvirtual_target_info->virtual_target_name, MAXBUF, "%s", virtual_target_name);
385
386     buf = get_config_value(info_file, HARDWARE_GROUP, RESOLUTION_KEY);
387     snprintf(pvirtual_target_info->resolution, MAXBUF, "%s", buf);
388     g_free(buf);
389
390     pvirtual_target_info->button_type = get_config_type(info_file, HARDWARE_GROUP, BUTTON_TYPE_KEY);
391
392     pvirtual_target_info->sdcard_type = get_config_type(info_file, HARDWARE_GROUP, SDCARD_TYPE_KEY);
393     if(pvirtual_target_info->sdcard_type == 0)
394     {
395         memset(pvirtual_target_info->sdcard_path, 0x00, MAXBUF);
396     }
397     else
398     {
399         buf = get_config_value(info_file, HARDWARE_GROUP, SDCARD_PATH_KEY);
400         snprintf(pvirtual_target_info->sdcard_path, MAXBUF, "%s", buf);
401         g_free(buf);
402     }
403
404     pvirtual_target_info->ram_size = get_config_type(info_file, HARDWARE_GROUP, RAM_SIZE_KEY);
405
406     buf = get_config_value(info_file, HARDWARE_GROUP, DISK_PATH_KEY);
407     //  buf = get_virtual_target_path(virtual_target_name);
408     if(!buf && strlen(startup_option.disk) > 0)
409         buf = startup_option.disk;
410     snprintf(pvirtual_target_info->diskimg_path, MAXBUF, "%s", buf);
411     g_free(buf);
412
413     pvirtual_target_info->snapshot_saved = get_config_type(info_file, ETC_GROUP, SNAPSHOT_SAVED_KEY);
414     if(pvirtual_target_info->snapshot_saved == 0)
415     {
416         memset(pvirtual_target_info->snapshot_saved_date, 0x00, MAXBUF);
417     }
418     else
419     {
420         buf = get_config_value(info_file, ETC_GROUP, SNAPSHOT_SAVED_DATE_KEY);
421         snprintf(pvirtual_target_info->snapshot_saved_date, MAXBUF, "%s", buf);
422         g_free(buf);
423     }
424
425     /* get DPI info from config.ini */
426     buf = get_config_value(info_file, HARDWARE_GROUP, DPI_KEY);
427     snprintf(pvirtual_target_info->dpi, MAXBUF, "%s", buf);
428     //fprintf(stderr, "DPI = %s\n", pvirtual_target_info->dpi);
429
430     g_free(virtual_target_path);
431     g_free(info_file);
432
433     return status;
434 }
435
436
437 /* sanity check on target path */
438 int is_valid_target(const gchar *path)
439 {
440     if (g_file_test(path, G_FILE_TEST_IS_DIR | G_FILE_TEST_EXISTS) == FALSE) {
441         ERR( "target file: %s is not exist.\n", path);
442         return -1;
443     }
444
445     return 0;
446 }
447
448
449 /**
450  * @brief   check about skin
451  * @param   filename : skin path (ex: /opt/xo-sim/skins/320x320/320x320_1FB.dbi)
452  * @return  0 fail, 1 success
453  * @date    Nov 17. 2008
454  * */
455 int is_valid_skin (gchar *file)
456 {
457     if (file == NULL)
458         return FALSE;
459
460     if ((g_file_test(file, G_FILE_TEST_EXISTS) != FALSE) && g_str_has_suffix (file, ".dbi"))
461         return TRUE;
462
463     return FALSE;
464 }
465
466
467 /**
468  * @brief   get emulator config filepath for status
469  * @return  exist normal(1), not exist(0), error(-1)
470  * @date    Apr 19. 2009
471  * */
472
473 int is_valid_targetlist_file()
474 {
475     int status = 0;
476     gchar *targetlist_filepath = NULL;
477
478     targetlist_filepath = get_targetlist_filepath();
479
480     status = is_exist_file(targetlist_filepath);
481
482     if (status != -1) {
483         sprintf(SYSTEMINFO.conf_file, "%s", targetlist_filepath);
484     }
485
486     g_free(targetlist_filepath);
487
488     return status;
489 }
490
491
492 /**
493  * @brief   load emulator.conf  and create config_window for conf file status
494  * @param   SYSTEMINFO(SYSTEMINFO.conf_file)
495  * @return  fail(-1), success(0)
496  * @date    Apr 19. 2009
497  * */
498 int load_targetlistig_file(SYSINFO *pSYSTEMINFO)
499 {
500     int status = 0;
501     int result = 0;
502     char *virtual_target_path;
503     char *info_file;
504
505     int target_list_status = is_valid_target_list_file(pSYSTEMINFO);
506     if(target_list_status == -1 || target_list_status == FILE_NOT_EXISTS)
507     {
508         ERR( "load target list file error\n");
509         return -1;
510     }
511
512     int virtual_target_info_status = read_virtual_target_info_file(startup_option.vtm, &virtual_target_info);
513     if(virtual_target_info_status == -1)
514     {
515         ERR( "load target info file error\n");
516         return -1;
517     }
518     else
519     {
520         snprintf(pSYSTEMINFO->virtual_target_name, MAXBUF, "%s", startup_option.vtm);
521 //      virtual_target_path = get_virtual_target_path(startup_option.vtm);
522         virtual_target_path = get_virtual_target_path(startup_option.vtm);
523         info_file = g_strdup_printf("%sconfig.ini", virtual_target_path);
524         snprintf(pSYSTEMINFO->virtual_target_info_file, MAXPATH, "%s", info_file);
525     }
526
527     g_free(virtual_target_path);
528     g_free(info_file);
529
530     status = is_valid_targetlist_file();
531
532     switch ( status ) {
533     case FILE_EXISTS:
534
535         fill_configuration(CONF_EXIST_STARTUP_MODE);
536
537         result = read_config_file(SYSTEMINFO.virtual_target_info_file, &configuration);
538
539 //      if (result == -1) {
540 //          fill_configuration(CONF_INIT_MODE);
541
542         break;
543
544     case FILE_NOT_EXISTS :
545 //      fill_configuration(CONF_INIT_MODE);
546 //      if ((strlen(configuration.target_path) < 2))
547 //      create_config_file(SYSTEMINFO.virtual_target_info_file);
548         ERR( "load emulator config file \n");
549
550         break;
551
552     default:
553         ERR( "Emulator config file not exists!\n");
554
555         return -1;
556     }
557
558 //  write_config_file(SYSTEMINFO.virtual_target_info_file, &configuration);
559     startup_option_config_done = 1;
560
561     return 0;
562 }
563
564
565 /**
566  * @brief   load conf file
567  * @param   SYSTEMINFO
568  * @return  success  0,  fail    -1
569  * @date    Nov 6. 2008
570  * */
571 int load_config_file(SYSINFO *pSYSTEMINFO)
572 {
573 //  INFO( "default_target = %s \n", configuration.target_path);
574
575     /* 2. emulator config file load (emulator.conf) */
576
577     if (load_targetlistig_file(pSYSTEMINFO) == -1) {
578         ERR( "load emulator.conf file error!!\n");
579         return -1;
580     }
581
582     return 0;
583 }
584
585
586 int determine_skin(VIRTUALTARGETINFO *pvirtual_target_info, CONFIGURATION *pconfiguration)
587 {
588     int i;
589     int resolution_found = 0;
590     int button_type         = 0;
591     char *skin = NULL;
592     char *resolution[RESOLUTION_COUNT] = {"320x480", "480x800", "600x1024", "720x1280"};
593     char *button_types[BUTTON_TYPE_COUNT]   = {"","","not_use_","3keys_"};
594
595     for(i = 0; i < RESOLUTION_COUNT; i++)
596     {
597         if(strcmp(pvirtual_target_info->resolution, resolution[i]) == 0)
598         {
599             resolution_found = 1;
600             break;
601         }
602     }
603
604     if(resolution_found == 0)
605     {
606         ERR( "unknown resolution\n");
607         return -1;
608     }
609
610     button_type = pvirtual_target_info->button_type;
611         if (button_type !=0 &&  button_type != 1 &&  button_type != 3)
612         {
613                 ERR( "unknown button type : %d\n", button_type);
614                 return -1;
615         }
616
617     skin = g_strdup(resolution[i]);
618
619     snprintf(pconfiguration->skin_path, MAXBUF, "%s/emul_%s%s/default.dbi", get_skin_path(), button_types[button_type], skin);
620
621     if(is_valid_skin(pconfiguration->skin_path) == 0)
622     {
623         ERR( "skin file is invalid\n");
624         g_free(skin);
625         return -1;
626     }
627
628     g_free(skin);
629     return 0;
630 }
631
632
633 /**
634  * @brief   callback when ok button clicked in option window
635  * @param   void
636  * @param   result
637  * @date    Apr 21. 2009
638  * */
639 void qemu_option_set_to_config(arglist *al)
640 {
641     gboolean userdata_exist = FALSE;
642
643     const gchar *exec_path = get_exec_path();
644
645     int width = (int)(PHONE.mode[UISTATE.current_mode].lcd_list[0].lcd_region.w);
646     int height = (int)(PHONE.mode[UISTATE.current_mode].lcd_list[0].lcd_region.h);
647     int bpp = (int)(PHONE.mode[UISTATE.current_mode].lcd_list[0].bitsperpixel);
648
649     /* input kernel append*/
650
651     char kernel_kappend[MAXBUF] = {0, };
652     char fb1_format[MAXBUF] = {0, };
653
654     if (PHONE.mode[UISTATE.current_mode].lcd_list[1].bitsperpixel == 16)
655         sprintf(fb1_format, "rgb16");
656     else if (PHONE.mode[UISTATE.current_mode].lcd_list[1].bitsperpixel == 24)
657         sprintf(fb1_format, "rgb24");
658     else if(PHONE.mode[UISTATE.current_mode].lcd_list[1].nonstd == EMUL_PIXELFORMAT_YUV420P)
659         sprintf(fb1_format, "yuv420");
660     else if(PHONE.mode[UISTATE.current_mode].lcd_list[1].nonstd == EMUL_PIXELFORMAT_YUV422P)
661         sprintf(fb1_format, "yuv422");
662
663     /* console */
664
665     if (qemu_arch_is_arm()){
666         /* duallcd command line is used in hw/s5pc1xx.c to change the board revision */
667         if(PHONE.dual_display == 1)
668             strcpy(kernel_kappend, "console=ttySAC2,115200n8 duallcd mem=80M mem=256M@0x40000000 mem=128@0x50000000 mtdparts=tizen-onenand:1m(bootloader),256k(params),2816k(config),8m(csa),7m(kernel),1m(log),12m(modem),60m(qboot),-(UBI) ");
669         else
670             strcpy(kernel_kappend, "console=ttySAC2,115200n8 mem=80M mem=256M@0x40000000 mem=128@0x50000000 mtdparts=tizen-onenand:1m(bootloader),256k(params),2816k(config),8m(csa),7m(kernel),1m(log),12m(modem),60m(qboot),-(UBI) ");
671     }
672     else
673         strcpy(kernel_kappend, "console=ttyS0 ");
674
675     /*  video overlay */
676
677     if (!qemu_arch_is_arm()) {
678         if (strlen(fb1_format) > 0)  /* Using Overlay */
679             sprintf(&kernel_kappend[strlen(kernel_kappend)],
680                     "video=uvesafb:ywrap,overlay:%s,%dx%d-%d@60 ", fb1_format, width, height, bpp);
681         else
682             sprintf(&kernel_kappend[strlen(kernel_kappend)],
683                     "video=uvesafb:ywrap,%dx%d-%d@60 ", width, height, bpp);
684     }
685
686     char proxy[MIDBUF] ={0}, hostip[MIDBUF] = {0}, dns1[MIDBUF] = {0}, dns2[MIDBUF] = {0};
687
688     gethostproxy(proxy);
689     if (configuration.qemu_configuration.use_host_http_proxy == 1)
690         sprintf(&kernel_kappend[strlen(kernel_kappend)], "proxy=%s ", proxy);
691
692     gethostDNS(dns1, dns2);
693     if (configuration.qemu_configuration.use_host_dns_server == 1) {
694         if (strlen(dns1))   sprintf(&kernel_kappend[strlen(kernel_kappend)], "dns1=%s ", dns1);
695         if (strlen(dns2))   sprintf(&kernel_kappend[strlen(kernel_kappend)], "dns2=%s ", dns2);
696     }
697
698     // handover Host IP address to kernel side
699     /*
700     gethostIP(hostip);
701     if (strlen(hostip))
702         sprintf(&kernel_kappend[strlen(kernel_kappend)], "openglip=%s ", hostip);
703     */
704
705     // sdb port
706     sprintf(&kernel_kappend[strlen(kernel_kappend)], "sdb_port=%d ", get_sdb_base_port());
707
708     // get DPI value
709     if (strlen(virtual_target_info.dpi))
710         sprintf(&kernel_kappend[strlen(kernel_kappend)], "dpi=%s ", virtual_target_info.dpi);
711
712     /*
713      * for QEMU user mode networking (with -net user),
714      * our ip is 10.0.2.16, and the gateway is 10.0.2.2
715      * These address are hardcoded in QEMU
716      *
717      * For NFS to work /etc/exports should contain something like:
718      *
719      * /scratchbox/users/mike/targets  127.0.0.1(rw,all_squash,insecure,async,insecure_locks)
720      *
721      */
722
723 #define GUEST_IP_ADDRESS "10.0.2.16"
724 #define HOST_QEMU_ADDRESS "10.0.2.2"
725 #define BOOT_DRIVE "c"
726 #define KERNEL_LOGFILE_NAME "logs/emulator.klog"
727
728 #define VIRTIO_DISK
729     if(!configuration.qemu_configuration.diskimg_type) {
730         sprintf(&kernel_kappend[strlen(kernel_kappend)], "root=/dev/nfs rw ");
731         sprintf(&kernel_kappend[strlen(kernel_kappend)], "nfsroot=" HOST_QEMU_ADDRESS ":%s,udp,port=%d,v3 ",
732                 configuration.target_path, startup_option.mountPort);
733     }
734     else
735     {
736         if(qemu_arch_is_arm())
737             strcat(kernel_kappend, "root=/dev/hda ");
738         else
739 #ifdef VIRTIO_DISK
740             strcat(kernel_kappend, "root=/dev/vda rw ");
741 #else
742             strcat(kernel_kappend, "root=/dev/hda rw ");
743 #endif
744     }
745
746     /* user mode networking */
747
748     if (qemu_arch_is_arm())
749         sprintf(&kernel_kappend[strlen(kernel_kappend)], "ip=" GUEST_IP_ADDRESS "::" HOST_QEMU_ADDRESS ":255.255.255.0::usb0:none ");
750     else
751         sprintf(&kernel_kappend[strlen(kernel_kappend)], "ip=" GUEST_IP_ADDRESS "::" HOST_QEMU_ADDRESS ":255.255.255.0::eth0:none ");
752
753     sprintf(&kernel_kappend[strlen(kernel_kappend)], "%d", startup_option.run_level);
754
755     append_argvlist(al, "%s", exec_path);
756     if (qemu_arch_is_arm()) {
757         if(configuration.qemu_configuration.diskimg_type) {
758             append_argvlist(al, "-hda");
759             append_argvlist(al, "%s", virtual_target_info.diskimg_path);
760         }
761     }
762     /*this is for i386*/
763     else
764     {
765         if(configuration.qemu_configuration.diskimg_type) {
766             append_argvlist(al, "-drive");
767 #ifdef VIRTIO_DISK
768             append_argvlist(al, "file=%s,if=virtio", virtual_target_info.diskimg_path);
769 #else
770             append_argvlist(al, "file=%s", virtual_target_info.diskimg_path);
771 #endif
772             gchar userdata_buf[MAXBUF] = {0, };
773             char *target_name = basename(configuration.target_path);
774             snprintf(userdata_buf, MAXBUF, "%s/opt/%s-userdata.img", configuration.target_path, target_name);
775             if (is_exist_file(userdata_buf) == 1) {
776                 append_argvlist(al, "-hdb");
777                 append_argvlist(al, "%s", userdata_buf);
778                 userdata_exist = TRUE;
779             }
780         }
781     }
782
783     append_argvlist(al, "-boot");
784     append_argvlist(al, "%s", BOOT_DRIVE);
785
786     /* snapshot boot set  -loadvm snapshot option */
787     if(configuration.qemu_configuration.save_emulator_state) {
788         append_argvlist(al,"-loadvm");
789         append_argvlist(al,"snapshot");
790     }
791
792     append_argvlist(al, "-append");
793     append_argvlist(al, "%s", kernel_kappend);
794
795     if (!startup_option.no_dump) {
796         gchar kernel_log_path[MAXBUF] = {0, };
797         strcpy(kernel_log_path, get_virtual_target_path(startup_option.vtm));
798         strcat(kernel_log_path, KERNEL_LOGFILE_NAME);
799         append_argvlist(al, "-serial");
800         append_argvlist(al, "file:%s", kernel_log_path);
801     }
802     else
803     {
804 //  else if (configuration.qemu_configuration.telnet_type == 1) {
805         append_argvlist(al, "-serial");
806         append_argvlist(al, "telnet:localhost:%s,server,nowait,ipv4",
807                         configuration.qemu_configuration.telnet_port);
808     }
809
810     if (!qemu_arch_is_arm()) {
811         if(virtual_target_info.sdcard_type != 0) {
812 #ifdef VIRTIO_DISK
813             append_argvlist(al, "-drive");
814             append_argvlist(al, "file=%s,if=virtio", virtual_target_info.sdcard_path);
815 #else
816             if (userdata_exist)
817                 append_argvlist(al, "-hdc");
818             else
819                 append_argvlist(al, "-hdb");
820             append_argvlist(al, "%s", virtual_target_info.sdcard_path);
821 #endif
822         }
823     }
824
825     append_argvlist(al, "-m");
826     append_argvlist(al, "%d", virtual_target_info.ram_size);
827
828 #if 0
829     printf("startup option : \n\n");
830     printf("target : %s\n", startup_option.target);
831     printf("disk : %s\n", startup_option.disk);
832     printf("skin : %s\n", startup_option.skin);
833     printf("loglevel : %d\n", startup_option.log_level);
834     printf("runlevel : %d\n", startup_option.run_level);
835     printf("target_log : %d\n", startup_option.target_log);
836     printf("mountport : %d\n", startup_option.mountPort);
837     printf("sshport : %d\n", startup_option.ssh_port);
838     printf("telnetport : %d\n", startup_option.telnet_port);
839     printf("configuration : \n\n");
840     printf("shell %d, telephony %d, gpsd %d, compass %d, cmd_type %d, ",configuration.enable_shell
841             , configuration.enable_telephony_emulator, configuration.enable_gpsd, configuration.enable_compass
842             , configuration.cmd_type);
843     printf("mount_port %d, target_path : %s\n", configuration.mount_port, configuration.target_path);
844     printf("qemu configuration : \n\n");
845     printf("proxy %d, dns %d, telnetport %s, telnettype %d, sdcardtype %d\n",
846             configuration.qemu_configuration.use_host_http_proxy, configuration.qemu_configuration.use_host_dns_server,
847             configuration.qemu_configuration.telnet_port, configuration.qemu_configuration.telnet_type, configuration.qemu_configuration.sdcard_type);
848     printf("sdcardpath : %s, diskimg_type %d, diskimg_path %s\n",
849             configuration.qemu_configuration.sdcard_path, configuration.qemu_configuration.diskimg_type,
850             configuration.qemu_configuration.diskimg_path);
851     printf("console cmdtype %d, console cmd %s\n", configuration.qemu_configuration.serial_console_command_type,
852             configuration.qemu_configuration.serial_console_command);
853     printf("save state %d, saved %d, saved date %s\n\n", configuration.qemu_configuration.save_simulator_state,
854             configuration.qemu_configuration.snapshot_saved,
855             configuration.qemu_configuration.snapshot_saved_date);
856 #endif
857 }
858
859
860 const char *get_target_path(void)
861 {
862     return configuration.target_path;
863 }