blob: c2f8663d4c9c2cc760aa2256a217c1126e26dc03 [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
Vladimir Chtchetkineb8dcaff2011-09-17 11:15:47 -0700158/* Parses a -webcam option, extracting 'name', and 'dir' values.
159 * Param:
160 * param - -webcam option, that should be formatted as such:
161 * name=<name>[,dir=<direction>]
162 * name, name_size - buffer (and its size) where to receive <name>
163 * dir, dir_size - buffer (and its size) where to receive <direction>
164 */
165static void
166_parseWebcamOption(const char* param,
167 char* name, size_t name_size,
168 char* dir, size_t dir_size)
169{
170 const char* dr;
171 const char* wc_opt = param;
172
173 /* Must start with 'name=' */
174 if (strlen(wc_opt) <= 5 || memcmp(wc_opt, "name=", 5)) {
175 derror("Invalid value for -webcam parameter: %s\n", param);
176 exit(1);
177 }
178
179 /* Move on to 'name' value. */
180 wc_opt += 5;
181 dr = strchr(wc_opt, ',');
182 if (dr == NULL) {
183 dr = wc_opt + strlen(wc_opt);
184 }
185
186 /* Make sure that <name> fits */
187 if ((dr - wc_opt) < name_size) {
188 memcpy(name, wc_opt, dr - wc_opt);
189 name[dr - wc_opt] = '\0';
190 if (*dr == '\0') {
191 /* Default direction value is 'front' */
192 strcpy(dir, "front");
193 return;
194 } else {
195 dr++;
196 }
197 } else {
198 derror("Invalid <name> value for -webcam parameter: %s\n", param);
199 exit(1);
200 }
201
202 /* Parse 'dir'. Must begin with 'dir=' */
203 if (strlen(dr) <= 4 || memcmp(dr, "dir=", 4)) {
204 derror("Invalid value for -webcam parameter: %s\n", param);
205 exit(1);
206 }
207 dr += 4;
208 /* Check the bounds, and the values */
209 if (strlen(dr) >= dir_size || (strcmp(dr, "front") && strcmp(dr, "back"))) {
210 derror("Invalid <direction> value for -webcam parameter: %s\n"
211 "Valid values are: 'front', or 'back'\n", param);
212 exit(1);
213 }
214 strcpy(dir, dr);
215}
216
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800217int main(int argc, char **argv)
218{
219 char tmp[MAX_PATH];
220 char* tmpend = tmp + sizeof(tmp);
221 char* args[128];
222 int n;
223 char* opt;
David 'Digit' Turner5e736932011-03-18 00:02:14 +0100224 /* The emulator always uses the first serial port for kernel messages
225 * and the second one for qemud. So start at the third if we need one
226 * for logcat or 'shell'
227 */
228 int serial = 2;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800229 int shell_serial = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800230
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +0200231 int forceArmv7 = 0;
232
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800233 AndroidHwConfig* hw;
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200234 AvdInfo* avd;
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100235 AConfig* skinConfig;
236 char* skinPath;
Vladimir Chtchetkine83ffd662011-02-11 12:40:59 -0800237 int inAndroidBuild;
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100238 uint64_t defaultPartitionSize = convertMBToBytes(66);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800239
240 AndroidOptions opts[1];
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700241 /* net.shared_net_ip boot property value. */
242 char boot_prop_ip[64];
243 boot_prop_ip[0] = '\0';
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800244
245 args[0] = argv[0];
246
247 if ( android_parse_options( &argc, &argv, opts ) < 0 ) {
248 exit(1);
249 }
250
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100251#ifdef _WIN32
252 socket_init();
253#endif
254
255 handle_ui_options(opts);
256
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800257 while (argc-- > 1) {
258 opt = (++argv)[0];
259
260 if(!strcmp(opt, "-qemu")) {
261 argc--;
262 argv++;
263 break;
264 }
265
266 if (!strcmp(opt, "-help")) {
267 emulator_help();
268 }
269
270 if (!strncmp(opt, "-help-",6)) {
271 STRALLOC_DEFINE(out);
272 opt += 6;
273
274 if (!strcmp(opt, "all")) {
275 android_help_all(out);
276 }
277 else if (android_help_for_option(opt, out) == 0) {
278 /* ok */
279 }
280 else if (android_help_for_topic(opt, out) == 0) {
281 /* ok */
282 }
283 if (out->n > 0) {
284 printf("\n%.*s", out->n, out->s);
285 exit(0);
286 }
287
288 fprintf(stderr, "unknown option: -help-%s\n", opt);
289 fprintf(stderr, "please use -help for a list of valid topics\n");
290 exit(1);
291 }
292
293 if (opt[0] == '-') {
294 fprintf(stderr, "unknown option: %s\n", opt);
295 fprintf(stderr, "please use -help for a list of valid options\n");
296 exit(1);
297 }
298
299 fprintf(stderr, "invalid command-line parameter: %s.\n", opt);
300 fprintf(stderr, "Hint: use '@foo' to launch a virtual device named 'foo'.\n");
301 fprintf(stderr, "please use -help for more information\n");
302 exit(1);
303 }
304
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800305 if (opts->version) {
306 printf("Android emulator version %s\n"
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100307 "Copyright (C) 2006-2011 The Android Open Source Project and many others.\n"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800308 "This program is a derivative of the QEMU CPU emulator (www.qemu.org).\n\n",
309#if defined ANDROID_BUILD_ID
310 VERSION_STRING " (build_id " STRINGIFY(ANDROID_BUILD_ID) ")" );
311#else
312 VERSION_STRING);
313#endif
314 printf(" This software is licensed under the terms of the GNU General Public\n"
315 " License version 2, as published by the Free Software Foundation, and\n"
316 " may be copied, distributed, and modified under those terms.\n\n"
317 " This program is distributed in the hope that it will be useful,\n"
318 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
319 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
320 " GNU General Public License for more details.\n\n");
321
322 exit(0);
323 }
324
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100325 if (opts->snapshot_list) {
David 'Digit' Turnerd80a7862011-05-05 10:24:43 +0200326 if (opts->snapstorage == NULL) {
327 /* Need to find the default snapstorage */
328 avd = createAVD(opts, &inAndroidBuild);
329 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
330 if (opts->snapstorage != NULL) {
331 D("autoconfig: -snapstorage %s", opts->snapstorage);
332 } else {
333 if (inAndroidBuild) {
334 derror("You must use the -snapstorage <file> option to specify a snapshot storage file!\n");
335 } else {
336 derror("This AVD doesn't have snapshotting enabled!\n");
337 }
338 exit(1);
339 }
340 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100341 snapshot_print_and_exit(opts->snapstorage);
342 }
343
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100344 sanitizeOptions(opts);
345
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100346 /* Initialization of UI started with -attach-core should work differently
347 * than initialization of UI that starts the core. In particular....
348 */
349
350 /* -charmap is incompatible with -attach-core, because particular
351 * charmap gets set up in the running core. */
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100352 if (android_charmap_setup(opts->charmap)) {
353 exit(1);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800354 }
355
Vladimir Chtchetkine83ffd662011-02-11 12:40:59 -0800356 /* Parses options and builds an appropriate AVD. */
David 'Digit' Turner462564f2011-02-23 13:32:37 +0100357 avd = android_avdInfo = createAVD(opts, &inAndroidBuild);
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200358
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800359 /* get the skin from the virtual device configuration */
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100360 if (opts->skindir != NULL) {
361 if (opts->skin == NULL) {
362 /* NOTE: Normally handled by sanitizeOptions(), just be safe */
363 derror("The -skindir <path> option requires a -skin <name> option");
364 exit(2);
365 }
366 } else {
367 char* skinName;
368 char* skinDir;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800369
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100370 avdInfo_getSkinInfo(avd, &skinName, &skinDir);
371
372 if (opts->skin == NULL) {
373 opts->skin = skinName;
374 D("autoconfig: -skin %s", opts->skin);
375 } else {
376 AFREE(skinName);
377 }
378
379 opts->skindir = skinDir;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800380 D("autoconfig: -skindir %s", opts->skindir);
381 }
382
383 /* Read hardware configuration */
384 hw = android_hw;
David 'Digit' Turnerb64325d2011-03-22 16:07:01 +0100385 if (avdInfo_initHwConfig(avd, hw) < 0) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800386 derror("could not read hardware configuration ?");
387 exit(1);
388 }
389
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800390 if (opts->keyset) {
391 parse_keyset(opts->keyset, opts);
392 if (!android_keyset) {
393 fprintf(stderr,
394 "emulator: WARNING: could not find keyset file named '%s',"
395 " using defaults instead\n",
396 opts->keyset);
397 }
398 }
399 if (!android_keyset) {
400 parse_keyset("default", opts);
401 if (!android_keyset) {
402 android_keyset = skin_keyset_new_from_text( skin_keyset_get_default() );
403 if (!android_keyset) {
404 fprintf(stderr, "PANIC: default keyset file is corrupted !!\n" );
405 fprintf(stderr, "PANIC: please update the code in android/skin/keyset.c\n" );
406 exit(1);
407 }
408 if (!opts->keyset)
409 write_default_keyset();
410 }
411 }
412
Dries Harnie40beab42010-05-15 17:04:47 +0200413 if (opts->shared_net_id) {
414 char* end;
415 long shared_net_id = strtol(opts->shared_net_id, &end, 0);
416 if (end == NULL || *end || shared_net_id < 1 || shared_net_id > 255) {
417 fprintf(stderr, "option -shared-net-id must be an integer between 1 and 255\n");
418 exit(1);
419 }
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700420 snprintf(boot_prop_ip, sizeof(boot_prop_ip),
421 "net.shared_net_ip=10.1.2.%ld", shared_net_id);
Dries Harnie40beab42010-05-15 17:04:47 +0200422 }
423
424
David 'Digit' Turner755811e2011-02-07 13:38:25 +0100425 user_config_init();
David 'Digit' Turner2507cab2011-02-10 16:29:17 +0100426 parse_skin_files(opts->skindir, opts->skin, opts, hw,
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100427 &skinConfig, &skinPath);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800428
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100429 if (!opts->netspeed && skin_network_speed) {
430 D("skin network speed: '%s'", skin_network_speed);
431 if (strcmp(skin_network_speed, NETWORK_SPEED_DEFAULT) != 0) {
432 opts->netspeed = (char*)skin_network_speed;
433 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800434 }
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100435 if (!opts->netdelay && skin_network_delay) {
436 D("skin network delay: '%s'", skin_network_delay);
437 if (strcmp(skin_network_delay, NETWORK_DELAY_DEFAULT) != 0) {
438 opts->netdelay = (char*)skin_network_delay;
439 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800440 }
441
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800442 if (opts->trace) {
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200443 char* tracePath = avdInfo_getTracePath(avd, opts->trace);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800444 int ret;
445
446 if (tracePath == NULL) {
447 derror( "bad -trace parameter" );
448 exit(1);
449 }
450 ret = path_mkdir_if_needed( tracePath, 0755 );
451 if (ret < 0) {
452 fprintf(stderr, "could not create directory '%s'\n", tmp);
453 exit(2);
454 }
455 opts->trace = tracePath;
456 }
457
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800458 n = 1;
459 /* generate arguments for the underlying qemu main() */
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700460 {
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100461 char* kernelFile = opts->kernel;
462 int kernelFileLen;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700463
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100464 if (kernelFile == NULL) {
465 kernelFile = avdInfo_getKernelPath(avd);
466 if (kernelFile == NULL) {
467 derror( "This AVD's configuration is missing a kernel file!!" );
468 exit(2);
469 }
470 D("autoconfig: -kernel %s", kernelFile);
471 }
472 if (!path_exists(kernelFile)) {
473 derror( "Invalid or missing kernel image file: %s", kernelFile );
474 exit(2);
475 }
476
477 hw->kernel_path = kernelFile;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700478
479 /* If the kernel image name ends in "-armv7", then change the cpu
480 * type automatically. This is a poor man's approach to configuration
481 * management, but should allow us to get past building ARMv7
482 * system images with dex preopt pass without introducing too many
483 * changes to the emulator sources.
484 *
485 * XXX:
486 * A 'proper' change would require adding some sort of hardware-property
487 * to each AVD config file, then automatically determine its value for
488 * full Android builds (depending on some environment variable), plus
489 * some build system changes. I prefer not to do that for now for reasons
490 * of simplicity.
491 */
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100492 kernelFileLen = strlen(kernelFile);
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700493 if (kernelFileLen > 6 && !memcmp(kernelFile + kernelFileLen - 6, "-armv7", 6)) {
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +0200494 forceArmv7 = 1;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700495 }
496 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800497
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700498 if (boot_prop_ip[0]) {
499 args[n++] = "-boot-property";
500 args[n++] = boot_prop_ip;
501 }
502
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -0700503 if (opts->tcpdump) {
504 args[n++] = "-tcpdump";
505 args[n++] = opts->tcpdump;
506 }
507
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700508#ifdef CONFIG_NAND_LIMITS
509 if (opts->nand_limits) {
510 args[n++] = "-nand-limits";
511 args[n++] = opts->nand_limits;
512 }
513#endif
514
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100515 if (opts->timezone) {
516 args[n++] = "-timezone";
517 args[n++] = opts->timezone;
518 }
519
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700520 if (opts->netspeed) {
521 args[n++] = "-netspeed";
522 args[n++] = opts->netspeed;
523 }
524 if (opts->netdelay) {
525 args[n++] = "-netdelay";
526 args[n++] = opts->netdelay;
527 }
528 if (opts->netfast) {
529 args[n++] = "-netfast";
530 }
531
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700532 if (opts->audio) {
533 args[n++] = "-audio";
534 args[n++] = opts->audio;
535 }
536
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700537 if (opts->cpu_delay) {
538 args[n++] = "-cpu-delay";
539 args[n++] = opts->cpu_delay;
540 }
541
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -0700542 if (opts->dns_server) {
543 args[n++] = "-dns-server";
544 args[n++] = opts->dns_server;
545 }
546
David 'Digit' Turner9ff69722011-09-13 12:32:52 +0200547 /* opts->ramdisk is never NULL (see createAVD) here */
548 if (opts->ramdisk) {
549 AFREE(hw->disk_ramdisk_path);
550 hw->disk_ramdisk_path = ASTRDUP(opts->ramdisk);
551 }
552 else if (!hw->disk_ramdisk_path[0]) {
553 hw->disk_ramdisk_path = avdInfo_getRamdiskPath(avd);
554 D("autoconfig: -ramdisk %s", hw->disk_ramdisk_path);
555 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800556
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100557 /* -partition-size is used to specify the max size of both the system
558 * and data partition sizes.
559 */
560 if (opts->partition_size) {
561 char* end;
562 long sizeMB = strtol(opts->partition_size, &end, 0);
563 long minSizeMB = 10;
564 long maxSizeMB = LONG_MAX / ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800565
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100566 if (sizeMB < 0 || *end != 0) {
567 derror( "-partition-size must be followed by a positive integer" );
568 exit(1);
569 }
570 if (sizeMB < minSizeMB || sizeMB > maxSizeMB) {
571 derror( "partition-size (%d) must be between %dMB and %dMB",
572 sizeMB, minSizeMB, maxSizeMB );
573 exit(1);
574 }
575 defaultPartitionSize = (uint64_t) sizeMB * ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800576 }
577
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100578
579 /** SYSTEM PARTITION **/
580
581 if (opts->sysdir == NULL) {
582 if (avdInfo_inAndroidBuild(avd)) {
583 opts->sysdir = ASTRDUP(avdInfo_getContentPath(avd));
584 D("autoconfig: -sysdir %s", opts->sysdir);
585 }
586 }
587
588 if (opts->sysdir != NULL) {
589 if (!path_exists(opts->sysdir)) {
590 derror("Directory does not exist: %s", opts->sysdir);
591 exit(1);
592 }
593 }
594
595 {
596 char* rwImage = NULL;
597 char* initImage = NULL;
598
599 do {
600 if (opts->system == NULL) {
601 /* If -system is not used, try to find a runtime system image
602 * (i.e. system-qemu.img) in the content directory.
603 */
604 rwImage = avdInfo_getSystemImagePath(avd);
605 if (rwImage != NULL) {
606 break;
607 }
608 /* Otherwise, try to find the initial system image */
609 initImage = avdInfo_getSystemInitImagePath(avd);
610 if (initImage == NULL) {
611 derror("No initial system image for this configuration!");
612 exit(1);
613 }
614 break;
615 }
616
617 /* If -system <name> is used, use it to find the initial image */
David 'Digit' Turnerea283772011-07-07 04:40:27 +0200618 if (opts->sysdir != NULL && !path_exists(opts->system)) {
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100619 initImage = _getFullFilePath(opts->sysdir, opts->system);
620 } else {
621 initImage = ASTRDUP(opts->system);
622 }
623 if (!path_exists(initImage)) {
624 derror("System image file doesn't exist: %s", initImage);
625 exit(1);
626 }
627
628 } while (0);
629
630 if (rwImage != NULL) {
631 /* Use the read/write image file directly */
632 hw->disk_systemPartition_path = rwImage;
633 hw->disk_systemPartition_initPath = NULL;
634 D("Using direct system image: %s", rwImage);
635 } else if (initImage != NULL) {
636 hw->disk_systemPartition_path = NULL;
637 hw->disk_systemPartition_initPath = initImage;
638 D("Using initial system image: %s", initImage);
639 }
640
641 /* Check the size of the system partition image.
642 * If we have an AVD, it must be smaller than
643 * the disk.systemPartition.size hardware property.
644 *
645 * Otherwise, we need to adjust the systemPartitionSize
646 * automatically, and print a warning.
647 *
648 */
649 const char* systemImage = hw->disk_systemPartition_path;
650 uint64_t systemBytes;
651
652 if (systemImage == NULL)
653 systemImage = hw->disk_systemPartition_initPath;
654
655 if (path_get_size(systemImage, &systemBytes) < 0) {
656 derror("Missing system image: %s", systemImage);
657 exit(1);
658 }
659
660 hw->disk_systemPartition_size =
661 _adjustPartitionSize("system", systemBytes, defaultPartitionSize,
662 avdInfo_inAndroidBuild(avd));
663 }
664
665 /** DATA PARTITION **/
666
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100667 if (opts->datadir) {
668 if (!path_exists(opts->datadir)) {
669 derror("Invalid -datadir directory: %s", opts->datadir);
670 }
671 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800672
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100673 {
674 char* dataImage = NULL;
675 char* initImage = NULL;
676
677 do {
678 if (!opts->data) {
679 dataImage = avdInfo_getDataImagePath(avd);
680 if (dataImage != NULL) {
681 D("autoconfig: -data %s", dataImage);
682 break;
683 }
684 dataImage = avdInfo_getDefaultDataImagePath(avd);
685 if (dataImage == NULL) {
686 derror("No data image path for this configuration!");
687 exit (1);
688 }
689 opts->wipe_data = 1;
690 break;
691 }
692
693 if (opts->datadir) {
694 dataImage = _getFullFilePath(opts->datadir, opts->data);
695 } else {
696 dataImage = ASTRDUP(opts->data);
697 }
698 } while (0);
699
700 if (opts->initdata != NULL) {
701 initImage = ASTRDUP(opts->initdata);
702 if (!path_exists(initImage)) {
703 derror("Invalid initial data image path: %s", initImage);
704 exit(1);
705 }
706 } else {
707 initImage = avdInfo_getDataInitImagePath(avd);
708 D("autoconfig: -initdata %s", initImage);
709 }
710
711 hw->disk_dataPartition_path = dataImage;
712 if (opts->wipe_data) {
713 hw->disk_dataPartition_initPath = initImage;
714 } else {
715 hw->disk_dataPartition_initPath = NULL;
716 }
717
Maciek Molerusf7584112011-06-15 22:26:35 +0200718 uint64_t defaultBytes =
719 hw->disk_dataPartition_size == 0 ?
720 defaultPartitionSize :
721 convertMBToBytes(hw->disk_dataPartition_size);
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100722 uint64_t dataBytes;
723 const char* dataPath = hw->disk_dataPartition_initPath;
724
725 if (dataPath == NULL)
726 dataPath = hw->disk_dataPartition_path;
727
728 path_get_size(dataPath, &dataBytes);
729
730 hw->disk_dataPartition_size =
731 _adjustPartitionSize("data", dataBytes, defaultBytes,
732 avdInfo_inAndroidBuild(avd));
733 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800734
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100735 /** CACHE PARTITION **/
736
737 if (opts->no_cache) {
738 /* No cache partition at all */
739 hw->disk_cachePartition = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800740 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100741 else if (!hw->disk_cachePartition) {
742 if (opts->cache) {
743 dwarning( "Emulated hardware doesn't support a cache partition. -cache option ignored!" );
744 opts->cache = NULL;
745 }
746 }
747 else
748 {
749 if (!opts->cache) {
750 /* Find the current cache partition file */
751 opts->cache = avdInfo_getCachePath(avd);
752 if (opts->cache == NULL) {
753 /* The file does not exists, we will force its creation
754 * if we are not in the Android build system. Otherwise,
755 * a temporary file will be used.
756 */
757 if (!avdInfo_inAndroidBuild(avd)) {
758 opts->cache = avdInfo_getDefaultCachePath(avd);
759 }
760 }
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100761 if (opts->cache) {
762 D("autoconfig: -cache %s", opts->cache);
763 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100764 }
765
766 if (opts->cache) {
767 hw->disk_cachePartition_path = ASTRDUP(opts->cache);
768 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800769 }
770
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100771 /** SD CARD PARTITION */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800772
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100773 if (!hw->hw_sdCard) {
774 /* No SD Card emulation, so -sdcard will be ignored */
775 if (opts->sdcard) {
776 dwarning( "Emulated hardware doesn't support SD Cards. -sdcard option ignored." );
777 opts->sdcard = NULL;
778 }
779 } else {
780 /* Auto-configure -sdcard if it is not available */
781 if (!opts->sdcard) {
782 do {
783 /* If -datadir <path> is used, look for a sdcard.img file here */
784 if (opts->datadir) {
785 bufprint(tmp, tmpend, "%s/%s", opts->datadir, "system.img");
786 if (path_exists(tmp)) {
787 opts->sdcard = strdup(tmp);
788 break;
789 }
790 }
791
792 /* Otherwise, look at the AVD's content */
793 opts->sdcard = avdInfo_getSdCardPath(avd);
794 if (opts->sdcard != NULL) {
795 break;
796 }
797
798 /* Nothing */
799 } while (0);
800
801 if (opts->sdcard) {
802 D("autoconfig: -sdcard %s", opts->sdcard);
803 }
804 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800805 }
806
807 if(opts->sdcard) {
808 uint64_t size;
809 if (path_get_size(opts->sdcard, &size) == 0) {
810 /* see if we have an sdcard image. get its size if it exists */
David 'Digit' Turner8b657e52009-12-01 13:38:21 -0800811 /* due to what looks like limitations of the MMC protocol, one has
812 * to use an SD Card image that is equal or larger than 9 MB
813 */
814 if (size < 9*1024*1024ULL) {
815 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 -0800816 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100817 hw->hw_sdCard_path = ASTRDUP(opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800818 }
819 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100820 dwarning("no SD Card image at '%s'", opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800821 }
822 }
823
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100824
825 /** SNAPSHOT STORAGE HANDLING */
826
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100827 /* Determine snapstorage path. -no-snapstorage disables all snapshotting
828 * support. This means you can't resume a snapshot at load, save it at
829 * exit, or even load/save them dynamically at runtime with the console.
830 */
831 if (opts->no_snapstorage) {
832
833 if (opts->snapshot) {
834 dwarning("ignoring -snapshot option due to the use of -no-snapstorage");
835 opts->snapshot = NULL;
836 }
837
838 if (opts->snapstorage) {
839 dwarning("ignoring -snapstorage option due to the use of -no-snapstorage");
840 opts->snapstorage = NULL;
841 }
842 }
843 else
844 {
845 if (!opts->snapstorage) {
846 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
847 if (opts->snapstorage != NULL) {
848 D("autoconfig: -snapstorage %s", opts->snapstorage);
Ot ten Thije353b3b12010-10-05 17:53:30 +0100849 }
850 }
851
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100852 if (opts->snapstorage && !path_exists(opts->snapstorage)) {
853 D("no image at '%s', state snapshots disabled", opts->snapstorage);
854 opts->snapstorage = NULL;
Ot ten Thije353b3b12010-10-05 17:53:30 +0100855 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100856 }
857
858 /* If we have a valid snapshot storage path */
859
860 if (opts->snapstorage) {
861
862 hw->disk_snapStorage_path = ASTRDUP(opts->snapstorage);
863
864 /* -no-snapshot is equivalent to using both -no-snapshot-load
865 * and -no-snapshot-save. You can still load/save snapshots dynamically
866 * from the console though.
867 */
868 if (opts->no_snapshot) {
869
870 opts->no_snapshot_load = 1;
871 opts->no_snapshot_save = 1;
872
873 if (opts->snapshot) {
874 dwarning("ignoring -snapshot option due to the use of -no-snapshot.");
875 }
876 }
877
878 if (!opts->no_snapshot_load || !opts->no_snapshot_save) {
879 if (opts->snapshot == NULL) {
880 opts->snapshot = "default-boot";
881 D("autoconfig: -snapshot %s", opts->snapshot);
882 }
883 }
884
885 /* We still use QEMU command-line options for the following since
886 * they can change from one invokation to the next and don't really
887 * correspond to the hardware configuration itself.
888 */
889 if (!opts->no_snapshot_load) {
890 args[n++] = "-loadvm";
891 args[n++] = ASTRDUP(opts->snapshot);
892 }
893
894 if (!opts->no_snapshot_save) {
895 args[n++] = "-savevm-on-exit";
896 args[n++] = ASTRDUP(opts->snapshot);
897 }
898
Tim Baverstock622b8f42010-12-07 11:36:59 +0000899 if (opts->no_snapshot_update_time) {
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100900 args[n++] = "-snapshot-no-time-update";
Tim Baverstock622b8f42010-12-07 11:36:59 +0000901 }
Ot ten Thijeae835ac2010-10-18 13:37:37 +0100902 }
Ot ten Thije353b3b12010-10-05 17:53:30 +0100903
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800904 if (!opts->logcat || opts->logcat[0] == 0) {
905 opts->logcat = getenv("ANDROID_LOG_TAGS");
906 if (opts->logcat && opts->logcat[0] == 0)
907 opts->logcat = NULL;
908 }
909
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800910 /* we always send the kernel messages from ttyS0 to android_kmsg */
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100911 if (opts->show_kernel) {
912 args[n++] = "-show-kernel";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800913 }
914
915 /* XXXX: TODO: implement -shell and -logcat through qemud instead */
916 if (!opts->shell_serial) {
917#ifdef _WIN32
918 opts->shell_serial = "con:";
919#else
920 opts->shell_serial = "stdio";
921#endif
922 }
923 else
924 opts->shell = 1;
925
926 if (opts->shell || opts->logcat) {
927 args[n++] = "-serial";
928 args[n++] = opts->shell_serial;
929 shell_serial = serial++;
930 }
931
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100932 if (opts->radio) {
933 args[n++] = "-radio";
934 args[n++] = opts->radio;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800935 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800936
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100937 if (opts->gps) {
938 args[n++] = "-gps";
939 args[n++] = opts->gps;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800940 }
941
942 if (opts->memory) {
943 char* end;
944 long ramSize = strtol(opts->memory, &end, 0);
945 if (ramSize < 0 || *end != 0) {
946 derror( "-memory must be followed by a positive integer" );
947 exit(1);
948 }
949 if (ramSize < 32 || ramSize > 4096) {
950 derror( "physical memory size must be between 32 and 4096 MB" );
951 exit(1);
952 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100953 hw->hw_ramSize = ramSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800954 }
955 if (!opts->memory) {
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100956 int ramSize = hw->hw_ramSize;
957 if (ramSize <= 0) {
958 /* Compute the default RAM size based on the size of screen.
959 * This is only used when the skin doesn't provide the ram
960 * size through its hardware.ini (i.e. legacy ones) or when
961 * in the full Android build system.
962 */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100963 int64_t pixels = hw->hw_lcd_width * hw->hw_lcd_height;
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100964 /* The following thresholds are a bit liberal, but we
965 * essentially want to ensure the following mappings:
966 *
967 * 320x480 -> 96
968 * 800x600 -> 128
969 * 1024x768 -> 256
970 *
971 * These are just simple heuristics, they could change in
972 * the future.
973 */
974 if (pixels <= 250000)
975 ramSize = 96;
976 else if (pixels <= 500000)
977 ramSize = 128;
978 else
979 ramSize = 256;
980 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100981 hw->hw_ramSize = ramSize;
982 }
983
984 D("Physical RAM size: %dMB\n", hw->hw_ramSize);
985
986 if (hw->vm_heapSize == 0) {
987 /* Compute the default heap size based on the RAM size.
988 * Essentially, we want to ensure the following liberal mappings:
989 *
990 * 96MB RAM -> 16MB heap
991 * 128MB RAM -> 24MB heap
992 * 256MB RAM -> 48MB heap
993 */
994 int ramSize = hw->hw_ramSize;
995 int heapSize;
996
997 if (ramSize < 100)
998 heapSize = 16;
999 else if (ramSize < 192)
1000 heapSize = 24;
1001 else
1002 heapSize = 48;
1003
1004 hw->vm_heapSize = heapSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001005 }
1006
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001007 if (opts->trace) {
1008 args[n++] = "-trace";
1009 args[n++] = opts->trace;
1010 args[n++] = "-tracing";
1011 args[n++] = "off";
1012 }
1013
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -07001014 /* Pass boot properties to the core. */
1015 if (opts->prop != NULL) {
1016 ParamList* pl = opts->prop;
1017 for ( ; pl != NULL; pl = pl->next ) {
1018 args[n++] = "-boot-property";
1019 args[n++] = pl->param;
1020 }
1021 }
1022
David 'Digit' Turner318e4f22009-05-25 18:01:03 +02001023 /* Setup the kernel init options
1024 */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001025 {
1026 static char params[1024];
1027 char *p = params, *end = p + sizeof(params);
1028
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +01001029 /* Don't worry about having a leading space here, this is handled
1030 * by the core later. */
1031
Jun Nakajima334ab472011-02-02 23:49:59 -08001032#ifdef TARGET_I386
1033 p = bufprint(p, end, " androidboot.hardware=goldfish");
Jun Nakajimabac9add2011-02-08 22:10:52 -08001034 p = bufprint(p, end, " clocksource=pit");
Jun Nakajima334ab472011-02-02 23:49:59 -08001035#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001036
1037 if (opts->shell || opts->logcat) {
1038 p = bufprint(p, end, " androidboot.console=ttyS%d", shell_serial );
1039 }
1040
1041 if (opts->trace) {
1042 p = bufprint(p, end, " android.tracing=1");
1043 }
1044
1045 if (!opts->no_jni) {
1046 p = bufprint(p, end, " android.checkjni=1");
1047 }
1048
1049 if (opts->no_boot_anim) {
1050 p = bufprint( p, end, " android.bootanim=0" );
1051 }
1052
1053 if (opts->logcat) {
1054 char* q = bufprint(p, end, " androidboot.logcat=%s", opts->logcat);
1055
1056 if (q < end) {
1057 /* replace any space by a comma ! */
1058 {
1059 int nn;
1060 for (nn = 1; p[nn] != 0; nn++)
1061 if (p[nn] == ' ' || p[nn] == '\t')
1062 p[nn] = ',';
1063 p += nn;
1064 }
1065 }
1066 p = q;
1067 }
1068
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001069 if (opts->bootchart) {
1070 p = bufprint(p, end, " androidboot.bootchart=%s", opts->bootchart);
1071 }
1072
1073 if (p >= end) {
1074 fprintf(stderr, "### ERROR: kernel parameters too long\n");
1075 exit(1);
1076 }
1077
David 'Digit' Turner0b019492011-03-01 14:02:42 +01001078 hw->kernel_parameters = strdup(params);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001079 }
1080
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07001081 if (opts->ports) {
1082 args[n++] = "-android-ports";
1083 args[n++] = opts->ports;
1084 }
1085
1086 if (opts->port) {
1087 args[n++] = "-android-port";
1088 args[n++] = opts->port;
1089 }
1090
1091 if (opts->report_console) {
1092 args[n++] = "-android-report-console";
1093 args[n++] = opts->report_console;
1094 }
1095
1096 if (opts->http_proxy) {
1097 args[n++] = "-http-proxy";
1098 args[n++] = opts->http_proxy;
1099 }
1100
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001101 if (!opts->charmap) {
1102 /* Try to find a valid charmap name */
1103 char* charmap = avdInfo_getCharmapFile(avd, hw->hw_keyboard_charmap);
1104 if (charmap != NULL) {
1105 D("autoconfig: -charmap %s", charmap);
1106 opts->charmap = charmap;
1107 }
1108 }
1109
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001110 if (opts->charmap) {
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001111 char charmap_name[AKEYCHARMAP_NAME_SIZE];
1112
1113 if (!path_exists(opts->charmap)) {
1114 derror("Charmap file does not exist: %s", opts->charmap);
1115 exit(1);
1116 }
1117 /* We need to store the charmap name in the hardware configuration.
1118 * However, the charmap file itself is only used by the UI component
1119 * and doesn't need to be set to the emulation engine.
1120 */
1121 kcm_extract_charmap_name(opts->charmap, charmap_name,
1122 sizeof(charmap_name));
1123 AFREE(hw->hw_keyboard_charmap);
1124 hw->hw_keyboard_charmap = ASTRDUP(charmap_name);
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001125 }
1126
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07001127 if (opts->memcheck) {
1128 args[n++] = "-android-memcheck";
1129 args[n++] = opts->memcheck;
1130 }
1131
David Turner9da935d2011-09-12 21:27:56 +02001132 if (opts->gpu) {
1133 const char* gpu = opts->gpu;
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001134 if (!strcmp(gpu,"on") || !strcmp(gpu,"enable")) {
David Turner9da935d2011-09-12 21:27:56 +02001135 hw->hw_gpu_enabled = 1;
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001136 } else if (!strcmp(gpu,"off") || !strcmp(gpu,"disable")) {
David Turner9da935d2011-09-12 21:27:56 +02001137 hw->hw_gpu_enabled = 0;
1138 } else if (!strcmp(gpu,"auto")) {
1139 /* Nothing to do */
1140 } else {
1141 derror("Invalid value for -gpu <mode> parameter: %s\n", gpu);
1142 derror("Valid values are: on, off or auto\n");
1143 exit(1);
1144 }
1145 }
1146
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001147 if (opts->fake_camera) {
1148 if (!strcmp(opts->fake_camera, "back") ||
1149 !strcmp(opts->fake_camera, "front") ||
1150 !strcmp(opts->fake_camera, "off")) {
1151 hw->hw_fakeCamera = ASTRDUP(opts->fake_camera);
1152 } else {
1153 derror("Invalid value for -fake-camera <mode> parameter: %s\n",
1154 opts->fake_camera);
1155 derror("Valid values are: back, front, or off\n");
1156 exit(1);
1157 }
1158 }
1159
Vladimir Chtchetkineb8dcaff2011-09-17 11:15:47 -07001160 if (opts->webcam != NULL) {
1161 ParamList* pl = opts->webcam;
1162 int webcam_num = 0;
1163 for ( ; pl != NULL; pl = pl->next ) {
1164 char webcam_name[64];
1165 char webcam_dir[16];
1166 if (!strcmp(pl->param, "off")) {
1167 /* If 'off' is passed, there must be no other -webcam options. */
1168 if (webcam_num || pl->next != NULL) {
1169 derror("'-webcam off' cannot be combined with other -webcam otions\n");
1170 exit(1);
1171 }
1172 break;
1173 }
1174 if (!strcmp(pl->param, "list")) {
1175 /* If 'list' is passed, there must be no other -webcam options. */
1176 if (webcam_num || pl->next != NULL) {
1177 derror("'-webcam list' cannot be combined with other -webcam otions\n");
1178 exit(1);
1179 }
1180 args[n++] = "-list-webcam";
1181 break;
1182 }
1183 /* Extract name, and direction */
1184 _parseWebcamOption(pl->param, webcam_name, sizeof(webcam_name),
1185 webcam_dir, sizeof(webcam_dir));
1186 /* Save them to appropriate field in hw.ini */
1187 switch (webcam_num) {
1188 case 0:
1189 hw->hw_webcam_0_name = ASTRDUP(webcam_name);
1190 hw->hw_webcam_0_direction = ASTRDUP(webcam_dir);
1191 break;
1192 case 1:
1193 hw->hw_webcam_1_name = ASTRDUP(webcam_name);
1194 hw->hw_webcam_1_direction = ASTRDUP(webcam_dir);
1195 break;
1196 case 2:
1197 hw->hw_webcam_2_name = ASTRDUP(webcam_name);
1198 hw->hw_webcam_2_direction = ASTRDUP(webcam_dir);
1199 break;
1200 case 3:
1201 hw->hw_webcam_3_name = ASTRDUP(webcam_name);
1202 hw->hw_webcam_3_direction = ASTRDUP(webcam_dir);
1203 break;
1204 case 4:
1205 hw->hw_webcam_4_name = ASTRDUP(webcam_name);
1206 hw->hw_webcam_4_direction = ASTRDUP(webcam_dir);
1207 break;
1208 case 5:
1209 hw->hw_webcam_5_name = ASTRDUP(webcam_name);
1210 hw->hw_webcam_5_direction = ASTRDUP(webcam_dir);
1211 break;
1212 default:
1213 derror("Too many -webcam options. Maximum number of -webcam options is 6\n");
1214 exit(1);
1215 }
1216 webcam_num++;
1217 }
1218 hw->hw_webcam_count = webcam_num;
1219 }
1220
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01001221 /* physical memory is now in hw->hw_ramSize */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001222
David 'Digit' Turner53eb66d2011-03-01 14:58:23 +01001223 hw->avd_name = ASTRDUP(avdInfo_getName(avd));
David 'Digit' Turner6b8555c2011-02-17 04:28:19 +01001224
Dries Harnie40beab42010-05-15 17:04:47 +02001225 /* Set up the interfaces for inter-emulator networking */
1226 if (opts->shared_net_id) {
1227 unsigned int shared_net_id = atoi(opts->shared_net_id);
1228 char nic[37];
Dries Harnie40beab42010-05-15 17:04:47 +02001229
1230 args[n++] = "-net";
1231 args[n++] = "nic,vlan=0";
1232 args[n++] = "-net";
1233 args[n++] = "user,vlan=0";
Dries Harnie111d6f82010-06-09 21:42:18 +02001234
1235 args[n++] = "-net";
1236 snprintf(nic, sizeof nic, "nic,vlan=1,macaddr=52:54:00:12:34:%02x", shared_net_id);
1237 args[n++] = strdup(nic);
1238 args[n++] = "-net";
1239 args[n++] = "socket,vlan=1,mcast=230.0.0.10:1234";
Dries Harnie40beab42010-05-15 17:04:47 +02001240 }
1241
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001242 while(argc-- > 0) {
1243 args[n++] = *argv++;
1244 }
1245 args[n] = 0;
1246
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +02001247 /* If the target ABI is armeabi-v7a, we can auto-detect the cpu model
1248 * as a cortex-a8, instead of the default (arm926) which only emulates
1249 * an ARMv5TE CPU.
1250 */
1251 if (!forceArmv7 && hw->hw_cpu_model[0] == '\0')
1252 {
1253 char* abi = avdInfo_getTargetAbi(avd);
1254 if (abi != NULL) {
1255 if (!strcmp(abi, "armeabi-v7a")) {
1256 forceArmv7 = 1;
1257 }
1258 AFREE(abi);
1259 }
1260 }
1261
1262 if (forceArmv7 != 0) {
1263 AFREE(hw->hw_cpu_model);
1264 hw->hw_cpu_model = ASTRDUP("cortex-a8");
1265 D("Auto-config: -qemu -cpu %s", hw->hw_cpu_model);
1266 }
1267
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001268 /* Generate a hardware-qemu.ini for this AVD. The real hardware
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001269 * configuration is ususally stored in several files, e.g. the AVD's
1270 * config.ini plus the skin-specific hardware.ini.
1271 *
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001272 * The new file will group all definitions and will be used to
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001273 * launch the core with the -android-hw <file> option.
1274 */
1275 {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001276 const char* coreHwIniPath = avdInfo_getCoreHwIniPath(avd);
1277 IniFile* hwIni = iniFile_newFromMemory("", NULL);
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001278 androidHwConfig_write(hw, hwIni);
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001279
1280 if (filelock_create(coreHwIniPath) == NULL) {
1281 /* The AVD is already in use, we still support this as an
1282 * experimental feature. Use a temporary hardware-qemu.ini
1283 * file though to avoid overwriting the existing one. */
1284 TempFile* tempIni = tempfile_create();
1285 coreHwIniPath = tempfile_path(tempIni);
1286 }
1287
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001288 if (iniFile_saveToFile(hwIni, coreHwIniPath) < 0) {
1289 derror("Could not write hardware.ini to %s: %s", coreHwIniPath, strerror(errno));
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001290 exit(2);
1291 }
1292 args[n++] = "-android-hw";
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001293 args[n++] = strdup(coreHwIniPath);
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +02001294
1295 /* In verbose mode, dump the file's content */
1296 if (VERBOSE_CHECK(init)) {
1297 FILE* file = fopen(coreHwIniPath, "rt");
1298 if (file == NULL) {
1299 derror("Could not open hardware configuration file: %s\n",
1300 coreHwIniPath);
1301 } else {
1302 LineInput* input = lineInput_newFromStdFile(file);
1303 const char* line;
1304 printf("Content of hardware configuration file:\n");
1305 while ((line = lineInput_getLine(input)) != NULL) {
1306 printf(" %s\n", line);
1307 }
1308 printf(".\n");
1309 lineInput_free(input);
1310 fclose(file);
1311 }
1312 }
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001313 }
1314
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001315 if(VERBOSE_CHECK(init)) {
1316 int i;
David 'Digit' Turner33361762011-01-19 22:11:03 +01001317 printf("QEMU options list:\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001318 for(i = 0; i < n; i++) {
David 'Digit' Turner33361762011-01-19 22:11:03 +01001319 printf("emulator: argv[%02d] = \"%s\"\n", i, args[i]);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001320 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001321 /* Dump final command-line option to make debugging the core easier */
1322 printf("Concatenated QEMU options:\n");
1323 for (i = 0; i < n; i++) {
David 'Digit' Turner26722dd2011-02-24 16:40:20 +01001324 /* To make it easier to copy-paste the output to a command-line,
1325 * quote anything that contains spaces.
1326 */
1327 if (strchr(args[i], ' ') != NULL) {
1328 printf(" '%s'", args[i]);
1329 } else {
1330 printf(" %s", args[i]);
1331 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001332 }
1333 printf("\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001334 }
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +01001335
1336 /* Setup SDL UI just before calling the code */
1337 init_sdl_ui(skinConfig, skinPath, opts);
1338
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +01001339 if (attach_ui_to_core(opts) < 0) {
1340 derror("Can't attach to core!");
1341 exit(1);
1342 }
1343
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001344 return qemu_main(n, args);
1345}