blob: ffa42aa3cebfb9b5012188eed7fff89ce51c44cf [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
David 'Digit' Turnercc330d42013-12-14 23:26:42 +010021#include "android/sockets.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080022
23#include "android/android.h"
24#include "qemu-common.h"
David 'Digit' Turner34c48ff2013-12-15 00:25:03 +010025#include "sysemu/sysemu.h"
David 'Digit' Turner1c31e3e2013-12-14 20:07:17 +010026#include "ui/console.h"
David 'Digit' Turnerd4e803c2013-12-14 23:45:50 +010027#include "android/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"
David 'Digit' Turnerd413fa52013-12-14 23:35:20 +010058#include "android/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 {
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700148 snprintf(temp, sizeof temp, "(%" PRIu64 " bytes > %" PRIu64 " bytes)", imageBytes, defaultBytes);
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100149 }
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;
Vladimir Chtchetkine88078b82012-04-19 12:24:38 -0700179 uint64_t defaultPartitionSize = convertMBToBytes(200);
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);
Xavier Ducrohet689d1142012-04-19 12:54:08 -0700322
323 /* update the avd hw config from this new skin */
324 avdInfo_getSkinHardwareIni(avd, opts->skin, opts->skindir);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800325 }
326
Siva Velusamyd8999182012-10-08 18:02:30 -0700327 if (opts->dynamic_skin == 0) {
328 opts->dynamic_skin = avdInfo_shouldUseDynamicSkin(avd);
329 }
330
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800331 /* Read hardware configuration */
332 hw = android_hw;
David 'Digit' Turnerb64325d2011-03-22 16:07:01 +0100333 if (avdInfo_initHwConfig(avd, hw) < 0) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800334 derror("could not read hardware configuration ?");
335 exit(1);
336 }
337
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800338 if (opts->keyset) {
339 parse_keyset(opts->keyset, opts);
340 if (!android_keyset) {
341 fprintf(stderr,
342 "emulator: WARNING: could not find keyset file named '%s',"
343 " using defaults instead\n",
344 opts->keyset);
345 }
346 }
347 if (!android_keyset) {
348 parse_keyset("default", opts);
349 if (!android_keyset) {
350 android_keyset = skin_keyset_new_from_text( skin_keyset_get_default() );
351 if (!android_keyset) {
352 fprintf(stderr, "PANIC: default keyset file is corrupted !!\n" );
353 fprintf(stderr, "PANIC: please update the code in android/skin/keyset.c\n" );
354 exit(1);
355 }
356 if (!opts->keyset)
357 write_default_keyset();
358 }
359 }
360
Dries Harnie40beab42010-05-15 17:04:47 +0200361 if (opts->shared_net_id) {
362 char* end;
363 long shared_net_id = strtol(opts->shared_net_id, &end, 0);
364 if (end == NULL || *end || shared_net_id < 1 || shared_net_id > 255) {
365 fprintf(stderr, "option -shared-net-id must be an integer between 1 and 255\n");
366 exit(1);
367 }
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700368 snprintf(boot_prop_ip, sizeof(boot_prop_ip),
369 "net.shared_net_ip=10.1.2.%ld", shared_net_id);
Dries Harnie40beab42010-05-15 17:04:47 +0200370 }
371
372
David 'Digit' Turner755811e2011-02-07 13:38:25 +0100373 user_config_init();
David 'Digit' Turner2507cab2011-02-10 16:29:17 +0100374 parse_skin_files(opts->skindir, opts->skin, opts, hw,
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100375 &skinConfig, &skinPath);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800376
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100377 if (!opts->netspeed && skin_network_speed) {
378 D("skin network speed: '%s'", skin_network_speed);
379 if (strcmp(skin_network_speed, NETWORK_SPEED_DEFAULT) != 0) {
380 opts->netspeed = (char*)skin_network_speed;
381 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800382 }
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100383 if (!opts->netdelay && skin_network_delay) {
384 D("skin network delay: '%s'", skin_network_delay);
385 if (strcmp(skin_network_delay, NETWORK_DELAY_DEFAULT) != 0) {
386 opts->netdelay = (char*)skin_network_delay;
387 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800388 }
389
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800390 if (opts->trace) {
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200391 char* tracePath = avdInfo_getTracePath(avd, opts->trace);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800392 int ret;
393
394 if (tracePath == NULL) {
395 derror( "bad -trace parameter" );
396 exit(1);
397 }
398 ret = path_mkdir_if_needed( tracePath, 0755 );
399 if (ret < 0) {
400 fprintf(stderr, "could not create directory '%s'\n", tmp);
401 exit(2);
402 }
403 opts->trace = tracePath;
404 }
405
Vladimir Chtchetkine33f89d02011-09-28 09:19:09 -0700406 /* Update CPU architecture for HW configs created from build dir. */
407 if (inAndroidBuild) {
408#if defined(TARGET_ARM)
409 free(android_hw->hw_cpu_arch);
410 android_hw->hw_cpu_arch = ASTRDUP("arm");
411#elif defined(TARGET_I386)
412 free(android_hw->hw_cpu_arch);
413 android_hw->hw_cpu_arch = ASTRDUP("x86");
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700414#elif defined(TARGET_MIPS)
415 free(android_hw->hw_cpu_arch);
416 android_hw->hw_cpu_arch = ASTRDUP("mips");
Vladimir Chtchetkine33f89d02011-09-28 09:19:09 -0700417#endif
418 }
419
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800420 n = 1;
421 /* generate arguments for the underlying qemu main() */
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700422 {
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100423 char* kernelFile = opts->kernel;
424 int kernelFileLen;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700425
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100426 if (kernelFile == NULL) {
427 kernelFile = avdInfo_getKernelPath(avd);
428 if (kernelFile == NULL) {
429 derror( "This AVD's configuration is missing a kernel file!!" );
430 exit(2);
431 }
432 D("autoconfig: -kernel %s", kernelFile);
433 }
434 if (!path_exists(kernelFile)) {
435 derror( "Invalid or missing kernel image file: %s", kernelFile );
436 exit(2);
437 }
438
439 hw->kernel_path = kernelFile;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700440
441 /* If the kernel image name ends in "-armv7", then change the cpu
442 * type automatically. This is a poor man's approach to configuration
443 * management, but should allow us to get past building ARMv7
444 * system images with dex preopt pass without introducing too many
445 * changes to the emulator sources.
446 *
447 * XXX:
448 * A 'proper' change would require adding some sort of hardware-property
449 * to each AVD config file, then automatically determine its value for
450 * full Android builds (depending on some environment variable), plus
451 * some build system changes. I prefer not to do that for now for reasons
452 * of simplicity.
453 */
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100454 kernelFileLen = strlen(kernelFile);
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700455 if (kernelFileLen > 6 && !memcmp(kernelFile + kernelFileLen - 6, "-armv7", 6)) {
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +0200456 forceArmv7 = 1;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700457 }
458 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800459
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700460 if (boot_prop_ip[0]) {
461 args[n++] = "-boot-property";
462 args[n++] = boot_prop_ip;
463 }
464
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -0700465 if (opts->tcpdump) {
466 args[n++] = "-tcpdump";
467 args[n++] = opts->tcpdump;
468 }
469
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700470#ifdef CONFIG_NAND_LIMITS
471 if (opts->nand_limits) {
472 args[n++] = "-nand-limits";
473 args[n++] = opts->nand_limits;
474 }
475#endif
476
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100477 if (opts->timezone) {
478 args[n++] = "-timezone";
479 args[n++] = opts->timezone;
480 }
481
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700482 if (opts->netspeed) {
483 args[n++] = "-netspeed";
484 args[n++] = opts->netspeed;
485 }
486 if (opts->netdelay) {
487 args[n++] = "-netdelay";
488 args[n++] = opts->netdelay;
489 }
490 if (opts->netfast) {
491 args[n++] = "-netfast";
492 }
493
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700494 if (opts->audio) {
495 args[n++] = "-audio";
496 args[n++] = opts->audio;
497 }
498
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700499 if (opts->cpu_delay) {
500 args[n++] = "-cpu-delay";
501 args[n++] = opts->cpu_delay;
502 }
503
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -0700504 if (opts->dns_server) {
505 args[n++] = "-dns-server";
506 args[n++] = opts->dns_server;
507 }
508
David 'Digit' Turner9ff69722011-09-13 12:32:52 +0200509 /* opts->ramdisk is never NULL (see createAVD) here */
510 if (opts->ramdisk) {
511 AFREE(hw->disk_ramdisk_path);
512 hw->disk_ramdisk_path = ASTRDUP(opts->ramdisk);
513 }
514 else if (!hw->disk_ramdisk_path[0]) {
515 hw->disk_ramdisk_path = avdInfo_getRamdiskPath(avd);
516 D("autoconfig: -ramdisk %s", hw->disk_ramdisk_path);
517 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800518
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100519 /* -partition-size is used to specify the max size of both the system
520 * and data partition sizes.
521 */
522 if (opts->partition_size) {
523 char* end;
524 long sizeMB = strtol(opts->partition_size, &end, 0);
525 long minSizeMB = 10;
526 long maxSizeMB = LONG_MAX / ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800527
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100528 if (sizeMB < 0 || *end != 0) {
529 derror( "-partition-size must be followed by a positive integer" );
530 exit(1);
531 }
532 if (sizeMB < minSizeMB || sizeMB > maxSizeMB) {
533 derror( "partition-size (%d) must be between %dMB and %dMB",
534 sizeMB, minSizeMB, maxSizeMB );
535 exit(1);
536 }
537 defaultPartitionSize = (uint64_t) sizeMB * ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800538 }
539
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100540
541 /** SYSTEM PARTITION **/
542
543 if (opts->sysdir == NULL) {
544 if (avdInfo_inAndroidBuild(avd)) {
545 opts->sysdir = ASTRDUP(avdInfo_getContentPath(avd));
546 D("autoconfig: -sysdir %s", opts->sysdir);
547 }
548 }
549
550 if (opts->sysdir != NULL) {
551 if (!path_exists(opts->sysdir)) {
552 derror("Directory does not exist: %s", opts->sysdir);
553 exit(1);
554 }
555 }
556
557 {
558 char* rwImage = NULL;
559 char* initImage = NULL;
560
561 do {
562 if (opts->system == NULL) {
563 /* If -system is not used, try to find a runtime system image
564 * (i.e. system-qemu.img) in the content directory.
565 */
566 rwImage = avdInfo_getSystemImagePath(avd);
567 if (rwImage != NULL) {
568 break;
569 }
570 /* Otherwise, try to find the initial system image */
571 initImage = avdInfo_getSystemInitImagePath(avd);
572 if (initImage == NULL) {
573 derror("No initial system image for this configuration!");
574 exit(1);
575 }
576 break;
577 }
578
579 /* If -system <name> is used, use it to find the initial image */
David 'Digit' Turnerea283772011-07-07 04:40:27 +0200580 if (opts->sysdir != NULL && !path_exists(opts->system)) {
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100581 initImage = _getFullFilePath(opts->sysdir, opts->system);
582 } else {
583 initImage = ASTRDUP(opts->system);
584 }
585 if (!path_exists(initImage)) {
586 derror("System image file doesn't exist: %s", initImage);
587 exit(1);
588 }
589
590 } while (0);
591
592 if (rwImage != NULL) {
593 /* Use the read/write image file directly */
594 hw->disk_systemPartition_path = rwImage;
595 hw->disk_systemPartition_initPath = NULL;
596 D("Using direct system image: %s", rwImage);
597 } else if (initImage != NULL) {
598 hw->disk_systemPartition_path = NULL;
599 hw->disk_systemPartition_initPath = initImage;
600 D("Using initial system image: %s", initImage);
601 }
602
603 /* Check the size of the system partition image.
604 * If we have an AVD, it must be smaller than
605 * the disk.systemPartition.size hardware property.
606 *
607 * Otherwise, we need to adjust the systemPartitionSize
608 * automatically, and print a warning.
609 *
610 */
611 const char* systemImage = hw->disk_systemPartition_path;
612 uint64_t systemBytes;
613
614 if (systemImage == NULL)
615 systemImage = hw->disk_systemPartition_initPath;
616
617 if (path_get_size(systemImage, &systemBytes) < 0) {
618 derror("Missing system image: %s", systemImage);
619 exit(1);
620 }
621
622 hw->disk_systemPartition_size =
623 _adjustPartitionSize("system", systemBytes, defaultPartitionSize,
624 avdInfo_inAndroidBuild(avd));
625 }
626
627 /** DATA PARTITION **/
628
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100629 if (opts->datadir) {
630 if (!path_exists(opts->datadir)) {
631 derror("Invalid -datadir directory: %s", opts->datadir);
632 }
633 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800634
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100635 {
636 char* dataImage = NULL;
637 char* initImage = NULL;
638
639 do {
640 if (!opts->data) {
641 dataImage = avdInfo_getDataImagePath(avd);
642 if (dataImage != NULL) {
643 D("autoconfig: -data %s", dataImage);
644 break;
645 }
646 dataImage = avdInfo_getDefaultDataImagePath(avd);
647 if (dataImage == NULL) {
648 derror("No data image path for this configuration!");
649 exit (1);
650 }
651 opts->wipe_data = 1;
652 break;
653 }
654
655 if (opts->datadir) {
656 dataImage = _getFullFilePath(opts->datadir, opts->data);
657 } else {
658 dataImage = ASTRDUP(opts->data);
659 }
660 } while (0);
661
662 if (opts->initdata != NULL) {
663 initImage = ASTRDUP(opts->initdata);
664 if (!path_exists(initImage)) {
665 derror("Invalid initial data image path: %s", initImage);
666 exit(1);
667 }
668 } else {
669 initImage = avdInfo_getDataInitImagePath(avd);
670 D("autoconfig: -initdata %s", initImage);
671 }
672
673 hw->disk_dataPartition_path = dataImage;
674 if (opts->wipe_data) {
675 hw->disk_dataPartition_initPath = initImage;
676 } else {
677 hw->disk_dataPartition_initPath = NULL;
678 }
679
Maciek Molerusf7584112011-06-15 22:26:35 +0200680 uint64_t defaultBytes =
681 hw->disk_dataPartition_size == 0 ?
682 defaultPartitionSize :
Vladimir Chtchetkined4f5a3a2012-03-08 14:20:20 -0800683 hw->disk_dataPartition_size;
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100684 uint64_t dataBytes;
685 const char* dataPath = hw->disk_dataPartition_initPath;
686
687 if (dataPath == NULL)
688 dataPath = hw->disk_dataPartition_path;
689
690 path_get_size(dataPath, &dataBytes);
691
692 hw->disk_dataPartition_size =
693 _adjustPartitionSize("data", dataBytes, defaultBytes,
694 avdInfo_inAndroidBuild(avd));
695 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800696
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100697 /** CACHE PARTITION **/
698
699 if (opts->no_cache) {
700 /* No cache partition at all */
701 hw->disk_cachePartition = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800702 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100703 else if (!hw->disk_cachePartition) {
704 if (opts->cache) {
705 dwarning( "Emulated hardware doesn't support a cache partition. -cache option ignored!" );
706 opts->cache = NULL;
707 }
708 }
709 else
710 {
711 if (!opts->cache) {
712 /* Find the current cache partition file */
713 opts->cache = avdInfo_getCachePath(avd);
714 if (opts->cache == NULL) {
715 /* The file does not exists, we will force its creation
716 * if we are not in the Android build system. Otherwise,
717 * a temporary file will be used.
718 */
719 if (!avdInfo_inAndroidBuild(avd)) {
720 opts->cache = avdInfo_getDefaultCachePath(avd);
721 }
722 }
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100723 if (opts->cache) {
724 D("autoconfig: -cache %s", opts->cache);
725 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100726 }
727
728 if (opts->cache) {
729 hw->disk_cachePartition_path = ASTRDUP(opts->cache);
730 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800731 }
732
Vladimir Chtchetkine6f50aa32012-04-26 08:20:18 -0700733 if (hw->disk_cachePartition_path && opts->cache_size) {
734 /* Set cache partition size per user options. */
735 char* end;
736 long sizeMB = strtol(opts->cache_size, &end, 0);
737
738 if (sizeMB < 0 || *end != 0) {
739 derror( "-cache-size must be followed by a positive integer" );
740 exit(1);
741 }
742 hw->disk_cachePartition_size = (uint64_t) sizeMB * ONE_MB;
743 }
744
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100745 /** SD CARD PARTITION */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800746
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100747 if (!hw->hw_sdCard) {
748 /* No SD Card emulation, so -sdcard will be ignored */
749 if (opts->sdcard) {
750 dwarning( "Emulated hardware doesn't support SD Cards. -sdcard option ignored." );
751 opts->sdcard = NULL;
752 }
753 } else {
754 /* Auto-configure -sdcard if it is not available */
755 if (!opts->sdcard) {
756 do {
757 /* If -datadir <path> is used, look for a sdcard.img file here */
758 if (opts->datadir) {
759 bufprint(tmp, tmpend, "%s/%s", opts->datadir, "system.img");
760 if (path_exists(tmp)) {
761 opts->sdcard = strdup(tmp);
762 break;
763 }
764 }
765
766 /* Otherwise, look at the AVD's content */
767 opts->sdcard = avdInfo_getSdCardPath(avd);
768 if (opts->sdcard != NULL) {
769 break;
770 }
771
772 /* Nothing */
773 } while (0);
774
775 if (opts->sdcard) {
776 D("autoconfig: -sdcard %s", opts->sdcard);
777 }
778 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800779 }
780
781 if(opts->sdcard) {
782 uint64_t size;
783 if (path_get_size(opts->sdcard, &size) == 0) {
784 /* see if we have an sdcard image. get its size if it exists */
David 'Digit' Turner8b657e52009-12-01 13:38:21 -0800785 /* due to what looks like limitations of the MMC protocol, one has
786 * to use an SD Card image that is equal or larger than 9 MB
787 */
788 if (size < 9*1024*1024ULL) {
789 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 -0800790 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100791 hw->hw_sdCard_path = ASTRDUP(opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800792 }
793 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100794 dwarning("no SD Card image at '%s'", opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800795 }
796 }
797
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100798
799 /** SNAPSHOT STORAGE HANDLING */
800
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100801 /* Determine snapstorage path. -no-snapstorage disables all snapshotting
802 * support. This means you can't resume a snapshot at load, save it at
803 * exit, or even load/save them dynamically at runtime with the console.
804 */
805 if (opts->no_snapstorage) {
806
807 if (opts->snapshot) {
808 dwarning("ignoring -snapshot option due to the use of -no-snapstorage");
809 opts->snapshot = NULL;
810 }
811
812 if (opts->snapstorage) {
813 dwarning("ignoring -snapstorage option due to the use of -no-snapstorage");
814 opts->snapstorage = NULL;
815 }
816 }
817 else
818 {
Vladimir Chtchetkine873c3cb2012-03-14 12:46:51 -0700819 if (!opts->snapstorage && avdInfo_getSnapshotPresent(avd)) {
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100820 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
821 if (opts->snapstorage != NULL) {
822 D("autoconfig: -snapstorage %s", opts->snapstorage);
Ot ten Thije353b3b12010-10-05 17:53:30 +0100823 }
824 }
825
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100826 if (opts->snapstorage && !path_exists(opts->snapstorage)) {
827 D("no image at '%s', state snapshots disabled", opts->snapstorage);
828 opts->snapstorage = NULL;
Ot ten Thije353b3b12010-10-05 17:53:30 +0100829 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100830 }
831
832 /* If we have a valid snapshot storage path */
833
834 if (opts->snapstorage) {
835
836 hw->disk_snapStorage_path = ASTRDUP(opts->snapstorage);
837
838 /* -no-snapshot is equivalent to using both -no-snapshot-load
839 * and -no-snapshot-save. You can still load/save snapshots dynamically
840 * from the console though.
841 */
842 if (opts->no_snapshot) {
843
844 opts->no_snapshot_load = 1;
845 opts->no_snapshot_save = 1;
846
847 if (opts->snapshot) {
848 dwarning("ignoring -snapshot option due to the use of -no-snapshot.");
849 }
850 }
851
852 if (!opts->no_snapshot_load || !opts->no_snapshot_save) {
853 if (opts->snapshot == NULL) {
854 opts->snapshot = "default-boot";
855 D("autoconfig: -snapshot %s", opts->snapshot);
856 }
857 }
858
859 /* We still use QEMU command-line options for the following since
860 * they can change from one invokation to the next and don't really
861 * correspond to the hardware configuration itself.
862 */
863 if (!opts->no_snapshot_load) {
864 args[n++] = "-loadvm";
865 args[n++] = ASTRDUP(opts->snapshot);
866 }
867
868 if (!opts->no_snapshot_save) {
869 args[n++] = "-savevm-on-exit";
870 args[n++] = ASTRDUP(opts->snapshot);
871 }
872
Tim Baverstock622b8f42010-12-07 11:36:59 +0000873 if (opts->no_snapshot_update_time) {
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100874 args[n++] = "-snapshot-no-time-update";
Tim Baverstock622b8f42010-12-07 11:36:59 +0000875 }
Ot ten Thijeae835ac2010-10-18 13:37:37 +0100876 }
Ot ten Thije353b3b12010-10-05 17:53:30 +0100877
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800878 if (!opts->logcat || opts->logcat[0] == 0) {
879 opts->logcat = getenv("ANDROID_LOG_TAGS");
880 if (opts->logcat && opts->logcat[0] == 0)
881 opts->logcat = NULL;
882 }
883
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800884 /* we always send the kernel messages from ttyS0 to android_kmsg */
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100885 if (opts->show_kernel) {
886 args[n++] = "-show-kernel";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800887 }
888
889 /* XXXX: TODO: implement -shell and -logcat through qemud instead */
890 if (!opts->shell_serial) {
891#ifdef _WIN32
892 opts->shell_serial = "con:";
893#else
894 opts->shell_serial = "stdio";
895#endif
896 }
897 else
898 opts->shell = 1;
899
900 if (opts->shell || opts->logcat) {
901 args[n++] = "-serial";
902 args[n++] = opts->shell_serial;
903 shell_serial = serial++;
904 }
905
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100906 if (opts->radio) {
907 args[n++] = "-radio";
908 args[n++] = opts->radio;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800909 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800910
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100911 if (opts->gps) {
912 args[n++] = "-gps";
913 args[n++] = opts->gps;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800914 }
915
Nick Kralevich185231a2013-10-07 13:54:31 -0700916 if (opts->selinux) {
917 if ((strcmp(opts->selinux, "permissive") != 0)
918 && (strcmp(opts->selinux, "disabled") != 0)) {
919 derror("-selinux must be \"disabled\" or \"permissive\"");
920 exit(1);
921 }
922 }
923
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800924 if (opts->memory) {
925 char* end;
926 long ramSize = strtol(opts->memory, &end, 0);
927 if (ramSize < 0 || *end != 0) {
928 derror( "-memory must be followed by a positive integer" );
929 exit(1);
930 }
931 if (ramSize < 32 || ramSize > 4096) {
932 derror( "physical memory size must be between 32 and 4096 MB" );
933 exit(1);
934 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100935 hw->hw_ramSize = ramSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800936 }
937 if (!opts->memory) {
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100938 int ramSize = hw->hw_ramSize;
939 if (ramSize <= 0) {
940 /* Compute the default RAM size based on the size of screen.
941 * This is only used when the skin doesn't provide the ram
942 * size through its hardware.ini (i.e. legacy ones) or when
943 * in the full Android build system.
944 */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100945 int64_t pixels = hw->hw_lcd_width * hw->hw_lcd_height;
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100946 /* The following thresholds are a bit liberal, but we
947 * essentially want to ensure the following mappings:
948 *
949 * 320x480 -> 96
950 * 800x600 -> 128
951 * 1024x768 -> 256
952 *
953 * These are just simple heuristics, they could change in
954 * the future.
955 */
956 if (pixels <= 250000)
957 ramSize = 96;
958 else if (pixels <= 500000)
959 ramSize = 128;
960 else
961 ramSize = 256;
962 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100963 hw->hw_ramSize = ramSize;
964 }
965
966 D("Physical RAM size: %dMB\n", hw->hw_ramSize);
967
968 if (hw->vm_heapSize == 0) {
969 /* Compute the default heap size based on the RAM size.
970 * Essentially, we want to ensure the following liberal mappings:
971 *
972 * 96MB RAM -> 16MB heap
973 * 128MB RAM -> 24MB heap
974 * 256MB RAM -> 48MB heap
975 */
976 int ramSize = hw->hw_ramSize;
977 int heapSize;
978
979 if (ramSize < 100)
980 heapSize = 16;
981 else if (ramSize < 192)
982 heapSize = 24;
983 else
984 heapSize = 48;
985
986 hw->vm_heapSize = heapSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800987 }
988
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800989 if (opts->trace) {
990 args[n++] = "-trace";
991 args[n++] = opts->trace;
992 args[n++] = "-tracing";
993 args[n++] = "off";
994 }
995
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700996 /* Pass boot properties to the core. */
997 if (opts->prop != NULL) {
998 ParamList* pl = opts->prop;
999 for ( ; pl != NULL; pl = pl->next ) {
1000 args[n++] = "-boot-property";
1001 args[n++] = pl->param;
1002 }
1003 }
1004
David 'Digit' Turner318e4f22009-05-25 18:01:03 +02001005 /* Setup the kernel init options
1006 */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001007 {
1008 static char params[1024];
1009 char *p = params, *end = p + sizeof(params);
1010
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +01001011 /* Don't worry about having a leading space here, this is handled
1012 * by the core later. */
1013
Jun Nakajima334ab472011-02-02 23:49:59 -08001014#ifdef TARGET_I386
1015 p = bufprint(p, end, " androidboot.hardware=goldfish");
Jun Nakajimabac9add2011-02-08 22:10:52 -08001016 p = bufprint(p, end, " clocksource=pit");
Jun Nakajima334ab472011-02-02 23:49:59 -08001017#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001018
1019 if (opts->shell || opts->logcat) {
1020 p = bufprint(p, end, " androidboot.console=ttyS%d", shell_serial );
1021 }
1022
1023 if (opts->trace) {
1024 p = bufprint(p, end, " android.tracing=1");
1025 }
1026
1027 if (!opts->no_jni) {
1028 p = bufprint(p, end, " android.checkjni=1");
1029 }
1030
1031 if (opts->no_boot_anim) {
1032 p = bufprint( p, end, " android.bootanim=0" );
1033 }
1034
1035 if (opts->logcat) {
1036 char* q = bufprint(p, end, " androidboot.logcat=%s", opts->logcat);
1037
1038 if (q < end) {
1039 /* replace any space by a comma ! */
1040 {
1041 int nn;
1042 for (nn = 1; p[nn] != 0; nn++)
1043 if (p[nn] == ' ' || p[nn] == '\t')
1044 p[nn] = ',';
1045 p += nn;
1046 }
1047 }
1048 p = q;
1049 }
1050
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001051 if (opts->bootchart) {
1052 p = bufprint(p, end, " androidboot.bootchart=%s", opts->bootchart);
1053 }
1054
Nick Kralevich185231a2013-10-07 13:54:31 -07001055 if (opts->selinux) {
1056 p = bufprint(p, end, " androidboot.selinux=%s", opts->selinux);
1057 }
1058
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001059 if (p >= end) {
1060 fprintf(stderr, "### ERROR: kernel parameters too long\n");
1061 exit(1);
1062 }
1063
David 'Digit' Turner0b019492011-03-01 14:02:42 +01001064 hw->kernel_parameters = strdup(params);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001065 }
1066
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07001067 if (opts->ports) {
1068 args[n++] = "-android-ports";
1069 args[n++] = opts->ports;
1070 }
1071
1072 if (opts->port) {
1073 args[n++] = "-android-port";
1074 args[n++] = opts->port;
1075 }
1076
1077 if (opts->report_console) {
1078 args[n++] = "-android-report-console";
1079 args[n++] = opts->report_console;
1080 }
1081
1082 if (opts->http_proxy) {
1083 args[n++] = "-http-proxy";
1084 args[n++] = opts->http_proxy;
1085 }
1086
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001087 if (!opts->charmap) {
1088 /* Try to find a valid charmap name */
1089 char* charmap = avdInfo_getCharmapFile(avd, hw->hw_keyboard_charmap);
1090 if (charmap != NULL) {
1091 D("autoconfig: -charmap %s", charmap);
1092 opts->charmap = charmap;
1093 }
1094 }
1095
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001096 if (opts->charmap) {
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001097 char charmap_name[AKEYCHARMAP_NAME_SIZE];
1098
1099 if (!path_exists(opts->charmap)) {
1100 derror("Charmap file does not exist: %s", opts->charmap);
1101 exit(1);
1102 }
1103 /* We need to store the charmap name in the hardware configuration.
1104 * However, the charmap file itself is only used by the UI component
1105 * and doesn't need to be set to the emulation engine.
1106 */
1107 kcm_extract_charmap_name(opts->charmap, charmap_name,
1108 sizeof(charmap_name));
1109 AFREE(hw->hw_keyboard_charmap);
1110 hw->hw_keyboard_charmap = ASTRDUP(charmap_name);
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001111 }
1112
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07001113 if (opts->memcheck) {
1114 args[n++] = "-android-memcheck";
1115 args[n++] = opts->memcheck;
1116 }
1117
David Turner9da935d2011-09-12 21:27:56 +02001118 if (opts->gpu) {
1119 const char* gpu = opts->gpu;
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001120 if (!strcmp(gpu,"on") || !strcmp(gpu,"enable")) {
David Turner9da935d2011-09-12 21:27:56 +02001121 hw->hw_gpu_enabled = 1;
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001122 } else if (!strcmp(gpu,"off") || !strcmp(gpu,"disable")) {
David Turner9da935d2011-09-12 21:27:56 +02001123 hw->hw_gpu_enabled = 0;
1124 } else if (!strcmp(gpu,"auto")) {
1125 /* Nothing to do */
1126 } else {
1127 derror("Invalid value for -gpu <mode> parameter: %s\n", gpu);
1128 derror("Valid values are: on, off or auto\n");
1129 exit(1);
1130 }
1131 }
1132
Vladimir Chtchetkine9242b332012-02-10 08:29:22 -08001133 /* Quit emulator on condition that both, gpu and snapstorage are on. This is
1134 * a temporary solution preventing the emulator from crashing until GPU state
1135 * can be properly saved / resored in snapshot file. */
1136 if (hw->hw_gpu_enabled && opts->snapstorage && (!opts->no_snapshot_load ||
1137 !opts->no_snapshot_save)) {
1138 derror("Snapshots and gpu are mutually exclusive at this point. Please turn one of them off, and restart the emulator.");
1139 exit(1);
1140 }
1141
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001142 /* Deal with camera emulation */
1143 if (opts->webcam_list) {
1144 /* List connected webcameras */
1145 args[n++] = "-list-webcam";
1146 }
1147
1148 if (opts->camera_back) {
1149 /* Validate parameter. */
1150 if (memcmp(opts->camera_back, "webcam", 6) &&
1151 strcmp(opts->camera_back, "emulated") &&
1152 strcmp(opts->camera_back, "none")) {
1153 derror("Invalid value for -camera-back <mode> parameter: %s\n"
1154 "Valid values are: 'emulated', 'webcam<N>', or 'none'\n",
1155 opts->camera_back);
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001156 exit(1);
1157 }
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001158 hw->hw_camera_back = ASTRDUP(opts->camera_back);
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001159 }
1160
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001161 if (opts->camera_front) {
1162 /* Validate parameter. */
1163 if (memcmp(opts->camera_front, "webcam", 6) &&
1164 strcmp(opts->camera_front, "emulated") &&
1165 strcmp(opts->camera_front, "none")) {
1166 derror("Invalid value for -camera-front <mode> parameter: %s\n"
1167 "Valid values are: 'emulated', 'webcam<N>', or 'none'\n",
1168 opts->camera_front);
1169 exit(1);
Vladimir Chtchetkineb8dcaff2011-09-17 11:15:47 -07001170 }
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001171 hw->hw_camera_front = ASTRDUP(opts->camera_front);
Vladimir Chtchetkinef8675c22012-01-06 10:31:41 -08001172 }
1173
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01001174 /* physical memory is now in hw->hw_ramSize */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001175
David 'Digit' Turner53eb66d2011-03-01 14:58:23 +01001176 hw->avd_name = ASTRDUP(avdInfo_getName(avd));
David 'Digit' Turner6b8555c2011-02-17 04:28:19 +01001177
Dries Harnie40beab42010-05-15 17:04:47 +02001178 /* Set up the interfaces for inter-emulator networking */
1179 if (opts->shared_net_id) {
1180 unsigned int shared_net_id = atoi(opts->shared_net_id);
1181 char nic[37];
Dries Harnie40beab42010-05-15 17:04:47 +02001182
1183 args[n++] = "-net";
1184 args[n++] = "nic,vlan=0";
1185 args[n++] = "-net";
1186 args[n++] = "user,vlan=0";
Dries Harnie111d6f82010-06-09 21:42:18 +02001187
1188 args[n++] = "-net";
1189 snprintf(nic, sizeof nic, "nic,vlan=1,macaddr=52:54:00:12:34:%02x", shared_net_id);
1190 args[n++] = strdup(nic);
1191 args[n++] = "-net";
1192 args[n++] = "socket,vlan=1,mcast=230.0.0.10:1234";
Dries Harnie40beab42010-05-15 17:04:47 +02001193 }
1194
Vladimir Chtchetkine8dd31e82012-02-15 17:16:04 -08001195 /* Setup screen emulation */
1196 if (opts->screen) {
Vladimir Chtchetkine863d1012012-03-16 12:25:23 -07001197 if (strcmp(opts->screen, "touch") &&
1198 strcmp(opts->screen, "multi-touch") &&
1199 strcmp(opts->screen, "no-touch")) {
1200
1201 derror("Invalid value for -screen <mode> parameter: %s\n"
1202 "Valid values are: touch, multi-touch, or no-touch\n",
1203 opts->screen);
Vladimir Chtchetkine8dd31e82012-02-15 17:16:04 -08001204 exit(1);
1205 }
Vladimir Chtchetkine863d1012012-03-16 12:25:23 -07001206 hw->hw_screen = ASTRDUP(opts->screen);
Vladimir Chtchetkine8dd31e82012-02-15 17:16:04 -08001207 }
1208
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001209 while(argc-- > 0) {
1210 args[n++] = *argv++;
1211 }
1212 args[n] = 0;
1213
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +02001214 /* If the target ABI is armeabi-v7a, we can auto-detect the cpu model
1215 * as a cortex-a8, instead of the default (arm926) which only emulates
1216 * an ARMv5TE CPU.
1217 */
1218 if (!forceArmv7 && hw->hw_cpu_model[0] == '\0')
1219 {
1220 char* abi = avdInfo_getTargetAbi(avd);
1221 if (abi != NULL) {
1222 if (!strcmp(abi, "armeabi-v7a")) {
1223 forceArmv7 = 1;
1224 }
1225 AFREE(abi);
1226 }
1227 }
1228
1229 if (forceArmv7 != 0) {
1230 AFREE(hw->hw_cpu_model);
1231 hw->hw_cpu_model = ASTRDUP("cortex-a8");
1232 D("Auto-config: -qemu -cpu %s", hw->hw_cpu_model);
1233 }
1234
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001235 /* Generate a hardware-qemu.ini for this AVD. The real hardware
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001236 * configuration is ususally stored in several files, e.g. the AVD's
1237 * config.ini plus the skin-specific hardware.ini.
1238 *
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001239 * The new file will group all definitions and will be used to
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001240 * launch the core with the -android-hw <file> option.
1241 */
1242 {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001243 const char* coreHwIniPath = avdInfo_getCoreHwIniPath(avd);
1244 IniFile* hwIni = iniFile_newFromMemory("", NULL);
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001245 androidHwConfig_write(hw, hwIni);
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001246
1247 if (filelock_create(coreHwIniPath) == NULL) {
1248 /* The AVD is already in use, we still support this as an
1249 * experimental feature. Use a temporary hardware-qemu.ini
1250 * file though to avoid overwriting the existing one. */
1251 TempFile* tempIni = tempfile_create();
1252 coreHwIniPath = tempfile_path(tempIni);
1253 }
1254
Vladimir Chtchetkinedb450d72012-01-12 13:37:40 -08001255 /* While saving HW config, ignore valueless entries. This will not break
1256 * anything, but will significantly simplify comparing the current HW
1257 * config with the one that has been associated with a snapshot (in case
1258 * VM starts from a snapshot for this instance of emulator). */
1259 if (iniFile_saveToFileClean(hwIni, coreHwIniPath) < 0) {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001260 derror("Could not write hardware.ini to %s: %s", coreHwIniPath, strerror(errno));
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001261 exit(2);
1262 }
1263 args[n++] = "-android-hw";
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001264 args[n++] = strdup(coreHwIniPath);
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +02001265
1266 /* In verbose mode, dump the file's content */
1267 if (VERBOSE_CHECK(init)) {
1268 FILE* file = fopen(coreHwIniPath, "rt");
1269 if (file == NULL) {
1270 derror("Could not open hardware configuration file: %s\n",
1271 coreHwIniPath);
1272 } else {
1273 LineInput* input = lineInput_newFromStdFile(file);
1274 const char* line;
1275 printf("Content of hardware configuration file:\n");
1276 while ((line = lineInput_getLine(input)) != NULL) {
1277 printf(" %s\n", line);
1278 }
1279 printf(".\n");
1280 lineInput_free(input);
1281 fclose(file);
1282 }
1283 }
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001284 }
1285
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001286 if(VERBOSE_CHECK(init)) {
1287 int i;
David 'Digit' Turner33361762011-01-19 22:11:03 +01001288 printf("QEMU options list:\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001289 for(i = 0; i < n; i++) {
David 'Digit' Turner33361762011-01-19 22:11:03 +01001290 printf("emulator: argv[%02d] = \"%s\"\n", i, args[i]);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001291 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001292 /* Dump final command-line option to make debugging the core easier */
1293 printf("Concatenated QEMU options:\n");
1294 for (i = 0; i < n; i++) {
David 'Digit' Turner26722dd2011-02-24 16:40:20 +01001295 /* To make it easier to copy-paste the output to a command-line,
1296 * quote anything that contains spaces.
1297 */
1298 if (strchr(args[i], ' ') != NULL) {
1299 printf(" '%s'", args[i]);
1300 } else {
1301 printf(" %s", args[i]);
1302 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001303 }
1304 printf("\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001305 }
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +01001306
1307 /* Setup SDL UI just before calling the code */
1308 init_sdl_ui(skinConfig, skinPath, opts);
1309
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +01001310 if (attach_ui_to_core(opts) < 0) {
1311 derror("Can't attach to core!");
1312 exit(1);
1313 }
1314
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001315 return qemu_main(n, args);
1316}