blob: 0b1d64cf579a37219ddefd6ca9f2605f68207d34 [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' Turner9ff69722011-09-13 12:32:52 +0200488 /* opts->ramdisk is never NULL (see createAVD) here */
489 if (opts->ramdisk) {
490 AFREE(hw->disk_ramdisk_path);
491 hw->disk_ramdisk_path = ASTRDUP(opts->ramdisk);
492 }
493 else if (!hw->disk_ramdisk_path[0]) {
494 hw->disk_ramdisk_path = avdInfo_getRamdiskPath(avd);
495 D("autoconfig: -ramdisk %s", hw->disk_ramdisk_path);
496 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800497
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100498 /* -partition-size is used to specify the max size of both the system
499 * and data partition sizes.
500 */
501 if (opts->partition_size) {
502 char* end;
503 long sizeMB = strtol(opts->partition_size, &end, 0);
504 long minSizeMB = 10;
505 long maxSizeMB = LONG_MAX / ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800506
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100507 if (sizeMB < 0 || *end != 0) {
508 derror( "-partition-size must be followed by a positive integer" );
509 exit(1);
510 }
511 if (sizeMB < minSizeMB || sizeMB > maxSizeMB) {
512 derror( "partition-size (%d) must be between %dMB and %dMB",
513 sizeMB, minSizeMB, maxSizeMB );
514 exit(1);
515 }
516 defaultPartitionSize = (uint64_t) sizeMB * ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800517 }
518
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100519
520 /** SYSTEM PARTITION **/
521
522 if (opts->sysdir == NULL) {
523 if (avdInfo_inAndroidBuild(avd)) {
524 opts->sysdir = ASTRDUP(avdInfo_getContentPath(avd));
525 D("autoconfig: -sysdir %s", opts->sysdir);
526 }
527 }
528
529 if (opts->sysdir != NULL) {
530 if (!path_exists(opts->sysdir)) {
531 derror("Directory does not exist: %s", opts->sysdir);
532 exit(1);
533 }
534 }
535
536 {
537 char* rwImage = NULL;
538 char* initImage = NULL;
539
540 do {
541 if (opts->system == NULL) {
542 /* If -system is not used, try to find a runtime system image
543 * (i.e. system-qemu.img) in the content directory.
544 */
545 rwImage = avdInfo_getSystemImagePath(avd);
546 if (rwImage != NULL) {
547 break;
548 }
549 /* Otherwise, try to find the initial system image */
550 initImage = avdInfo_getSystemInitImagePath(avd);
551 if (initImage == NULL) {
552 derror("No initial system image for this configuration!");
553 exit(1);
554 }
555 break;
556 }
557
558 /* If -system <name> is used, use it to find the initial image */
David 'Digit' Turnerea283772011-07-07 04:40:27 +0200559 if (opts->sysdir != NULL && !path_exists(opts->system)) {
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100560 initImage = _getFullFilePath(opts->sysdir, opts->system);
561 } else {
562 initImage = ASTRDUP(opts->system);
563 }
564 if (!path_exists(initImage)) {
565 derror("System image file doesn't exist: %s", initImage);
566 exit(1);
567 }
568
569 } while (0);
570
571 if (rwImage != NULL) {
572 /* Use the read/write image file directly */
573 hw->disk_systemPartition_path = rwImage;
574 hw->disk_systemPartition_initPath = NULL;
575 D("Using direct system image: %s", rwImage);
576 } else if (initImage != NULL) {
577 hw->disk_systemPartition_path = NULL;
578 hw->disk_systemPartition_initPath = initImage;
579 D("Using initial system image: %s", initImage);
580 }
581
582 /* Check the size of the system partition image.
583 * If we have an AVD, it must be smaller than
584 * the disk.systemPartition.size hardware property.
585 *
586 * Otherwise, we need to adjust the systemPartitionSize
587 * automatically, and print a warning.
588 *
589 */
590 const char* systemImage = hw->disk_systemPartition_path;
591 uint64_t systemBytes;
592
593 if (systemImage == NULL)
594 systemImage = hw->disk_systemPartition_initPath;
595
596 if (path_get_size(systemImage, &systemBytes) < 0) {
597 derror("Missing system image: %s", systemImage);
598 exit(1);
599 }
600
601 hw->disk_systemPartition_size =
602 _adjustPartitionSize("system", systemBytes, defaultPartitionSize,
603 avdInfo_inAndroidBuild(avd));
604 }
605
606 /** DATA PARTITION **/
607
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100608 if (opts->datadir) {
609 if (!path_exists(opts->datadir)) {
610 derror("Invalid -datadir directory: %s", opts->datadir);
611 }
612 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800613
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100614 {
615 char* dataImage = NULL;
616 char* initImage = NULL;
617
618 do {
619 if (!opts->data) {
620 dataImage = avdInfo_getDataImagePath(avd);
621 if (dataImage != NULL) {
622 D("autoconfig: -data %s", dataImage);
623 break;
624 }
625 dataImage = avdInfo_getDefaultDataImagePath(avd);
626 if (dataImage == NULL) {
627 derror("No data image path for this configuration!");
628 exit (1);
629 }
630 opts->wipe_data = 1;
631 break;
632 }
633
634 if (opts->datadir) {
635 dataImage = _getFullFilePath(opts->datadir, opts->data);
636 } else {
637 dataImage = ASTRDUP(opts->data);
638 }
639 } while (0);
640
641 if (opts->initdata != NULL) {
642 initImage = ASTRDUP(opts->initdata);
643 if (!path_exists(initImage)) {
644 derror("Invalid initial data image path: %s", initImage);
645 exit(1);
646 }
647 } else {
648 initImage = avdInfo_getDataInitImagePath(avd);
649 D("autoconfig: -initdata %s", initImage);
650 }
651
652 hw->disk_dataPartition_path = dataImage;
653 if (opts->wipe_data) {
654 hw->disk_dataPartition_initPath = initImage;
655 } else {
656 hw->disk_dataPartition_initPath = NULL;
657 }
658
Maciek Molerusf7584112011-06-15 22:26:35 +0200659 uint64_t defaultBytes =
660 hw->disk_dataPartition_size == 0 ?
661 defaultPartitionSize :
662 convertMBToBytes(hw->disk_dataPartition_size);
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100663 uint64_t dataBytes;
664 const char* dataPath = hw->disk_dataPartition_initPath;
665
666 if (dataPath == NULL)
667 dataPath = hw->disk_dataPartition_path;
668
669 path_get_size(dataPath, &dataBytes);
670
671 hw->disk_dataPartition_size =
672 _adjustPartitionSize("data", dataBytes, defaultBytes,
673 avdInfo_inAndroidBuild(avd));
674 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800675
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100676 /** CACHE PARTITION **/
677
678 if (opts->no_cache) {
679 /* No cache partition at all */
680 hw->disk_cachePartition = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800681 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100682 else if (!hw->disk_cachePartition) {
683 if (opts->cache) {
684 dwarning( "Emulated hardware doesn't support a cache partition. -cache option ignored!" );
685 opts->cache = NULL;
686 }
687 }
688 else
689 {
690 if (!opts->cache) {
691 /* Find the current cache partition file */
692 opts->cache = avdInfo_getCachePath(avd);
693 if (opts->cache == NULL) {
694 /* The file does not exists, we will force its creation
695 * if we are not in the Android build system. Otherwise,
696 * a temporary file will be used.
697 */
698 if (!avdInfo_inAndroidBuild(avd)) {
699 opts->cache = avdInfo_getDefaultCachePath(avd);
700 }
701 }
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100702 if (opts->cache) {
703 D("autoconfig: -cache %s", opts->cache);
704 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100705 }
706
707 if (opts->cache) {
708 hw->disk_cachePartition_path = ASTRDUP(opts->cache);
709 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800710 }
711
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100712 /** SD CARD PARTITION */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800713
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100714 if (!hw->hw_sdCard) {
715 /* No SD Card emulation, so -sdcard will be ignored */
716 if (opts->sdcard) {
717 dwarning( "Emulated hardware doesn't support SD Cards. -sdcard option ignored." );
718 opts->sdcard = NULL;
719 }
720 } else {
721 /* Auto-configure -sdcard if it is not available */
722 if (!opts->sdcard) {
723 do {
724 /* If -datadir <path> is used, look for a sdcard.img file here */
725 if (opts->datadir) {
726 bufprint(tmp, tmpend, "%s/%s", opts->datadir, "system.img");
727 if (path_exists(tmp)) {
728 opts->sdcard = strdup(tmp);
729 break;
730 }
731 }
732
733 /* Otherwise, look at the AVD's content */
734 opts->sdcard = avdInfo_getSdCardPath(avd);
735 if (opts->sdcard != NULL) {
736 break;
737 }
738
739 /* Nothing */
740 } while (0);
741
742 if (opts->sdcard) {
743 D("autoconfig: -sdcard %s", opts->sdcard);
744 }
745 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800746 }
747
748 if(opts->sdcard) {
749 uint64_t size;
750 if (path_get_size(opts->sdcard, &size) == 0) {
751 /* see if we have an sdcard image. get its size if it exists */
David 'Digit' Turner8b657e52009-12-01 13:38:21 -0800752 /* due to what looks like limitations of the MMC protocol, one has
753 * to use an SD Card image that is equal or larger than 9 MB
754 */
755 if (size < 9*1024*1024ULL) {
756 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 -0800757 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100758 hw->hw_sdCard_path = ASTRDUP(opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800759 }
760 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100761 dwarning("no SD Card image at '%s'", opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800762 }
763 }
764
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100765
766 /** SNAPSHOT STORAGE HANDLING */
767
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100768 /* Determine snapstorage path. -no-snapstorage disables all snapshotting
769 * support. This means you can't resume a snapshot at load, save it at
770 * exit, or even load/save them dynamically at runtime with the console.
771 */
772 if (opts->no_snapstorage) {
773
774 if (opts->snapshot) {
775 dwarning("ignoring -snapshot option due to the use of -no-snapstorage");
776 opts->snapshot = NULL;
777 }
778
779 if (opts->snapstorage) {
780 dwarning("ignoring -snapstorage option due to the use of -no-snapstorage");
781 opts->snapstorage = NULL;
782 }
783 }
784 else
785 {
786 if (!opts->snapstorage) {
787 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
788 if (opts->snapstorage != NULL) {
789 D("autoconfig: -snapstorage %s", opts->snapstorage);
Ot ten Thije353b3b12010-10-05 17:53:30 +0100790 }
791 }
792
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100793 if (opts->snapstorage && !path_exists(opts->snapstorage)) {
794 D("no image at '%s', state snapshots disabled", opts->snapstorage);
795 opts->snapstorage = NULL;
Ot ten Thije353b3b12010-10-05 17:53:30 +0100796 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100797 }
798
799 /* If we have a valid snapshot storage path */
800
801 if (opts->snapstorage) {
802
803 hw->disk_snapStorage_path = ASTRDUP(opts->snapstorage);
804
805 /* -no-snapshot is equivalent to using both -no-snapshot-load
806 * and -no-snapshot-save. You can still load/save snapshots dynamically
807 * from the console though.
808 */
809 if (opts->no_snapshot) {
810
811 opts->no_snapshot_load = 1;
812 opts->no_snapshot_save = 1;
813
814 if (opts->snapshot) {
815 dwarning("ignoring -snapshot option due to the use of -no-snapshot.");
816 }
817 }
818
819 if (!opts->no_snapshot_load || !opts->no_snapshot_save) {
820 if (opts->snapshot == NULL) {
821 opts->snapshot = "default-boot";
822 D("autoconfig: -snapshot %s", opts->snapshot);
823 }
824 }
825
826 /* We still use QEMU command-line options for the following since
827 * they can change from one invokation to the next and don't really
828 * correspond to the hardware configuration itself.
829 */
830 if (!opts->no_snapshot_load) {
831 args[n++] = "-loadvm";
832 args[n++] = ASTRDUP(opts->snapshot);
833 }
834
835 if (!opts->no_snapshot_save) {
836 args[n++] = "-savevm-on-exit";
837 args[n++] = ASTRDUP(opts->snapshot);
838 }
839
Tim Baverstock622b8f42010-12-07 11:36:59 +0000840 if (opts->no_snapshot_update_time) {
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100841 args[n++] = "-snapshot-no-time-update";
Tim Baverstock622b8f42010-12-07 11:36:59 +0000842 }
Ot ten Thijeae835ac2010-10-18 13:37:37 +0100843 }
Ot ten Thije353b3b12010-10-05 17:53:30 +0100844
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800845 if (!opts->logcat || opts->logcat[0] == 0) {
846 opts->logcat = getenv("ANDROID_LOG_TAGS");
847 if (opts->logcat && opts->logcat[0] == 0)
848 opts->logcat = NULL;
849 }
850
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800851 /* we always send the kernel messages from ttyS0 to android_kmsg */
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100852 if (opts->show_kernel) {
853 args[n++] = "-show-kernel";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800854 }
855
856 /* XXXX: TODO: implement -shell and -logcat through qemud instead */
857 if (!opts->shell_serial) {
858#ifdef _WIN32
859 opts->shell_serial = "con:";
860#else
861 opts->shell_serial = "stdio";
862#endif
863 }
864 else
865 opts->shell = 1;
866
867 if (opts->shell || opts->logcat) {
868 args[n++] = "-serial";
869 args[n++] = opts->shell_serial;
870 shell_serial = serial++;
871 }
872
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100873 if (opts->radio) {
874 args[n++] = "-radio";
875 args[n++] = opts->radio;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800876 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800877
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100878 if (opts->gps) {
879 args[n++] = "-gps";
880 args[n++] = opts->gps;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800881 }
882
883 if (opts->memory) {
884 char* end;
885 long ramSize = strtol(opts->memory, &end, 0);
886 if (ramSize < 0 || *end != 0) {
887 derror( "-memory must be followed by a positive integer" );
888 exit(1);
889 }
890 if (ramSize < 32 || ramSize > 4096) {
891 derror( "physical memory size must be between 32 and 4096 MB" );
892 exit(1);
893 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100894 hw->hw_ramSize = ramSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800895 }
896 if (!opts->memory) {
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100897 int ramSize = hw->hw_ramSize;
898 if (ramSize <= 0) {
899 /* Compute the default RAM size based on the size of screen.
900 * This is only used when the skin doesn't provide the ram
901 * size through its hardware.ini (i.e. legacy ones) or when
902 * in the full Android build system.
903 */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100904 int64_t pixels = hw->hw_lcd_width * hw->hw_lcd_height;
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100905 /* The following thresholds are a bit liberal, but we
906 * essentially want to ensure the following mappings:
907 *
908 * 320x480 -> 96
909 * 800x600 -> 128
910 * 1024x768 -> 256
911 *
912 * These are just simple heuristics, they could change in
913 * the future.
914 */
915 if (pixels <= 250000)
916 ramSize = 96;
917 else if (pixels <= 500000)
918 ramSize = 128;
919 else
920 ramSize = 256;
921 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100922 hw->hw_ramSize = ramSize;
923 }
924
925 D("Physical RAM size: %dMB\n", hw->hw_ramSize);
926
927 if (hw->vm_heapSize == 0) {
928 /* Compute the default heap size based on the RAM size.
929 * Essentially, we want to ensure the following liberal mappings:
930 *
931 * 96MB RAM -> 16MB heap
932 * 128MB RAM -> 24MB heap
933 * 256MB RAM -> 48MB heap
934 */
935 int ramSize = hw->hw_ramSize;
936 int heapSize;
937
938 if (ramSize < 100)
939 heapSize = 16;
940 else if (ramSize < 192)
941 heapSize = 24;
942 else
943 heapSize = 48;
944
945 hw->vm_heapSize = heapSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800946 }
947
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800948 if (opts->trace) {
949 args[n++] = "-trace";
950 args[n++] = opts->trace;
951 args[n++] = "-tracing";
952 args[n++] = "off";
953 }
954
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700955 /* Pass boot properties to the core. */
956 if (opts->prop != NULL) {
957 ParamList* pl = opts->prop;
958 for ( ; pl != NULL; pl = pl->next ) {
959 args[n++] = "-boot-property";
960 args[n++] = pl->param;
961 }
962 }
963
David 'Digit' Turner318e4f22009-05-25 18:01:03 +0200964 /* Setup the kernel init options
965 */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800966 {
967 static char params[1024];
968 char *p = params, *end = p + sizeof(params);
969
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100970 /* Don't worry about having a leading space here, this is handled
971 * by the core later. */
972
Jun Nakajima334ab472011-02-02 23:49:59 -0800973#ifdef TARGET_I386
974 p = bufprint(p, end, " androidboot.hardware=goldfish");
Jun Nakajimabac9add2011-02-08 22:10:52 -0800975 p = bufprint(p, end, " clocksource=pit");
Jun Nakajima334ab472011-02-02 23:49:59 -0800976#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800977
978 if (opts->shell || opts->logcat) {
979 p = bufprint(p, end, " androidboot.console=ttyS%d", shell_serial );
980 }
981
982 if (opts->trace) {
983 p = bufprint(p, end, " android.tracing=1");
984 }
985
986 if (!opts->no_jni) {
987 p = bufprint(p, end, " android.checkjni=1");
988 }
989
990 if (opts->no_boot_anim) {
991 p = bufprint( p, end, " android.bootanim=0" );
992 }
993
994 if (opts->logcat) {
995 char* q = bufprint(p, end, " androidboot.logcat=%s", opts->logcat);
996
997 if (q < end) {
998 /* replace any space by a comma ! */
999 {
1000 int nn;
1001 for (nn = 1; p[nn] != 0; nn++)
1002 if (p[nn] == ' ' || p[nn] == '\t')
1003 p[nn] = ',';
1004 p += nn;
1005 }
1006 }
1007 p = q;
1008 }
1009
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001010 if (opts->bootchart) {
1011 p = bufprint(p, end, " androidboot.bootchart=%s", opts->bootchart);
1012 }
1013
1014 if (p >= end) {
1015 fprintf(stderr, "### ERROR: kernel parameters too long\n");
1016 exit(1);
1017 }
1018
David 'Digit' Turner0b019492011-03-01 14:02:42 +01001019 hw->kernel_parameters = strdup(params);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001020 }
1021
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07001022 if (opts->ports) {
1023 args[n++] = "-android-ports";
1024 args[n++] = opts->ports;
1025 }
1026
1027 if (opts->port) {
1028 args[n++] = "-android-port";
1029 args[n++] = opts->port;
1030 }
1031
1032 if (opts->report_console) {
1033 args[n++] = "-android-report-console";
1034 args[n++] = opts->report_console;
1035 }
1036
1037 if (opts->http_proxy) {
1038 args[n++] = "-http-proxy";
1039 args[n++] = opts->http_proxy;
1040 }
1041
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001042 if (!opts->charmap) {
1043 /* Try to find a valid charmap name */
1044 char* charmap = avdInfo_getCharmapFile(avd, hw->hw_keyboard_charmap);
1045 if (charmap != NULL) {
1046 D("autoconfig: -charmap %s", charmap);
1047 opts->charmap = charmap;
1048 }
1049 }
1050
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001051 if (opts->charmap) {
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001052 char charmap_name[AKEYCHARMAP_NAME_SIZE];
1053
1054 if (!path_exists(opts->charmap)) {
1055 derror("Charmap file does not exist: %s", opts->charmap);
1056 exit(1);
1057 }
1058 /* We need to store the charmap name in the hardware configuration.
1059 * However, the charmap file itself is only used by the UI component
1060 * and doesn't need to be set to the emulation engine.
1061 */
1062 kcm_extract_charmap_name(opts->charmap, charmap_name,
1063 sizeof(charmap_name));
1064 AFREE(hw->hw_keyboard_charmap);
1065 hw->hw_keyboard_charmap = ASTRDUP(charmap_name);
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001066 }
1067
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07001068 if (opts->memcheck) {
1069 args[n++] = "-android-memcheck";
1070 args[n++] = opts->memcheck;
1071 }
1072
David Turner9da935d2011-09-12 21:27:56 +02001073 if (opts->gpu) {
1074 const char* gpu = opts->gpu;
1075 if (!strcmp(gpu,"on") || !strcmp(gpu,"enabled")) {
1076 hw->hw_gpu_enabled = 1;
1077 } else if (!strcmp(gpu,"off") || !strcmp(gpu,"disabled")) {
1078 hw->hw_gpu_enabled = 0;
1079 } else if (!strcmp(gpu,"auto")) {
1080 /* Nothing to do */
1081 } else {
1082 derror("Invalid value for -gpu <mode> parameter: %s\n", gpu);
1083 derror("Valid values are: on, off or auto\n");
1084 exit(1);
1085 }
1086 }
1087
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01001088 /* physical memory is now in hw->hw_ramSize */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001089
David 'Digit' Turner53eb66d2011-03-01 14:58:23 +01001090 hw->avd_name = ASTRDUP(avdInfo_getName(avd));
David 'Digit' Turner6b8555c2011-02-17 04:28:19 +01001091
Dries Harnie40beab42010-05-15 17:04:47 +02001092 /* Set up the interfaces for inter-emulator networking */
1093 if (opts->shared_net_id) {
1094 unsigned int shared_net_id = atoi(opts->shared_net_id);
1095 char nic[37];
Dries Harnie40beab42010-05-15 17:04:47 +02001096
1097 args[n++] = "-net";
1098 args[n++] = "nic,vlan=0";
1099 args[n++] = "-net";
1100 args[n++] = "user,vlan=0";
Dries Harnie111d6f82010-06-09 21:42:18 +02001101
1102 args[n++] = "-net";
1103 snprintf(nic, sizeof nic, "nic,vlan=1,macaddr=52:54:00:12:34:%02x", shared_net_id);
1104 args[n++] = strdup(nic);
1105 args[n++] = "-net";
1106 args[n++] = "socket,vlan=1,mcast=230.0.0.10:1234";
Dries Harnie40beab42010-05-15 17:04:47 +02001107 }
1108
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001109 while(argc-- > 0) {
1110 args[n++] = *argv++;
1111 }
1112 args[n] = 0;
1113
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +02001114 /* If the target ABI is armeabi-v7a, we can auto-detect the cpu model
1115 * as a cortex-a8, instead of the default (arm926) which only emulates
1116 * an ARMv5TE CPU.
1117 */
1118 if (!forceArmv7 && hw->hw_cpu_model[0] == '\0')
1119 {
1120 char* abi = avdInfo_getTargetAbi(avd);
1121 if (abi != NULL) {
1122 if (!strcmp(abi, "armeabi-v7a")) {
1123 forceArmv7 = 1;
1124 }
1125 AFREE(abi);
1126 }
1127 }
1128
1129 if (forceArmv7 != 0) {
1130 AFREE(hw->hw_cpu_model);
1131 hw->hw_cpu_model = ASTRDUP("cortex-a8");
1132 D("Auto-config: -qemu -cpu %s", hw->hw_cpu_model);
1133 }
1134
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001135 /* Generate a hardware-qemu.ini for this AVD. The real hardware
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001136 * configuration is ususally stored in several files, e.g. the AVD's
1137 * config.ini plus the skin-specific hardware.ini.
1138 *
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001139 * The new file will group all definitions and will be used to
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001140 * launch the core with the -android-hw <file> option.
1141 */
1142 {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001143 const char* coreHwIniPath = avdInfo_getCoreHwIniPath(avd);
1144 IniFile* hwIni = iniFile_newFromMemory("", NULL);
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001145 androidHwConfig_write(hw, hwIni);
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001146
1147 if (filelock_create(coreHwIniPath) == NULL) {
1148 /* The AVD is already in use, we still support this as an
1149 * experimental feature. Use a temporary hardware-qemu.ini
1150 * file though to avoid overwriting the existing one. */
1151 TempFile* tempIni = tempfile_create();
1152 coreHwIniPath = tempfile_path(tempIni);
1153 }
1154
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001155 if (iniFile_saveToFile(hwIni, coreHwIniPath) < 0) {
1156 derror("Could not write hardware.ini to %s: %s", coreHwIniPath, strerror(errno));
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001157 exit(2);
1158 }
1159 args[n++] = "-android-hw";
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001160 args[n++] = strdup(coreHwIniPath);
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +02001161
1162 /* In verbose mode, dump the file's content */
1163 if (VERBOSE_CHECK(init)) {
1164 FILE* file = fopen(coreHwIniPath, "rt");
1165 if (file == NULL) {
1166 derror("Could not open hardware configuration file: %s\n",
1167 coreHwIniPath);
1168 } else {
1169 LineInput* input = lineInput_newFromStdFile(file);
1170 const char* line;
1171 printf("Content of hardware configuration file:\n");
1172 while ((line = lineInput_getLine(input)) != NULL) {
1173 printf(" %s\n", line);
1174 }
1175 printf(".\n");
1176 lineInput_free(input);
1177 fclose(file);
1178 }
1179 }
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001180 }
1181
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001182 if(VERBOSE_CHECK(init)) {
1183 int i;
David 'Digit' Turner33361762011-01-19 22:11:03 +01001184 printf("QEMU options list:\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001185 for(i = 0; i < n; i++) {
David 'Digit' Turner33361762011-01-19 22:11:03 +01001186 printf("emulator: argv[%02d] = \"%s\"\n", i, args[i]);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001187 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001188 /* Dump final command-line option to make debugging the core easier */
1189 printf("Concatenated QEMU options:\n");
1190 for (i = 0; i < n; i++) {
David 'Digit' Turner26722dd2011-02-24 16:40:20 +01001191 /* To make it easier to copy-paste the output to a command-line,
1192 * quote anything that contains spaces.
1193 */
1194 if (strchr(args[i], ' ') != NULL) {
1195 printf(" '%s'", args[i]);
1196 } else {
1197 printf(" %s", args[i]);
1198 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001199 }
1200 printf("\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001201 }
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +01001202
1203 /* Setup SDL UI just before calling the code */
1204 init_sdl_ui(skinConfig, skinPath, opts);
1205
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +01001206 if (attach_ui_to_core(opts) < 0) {
1207 derror("Can't attach to core!");
1208 exit(1);
1209 }
1210
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001211 return qemu_main(n, args);
1212}