blob: 814d2ec9b621935598941175920af6b61165897f [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 */
David 'Digit' Turnerea283772011-07-07 04:40:27 +0200552 if (opts->sysdir != NULL && !path_exists(opts->system)) {
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100553 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
Maciek Molerusf7584112011-06-15 22:26:35 +0200652 uint64_t defaultBytes =
653 hw->disk_dataPartition_size == 0 ?
654 defaultPartitionSize :
655 convertMBToBytes(hw->disk_dataPartition_size);
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100656 uint64_t dataBytes;
657 const char* dataPath = hw->disk_dataPartition_initPath;
658
659 if (dataPath == NULL)
660 dataPath = hw->disk_dataPartition_path;
661
662 path_get_size(dataPath, &dataBytes);
663
664 hw->disk_dataPartition_size =
665 _adjustPartitionSize("data", dataBytes, defaultBytes,
666 avdInfo_inAndroidBuild(avd));
667 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800668
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100669 /** CACHE PARTITION **/
670
671 if (opts->no_cache) {
672 /* No cache partition at all */
673 hw->disk_cachePartition = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800674 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100675 else if (!hw->disk_cachePartition) {
676 if (opts->cache) {
677 dwarning( "Emulated hardware doesn't support a cache partition. -cache option ignored!" );
678 opts->cache = NULL;
679 }
680 }
681 else
682 {
683 if (!opts->cache) {
684 /* Find the current cache partition file */
685 opts->cache = avdInfo_getCachePath(avd);
686 if (opts->cache == NULL) {
687 /* The file does not exists, we will force its creation
688 * if we are not in the Android build system. Otherwise,
689 * a temporary file will be used.
690 */
691 if (!avdInfo_inAndroidBuild(avd)) {
692 opts->cache = avdInfo_getDefaultCachePath(avd);
693 }
694 }
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100695 if (opts->cache) {
696 D("autoconfig: -cache %s", opts->cache);
697 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100698 }
699
700 if (opts->cache) {
701 hw->disk_cachePartition_path = ASTRDUP(opts->cache);
702 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800703 }
704
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100705 /** SD CARD PARTITION */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800706
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100707 if (!hw->hw_sdCard) {
708 /* No SD Card emulation, so -sdcard will be ignored */
709 if (opts->sdcard) {
710 dwarning( "Emulated hardware doesn't support SD Cards. -sdcard option ignored." );
711 opts->sdcard = NULL;
712 }
713 } else {
714 /* Auto-configure -sdcard if it is not available */
715 if (!opts->sdcard) {
716 do {
717 /* If -datadir <path> is used, look for a sdcard.img file here */
718 if (opts->datadir) {
719 bufprint(tmp, tmpend, "%s/%s", opts->datadir, "system.img");
720 if (path_exists(tmp)) {
721 opts->sdcard = strdup(tmp);
722 break;
723 }
724 }
725
726 /* Otherwise, look at the AVD's content */
727 opts->sdcard = avdInfo_getSdCardPath(avd);
728 if (opts->sdcard != NULL) {
729 break;
730 }
731
732 /* Nothing */
733 } while (0);
734
735 if (opts->sdcard) {
736 D("autoconfig: -sdcard %s", opts->sdcard);
737 }
738 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800739 }
740
741 if(opts->sdcard) {
742 uint64_t size;
743 if (path_get_size(opts->sdcard, &size) == 0) {
744 /* see if we have an sdcard image. get its size if it exists */
David 'Digit' Turner8b657e52009-12-01 13:38:21 -0800745 /* due to what looks like limitations of the MMC protocol, one has
746 * to use an SD Card image that is equal or larger than 9 MB
747 */
748 if (size < 9*1024*1024ULL) {
749 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 -0800750 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100751 hw->hw_sdCard_path = ASTRDUP(opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800752 }
753 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100754 dwarning("no SD Card image at '%s'", opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800755 }
756 }
757
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100758
759 /** SNAPSHOT STORAGE HANDLING */
760
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100761 /* Determine snapstorage path. -no-snapstorage disables all snapshotting
762 * support. This means you can't resume a snapshot at load, save it at
763 * exit, or even load/save them dynamically at runtime with the console.
764 */
765 if (opts->no_snapstorage) {
766
767 if (opts->snapshot) {
768 dwarning("ignoring -snapshot option due to the use of -no-snapstorage");
769 opts->snapshot = NULL;
770 }
771
772 if (opts->snapstorage) {
773 dwarning("ignoring -snapstorage option due to the use of -no-snapstorage");
774 opts->snapstorage = NULL;
775 }
776 }
777 else
778 {
779 if (!opts->snapstorage) {
780 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
781 if (opts->snapstorage != NULL) {
782 D("autoconfig: -snapstorage %s", opts->snapstorage);
Ot ten Thije353b3b12010-10-05 17:53:30 +0100783 }
784 }
785
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100786 if (opts->snapstorage && !path_exists(opts->snapstorage)) {
787 D("no image at '%s', state snapshots disabled", opts->snapstorage);
788 opts->snapstorage = NULL;
Ot ten Thije353b3b12010-10-05 17:53:30 +0100789 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100790 }
791
792 /* If we have a valid snapshot storage path */
793
794 if (opts->snapstorage) {
795
796 hw->disk_snapStorage_path = ASTRDUP(opts->snapstorage);
797
798 /* -no-snapshot is equivalent to using both -no-snapshot-load
799 * and -no-snapshot-save. You can still load/save snapshots dynamically
800 * from the console though.
801 */
802 if (opts->no_snapshot) {
803
804 opts->no_snapshot_load = 1;
805 opts->no_snapshot_save = 1;
806
807 if (opts->snapshot) {
808 dwarning("ignoring -snapshot option due to the use of -no-snapshot.");
809 }
810 }
811
812 if (!opts->no_snapshot_load || !opts->no_snapshot_save) {
813 if (opts->snapshot == NULL) {
814 opts->snapshot = "default-boot";
815 D("autoconfig: -snapshot %s", opts->snapshot);
816 }
817 }
818
819 /* We still use QEMU command-line options for the following since
820 * they can change from one invokation to the next and don't really
821 * correspond to the hardware configuration itself.
822 */
823 if (!opts->no_snapshot_load) {
824 args[n++] = "-loadvm";
825 args[n++] = ASTRDUP(opts->snapshot);
826 }
827
828 if (!opts->no_snapshot_save) {
829 args[n++] = "-savevm-on-exit";
830 args[n++] = ASTRDUP(opts->snapshot);
831 }
832
Tim Baverstock622b8f42010-12-07 11:36:59 +0000833 if (opts->no_snapshot_update_time) {
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100834 args[n++] = "-snapshot-no-time-update";
Tim Baverstock622b8f42010-12-07 11:36:59 +0000835 }
Ot ten Thijeae835ac2010-10-18 13:37:37 +0100836 }
Ot ten Thije353b3b12010-10-05 17:53:30 +0100837
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800838 if (!opts->logcat || opts->logcat[0] == 0) {
839 opts->logcat = getenv("ANDROID_LOG_TAGS");
840 if (opts->logcat && opts->logcat[0] == 0)
841 opts->logcat = NULL;
842 }
843
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800844 /* we always send the kernel messages from ttyS0 to android_kmsg */
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100845 if (opts->show_kernel) {
846 args[n++] = "-show-kernel";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800847 }
848
849 /* XXXX: TODO: implement -shell and -logcat through qemud instead */
850 if (!opts->shell_serial) {
851#ifdef _WIN32
852 opts->shell_serial = "con:";
853#else
854 opts->shell_serial = "stdio";
855#endif
856 }
857 else
858 opts->shell = 1;
859
860 if (opts->shell || opts->logcat) {
861 args[n++] = "-serial";
862 args[n++] = opts->shell_serial;
863 shell_serial = serial++;
864 }
865
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100866 if (opts->radio) {
867 args[n++] = "-radio";
868 args[n++] = opts->radio;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800869 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800870
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100871 if (opts->gps) {
872 args[n++] = "-gps";
873 args[n++] = opts->gps;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800874 }
875
876 if (opts->memory) {
877 char* end;
878 long ramSize = strtol(opts->memory, &end, 0);
879 if (ramSize < 0 || *end != 0) {
880 derror( "-memory must be followed by a positive integer" );
881 exit(1);
882 }
883 if (ramSize < 32 || ramSize > 4096) {
884 derror( "physical memory size must be between 32 and 4096 MB" );
885 exit(1);
886 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100887 hw->hw_ramSize = ramSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800888 }
889 if (!opts->memory) {
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100890 int ramSize = hw->hw_ramSize;
891 if (ramSize <= 0) {
892 /* Compute the default RAM size based on the size of screen.
893 * This is only used when the skin doesn't provide the ram
894 * size through its hardware.ini (i.e. legacy ones) or when
895 * in the full Android build system.
896 */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100897 int64_t pixels = hw->hw_lcd_width * hw->hw_lcd_height;
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100898 /* The following thresholds are a bit liberal, but we
899 * essentially want to ensure the following mappings:
900 *
901 * 320x480 -> 96
902 * 800x600 -> 128
903 * 1024x768 -> 256
904 *
905 * These are just simple heuristics, they could change in
906 * the future.
907 */
908 if (pixels <= 250000)
909 ramSize = 96;
910 else if (pixels <= 500000)
911 ramSize = 128;
912 else
913 ramSize = 256;
914 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100915 hw->hw_ramSize = ramSize;
916 }
917
918 D("Physical RAM size: %dMB\n", hw->hw_ramSize);
919
920 if (hw->vm_heapSize == 0) {
921 /* Compute the default heap size based on the RAM size.
922 * Essentially, we want to ensure the following liberal mappings:
923 *
924 * 96MB RAM -> 16MB heap
925 * 128MB RAM -> 24MB heap
926 * 256MB RAM -> 48MB heap
927 */
928 int ramSize = hw->hw_ramSize;
929 int heapSize;
930
931 if (ramSize < 100)
932 heapSize = 16;
933 else if (ramSize < 192)
934 heapSize = 24;
935 else
936 heapSize = 48;
937
938 hw->vm_heapSize = heapSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800939 }
940
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800941 if (opts->trace) {
942 args[n++] = "-trace";
943 args[n++] = opts->trace;
944 args[n++] = "-tracing";
945 args[n++] = "off";
946 }
947
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700948 /* Pass boot properties to the core. */
949 if (opts->prop != NULL) {
950 ParamList* pl = opts->prop;
951 for ( ; pl != NULL; pl = pl->next ) {
952 args[n++] = "-boot-property";
953 args[n++] = pl->param;
954 }
955 }
956
David 'Digit' Turner318e4f22009-05-25 18:01:03 +0200957 /* Setup the kernel init options
958 */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800959 {
960 static char params[1024];
961 char *p = params, *end = p + sizeof(params);
962
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100963 /* Don't worry about having a leading space here, this is handled
964 * by the core later. */
965
Jun Nakajima334ab472011-02-02 23:49:59 -0800966#ifdef TARGET_I386
967 p = bufprint(p, end, " androidboot.hardware=goldfish");
Jun Nakajimabac9add2011-02-08 22:10:52 -0800968 p = bufprint(p, end, " clocksource=pit");
Jun Nakajima334ab472011-02-02 23:49:59 -0800969#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800970
971 if (opts->shell || opts->logcat) {
972 p = bufprint(p, end, " androidboot.console=ttyS%d", shell_serial );
973 }
974
975 if (opts->trace) {
976 p = bufprint(p, end, " android.tracing=1");
977 }
978
979 if (!opts->no_jni) {
980 p = bufprint(p, end, " android.checkjni=1");
981 }
982
983 if (opts->no_boot_anim) {
984 p = bufprint( p, end, " android.bootanim=0" );
985 }
986
987 if (opts->logcat) {
988 char* q = bufprint(p, end, " androidboot.logcat=%s", opts->logcat);
989
990 if (q < end) {
991 /* replace any space by a comma ! */
992 {
993 int nn;
994 for (nn = 1; p[nn] != 0; nn++)
995 if (p[nn] == ' ' || p[nn] == '\t')
996 p[nn] = ',';
997 p += nn;
998 }
999 }
1000 p = q;
1001 }
1002
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001003 if (opts->bootchart) {
1004 p = bufprint(p, end, " androidboot.bootchart=%s", opts->bootchart);
1005 }
1006
1007 if (p >= end) {
1008 fprintf(stderr, "### ERROR: kernel parameters too long\n");
1009 exit(1);
1010 }
1011
David 'Digit' Turner0b019492011-03-01 14:02:42 +01001012 hw->kernel_parameters = strdup(params);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001013 }
1014
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07001015 if (opts->ports) {
1016 args[n++] = "-android-ports";
1017 args[n++] = opts->ports;
1018 }
1019
1020 if (opts->port) {
1021 args[n++] = "-android-port";
1022 args[n++] = opts->port;
1023 }
1024
1025 if (opts->report_console) {
1026 args[n++] = "-android-report-console";
1027 args[n++] = opts->report_console;
1028 }
1029
1030 if (opts->http_proxy) {
1031 args[n++] = "-http-proxy";
1032 args[n++] = opts->http_proxy;
1033 }
1034
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001035 if (opts->charmap) {
Xavier Ducrohetcccd28c2011-08-11 17:36:34 -07001036 args[n++] = "-charmap";
1037 args[n++] = opts->charmap;
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001038 }
1039
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07001040 if (opts->memcheck) {
1041 args[n++] = "-android-memcheck";
1042 args[n++] = opts->memcheck;
1043 }
1044
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01001045 /* physical memory is now in hw->hw_ramSize */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001046
David 'Digit' Turner53eb66d2011-03-01 14:58:23 +01001047 hw->avd_name = ASTRDUP(avdInfo_getName(avd));
David 'Digit' Turner6b8555c2011-02-17 04:28:19 +01001048
Dries Harnie40beab42010-05-15 17:04:47 +02001049 /* Set up the interfaces for inter-emulator networking */
1050 if (opts->shared_net_id) {
1051 unsigned int shared_net_id = atoi(opts->shared_net_id);
1052 char nic[37];
Dries Harnie40beab42010-05-15 17:04:47 +02001053
1054 args[n++] = "-net";
1055 args[n++] = "nic,vlan=0";
1056 args[n++] = "-net";
1057 args[n++] = "user,vlan=0";
Dries Harnie111d6f82010-06-09 21:42:18 +02001058
1059 args[n++] = "-net";
1060 snprintf(nic, sizeof nic, "nic,vlan=1,macaddr=52:54:00:12:34:%02x", shared_net_id);
1061 args[n++] = strdup(nic);
1062 args[n++] = "-net";
1063 args[n++] = "socket,vlan=1,mcast=230.0.0.10:1234";
Dries Harnie40beab42010-05-15 17:04:47 +02001064 }
1065
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001066 while(argc-- > 0) {
1067 args[n++] = *argv++;
1068 }
1069 args[n] = 0;
1070
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +02001071 /* If the target ABI is armeabi-v7a, we can auto-detect the cpu model
1072 * as a cortex-a8, instead of the default (arm926) which only emulates
1073 * an ARMv5TE CPU.
1074 */
1075 if (!forceArmv7 && hw->hw_cpu_model[0] == '\0')
1076 {
1077 char* abi = avdInfo_getTargetAbi(avd);
1078 if (abi != NULL) {
1079 if (!strcmp(abi, "armeabi-v7a")) {
1080 forceArmv7 = 1;
1081 }
1082 AFREE(abi);
1083 }
1084 }
1085
1086 if (forceArmv7 != 0) {
1087 AFREE(hw->hw_cpu_model);
1088 hw->hw_cpu_model = ASTRDUP("cortex-a8");
1089 D("Auto-config: -qemu -cpu %s", hw->hw_cpu_model);
1090 }
1091
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001092 /* Generate a hardware-qemu.ini for this AVD. The real hardware
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001093 * configuration is ususally stored in several files, e.g. the AVD's
1094 * config.ini plus the skin-specific hardware.ini.
1095 *
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001096 * The new file will group all definitions and will be used to
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001097 * launch the core with the -android-hw <file> option.
1098 */
1099 {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001100 const char* coreHwIniPath = avdInfo_getCoreHwIniPath(avd);
1101 IniFile* hwIni = iniFile_newFromMemory("", NULL);
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001102 androidHwConfig_write(hw, hwIni);
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001103
1104 if (filelock_create(coreHwIniPath) == NULL) {
1105 /* The AVD is already in use, we still support this as an
1106 * experimental feature. Use a temporary hardware-qemu.ini
1107 * file though to avoid overwriting the existing one. */
1108 TempFile* tempIni = tempfile_create();
1109 coreHwIniPath = tempfile_path(tempIni);
1110 }
1111
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001112 if (iniFile_saveToFile(hwIni, coreHwIniPath) < 0) {
1113 derror("Could not write hardware.ini to %s: %s", coreHwIniPath, strerror(errno));
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001114 exit(2);
1115 }
1116 args[n++] = "-android-hw";
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001117 args[n++] = strdup(coreHwIniPath);
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +02001118
1119 /* In verbose mode, dump the file's content */
1120 if (VERBOSE_CHECK(init)) {
1121 FILE* file = fopen(coreHwIniPath, "rt");
1122 if (file == NULL) {
1123 derror("Could not open hardware configuration file: %s\n",
1124 coreHwIniPath);
1125 } else {
1126 LineInput* input = lineInput_newFromStdFile(file);
1127 const char* line;
1128 printf("Content of hardware configuration file:\n");
1129 while ((line = lineInput_getLine(input)) != NULL) {
1130 printf(" %s\n", line);
1131 }
1132 printf(".\n");
1133 lineInput_free(input);
1134 fclose(file);
1135 }
1136 }
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001137 }
1138
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001139 if(VERBOSE_CHECK(init)) {
1140 int i;
David 'Digit' Turner33361762011-01-19 22:11:03 +01001141 printf("QEMU options list:\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001142 for(i = 0; i < n; i++) {
David 'Digit' Turner33361762011-01-19 22:11:03 +01001143 printf("emulator: argv[%02d] = \"%s\"\n", i, args[i]);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001144 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001145 /* Dump final command-line option to make debugging the core easier */
1146 printf("Concatenated QEMU options:\n");
1147 for (i = 0; i < n; i++) {
David 'Digit' Turner26722dd2011-02-24 16:40:20 +01001148 /* To make it easier to copy-paste the output to a command-line,
1149 * quote anything that contains spaces.
1150 */
1151 if (strchr(args[i], ' ') != NULL) {
1152 printf(" '%s'", args[i]);
1153 } else {
1154 printf(" %s", args[i]);
1155 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001156 }
1157 printf("\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001158 }
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +01001159
1160 /* Setup SDL UI just before calling the code */
1161 init_sdl_ui(skinConfig, skinPath, opts);
1162
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +01001163 if (attach_ui_to_core(opts) < 0) {
1164 derror("Can't attach to core!");
1165 exit(1);
1166 }
1167
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001168 return qemu_main(n, args);
1169}