blob: 77d3c6907afeb6f9c468be0d7b02255da29f52c0 [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/* Copyright (C) 2006-2008 The Android Open Source Project
2**
3** This software is licensed under the terms of the GNU General Public
4** License version 2, as published by the Free Software Foundation, and
5** may be copied, distributed, and modified under those terms.
6**
7** This program is distributed in the hope that it will be useful,
8** but WITHOUT ANY WARRANTY; without even the implied warranty of
9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10** GNU General Public License for more details.
11*/
12
13#include <signal.h>
14#include <unistd.h>
15#include <string.h>
16#include <sys/time.h>
17#ifdef _WIN32
18#include <process.h>
19#endif
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -070020
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080021#include "sockets.h"
22
23#include "android/android.h"
24#include "qemu-common.h"
25#include "sysemu.h"
26#include "console.h"
David 'Digit' Turner34f29742010-05-25 18:16:10 -070027#include "user-events.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080028
29#include <SDL.h>
30#include <SDL_syswm.h>
31
32#include "math.h"
33
34#include "android/charmap.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080035#include "android/utils/debug.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080036#include "android/config.h"
37#include "android/config/config.h"
38
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080039#include "android/user-config.h"
40#include "android/utils/bufprint.h"
David 'Digit' Turner26d41532011-03-01 15:03:07 +010041#include "android/utils/filelock.h"
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +020042#include "android/utils/lineinput.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080043#include "android/utils/path.h"
David 'Digit' Turner622f1532011-02-01 17:48:37 +010044#include "android/utils/tempfile.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080045
David 'Digit' Turnerf8456272011-02-02 12:34:14 +010046#include "android/main-common.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080047#include "android/help.h"
48#include "hw/goldfish_nand.h"
49
50#include "android/globals.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080051
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -080052#include "android/qemulator.h"
David 'Digit' Turner055ae422010-07-27 11:34:16 -070053#include "android/display.h"
Vladimir Chtchetkine01193622010-05-11 13:07:22 -070054
Ot ten Thijeae835ac2010-10-18 13:37:37 +010055#include "android/snapshot.h"
56
David 'Digit' Turnere3fdd072011-02-02 14:43:23 +010057#include "android/framebuffer.h"
Vladimir Chtchetkine9a33e852010-11-08 16:52:04 -080058#include "iolooper.h"
David 'Digit' Turner055ae422010-07-27 11:34:16 -070059
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080060AndroidRotation android_framebuffer_rotation;
61
62#define STRINGIFY(x) _STRINGIFY(x)
63#define _STRINGIFY(x) #x
64
David 'Digit' Turnera383d022009-12-03 13:50:00 -080065#ifdef ANDROID_SDK_TOOLS_REVISION
66# define VERSION_STRING STRINGIFY(ANDROID_SDK_TOOLS_REVISION)".0"
67#else
68# define VERSION_STRING "standalone"
69#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080070
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080071#define D(...) do { if (VERBOSE_CHECK(init)) dprint(__VA_ARGS__); } while (0)
72
73extern int control_console_start( int port ); /* in control.c */
74
75extern int qemu_milli_needed;
76
77/* the default device DPI if none is specified by the skin
78 */
79#define DEFAULT_DEVICE_DPI 165
80
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080081#ifdef CONFIG_TRACE
82extern void start_tracing(void);
83extern void stop_tracing(void);
84#endif
85
86unsigned long android_verbose;
87
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080088int qemu_main(int argc, char **argv);
89
90/* this function dumps the QEMU help */
91extern void help( void );
92extern void emulator_help( void );
93
94#define VERBOSE_OPT(str,var) { str, &var }
95
96#define _VERBOSE_TAG(x,y) { #x, VERBOSE_##x, y },
97static const struct { const char* name; int flag; const char* text; }
98verbose_options[] = {
99 VERBOSE_TAG_LIST
100 { 0, 0, 0 }
101};
102
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800103void emulator_help( void )
104{
105 STRALLOC_DEFINE(out);
106 android_help_main(out);
107 printf( "%.*s", out->n, out->s );
108 stralloc_reset(out);
109 exit(1);
110}
111
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100112/* TODO: Put in shared source file */
113static char*
114_getFullFilePath( const char* rootPath, const char* fileName )
115{
116 if (path_is_absolute(fileName)) {
117 return ASTRDUP(fileName);
118 } else {
119 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
120
121 p = bufprint(temp, end, "%s/%s", rootPath, fileName);
122 if (p >= end) {
123 return NULL;
124 }
125 return ASTRDUP(temp);
126 }
127}
128
129static uint64_t
130_adjustPartitionSize( const char* description,
131 uint64_t imageBytes,
132 uint64_t defaultBytes,
133 int inAndroidBuild )
134{
135 char temp[64];
136 unsigned imageMB;
137 unsigned defaultMB;
138
139 if (imageBytes <= defaultBytes)
140 return defaultBytes;
141
142 imageMB = convertBytesToMB(imageBytes);
143 defaultMB = convertBytesToMB(defaultBytes);
144
145 if (imageMB > defaultMB) {
146 snprintf(temp, sizeof temp, "(%d MB > %d MB)", imageMB, defaultMB);
147 } else {
148 snprintf(temp, sizeof temp, "(%lld bytes > %lld bytes)", imageBytes, defaultBytes);
149 }
150
151 if (inAndroidBuild) {
152 dwarning("%s partition size adjusted to match image file %s\n", description, temp);
153 }
154
155 return convertMBToBytes(imageMB);
156}
157
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800158int main(int argc, char **argv)
159{
160 char tmp[MAX_PATH];
161 char* tmpend = tmp + sizeof(tmp);
162 char* args[128];
163 int n;
164 char* opt;
David 'Digit' Turner5e736932011-03-18 00:02:14 +0100165 /* The emulator always uses the first serial port for kernel messages
166 * and the second one for qemud. So start at the third if we need one
167 * for logcat or 'shell'
168 */
169 int serial = 2;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800170 int shell_serial = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800171
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +0200172 int forceArmv7 = 0;
173
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800174 AndroidHwConfig* hw;
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200175 AvdInfo* avd;
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100176 AConfig* skinConfig;
177 char* skinPath;
Vladimir Chtchetkine83ffd662011-02-11 12:40:59 -0800178 int inAndroidBuild;
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100179 uint64_t defaultPartitionSize = convertMBToBytes(66);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800180
181 AndroidOptions opts[1];
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700182 /* net.shared_net_ip boot property value. */
183 char boot_prop_ip[64];
184 boot_prop_ip[0] = '\0';
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800185
186 args[0] = argv[0];
187
188 if ( android_parse_options( &argc, &argv, opts ) < 0 ) {
189 exit(1);
190 }
191
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100192#ifdef _WIN32
193 socket_init();
194#endif
195
196 handle_ui_options(opts);
197
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800198 while (argc-- > 1) {
199 opt = (++argv)[0];
200
201 if(!strcmp(opt, "-qemu")) {
202 argc--;
203 argv++;
204 break;
205 }
206
207 if (!strcmp(opt, "-help")) {
208 emulator_help();
209 }
210
211 if (!strncmp(opt, "-help-",6)) {
212 STRALLOC_DEFINE(out);
213 opt += 6;
214
215 if (!strcmp(opt, "all")) {
216 android_help_all(out);
217 }
218 else if (android_help_for_option(opt, out) == 0) {
219 /* ok */
220 }
221 else if (android_help_for_topic(opt, out) == 0) {
222 /* ok */
223 }
224 if (out->n > 0) {
225 printf("\n%.*s", out->n, out->s);
226 exit(0);
227 }
228
229 fprintf(stderr, "unknown option: -help-%s\n", opt);
230 fprintf(stderr, "please use -help for a list of valid topics\n");
231 exit(1);
232 }
233
234 if (opt[0] == '-') {
235 fprintf(stderr, "unknown option: %s\n", opt);
236 fprintf(stderr, "please use -help for a list of valid options\n");
237 exit(1);
238 }
239
240 fprintf(stderr, "invalid command-line parameter: %s.\n", opt);
241 fprintf(stderr, "Hint: use '@foo' to launch a virtual device named 'foo'.\n");
242 fprintf(stderr, "please use -help for more information\n");
243 exit(1);
244 }
245
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800246 if (opts->version) {
247 printf("Android emulator version %s\n"
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100248 "Copyright (C) 2006-2011 The Android Open Source Project and many others.\n"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800249 "This program is a derivative of the QEMU CPU emulator (www.qemu.org).\n\n",
250#if defined ANDROID_BUILD_ID
251 VERSION_STRING " (build_id " STRINGIFY(ANDROID_BUILD_ID) ")" );
252#else
253 VERSION_STRING);
254#endif
255 printf(" This software is licensed under the terms of the GNU General Public\n"
256 " License version 2, as published by the Free Software Foundation, and\n"
257 " may be copied, distributed, and modified under those terms.\n\n"
258 " This program is distributed in the hope that it will be useful,\n"
259 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
260 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
261 " GNU General Public License for more details.\n\n");
262
263 exit(0);
264 }
265
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100266 if (opts->snapshot_list) {
David 'Digit' Turnerd80a7862011-05-05 10:24:43 +0200267 if (opts->snapstorage == NULL) {
268 /* Need to find the default snapstorage */
269 avd = createAVD(opts, &inAndroidBuild);
270 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
271 if (opts->snapstorage != NULL) {
272 D("autoconfig: -snapstorage %s", opts->snapstorage);
273 } else {
274 if (inAndroidBuild) {
275 derror("You must use the -snapstorage <file> option to specify a snapshot storage file!\n");
276 } else {
277 derror("This AVD doesn't have snapshotting enabled!\n");
278 }
279 exit(1);
280 }
281 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100282 snapshot_print_and_exit(opts->snapstorage);
283 }
284
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100285 sanitizeOptions(opts);
286
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100287 /* Initialization of UI started with -attach-core should work differently
288 * than initialization of UI that starts the core. In particular....
289 */
290
291 /* -charmap is incompatible with -attach-core, because particular
292 * charmap gets set up in the running core. */
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100293 if (android_charmap_setup(opts->charmap)) {
294 exit(1);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800295 }
296
Vladimir Chtchetkine83ffd662011-02-11 12:40:59 -0800297 /* Parses options and builds an appropriate AVD. */
David 'Digit' Turner462564f2011-02-23 13:32:37 +0100298 avd = android_avdInfo = createAVD(opts, &inAndroidBuild);
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200299
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800300 /* get the skin from the virtual device configuration */
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100301 if (opts->skindir != NULL) {
302 if (opts->skin == NULL) {
303 /* NOTE: Normally handled by sanitizeOptions(), just be safe */
304 derror("The -skindir <path> option requires a -skin <name> option");
305 exit(2);
306 }
307 } else {
308 char* skinName;
309 char* skinDir;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800310
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100311 avdInfo_getSkinInfo(avd, &skinName, &skinDir);
312
313 if (opts->skin == NULL) {
314 opts->skin = skinName;
315 D("autoconfig: -skin %s", opts->skin);
316 } else {
317 AFREE(skinName);
318 }
319
320 opts->skindir = skinDir;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800321 D("autoconfig: -skindir %s", opts->skindir);
322 }
323
324 /* Read hardware configuration */
325 hw = android_hw;
David 'Digit' Turnerb64325d2011-03-22 16:07:01 +0100326 if (avdInfo_initHwConfig(avd, hw) < 0) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800327 derror("could not read hardware configuration ?");
328 exit(1);
329 }
330
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800331 if (opts->keyset) {
332 parse_keyset(opts->keyset, opts);
333 if (!android_keyset) {
334 fprintf(stderr,
335 "emulator: WARNING: could not find keyset file named '%s',"
336 " using defaults instead\n",
337 opts->keyset);
338 }
339 }
340 if (!android_keyset) {
341 parse_keyset("default", opts);
342 if (!android_keyset) {
343 android_keyset = skin_keyset_new_from_text( skin_keyset_get_default() );
344 if (!android_keyset) {
345 fprintf(stderr, "PANIC: default keyset file is corrupted !!\n" );
346 fprintf(stderr, "PANIC: please update the code in android/skin/keyset.c\n" );
347 exit(1);
348 }
349 if (!opts->keyset)
350 write_default_keyset();
351 }
352 }
353
Dries Harnie40beab42010-05-15 17:04:47 +0200354 if (opts->shared_net_id) {
355 char* end;
356 long shared_net_id = strtol(opts->shared_net_id, &end, 0);
357 if (end == NULL || *end || shared_net_id < 1 || shared_net_id > 255) {
358 fprintf(stderr, "option -shared-net-id must be an integer between 1 and 255\n");
359 exit(1);
360 }
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700361 snprintf(boot_prop_ip, sizeof(boot_prop_ip),
362 "net.shared_net_ip=10.1.2.%ld", shared_net_id);
Dries Harnie40beab42010-05-15 17:04:47 +0200363 }
364
365
David 'Digit' Turner755811e2011-02-07 13:38:25 +0100366 user_config_init();
David 'Digit' Turner2507cab2011-02-10 16:29:17 +0100367 parse_skin_files(opts->skindir, opts->skin, opts, hw,
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100368 &skinConfig, &skinPath);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800369
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100370 if (!opts->netspeed && skin_network_speed) {
371 D("skin network speed: '%s'", skin_network_speed);
372 if (strcmp(skin_network_speed, NETWORK_SPEED_DEFAULT) != 0) {
373 opts->netspeed = (char*)skin_network_speed;
374 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800375 }
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100376 if (!opts->netdelay && skin_network_delay) {
377 D("skin network delay: '%s'", skin_network_delay);
378 if (strcmp(skin_network_delay, NETWORK_DELAY_DEFAULT) != 0) {
379 opts->netdelay = (char*)skin_network_delay;
380 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800381 }
382
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800383 if (opts->trace) {
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200384 char* tracePath = avdInfo_getTracePath(avd, opts->trace);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800385 int ret;
386
387 if (tracePath == NULL) {
388 derror( "bad -trace parameter" );
389 exit(1);
390 }
391 ret = path_mkdir_if_needed( tracePath, 0755 );
392 if (ret < 0) {
393 fprintf(stderr, "could not create directory '%s'\n", tmp);
394 exit(2);
395 }
396 opts->trace = tracePath;
397 }
398
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800399 n = 1;
400 /* generate arguments for the underlying qemu main() */
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700401 {
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100402 char* kernelFile = opts->kernel;
403 int kernelFileLen;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700404
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100405 if (kernelFile == NULL) {
406 kernelFile = avdInfo_getKernelPath(avd);
407 if (kernelFile == NULL) {
408 derror( "This AVD's configuration is missing a kernel file!!" );
409 exit(2);
410 }
411 D("autoconfig: -kernel %s", kernelFile);
412 }
413 if (!path_exists(kernelFile)) {
414 derror( "Invalid or missing kernel image file: %s", kernelFile );
415 exit(2);
416 }
417
418 hw->kernel_path = kernelFile;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700419
420 /* If the kernel image name ends in "-armv7", then change the cpu
421 * type automatically. This is a poor man's approach to configuration
422 * management, but should allow us to get past building ARMv7
423 * system images with dex preopt pass without introducing too many
424 * changes to the emulator sources.
425 *
426 * XXX:
427 * A 'proper' change would require adding some sort of hardware-property
428 * to each AVD config file, then automatically determine its value for
429 * full Android builds (depending on some environment variable), plus
430 * some build system changes. I prefer not to do that for now for reasons
431 * of simplicity.
432 */
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100433 kernelFileLen = strlen(kernelFile);
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700434 if (kernelFileLen > 6 && !memcmp(kernelFile + kernelFileLen - 6, "-armv7", 6)) {
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +0200435 forceArmv7 = 1;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700436 }
437 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800438
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700439 if (boot_prop_ip[0]) {
440 args[n++] = "-boot-property";
441 args[n++] = boot_prop_ip;
442 }
443
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -0700444 if (opts->tcpdump) {
445 args[n++] = "-tcpdump";
446 args[n++] = opts->tcpdump;
447 }
448
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700449#ifdef CONFIG_NAND_LIMITS
450 if (opts->nand_limits) {
451 args[n++] = "-nand-limits";
452 args[n++] = opts->nand_limits;
453 }
454#endif
455
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100456 if (opts->timezone) {
457 args[n++] = "-timezone";
458 args[n++] = opts->timezone;
459 }
460
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700461 if (opts->netspeed) {
462 args[n++] = "-netspeed";
463 args[n++] = opts->netspeed;
464 }
465 if (opts->netdelay) {
466 args[n++] = "-netdelay";
467 args[n++] = opts->netdelay;
468 }
469 if (opts->netfast) {
470 args[n++] = "-netfast";
471 }
472
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700473 if (opts->audio) {
474 args[n++] = "-audio";
475 args[n++] = opts->audio;
476 }
477
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700478 if (opts->cpu_delay) {
479 args[n++] = "-cpu-delay";
480 args[n++] = opts->cpu_delay;
481 }
482
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -0700483 if (opts->dns_server) {
484 args[n++] = "-dns-server";
485 args[n++] = opts->dns_server;
486 }
487
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100488 hw->disk_ramdisk_path = avdInfo_getRamdiskPath(avd);
489 D("autoconfig: -ramdisk %s", hw->disk_ramdisk_path);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800490
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100491 /* -partition-size is used to specify the max size of both the system
492 * and data partition sizes.
493 */
494 if (opts->partition_size) {
495 char* end;
496 long sizeMB = strtol(opts->partition_size, &end, 0);
497 long minSizeMB = 10;
498 long maxSizeMB = LONG_MAX / ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800499
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100500 if (sizeMB < 0 || *end != 0) {
501 derror( "-partition-size must be followed by a positive integer" );
502 exit(1);
503 }
504 if (sizeMB < minSizeMB || sizeMB > maxSizeMB) {
505 derror( "partition-size (%d) must be between %dMB and %dMB",
506 sizeMB, minSizeMB, maxSizeMB );
507 exit(1);
508 }
509 defaultPartitionSize = (uint64_t) sizeMB * ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800510 }
511
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100512
513 /** SYSTEM PARTITION **/
514
515 if (opts->sysdir == NULL) {
516 if (avdInfo_inAndroidBuild(avd)) {
517 opts->sysdir = ASTRDUP(avdInfo_getContentPath(avd));
518 D("autoconfig: -sysdir %s", opts->sysdir);
519 }
520 }
521
522 if (opts->sysdir != NULL) {
523 if (!path_exists(opts->sysdir)) {
524 derror("Directory does not exist: %s", opts->sysdir);
525 exit(1);
526 }
527 }
528
529 {
530 char* rwImage = NULL;
531 char* initImage = NULL;
532
533 do {
534 if (opts->system == NULL) {
535 /* If -system is not used, try to find a runtime system image
536 * (i.e. system-qemu.img) in the content directory.
537 */
538 rwImage = avdInfo_getSystemImagePath(avd);
539 if (rwImage != NULL) {
540 break;
541 }
542 /* Otherwise, try to find the initial system image */
543 initImage = avdInfo_getSystemInitImagePath(avd);
544 if (initImage == NULL) {
545 derror("No initial system image for this configuration!");
546 exit(1);
547 }
548 break;
549 }
550
551 /* If -system <name> is used, use it to find the initial image */
552 if (opts->sysdir != NULL) {
553 initImage = _getFullFilePath(opts->sysdir, opts->system);
554 } else {
555 initImage = ASTRDUP(opts->system);
556 }
557 if (!path_exists(initImage)) {
558 derror("System image file doesn't exist: %s", initImage);
559 exit(1);
560 }
561
562 } while (0);
563
564 if (rwImage != NULL) {
565 /* Use the read/write image file directly */
566 hw->disk_systemPartition_path = rwImage;
567 hw->disk_systemPartition_initPath = NULL;
568 D("Using direct system image: %s", rwImage);
569 } else if (initImage != NULL) {
570 hw->disk_systemPartition_path = NULL;
571 hw->disk_systemPartition_initPath = initImage;
572 D("Using initial system image: %s", initImage);
573 }
574
575 /* Check the size of the system partition image.
576 * If we have an AVD, it must be smaller than
577 * the disk.systemPartition.size hardware property.
578 *
579 * Otherwise, we need to adjust the systemPartitionSize
580 * automatically, and print a warning.
581 *
582 */
583 const char* systemImage = hw->disk_systemPartition_path;
584 uint64_t systemBytes;
585
586 if (systemImage == NULL)
587 systemImage = hw->disk_systemPartition_initPath;
588
589 if (path_get_size(systemImage, &systemBytes) < 0) {
590 derror("Missing system image: %s", systemImage);
591 exit(1);
592 }
593
594 hw->disk_systemPartition_size =
595 _adjustPartitionSize("system", systemBytes, defaultPartitionSize,
596 avdInfo_inAndroidBuild(avd));
597 }
598
599 /** DATA PARTITION **/
600
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100601 if (opts->datadir) {
602 if (!path_exists(opts->datadir)) {
603 derror("Invalid -datadir directory: %s", opts->datadir);
604 }
605 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800606
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100607 {
608 char* dataImage = NULL;
609 char* initImage = NULL;
610
611 do {
612 if (!opts->data) {
613 dataImage = avdInfo_getDataImagePath(avd);
614 if (dataImage != NULL) {
615 D("autoconfig: -data %s", dataImage);
616 break;
617 }
618 dataImage = avdInfo_getDefaultDataImagePath(avd);
619 if (dataImage == NULL) {
620 derror("No data image path for this configuration!");
621 exit (1);
622 }
623 opts->wipe_data = 1;
624 break;
625 }
626
627 if (opts->datadir) {
628 dataImage = _getFullFilePath(opts->datadir, opts->data);
629 } else {
630 dataImage = ASTRDUP(opts->data);
631 }
632 } while (0);
633
634 if (opts->initdata != NULL) {
635 initImage = ASTRDUP(opts->initdata);
636 if (!path_exists(initImage)) {
637 derror("Invalid initial data image path: %s", initImage);
638 exit(1);
639 }
640 } else {
641 initImage = avdInfo_getDataInitImagePath(avd);
642 D("autoconfig: -initdata %s", initImage);
643 }
644
645 hw->disk_dataPartition_path = dataImage;
646 if (opts->wipe_data) {
647 hw->disk_dataPartition_initPath = initImage;
648 } else {
649 hw->disk_dataPartition_initPath = NULL;
650 }
651
652 uint64_t defaultBytes = defaultPartitionSize;
653 uint64_t dataBytes;
654 const char* dataPath = hw->disk_dataPartition_initPath;
655
656 if (dataPath == NULL)
657 dataPath = hw->disk_dataPartition_path;
658
659 path_get_size(dataPath, &dataBytes);
660
661 hw->disk_dataPartition_size =
662 _adjustPartitionSize("data", dataBytes, defaultBytes,
663 avdInfo_inAndroidBuild(avd));
664 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800665
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100666 /** CACHE PARTITION **/
667
668 if (opts->no_cache) {
669 /* No cache partition at all */
670 hw->disk_cachePartition = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800671 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100672 else if (!hw->disk_cachePartition) {
673 if (opts->cache) {
674 dwarning( "Emulated hardware doesn't support a cache partition. -cache option ignored!" );
675 opts->cache = NULL;
676 }
677 }
678 else
679 {
680 if (!opts->cache) {
681 /* Find the current cache partition file */
682 opts->cache = avdInfo_getCachePath(avd);
683 if (opts->cache == NULL) {
684 /* The file does not exists, we will force its creation
685 * if we are not in the Android build system. Otherwise,
686 * a temporary file will be used.
687 */
688 if (!avdInfo_inAndroidBuild(avd)) {
689 opts->cache = avdInfo_getDefaultCachePath(avd);
690 }
691 }
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100692 if (opts->cache) {
693 D("autoconfig: -cache %s", opts->cache);
694 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100695 }
696
697 if (opts->cache) {
698 hw->disk_cachePartition_path = ASTRDUP(opts->cache);
699 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800700 }
701
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100702 /** SD CARD PARTITION */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800703
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100704 if (!hw->hw_sdCard) {
705 /* No SD Card emulation, so -sdcard will be ignored */
706 if (opts->sdcard) {
707 dwarning( "Emulated hardware doesn't support SD Cards. -sdcard option ignored." );
708 opts->sdcard = NULL;
709 }
710 } else {
711 /* Auto-configure -sdcard if it is not available */
712 if (!opts->sdcard) {
713 do {
714 /* If -datadir <path> is used, look for a sdcard.img file here */
715 if (opts->datadir) {
716 bufprint(tmp, tmpend, "%s/%s", opts->datadir, "system.img");
717 if (path_exists(tmp)) {
718 opts->sdcard = strdup(tmp);
719 break;
720 }
721 }
722
723 /* Otherwise, look at the AVD's content */
724 opts->sdcard = avdInfo_getSdCardPath(avd);
725 if (opts->sdcard != NULL) {
726 break;
727 }
728
729 /* Nothing */
730 } while (0);
731
732 if (opts->sdcard) {
733 D("autoconfig: -sdcard %s", opts->sdcard);
734 }
735 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800736 }
737
738 if(opts->sdcard) {
739 uint64_t size;
740 if (path_get_size(opts->sdcard, &size) == 0) {
741 /* see if we have an sdcard image. get its size if it exists */
David 'Digit' Turner8b657e52009-12-01 13:38:21 -0800742 /* due to what looks like limitations of the MMC protocol, one has
743 * to use an SD Card image that is equal or larger than 9 MB
744 */
745 if (size < 9*1024*1024ULL) {
746 fprintf(stderr, "### WARNING: SD Card files must be at least 9MB, ignoring '%s'\n", opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800747 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100748 hw->hw_sdCard_path = ASTRDUP(opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800749 }
750 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100751 dwarning("no SD Card image at '%s'", opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800752 }
753 }
754
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100755
756 /** SNAPSHOT STORAGE HANDLING */
757
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100758 /* Determine snapstorage path. -no-snapstorage disables all snapshotting
759 * support. This means you can't resume a snapshot at load, save it at
760 * exit, or even load/save them dynamically at runtime with the console.
761 */
762 if (opts->no_snapstorage) {
763
764 if (opts->snapshot) {
765 dwarning("ignoring -snapshot option due to the use of -no-snapstorage");
766 opts->snapshot = NULL;
767 }
768
769 if (opts->snapstorage) {
770 dwarning("ignoring -snapstorage option due to the use of -no-snapstorage");
771 opts->snapstorage = NULL;
772 }
773 }
774 else
775 {
776 if (!opts->snapstorage) {
777 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
778 if (opts->snapstorage != NULL) {
779 D("autoconfig: -snapstorage %s", opts->snapstorage);
Ot ten Thije353b3b12010-10-05 17:53:30 +0100780 }
781 }
782
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100783 if (opts->snapstorage && !path_exists(opts->snapstorage)) {
784 D("no image at '%s', state snapshots disabled", opts->snapstorage);
785 opts->snapstorage = NULL;
Ot ten Thije353b3b12010-10-05 17:53:30 +0100786 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100787 }
788
789 /* If we have a valid snapshot storage path */
790
791 if (opts->snapstorage) {
792
793 hw->disk_snapStorage_path = ASTRDUP(opts->snapstorage);
794
795 /* -no-snapshot is equivalent to using both -no-snapshot-load
796 * and -no-snapshot-save. You can still load/save snapshots dynamically
797 * from the console though.
798 */
799 if (opts->no_snapshot) {
800
801 opts->no_snapshot_load = 1;
802 opts->no_snapshot_save = 1;
803
804 if (opts->snapshot) {
805 dwarning("ignoring -snapshot option due to the use of -no-snapshot.");
806 }
807 }
808
809 if (!opts->no_snapshot_load || !opts->no_snapshot_save) {
810 if (opts->snapshot == NULL) {
811 opts->snapshot = "default-boot";
812 D("autoconfig: -snapshot %s", opts->snapshot);
813 }
814 }
815
816 /* We still use QEMU command-line options for the following since
817 * they can change from one invokation to the next and don't really
818 * correspond to the hardware configuration itself.
819 */
820 if (!opts->no_snapshot_load) {
821 args[n++] = "-loadvm";
822 args[n++] = ASTRDUP(opts->snapshot);
823 }
824
825 if (!opts->no_snapshot_save) {
826 args[n++] = "-savevm-on-exit";
827 args[n++] = ASTRDUP(opts->snapshot);
828 }
829
Tim Baverstock622b8f42010-12-07 11:36:59 +0000830 if (opts->no_snapshot_update_time) {
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100831 args[n++] = "-snapshot-no-time-update";
Tim Baverstock622b8f42010-12-07 11:36:59 +0000832 }
Ot ten Thijeae835ac2010-10-18 13:37:37 +0100833 }
Ot ten Thije353b3b12010-10-05 17:53:30 +0100834
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800835 if (!opts->logcat || opts->logcat[0] == 0) {
836 opts->logcat = getenv("ANDROID_LOG_TAGS");
837 if (opts->logcat && opts->logcat[0] == 0)
838 opts->logcat = NULL;
839 }
840
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800841 /* we always send the kernel messages from ttyS0 to android_kmsg */
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100842 if (opts->show_kernel) {
843 args[n++] = "-show-kernel";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800844 }
845
846 /* XXXX: TODO: implement -shell and -logcat through qemud instead */
847 if (!opts->shell_serial) {
848#ifdef _WIN32
849 opts->shell_serial = "con:";
850#else
851 opts->shell_serial = "stdio";
852#endif
853 }
854 else
855 opts->shell = 1;
856
857 if (opts->shell || opts->logcat) {
858 args[n++] = "-serial";
859 args[n++] = opts->shell_serial;
860 shell_serial = serial++;
861 }
862
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100863 if (opts->radio) {
864 args[n++] = "-radio";
865 args[n++] = opts->radio;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800866 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800867
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100868 if (opts->gps) {
869 args[n++] = "-gps";
870 args[n++] = opts->gps;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800871 }
872
873 if (opts->memory) {
874 char* end;
875 long ramSize = strtol(opts->memory, &end, 0);
876 if (ramSize < 0 || *end != 0) {
877 derror( "-memory must be followed by a positive integer" );
878 exit(1);
879 }
880 if (ramSize < 32 || ramSize > 4096) {
881 derror( "physical memory size must be between 32 and 4096 MB" );
882 exit(1);
883 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100884 hw->hw_ramSize = ramSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800885 }
886 if (!opts->memory) {
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100887 int ramSize = hw->hw_ramSize;
888 if (ramSize <= 0) {
889 /* Compute the default RAM size based on the size of screen.
890 * This is only used when the skin doesn't provide the ram
891 * size through its hardware.ini (i.e. legacy ones) or when
892 * in the full Android build system.
893 */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100894 int64_t pixels = hw->hw_lcd_width * hw->hw_lcd_height;
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100895 /* The following thresholds are a bit liberal, but we
896 * essentially want to ensure the following mappings:
897 *
898 * 320x480 -> 96
899 * 800x600 -> 128
900 * 1024x768 -> 256
901 *
902 * These are just simple heuristics, they could change in
903 * the future.
904 */
905 if (pixels <= 250000)
906 ramSize = 96;
907 else if (pixels <= 500000)
908 ramSize = 128;
909 else
910 ramSize = 256;
911 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100912 hw->hw_ramSize = ramSize;
913 }
914
915 D("Physical RAM size: %dMB\n", hw->hw_ramSize);
916
917 if (hw->vm_heapSize == 0) {
918 /* Compute the default heap size based on the RAM size.
919 * Essentially, we want to ensure the following liberal mappings:
920 *
921 * 96MB RAM -> 16MB heap
922 * 128MB RAM -> 24MB heap
923 * 256MB RAM -> 48MB heap
924 */
925 int ramSize = hw->hw_ramSize;
926 int heapSize;
927
928 if (ramSize < 100)
929 heapSize = 16;
930 else if (ramSize < 192)
931 heapSize = 24;
932 else
933 heapSize = 48;
934
935 hw->vm_heapSize = heapSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800936 }
937
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800938 if (opts->trace) {
939 args[n++] = "-trace";
940 args[n++] = opts->trace;
941 args[n++] = "-tracing";
942 args[n++] = "off";
943 }
944
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700945 /* Pass boot properties to the core. */
946 if (opts->prop != NULL) {
947 ParamList* pl = opts->prop;
948 for ( ; pl != NULL; pl = pl->next ) {
949 args[n++] = "-boot-property";
950 args[n++] = pl->param;
951 }
952 }
953
David 'Digit' Turner318e4f22009-05-25 18:01:03 +0200954 /* Setup the kernel init options
955 */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800956 {
957 static char params[1024];
958 char *p = params, *end = p + sizeof(params);
959
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100960 /* Don't worry about having a leading space here, this is handled
961 * by the core later. */
962
Jun Nakajima334ab472011-02-02 23:49:59 -0800963#ifdef TARGET_I386
964 p = bufprint(p, end, " androidboot.hardware=goldfish");
Jun Nakajimabac9add2011-02-08 22:10:52 -0800965 p = bufprint(p, end, " clocksource=pit");
Jun Nakajima334ab472011-02-02 23:49:59 -0800966#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800967
968 if (opts->shell || opts->logcat) {
969 p = bufprint(p, end, " androidboot.console=ttyS%d", shell_serial );
970 }
971
972 if (opts->trace) {
973 p = bufprint(p, end, " android.tracing=1");
974 }
975
976 if (!opts->no_jni) {
977 p = bufprint(p, end, " android.checkjni=1");
978 }
979
980 if (opts->no_boot_anim) {
981 p = bufprint( p, end, " android.bootanim=0" );
982 }
983
984 if (opts->logcat) {
985 char* q = bufprint(p, end, " androidboot.logcat=%s", opts->logcat);
986
987 if (q < end) {
988 /* replace any space by a comma ! */
989 {
990 int nn;
991 for (nn = 1; p[nn] != 0; nn++)
992 if (p[nn] == ' ' || p[nn] == '\t')
993 p[nn] = ',';
994 p += nn;
995 }
996 }
997 p = q;
998 }
999
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001000 if (opts->bootchart) {
1001 p = bufprint(p, end, " androidboot.bootchart=%s", opts->bootchart);
1002 }
1003
1004 if (p >= end) {
1005 fprintf(stderr, "### ERROR: kernel parameters too long\n");
1006 exit(1);
1007 }
1008
David 'Digit' Turner0b019492011-03-01 14:02:42 +01001009 hw->kernel_parameters = strdup(params);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001010 }
1011
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07001012 if (opts->ports) {
1013 args[n++] = "-android-ports";
1014 args[n++] = opts->ports;
1015 }
1016
1017 if (opts->port) {
1018 args[n++] = "-android-port";
1019 args[n++] = opts->port;
1020 }
1021
1022 if (opts->report_console) {
1023 args[n++] = "-android-report-console";
1024 args[n++] = opts->report_console;
1025 }
1026
1027 if (opts->http_proxy) {
1028 args[n++] = "-http-proxy";
1029 args[n++] = opts->http_proxy;
1030 }
1031
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001032 if (opts->charmap) {
1033 args[n++] = "-charmap";
1034 args[n++] = opts->charmap;
1035 }
1036
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07001037 if (opts->memcheck) {
1038 args[n++] = "-android-memcheck";
1039 args[n++] = opts->memcheck;
1040 }
1041
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01001042 /* physical memory is now in hw->hw_ramSize */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001043
David 'Digit' Turner53eb66d2011-03-01 14:58:23 +01001044 hw->avd_name = ASTRDUP(avdInfo_getName(avd));
David 'Digit' Turner6b8555c2011-02-17 04:28:19 +01001045
Dries Harnie40beab42010-05-15 17:04:47 +02001046 /* Set up the interfaces for inter-emulator networking */
1047 if (opts->shared_net_id) {
1048 unsigned int shared_net_id = atoi(opts->shared_net_id);
1049 char nic[37];
Dries Harnie40beab42010-05-15 17:04:47 +02001050
1051 args[n++] = "-net";
1052 args[n++] = "nic,vlan=0";
1053 args[n++] = "-net";
1054 args[n++] = "user,vlan=0";
Dries Harnie111d6f82010-06-09 21:42:18 +02001055
1056 args[n++] = "-net";
1057 snprintf(nic, sizeof nic, "nic,vlan=1,macaddr=52:54:00:12:34:%02x", shared_net_id);
1058 args[n++] = strdup(nic);
1059 args[n++] = "-net";
1060 args[n++] = "socket,vlan=1,mcast=230.0.0.10:1234";
Dries Harnie40beab42010-05-15 17:04:47 +02001061 }
1062
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001063 while(argc-- > 0) {
1064 args[n++] = *argv++;
1065 }
1066 args[n] = 0;
1067
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +02001068 /* If the target ABI is armeabi-v7a, we can auto-detect the cpu model
1069 * as a cortex-a8, instead of the default (arm926) which only emulates
1070 * an ARMv5TE CPU.
1071 */
1072 if (!forceArmv7 && hw->hw_cpu_model[0] == '\0')
1073 {
1074 char* abi = avdInfo_getTargetAbi(avd);
1075 if (abi != NULL) {
1076 if (!strcmp(abi, "armeabi-v7a")) {
1077 forceArmv7 = 1;
1078 }
1079 AFREE(abi);
1080 }
1081 }
1082
1083 if (forceArmv7 != 0) {
1084 AFREE(hw->hw_cpu_model);
1085 hw->hw_cpu_model = ASTRDUP("cortex-a8");
1086 D("Auto-config: -qemu -cpu %s", hw->hw_cpu_model);
1087 }
1088
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001089 /* Generate a hardware-qemu.ini for this AVD. The real hardware
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001090 * configuration is ususally stored in several files, e.g. the AVD's
1091 * config.ini plus the skin-specific hardware.ini.
1092 *
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001093 * The new file will group all definitions and will be used to
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001094 * launch the core with the -android-hw <file> option.
1095 */
1096 {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001097 const char* coreHwIniPath = avdInfo_getCoreHwIniPath(avd);
1098 IniFile* hwIni = iniFile_newFromMemory("", NULL);
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001099 androidHwConfig_write(hw, hwIni);
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001100
1101 if (filelock_create(coreHwIniPath) == NULL) {
1102 /* The AVD is already in use, we still support this as an
1103 * experimental feature. Use a temporary hardware-qemu.ini
1104 * file though to avoid overwriting the existing one. */
1105 TempFile* tempIni = tempfile_create();
1106 coreHwIniPath = tempfile_path(tempIni);
1107 }
1108
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001109 if (iniFile_saveToFile(hwIni, coreHwIniPath) < 0) {
1110 derror("Could not write hardware.ini to %s: %s", coreHwIniPath, strerror(errno));
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001111 exit(2);
1112 }
1113 args[n++] = "-android-hw";
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001114 args[n++] = strdup(coreHwIniPath);
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +02001115
1116 /* In verbose mode, dump the file's content */
1117 if (VERBOSE_CHECK(init)) {
1118 FILE* file = fopen(coreHwIniPath, "rt");
1119 if (file == NULL) {
1120 derror("Could not open hardware configuration file: %s\n",
1121 coreHwIniPath);
1122 } else {
1123 LineInput* input = lineInput_newFromStdFile(file);
1124 const char* line;
1125 printf("Content of hardware configuration file:\n");
1126 while ((line = lineInput_getLine(input)) != NULL) {
1127 printf(" %s\n", line);
1128 }
1129 printf(".\n");
1130 lineInput_free(input);
1131 fclose(file);
1132 }
1133 }
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001134 }
1135
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001136 if(VERBOSE_CHECK(init)) {
1137 int i;
David 'Digit' Turner33361762011-01-19 22:11:03 +01001138 printf("QEMU options list:\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001139 for(i = 0; i < n; i++) {
David 'Digit' Turner33361762011-01-19 22:11:03 +01001140 printf("emulator: argv[%02d] = \"%s\"\n", i, args[i]);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001141 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001142 /* Dump final command-line option to make debugging the core easier */
1143 printf("Concatenated QEMU options:\n");
1144 for (i = 0; i < n; i++) {
David 'Digit' Turner26722dd2011-02-24 16:40:20 +01001145 /* To make it easier to copy-paste the output to a command-line,
1146 * quote anything that contains spaces.
1147 */
1148 if (strchr(args[i], ' ') != NULL) {
1149 printf(" '%s'", args[i]);
1150 } else {
1151 printf(" %s", args[i]);
1152 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001153 }
1154 printf("\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001155 }
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +01001156
1157 /* Setup SDL UI just before calling the code */
1158 init_sdl_ui(skinConfig, skinPath, opts);
1159
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +01001160 if (attach_ui_to_core(opts) < 0) {
1161 derror("Can't attach to core!");
1162 exit(1);
1163 }
1164
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001165 return qemu_main(n, args);
1166}