blob: 1a10040e597abd7a857444b4daf234503b874765 [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' Turner9b3a4b02014-01-23 00:52:54 +010021#include "config.h"
David 'Digit' Turnercc330d42013-12-14 23:26:42 +010022#include "android/sockets.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080023
24#include "android/android.h"
25#include "qemu-common.h"
David 'Digit' Turner34c48ff2013-12-15 00:25:03 +010026#include "sysemu/sysemu.h"
David 'Digit' Turner1c31e3e2013-12-14 20:07:17 +010027#include "ui/console.h"
David 'Digit' Turnerd4e803c2013-12-14 23:45:50 +010028#include "android/user-events.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080029
30#include <SDL.h>
31#include <SDL_syswm.h>
32
33#include "math.h"
34
35#include "android/charmap.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080036#include "android/utils/debug.h"
David 'Digit' Turner73dd5fc2014-02-04 12:50:55 +010037#include "android/config-file.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080038#include "android/config/config.h"
39
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080040#include "android/user-config.h"
41#include "android/utils/bufprint.h"
David 'Digit' Turner26d41532011-03-01 15:03:07 +010042#include "android/utils/filelock.h"
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +020043#include "android/utils/lineinput.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080044#include "android/utils/path.h"
David 'Digit' Turner622f1532011-02-01 17:48:37 +010045#include "android/utils/tempfile.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080046
David 'Digit' Turnerf8456272011-02-02 12:34:14 +010047#include "android/main-common.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080048#include "android/help.h"
David 'Digit' Turnerf0665422013-12-17 10:47:09 +010049#include "hw/android/goldfish/nand.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080050
51#include "android/globals.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080052
Xavier Ducrohetfc8ed802011-02-09 18:04:23 -080053#include "android/qemulator.h"
David 'Digit' Turner055ae422010-07-27 11:34:16 -070054#include "android/display.h"
Vladimir Chtchetkine01193622010-05-11 13:07:22 -070055
Ot ten Thijeae835ac2010-10-18 13:37:37 +010056#include "android/snapshot.h"
57
David 'Digit' Turnere3fdd072011-02-02 14:43:23 +010058#include "android/framebuffer.h"
David 'Digit' Turnerd413fa52013-12-14 23:35:20 +010059#include "android/iolooper.h"
David 'Digit' Turner055ae422010-07-27 11:34:16 -070060
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080061AndroidRotation android_framebuffer_rotation;
62
63#define STRINGIFY(x) _STRINGIFY(x)
64#define _STRINGIFY(x) #x
65
David 'Digit' Turnera383d022009-12-03 13:50:00 -080066#ifdef ANDROID_SDK_TOOLS_REVISION
67# define VERSION_STRING STRINGIFY(ANDROID_SDK_TOOLS_REVISION)".0"
68#else
69# define VERSION_STRING "standalone"
70#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080071
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080072#define D(...) do { if (VERBOSE_CHECK(init)) dprint(__VA_ARGS__); } while (0)
73
74extern int control_console_start( int port ); /* in control.c */
75
76extern int qemu_milli_needed;
77
78/* the default device DPI if none is specified by the skin
79 */
80#define DEFAULT_DEVICE_DPI 165
81
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080082#ifdef CONFIG_TRACE
83extern void start_tracing(void);
84extern void stop_tracing(void);
85#endif
86
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080087int qemu_main(int argc, char **argv);
88
89/* this function dumps the QEMU help */
90extern void help( void );
91extern void emulator_help( void );
92
93#define VERBOSE_OPT(str,var) { str, &var }
94
95#define _VERBOSE_TAG(x,y) { #x, VERBOSE_##x, y },
96static const struct { const char* name; int flag; const char* text; }
97verbose_options[] = {
98 VERBOSE_TAG_LIST
99 { 0, 0, 0 }
100};
101
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800102void emulator_help( void )
103{
104 STRALLOC_DEFINE(out);
105 android_help_main(out);
106 printf( "%.*s", out->n, out->s );
107 stralloc_reset(out);
108 exit(1);
109}
110
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100111/* TODO: Put in shared source file */
112static char*
113_getFullFilePath( const char* rootPath, const char* fileName )
114{
115 if (path_is_absolute(fileName)) {
116 return ASTRDUP(fileName);
117 } else {
118 char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
119
120 p = bufprint(temp, end, "%s/%s", rootPath, fileName);
121 if (p >= end) {
122 return NULL;
123 }
124 return ASTRDUP(temp);
125 }
126}
127
128static uint64_t
129_adjustPartitionSize( const char* description,
130 uint64_t imageBytes,
131 uint64_t defaultBytes,
132 int inAndroidBuild )
133{
134 char temp[64];
135 unsigned imageMB;
136 unsigned defaultMB;
137
138 if (imageBytes <= defaultBytes)
139 return defaultBytes;
140
141 imageMB = convertBytesToMB(imageBytes);
142 defaultMB = convertBytesToMB(defaultBytes);
143
144 if (imageMB > defaultMB) {
145 snprintf(temp, sizeof temp, "(%d MB > %d MB)", imageMB, defaultMB);
146 } else {
Andrew Hsiehc7389bd2012-03-13 02:13:40 -0700147 snprintf(temp, sizeof temp, "(%" PRIu64 " bytes > %" PRIu64 " bytes)", imageBytes, defaultBytes);
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100148 }
149
150 if (inAndroidBuild) {
151 dwarning("%s partition size adjusted to match image file %s\n", description, temp);
152 }
153
154 return convertMBToBytes(imageMB);
155}
156
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800157int main(int argc, char **argv)
158{
159 char tmp[MAX_PATH];
160 char* tmpend = tmp + sizeof(tmp);
161 char* args[128];
162 int n;
163 char* opt;
David 'Digit' Turner5e736932011-03-18 00:02:14 +0100164 /* The emulator always uses the first serial port for kernel messages
165 * and the second one for qemud. So start at the third if we need one
166 * for logcat or 'shell'
167 */
168 int serial = 2;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800169 int shell_serial = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800170
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +0200171 int forceArmv7 = 0;
172
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800173 AndroidHwConfig* hw;
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200174 AvdInfo* avd;
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100175 AConfig* skinConfig;
176 char* skinPath;
Vladimir Chtchetkine83ffd662011-02-11 12:40:59 -0800177 int inAndroidBuild;
Vladimir Chtchetkine88078b82012-04-19 12:24:38 -0700178 uint64_t defaultPartitionSize = convertMBToBytes(200);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800179
180 AndroidOptions opts[1];
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700181 /* net.shared_net_ip boot property value. */
182 char boot_prop_ip[64];
183 boot_prop_ip[0] = '\0';
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800184
185 args[0] = argv[0];
186
187 if ( android_parse_options( &argc, &argv, opts ) < 0 ) {
188 exit(1);
189 }
190
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100191#ifdef _WIN32
192 socket_init();
193#endif
194
195 handle_ui_options(opts);
196
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800197 while (argc-- > 1) {
198 opt = (++argv)[0];
199
200 if(!strcmp(opt, "-qemu")) {
201 argc--;
202 argv++;
203 break;
204 }
205
206 if (!strcmp(opt, "-help")) {
207 emulator_help();
208 }
209
210 if (!strncmp(opt, "-help-",6)) {
211 STRALLOC_DEFINE(out);
212 opt += 6;
213
214 if (!strcmp(opt, "all")) {
215 android_help_all(out);
216 }
217 else if (android_help_for_option(opt, out) == 0) {
218 /* ok */
219 }
220 else if (android_help_for_topic(opt, out) == 0) {
221 /* ok */
222 }
223 if (out->n > 0) {
224 printf("\n%.*s", out->n, out->s);
225 exit(0);
226 }
227
228 fprintf(stderr, "unknown option: -help-%s\n", opt);
229 fprintf(stderr, "please use -help for a list of valid topics\n");
230 exit(1);
231 }
232
233 if (opt[0] == '-') {
234 fprintf(stderr, "unknown option: %s\n", opt);
235 fprintf(stderr, "please use -help for a list of valid options\n");
236 exit(1);
237 }
238
239 fprintf(stderr, "invalid command-line parameter: %s.\n", opt);
240 fprintf(stderr, "Hint: use '@foo' to launch a virtual device named 'foo'.\n");
241 fprintf(stderr, "please use -help for more information\n");
242 exit(1);
243 }
244
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800245 if (opts->version) {
246 printf("Android emulator version %s\n"
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100247 "Copyright (C) 2006-2011 The Android Open Source Project and many others.\n"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800248 "This program is a derivative of the QEMU CPU emulator (www.qemu.org).\n\n",
249#if defined ANDROID_BUILD_ID
250 VERSION_STRING " (build_id " STRINGIFY(ANDROID_BUILD_ID) ")" );
251#else
252 VERSION_STRING);
253#endif
254 printf(" This software is licensed under the terms of the GNU General Public\n"
255 " License version 2, as published by the Free Software Foundation, and\n"
256 " may be copied, distributed, and modified under those terms.\n\n"
257 " This program is distributed in the hope that it will be useful,\n"
258 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
259 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
260 " GNU General Public License for more details.\n\n");
261
262 exit(0);
263 }
264
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100265 if (opts->snapshot_list) {
David 'Digit' Turnerd80a7862011-05-05 10:24:43 +0200266 if (opts->snapstorage == NULL) {
267 /* Need to find the default snapstorage */
268 avd = createAVD(opts, &inAndroidBuild);
269 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
270 if (opts->snapstorage != NULL) {
271 D("autoconfig: -snapstorage %s", opts->snapstorage);
272 } else {
273 if (inAndroidBuild) {
274 derror("You must use the -snapstorage <file> option to specify a snapshot storage file!\n");
275 } else {
276 derror("This AVD doesn't have snapshotting enabled!\n");
277 }
278 exit(1);
279 }
280 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100281 snapshot_print_and_exit(opts->snapstorage);
282 }
283
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100284 sanitizeOptions(opts);
285
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100286 /* Initialization of UI started with -attach-core should work differently
287 * than initialization of UI that starts the core. In particular....
288 */
289
290 /* -charmap is incompatible with -attach-core, because particular
291 * charmap gets set up in the running core. */
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100292 if (android_charmap_setup(opts->charmap)) {
293 exit(1);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800294 }
295
Vladimir Chtchetkine83ffd662011-02-11 12:40:59 -0800296 /* Parses options and builds an appropriate AVD. */
David 'Digit' Turner462564f2011-02-23 13:32:37 +0100297 avd = android_avdInfo = createAVD(opts, &inAndroidBuild);
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200298
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800299 /* get the skin from the virtual device configuration */
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100300 if (opts->skindir != NULL) {
301 if (opts->skin == NULL) {
302 /* NOTE: Normally handled by sanitizeOptions(), just be safe */
303 derror("The -skindir <path> option requires a -skin <name> option");
304 exit(2);
305 }
306 } else {
307 char* skinName;
308 char* skinDir;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800309
David 'Digit' Turner25eb6552011-02-25 15:07:11 +0100310 avdInfo_getSkinInfo(avd, &skinName, &skinDir);
311
312 if (opts->skin == NULL) {
313 opts->skin = skinName;
314 D("autoconfig: -skin %s", opts->skin);
315 } else {
316 AFREE(skinName);
317 }
318
319 opts->skindir = skinDir;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800320 D("autoconfig: -skindir %s", opts->skindir);
Xavier Ducrohet689d1142012-04-19 12:54:08 -0700321
322 /* update the avd hw config from this new skin */
323 avdInfo_getSkinHardwareIni(avd, opts->skin, opts->skindir);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800324 }
325
Siva Velusamyd8999182012-10-08 18:02:30 -0700326 if (opts->dynamic_skin == 0) {
327 opts->dynamic_skin = avdInfo_shouldUseDynamicSkin(avd);
328 }
329
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800330 /* Read hardware configuration */
331 hw = android_hw;
David 'Digit' Turnerb64325d2011-03-22 16:07:01 +0100332 if (avdInfo_initHwConfig(avd, hw) < 0) {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800333 derror("could not read hardware configuration ?");
334 exit(1);
335 }
336
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800337 if (opts->keyset) {
338 parse_keyset(opts->keyset, opts);
339 if (!android_keyset) {
340 fprintf(stderr,
341 "emulator: WARNING: could not find keyset file named '%s',"
342 " using defaults instead\n",
343 opts->keyset);
344 }
345 }
346 if (!android_keyset) {
347 parse_keyset("default", opts);
348 if (!android_keyset) {
349 android_keyset = skin_keyset_new_from_text( skin_keyset_get_default() );
350 if (!android_keyset) {
351 fprintf(stderr, "PANIC: default keyset file is corrupted !!\n" );
352 fprintf(stderr, "PANIC: please update the code in android/skin/keyset.c\n" );
353 exit(1);
354 }
355 if (!opts->keyset)
356 write_default_keyset();
357 }
358 }
359
Dries Harnie40beab42010-05-15 17:04:47 +0200360 if (opts->shared_net_id) {
361 char* end;
362 long shared_net_id = strtol(opts->shared_net_id, &end, 0);
363 if (end == NULL || *end || shared_net_id < 1 || shared_net_id > 255) {
364 fprintf(stderr, "option -shared-net-id must be an integer between 1 and 255\n");
365 exit(1);
366 }
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700367 snprintf(boot_prop_ip, sizeof(boot_prop_ip),
368 "net.shared_net_ip=10.1.2.%ld", shared_net_id);
Dries Harnie40beab42010-05-15 17:04:47 +0200369 }
370
371
David 'Digit' Turner755811e2011-02-07 13:38:25 +0100372 user_config_init();
David 'Digit' Turner2507cab2011-02-10 16:29:17 +0100373 parse_skin_files(opts->skindir, opts->skin, opts, hw,
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100374 &skinConfig, &skinPath);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800375
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100376 if (!opts->netspeed && skin_network_speed) {
377 D("skin network speed: '%s'", skin_network_speed);
378 if (strcmp(skin_network_speed, NETWORK_SPEED_DEFAULT) != 0) {
379 opts->netspeed = (char*)skin_network_speed;
380 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800381 }
David 'Digit' Turner092361e2011-03-01 13:14:18 +0100382 if (!opts->netdelay && skin_network_delay) {
383 D("skin network delay: '%s'", skin_network_delay);
384 if (strcmp(skin_network_delay, NETWORK_DELAY_DEFAULT) != 0) {
385 opts->netdelay = (char*)skin_network_delay;
386 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800387 }
388
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800389 if (opts->trace) {
David 'Digit' Turnercd059b12009-08-28 19:36:27 +0200390 char* tracePath = avdInfo_getTracePath(avd, opts->trace);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800391 int ret;
392
393 if (tracePath == NULL) {
394 derror( "bad -trace parameter" );
395 exit(1);
396 }
397 ret = path_mkdir_if_needed( tracePath, 0755 );
398 if (ret < 0) {
399 fprintf(stderr, "could not create directory '%s'\n", tmp);
400 exit(2);
401 }
402 opts->trace = tracePath;
403 }
404
Vladimir Chtchetkine33f89d02011-09-28 09:19:09 -0700405 /* Update CPU architecture for HW configs created from build dir. */
406 if (inAndroidBuild) {
407#if defined(TARGET_ARM)
408 free(android_hw->hw_cpu_arch);
409 android_hw->hw_cpu_arch = ASTRDUP("arm");
410#elif defined(TARGET_I386)
411 free(android_hw->hw_cpu_arch);
412 android_hw->hw_cpu_arch = ASTRDUP("x86");
Bhanu Chetlapalli741dc132012-05-08 17:16:03 -0700413#elif defined(TARGET_MIPS)
414 free(android_hw->hw_cpu_arch);
415 android_hw->hw_cpu_arch = ASTRDUP("mips");
Vladimir Chtchetkine33f89d02011-09-28 09:19:09 -0700416#endif
417 }
418
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800419 n = 1;
420 /* generate arguments for the underlying qemu main() */
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700421 {
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100422 char* kernelFile = opts->kernel;
423 int kernelFileLen;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700424
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100425 if (kernelFile == NULL) {
426 kernelFile = avdInfo_getKernelPath(avd);
427 if (kernelFile == NULL) {
428 derror( "This AVD's configuration is missing a kernel file!!" );
429 exit(2);
430 }
431 D("autoconfig: -kernel %s", kernelFile);
432 }
433 if (!path_exists(kernelFile)) {
434 derror( "Invalid or missing kernel image file: %s", kernelFile );
435 exit(2);
436 }
437
438 hw->kernel_path = kernelFile;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700439
440 /* If the kernel image name ends in "-armv7", then change the cpu
441 * type automatically. This is a poor man's approach to configuration
442 * management, but should allow us to get past building ARMv7
443 * system images with dex preopt pass without introducing too many
444 * changes to the emulator sources.
445 *
446 * XXX:
447 * A 'proper' change would require adding some sort of hardware-property
448 * to each AVD config file, then automatically determine its value for
449 * full Android builds (depending on some environment variable), plus
450 * some build system changes. I prefer not to do that for now for reasons
451 * of simplicity.
452 */
David 'Digit' Turner0b019492011-03-01 14:02:42 +0100453 kernelFileLen = strlen(kernelFile);
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700454 if (kernelFileLen > 6 && !memcmp(kernelFile + kernelFileLen - 6, "-armv7", 6)) {
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +0200455 forceArmv7 = 1;
David 'Digit' Turner238b4b02009-09-20 13:10:19 -0700456 }
457 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800458
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700459 if (boot_prop_ip[0]) {
460 args[n++] = "-boot-property";
461 args[n++] = boot_prop_ip;
462 }
463
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -0700464 if (opts->tcpdump) {
465 args[n++] = "-tcpdump";
466 args[n++] = opts->tcpdump;
467 }
468
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700469#ifdef CONFIG_NAND_LIMITS
470 if (opts->nand_limits) {
471 args[n++] = "-nand-limits";
472 args[n++] = opts->nand_limits;
473 }
474#endif
475
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +0100476 if (opts->timezone) {
477 args[n++] = "-timezone";
478 args[n++] = opts->timezone;
479 }
480
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700481 if (opts->netspeed) {
482 args[n++] = "-netspeed";
483 args[n++] = opts->netspeed;
484 }
485 if (opts->netdelay) {
486 args[n++] = "-netdelay";
487 args[n++] = opts->netdelay;
488 }
489 if (opts->netfast) {
490 args[n++] = "-netfast";
491 }
492
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700493 if (opts->audio) {
494 args[n++] = "-audio";
495 args[n++] = opts->audio;
496 }
497
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700498 if (opts->cpu_delay) {
499 args[n++] = "-cpu-delay";
500 args[n++] = opts->cpu_delay;
501 }
502
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -0700503 if (opts->dns_server) {
504 args[n++] = "-dns-server";
505 args[n++] = opts->dns_server;
506 }
507
David 'Digit' Turner9ff69722011-09-13 12:32:52 +0200508 /* opts->ramdisk is never NULL (see createAVD) here */
509 if (opts->ramdisk) {
510 AFREE(hw->disk_ramdisk_path);
511 hw->disk_ramdisk_path = ASTRDUP(opts->ramdisk);
512 }
513 else if (!hw->disk_ramdisk_path[0]) {
514 hw->disk_ramdisk_path = avdInfo_getRamdiskPath(avd);
515 D("autoconfig: -ramdisk %s", hw->disk_ramdisk_path);
516 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800517
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100518 /* -partition-size is used to specify the max size of both the system
519 * and data partition sizes.
520 */
521 if (opts->partition_size) {
522 char* end;
523 long sizeMB = strtol(opts->partition_size, &end, 0);
524 long minSizeMB = 10;
525 long maxSizeMB = LONG_MAX / ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800526
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100527 if (sizeMB < 0 || *end != 0) {
528 derror( "-partition-size must be followed by a positive integer" );
529 exit(1);
530 }
531 if (sizeMB < minSizeMB || sizeMB > maxSizeMB) {
532 derror( "partition-size (%d) must be between %dMB and %dMB",
533 sizeMB, minSizeMB, maxSizeMB );
534 exit(1);
535 }
536 defaultPartitionSize = (uint64_t) sizeMB * ONE_MB;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800537 }
538
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100539
540 /** SYSTEM PARTITION **/
541
542 if (opts->sysdir == NULL) {
543 if (avdInfo_inAndroidBuild(avd)) {
544 opts->sysdir = ASTRDUP(avdInfo_getContentPath(avd));
545 D("autoconfig: -sysdir %s", opts->sysdir);
546 }
547 }
548
549 if (opts->sysdir != NULL) {
550 if (!path_exists(opts->sysdir)) {
551 derror("Directory does not exist: %s", opts->sysdir);
552 exit(1);
553 }
554 }
555
556 {
557 char* rwImage = NULL;
558 char* initImage = NULL;
559
560 do {
561 if (opts->system == NULL) {
562 /* If -system is not used, try to find a runtime system image
563 * (i.e. system-qemu.img) in the content directory.
564 */
565 rwImage = avdInfo_getSystemImagePath(avd);
566 if (rwImage != NULL) {
567 break;
568 }
569 /* Otherwise, try to find the initial system image */
570 initImage = avdInfo_getSystemInitImagePath(avd);
571 if (initImage == NULL) {
572 derror("No initial system image for this configuration!");
573 exit(1);
574 }
575 break;
576 }
577
578 /* If -system <name> is used, use it to find the initial image */
David 'Digit' Turnerea283772011-07-07 04:40:27 +0200579 if (opts->sysdir != NULL && !path_exists(opts->system)) {
David 'Digit' Turner40841b22011-03-01 14:04:00 +0100580 initImage = _getFullFilePath(opts->sysdir, opts->system);
581 } else {
582 initImage = ASTRDUP(opts->system);
583 }
584 if (!path_exists(initImage)) {
585 derror("System image file doesn't exist: %s", initImage);
586 exit(1);
587 }
588
589 } while (0);
590
591 if (rwImage != NULL) {
592 /* Use the read/write image file directly */
593 hw->disk_systemPartition_path = rwImage;
594 hw->disk_systemPartition_initPath = NULL;
595 D("Using direct system image: %s", rwImage);
596 } else if (initImage != NULL) {
597 hw->disk_systemPartition_path = NULL;
598 hw->disk_systemPartition_initPath = initImage;
599 D("Using initial system image: %s", initImage);
600 }
601
602 /* Check the size of the system partition image.
603 * If we have an AVD, it must be smaller than
604 * the disk.systemPartition.size hardware property.
605 *
606 * Otherwise, we need to adjust the systemPartitionSize
607 * automatically, and print a warning.
608 *
609 */
610 const char* systemImage = hw->disk_systemPartition_path;
611 uint64_t systemBytes;
612
613 if (systemImage == NULL)
614 systemImage = hw->disk_systemPartition_initPath;
615
616 if (path_get_size(systemImage, &systemBytes) < 0) {
617 derror("Missing system image: %s", systemImage);
618 exit(1);
619 }
620
621 hw->disk_systemPartition_size =
622 _adjustPartitionSize("system", systemBytes, defaultPartitionSize,
623 avdInfo_inAndroidBuild(avd));
624 }
625
626 /** DATA PARTITION **/
627
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100628 if (opts->datadir) {
629 if (!path_exists(opts->datadir)) {
630 derror("Invalid -datadir directory: %s", opts->datadir);
631 }
632 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800633
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100634 {
635 char* dataImage = NULL;
636 char* initImage = NULL;
637
638 do {
639 if (!opts->data) {
640 dataImage = avdInfo_getDataImagePath(avd);
641 if (dataImage != NULL) {
642 D("autoconfig: -data %s", dataImage);
643 break;
644 }
645 dataImage = avdInfo_getDefaultDataImagePath(avd);
646 if (dataImage == NULL) {
647 derror("No data image path for this configuration!");
648 exit (1);
649 }
650 opts->wipe_data = 1;
651 break;
652 }
653
654 if (opts->datadir) {
655 dataImage = _getFullFilePath(opts->datadir, opts->data);
656 } else {
657 dataImage = ASTRDUP(opts->data);
658 }
659 } while (0);
660
661 if (opts->initdata != NULL) {
662 initImage = ASTRDUP(opts->initdata);
663 if (!path_exists(initImage)) {
664 derror("Invalid initial data image path: %s", initImage);
665 exit(1);
666 }
667 } else {
668 initImage = avdInfo_getDataInitImagePath(avd);
669 D("autoconfig: -initdata %s", initImage);
670 }
671
672 hw->disk_dataPartition_path = dataImage;
673 if (opts->wipe_data) {
674 hw->disk_dataPartition_initPath = initImage;
675 } else {
676 hw->disk_dataPartition_initPath = NULL;
677 }
678
Maciek Molerusf7584112011-06-15 22:26:35 +0200679 uint64_t defaultBytes =
680 hw->disk_dataPartition_size == 0 ?
681 defaultPartitionSize :
Vladimir Chtchetkined4f5a3a2012-03-08 14:20:20 -0800682 hw->disk_dataPartition_size;
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +0100683 uint64_t dataBytes;
684 const char* dataPath = hw->disk_dataPartition_initPath;
685
686 if (dataPath == NULL)
687 dataPath = hw->disk_dataPartition_path;
688
689 path_get_size(dataPath, &dataBytes);
690
691 hw->disk_dataPartition_size =
692 _adjustPartitionSize("data", dataBytes, defaultBytes,
693 avdInfo_inAndroidBuild(avd));
694 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800695
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100696 /** CACHE PARTITION **/
697
698 if (opts->no_cache) {
699 /* No cache partition at all */
700 hw->disk_cachePartition = 0;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800701 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100702 else if (!hw->disk_cachePartition) {
703 if (opts->cache) {
704 dwarning( "Emulated hardware doesn't support a cache partition. -cache option ignored!" );
705 opts->cache = NULL;
706 }
707 }
708 else
709 {
710 if (!opts->cache) {
711 /* Find the current cache partition file */
712 opts->cache = avdInfo_getCachePath(avd);
713 if (opts->cache == NULL) {
714 /* The file does not exists, we will force its creation
715 * if we are not in the Android build system. Otherwise,
716 * a temporary file will be used.
717 */
718 if (!avdInfo_inAndroidBuild(avd)) {
719 opts->cache = avdInfo_getDefaultCachePath(avd);
720 }
721 }
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100722 if (opts->cache) {
723 D("autoconfig: -cache %s", opts->cache);
724 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100725 }
726
727 if (opts->cache) {
728 hw->disk_cachePartition_path = ASTRDUP(opts->cache);
729 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800730 }
731
Vladimir Chtchetkine6f50aa32012-04-26 08:20:18 -0700732 if (hw->disk_cachePartition_path && opts->cache_size) {
733 /* Set cache partition size per user options. */
734 char* end;
735 long sizeMB = strtol(opts->cache_size, &end, 0);
736
737 if (sizeMB < 0 || *end != 0) {
738 derror( "-cache-size must be followed by a positive integer" );
739 exit(1);
740 }
741 hw->disk_cachePartition_size = (uint64_t) sizeMB * ONE_MB;
742 }
743
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +0100744 /** SD CARD PARTITION */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800745
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100746 if (!hw->hw_sdCard) {
747 /* No SD Card emulation, so -sdcard will be ignored */
748 if (opts->sdcard) {
749 dwarning( "Emulated hardware doesn't support SD Cards. -sdcard option ignored." );
750 opts->sdcard = NULL;
751 }
752 } else {
753 /* Auto-configure -sdcard if it is not available */
754 if (!opts->sdcard) {
755 do {
756 /* If -datadir <path> is used, look for a sdcard.img file here */
757 if (opts->datadir) {
758 bufprint(tmp, tmpend, "%s/%s", opts->datadir, "system.img");
759 if (path_exists(tmp)) {
760 opts->sdcard = strdup(tmp);
761 break;
762 }
763 }
764
765 /* Otherwise, look at the AVD's content */
766 opts->sdcard = avdInfo_getSdCardPath(avd);
767 if (opts->sdcard != NULL) {
768 break;
769 }
770
771 /* Nothing */
772 } while (0);
773
774 if (opts->sdcard) {
775 D("autoconfig: -sdcard %s", opts->sdcard);
776 }
777 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800778 }
779
780 if(opts->sdcard) {
781 uint64_t size;
782 if (path_get_size(opts->sdcard, &size) == 0) {
783 /* see if we have an sdcard image. get its size if it exists */
David 'Digit' Turner8b657e52009-12-01 13:38:21 -0800784 /* due to what looks like limitations of the MMC protocol, one has
785 * to use an SD Card image that is equal or larger than 9 MB
786 */
787 if (size < 9*1024*1024ULL) {
788 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 -0800789 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100790 hw->hw_sdCard_path = ASTRDUP(opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800791 }
792 } else {
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100793 dwarning("no SD Card image at '%s'", opts->sdcard);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800794 }
795 }
796
David 'Digit' Turner48a3c662011-03-01 14:03:20 +0100797
798 /** SNAPSHOT STORAGE HANDLING */
799
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100800 /* Determine snapstorage path. -no-snapstorage disables all snapshotting
801 * support. This means you can't resume a snapshot at load, save it at
802 * exit, or even load/save them dynamically at runtime with the console.
803 */
804 if (opts->no_snapstorage) {
805
806 if (opts->snapshot) {
807 dwarning("ignoring -snapshot option due to the use of -no-snapstorage");
808 opts->snapshot = NULL;
809 }
810
811 if (opts->snapstorage) {
812 dwarning("ignoring -snapstorage option due to the use of -no-snapstorage");
813 opts->snapstorage = NULL;
814 }
815 }
816 else
817 {
Vladimir Chtchetkine873c3cb2012-03-14 12:46:51 -0700818 if (!opts->snapstorage && avdInfo_getSnapshotPresent(avd)) {
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100819 opts->snapstorage = avdInfo_getSnapStoragePath(avd);
820 if (opts->snapstorage != NULL) {
821 D("autoconfig: -snapstorage %s", opts->snapstorage);
Ot ten Thije353b3b12010-10-05 17:53:30 +0100822 }
823 }
824
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100825 if (opts->snapstorage && !path_exists(opts->snapstorage)) {
826 D("no image at '%s', state snapshots disabled", opts->snapstorage);
827 opts->snapstorage = NULL;
Ot ten Thije353b3b12010-10-05 17:53:30 +0100828 }
David 'Digit' Turner5f64b872011-02-28 23:23:05 +0100829 }
830
831 /* If we have a valid snapshot storage path */
832
833 if (opts->snapstorage) {
834
835 hw->disk_snapStorage_path = ASTRDUP(opts->snapstorage);
836
837 /* -no-snapshot is equivalent to using both -no-snapshot-load
838 * and -no-snapshot-save. You can still load/save snapshots dynamically
839 * from the console though.
840 */
841 if (opts->no_snapshot) {
842
843 opts->no_snapshot_load = 1;
844 opts->no_snapshot_save = 1;
845
846 if (opts->snapshot) {
847 dwarning("ignoring -snapshot option due to the use of -no-snapshot.");
848 }
849 }
850
851 if (!opts->no_snapshot_load || !opts->no_snapshot_save) {
852 if (opts->snapshot == NULL) {
853 opts->snapshot = "default-boot";
854 D("autoconfig: -snapshot %s", opts->snapshot);
855 }
856 }
857
858 /* We still use QEMU command-line options for the following since
859 * they can change from one invokation to the next and don't really
860 * correspond to the hardware configuration itself.
861 */
862 if (!opts->no_snapshot_load) {
863 args[n++] = "-loadvm";
864 args[n++] = ASTRDUP(opts->snapshot);
865 }
866
867 if (!opts->no_snapshot_save) {
868 args[n++] = "-savevm-on-exit";
869 args[n++] = ASTRDUP(opts->snapshot);
870 }
871
Tim Baverstock622b8f42010-12-07 11:36:59 +0000872 if (opts->no_snapshot_update_time) {
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +0100873 args[n++] = "-snapshot-no-time-update";
Tim Baverstock622b8f42010-12-07 11:36:59 +0000874 }
Ot ten Thijeae835ac2010-10-18 13:37:37 +0100875 }
Ot ten Thije353b3b12010-10-05 17:53:30 +0100876
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800877 if (!opts->logcat || opts->logcat[0] == 0) {
878 opts->logcat = getenv("ANDROID_LOG_TAGS");
879 if (opts->logcat && opts->logcat[0] == 0)
880 opts->logcat = NULL;
881 }
882
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800883 /* we always send the kernel messages from ttyS0 to android_kmsg */
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100884 if (opts->show_kernel) {
885 args[n++] = "-show-kernel";
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800886 }
887
888 /* XXXX: TODO: implement -shell and -logcat through qemud instead */
889 if (!opts->shell_serial) {
890#ifdef _WIN32
891 opts->shell_serial = "con:";
892#else
893 opts->shell_serial = "stdio";
894#endif
895 }
896 else
897 opts->shell = 1;
898
899 if (opts->shell || opts->logcat) {
900 args[n++] = "-serial";
901 args[n++] = opts->shell_serial;
902 shell_serial = serial++;
903 }
904
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100905 if (opts->radio) {
906 args[n++] = "-radio";
907 args[n++] = opts->radio;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800908 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800909
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100910 if (opts->gps) {
911 args[n++] = "-gps";
912 args[n++] = opts->gps;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800913 }
914
Nick Kralevich185231a2013-10-07 13:54:31 -0700915 if (opts->selinux) {
916 if ((strcmp(opts->selinux, "permissive") != 0)
917 && (strcmp(opts->selinux, "disabled") != 0)) {
918 derror("-selinux must be \"disabled\" or \"permissive\"");
919 exit(1);
920 }
921 }
922
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800923 if (opts->memory) {
924 char* end;
925 long ramSize = strtol(opts->memory, &end, 0);
926 if (ramSize < 0 || *end != 0) {
927 derror( "-memory must be followed by a positive integer" );
928 exit(1);
929 }
930 if (ramSize < 32 || ramSize > 4096) {
931 derror( "physical memory size must be between 32 and 4096 MB" );
932 exit(1);
933 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100934 hw->hw_ramSize = ramSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800935 }
936 if (!opts->memory) {
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100937 int ramSize = hw->hw_ramSize;
938 if (ramSize <= 0) {
939 /* Compute the default RAM size based on the size of screen.
940 * This is only used when the skin doesn't provide the ram
941 * size through its hardware.ini (i.e. legacy ones) or when
942 * in the full Android build system.
943 */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100944 int64_t pixels = hw->hw_lcd_width * hw->hw_lcd_height;
David 'Digit' Turner3bbc9192011-01-19 22:18:02 +0100945 /* The following thresholds are a bit liberal, but we
946 * essentially want to ensure the following mappings:
947 *
948 * 320x480 -> 96
949 * 800x600 -> 128
950 * 1024x768 -> 256
951 *
952 * These are just simple heuristics, they could change in
953 * the future.
954 */
955 if (pixels <= 250000)
956 ramSize = 96;
957 else if (pixels <= 500000)
958 ramSize = 128;
959 else
960 ramSize = 256;
961 }
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +0100962 hw->hw_ramSize = ramSize;
963 }
964
965 D("Physical RAM size: %dMB\n", hw->hw_ramSize);
966
967 if (hw->vm_heapSize == 0) {
968 /* Compute the default heap size based on the RAM size.
969 * Essentially, we want to ensure the following liberal mappings:
970 *
971 * 96MB RAM -> 16MB heap
972 * 128MB RAM -> 24MB heap
973 * 256MB RAM -> 48MB heap
974 */
975 int ramSize = hw->hw_ramSize;
976 int heapSize;
977
978 if (ramSize < 100)
979 heapSize = 16;
980 else if (ramSize < 192)
981 heapSize = 24;
982 else
983 heapSize = 48;
984
985 hw->vm_heapSize = heapSize;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800986 }
987
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800988 if (opts->trace) {
989 args[n++] = "-trace";
990 args[n++] = opts->trace;
991 args[n++] = "-tracing";
992 args[n++] = "off";
993 }
994
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700995 /* Pass boot properties to the core. */
996 if (opts->prop != NULL) {
997 ParamList* pl = opts->prop;
998 for ( ; pl != NULL; pl = pl->next ) {
999 args[n++] = "-boot-property";
1000 args[n++] = pl->param;
1001 }
1002 }
1003
David 'Digit' Turner318e4f22009-05-25 18:01:03 +02001004 /* Setup the kernel init options
1005 */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001006 {
1007 static char params[1024];
1008 char *p = params, *end = p + sizeof(params);
1009
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +01001010 /* Don't worry about having a leading space here, this is handled
1011 * by the core later. */
1012
Jun Nakajima334ab472011-02-02 23:49:59 -08001013#ifdef TARGET_I386
1014 p = bufprint(p, end, " androidboot.hardware=goldfish");
Jun Nakajimabac9add2011-02-08 22:10:52 -08001015 p = bufprint(p, end, " clocksource=pit");
Jun Nakajima334ab472011-02-02 23:49:59 -08001016#endif
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001017
1018 if (opts->shell || opts->logcat) {
1019 p = bufprint(p, end, " androidboot.console=ttyS%d", shell_serial );
1020 }
1021
1022 if (opts->trace) {
1023 p = bufprint(p, end, " android.tracing=1");
1024 }
1025
1026 if (!opts->no_jni) {
1027 p = bufprint(p, end, " android.checkjni=1");
1028 }
1029
1030 if (opts->no_boot_anim) {
1031 p = bufprint( p, end, " android.bootanim=0" );
1032 }
1033
1034 if (opts->logcat) {
1035 char* q = bufprint(p, end, " androidboot.logcat=%s", opts->logcat);
1036
1037 if (q < end) {
1038 /* replace any space by a comma ! */
1039 {
1040 int nn;
1041 for (nn = 1; p[nn] != 0; nn++)
1042 if (p[nn] == ' ' || p[nn] == '\t')
1043 p[nn] = ',';
1044 p += nn;
1045 }
1046 }
1047 p = q;
1048 }
1049
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001050 if (opts->bootchart) {
1051 p = bufprint(p, end, " androidboot.bootchart=%s", opts->bootchart);
1052 }
1053
Nick Kralevich185231a2013-10-07 13:54:31 -07001054 if (opts->selinux) {
1055 p = bufprint(p, end, " androidboot.selinux=%s", opts->selinux);
1056 }
1057
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001058 if (p >= end) {
1059 fprintf(stderr, "### ERROR: kernel parameters too long\n");
1060 exit(1);
1061 }
1062
David 'Digit' Turner0b019492011-03-01 14:02:42 +01001063 hw->kernel_parameters = strdup(params);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001064 }
1065
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07001066 if (opts->ports) {
1067 args[n++] = "-android-ports";
1068 args[n++] = opts->ports;
1069 }
1070
1071 if (opts->port) {
1072 args[n++] = "-android-port";
1073 args[n++] = opts->port;
1074 }
1075
1076 if (opts->report_console) {
1077 args[n++] = "-android-report-console";
1078 args[n++] = opts->report_console;
1079 }
1080
1081 if (opts->http_proxy) {
1082 args[n++] = "-http-proxy";
1083 args[n++] = opts->http_proxy;
1084 }
1085
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001086 if (!opts->charmap) {
1087 /* Try to find a valid charmap name */
1088 char* charmap = avdInfo_getCharmapFile(avd, hw->hw_keyboard_charmap);
1089 if (charmap != NULL) {
1090 D("autoconfig: -charmap %s", charmap);
1091 opts->charmap = charmap;
1092 }
1093 }
1094
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001095 if (opts->charmap) {
Xavier Ducrohet72d56112011-08-11 18:47:27 -07001096 char charmap_name[AKEYCHARMAP_NAME_SIZE];
1097
1098 if (!path_exists(opts->charmap)) {
1099 derror("Charmap file does not exist: %s", opts->charmap);
1100 exit(1);
1101 }
1102 /* We need to store the charmap name in the hardware configuration.
1103 * However, the charmap file itself is only used by the UI component
1104 * and doesn't need to be set to the emulation engine.
1105 */
1106 kcm_extract_charmap_name(opts->charmap, charmap_name,
1107 sizeof(charmap_name));
1108 AFREE(hw->hw_keyboard_charmap);
1109 hw->hw_keyboard_charmap = ASTRDUP(charmap_name);
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07001110 }
1111
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07001112 if (opts->memcheck) {
1113 args[n++] = "-android-memcheck";
1114 args[n++] = opts->memcheck;
1115 }
1116
David Turner9da935d2011-09-12 21:27:56 +02001117 if (opts->gpu) {
1118 const char* gpu = opts->gpu;
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001119 if (!strcmp(gpu,"on") || !strcmp(gpu,"enable")) {
David Turner9da935d2011-09-12 21:27:56 +02001120 hw->hw_gpu_enabled = 1;
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001121 } else if (!strcmp(gpu,"off") || !strcmp(gpu,"disable")) {
David Turner9da935d2011-09-12 21:27:56 +02001122 hw->hw_gpu_enabled = 0;
1123 } else if (!strcmp(gpu,"auto")) {
1124 /* Nothing to do */
1125 } else {
1126 derror("Invalid value for -gpu <mode> parameter: %s\n", gpu);
1127 derror("Valid values are: on, off or auto\n");
1128 exit(1);
1129 }
1130 }
1131
Vladimir Chtchetkine9242b332012-02-10 08:29:22 -08001132 /* Quit emulator on condition that both, gpu and snapstorage are on. This is
1133 * a temporary solution preventing the emulator from crashing until GPU state
1134 * can be properly saved / resored in snapshot file. */
1135 if (hw->hw_gpu_enabled && opts->snapstorage && (!opts->no_snapshot_load ||
1136 !opts->no_snapshot_save)) {
1137 derror("Snapshots and gpu are mutually exclusive at this point. Please turn one of them off, and restart the emulator.");
1138 exit(1);
1139 }
1140
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001141 /* Deal with camera emulation */
1142 if (opts->webcam_list) {
1143 /* List connected webcameras */
1144 args[n++] = "-list-webcam";
1145 }
1146
1147 if (opts->camera_back) {
1148 /* Validate parameter. */
1149 if (memcmp(opts->camera_back, "webcam", 6) &&
1150 strcmp(opts->camera_back, "emulated") &&
1151 strcmp(opts->camera_back, "none")) {
1152 derror("Invalid value for -camera-back <mode> parameter: %s\n"
1153 "Valid values are: 'emulated', 'webcam<N>', or 'none'\n",
1154 opts->camera_back);
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001155 exit(1);
1156 }
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001157 hw->hw_camera_back = ASTRDUP(opts->camera_back);
Vladimir Chtchetkineae0d8132011-09-13 10:48:02 -07001158 }
1159
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001160 if (opts->camera_front) {
1161 /* Validate parameter. */
1162 if (memcmp(opts->camera_front, "webcam", 6) &&
1163 strcmp(opts->camera_front, "emulated") &&
1164 strcmp(opts->camera_front, "none")) {
1165 derror("Invalid value for -camera-front <mode> parameter: %s\n"
1166 "Valid values are: 'emulated', 'webcam<N>', or 'none'\n",
1167 opts->camera_front);
1168 exit(1);
Vladimir Chtchetkineb8dcaff2011-09-17 11:15:47 -07001169 }
Vladimir Chtchetkine7485c292012-03-19 11:35:29 -07001170 hw->hw_camera_front = ASTRDUP(opts->camera_front);
Vladimir Chtchetkinef8675c22012-01-06 10:31:41 -08001171 }
1172
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01001173 /* physical memory is now in hw->hw_ramSize */
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001174
David 'Digit' Turner53eb66d2011-03-01 14:58:23 +01001175 hw->avd_name = ASTRDUP(avdInfo_getName(avd));
David 'Digit' Turner6b8555c2011-02-17 04:28:19 +01001176
Dries Harnie40beab42010-05-15 17:04:47 +02001177 /* Set up the interfaces for inter-emulator networking */
1178 if (opts->shared_net_id) {
1179 unsigned int shared_net_id = atoi(opts->shared_net_id);
1180 char nic[37];
Dries Harnie40beab42010-05-15 17:04:47 +02001181
1182 args[n++] = "-net";
1183 args[n++] = "nic,vlan=0";
1184 args[n++] = "-net";
1185 args[n++] = "user,vlan=0";
Dries Harnie111d6f82010-06-09 21:42:18 +02001186
1187 args[n++] = "-net";
1188 snprintf(nic, sizeof nic, "nic,vlan=1,macaddr=52:54:00:12:34:%02x", shared_net_id);
1189 args[n++] = strdup(nic);
1190 args[n++] = "-net";
1191 args[n++] = "socket,vlan=1,mcast=230.0.0.10:1234";
Dries Harnie40beab42010-05-15 17:04:47 +02001192 }
1193
Vladimir Chtchetkine8dd31e82012-02-15 17:16:04 -08001194 /* Setup screen emulation */
1195 if (opts->screen) {
Vladimir Chtchetkine863d1012012-03-16 12:25:23 -07001196 if (strcmp(opts->screen, "touch") &&
1197 strcmp(opts->screen, "multi-touch") &&
1198 strcmp(opts->screen, "no-touch")) {
1199
1200 derror("Invalid value for -screen <mode> parameter: %s\n"
1201 "Valid values are: touch, multi-touch, or no-touch\n",
1202 opts->screen);
Vladimir Chtchetkine8dd31e82012-02-15 17:16:04 -08001203 exit(1);
1204 }
Vladimir Chtchetkine863d1012012-03-16 12:25:23 -07001205 hw->hw_screen = ASTRDUP(opts->screen);
Vladimir Chtchetkine8dd31e82012-02-15 17:16:04 -08001206 }
1207
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001208 while(argc-- > 0) {
1209 args[n++] = *argv++;
1210 }
1211 args[n] = 0;
1212
David 'Digit' Turner2ed457e2011-06-15 17:29:50 +02001213 /* If the target ABI is armeabi-v7a, we can auto-detect the cpu model
1214 * as a cortex-a8, instead of the default (arm926) which only emulates
1215 * an ARMv5TE CPU.
1216 */
1217 if (!forceArmv7 && hw->hw_cpu_model[0] == '\0')
1218 {
1219 char* abi = avdInfo_getTargetAbi(avd);
1220 if (abi != NULL) {
1221 if (!strcmp(abi, "armeabi-v7a")) {
1222 forceArmv7 = 1;
1223 }
1224 AFREE(abi);
1225 }
1226 }
1227
1228 if (forceArmv7 != 0) {
1229 AFREE(hw->hw_cpu_model);
1230 hw->hw_cpu_model = ASTRDUP("cortex-a8");
1231 D("Auto-config: -qemu -cpu %s", hw->hw_cpu_model);
1232 }
1233
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001234 /* Generate a hardware-qemu.ini for this AVD. The real hardware
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001235 * configuration is ususally stored in several files, e.g. the AVD's
1236 * config.ini plus the skin-specific hardware.ini.
1237 *
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001238 * The new file will group all definitions and will be used to
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001239 * launch the core with the -android-hw <file> option.
1240 */
1241 {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001242 const char* coreHwIniPath = avdInfo_getCoreHwIniPath(avd);
1243 IniFile* hwIni = iniFile_newFromMemory("", NULL);
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001244 androidHwConfig_write(hw, hwIni);
David 'Digit' Turner26d41532011-03-01 15:03:07 +01001245
1246 if (filelock_create(coreHwIniPath) == NULL) {
1247 /* The AVD is already in use, we still support this as an
1248 * experimental feature. Use a temporary hardware-qemu.ini
1249 * file though to avoid overwriting the existing one. */
1250 TempFile* tempIni = tempfile_create();
1251 coreHwIniPath = tempfile_path(tempIni);
1252 }
1253
Vladimir Chtchetkinedb450d72012-01-12 13:37:40 -08001254 /* While saving HW config, ignore valueless entries. This will not break
1255 * anything, but will significantly simplify comparing the current HW
1256 * config with the one that has been associated with a snapshot (in case
1257 * VM starts from a snapshot for this instance of emulator). */
1258 if (iniFile_saveToFileClean(hwIni, coreHwIniPath) < 0) {
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001259 derror("Could not write hardware.ini to %s: %s", coreHwIniPath, strerror(errno));
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001260 exit(2);
1261 }
1262 args[n++] = "-android-hw";
David 'Digit' Turner42074e52011-02-10 16:03:28 +01001263 args[n++] = strdup(coreHwIniPath);
David 'Digit' Turner0a879bf2011-05-12 18:45:18 +02001264
1265 /* In verbose mode, dump the file's content */
1266 if (VERBOSE_CHECK(init)) {
1267 FILE* file = fopen(coreHwIniPath, "rt");
1268 if (file == NULL) {
1269 derror("Could not open hardware configuration file: %s\n",
1270 coreHwIniPath);
1271 } else {
1272 LineInput* input = lineInput_newFromStdFile(file);
1273 const char* line;
1274 printf("Content of hardware configuration file:\n");
1275 while ((line = lineInput_getLine(input)) != NULL) {
1276 printf(" %s\n", line);
1277 }
1278 printf(".\n");
1279 lineInput_free(input);
1280 fclose(file);
1281 }
1282 }
David 'Digit' Turner622f1532011-02-01 17:48:37 +01001283 }
1284
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001285 if(VERBOSE_CHECK(init)) {
1286 int i;
David 'Digit' Turner33361762011-01-19 22:11:03 +01001287 printf("QEMU options list:\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001288 for(i = 0; i < n; i++) {
David 'Digit' Turner33361762011-01-19 22:11:03 +01001289 printf("emulator: argv[%02d] = \"%s\"\n", i, args[i]);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001290 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001291 /* Dump final command-line option to make debugging the core easier */
1292 printf("Concatenated QEMU options:\n");
1293 for (i = 0; i < n; i++) {
David 'Digit' Turner26722dd2011-02-24 16:40:20 +01001294 /* To make it easier to copy-paste the output to a command-line,
1295 * quote anything that contains spaces.
1296 */
1297 if (strchr(args[i], ' ') != NULL) {
1298 printf(" '%s'", args[i]);
1299 } else {
1300 printf(" %s", args[i]);
1301 }
David 'Digit' Turner33361762011-01-19 22:11:03 +01001302 }
1303 printf("\n");
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001304 }
David 'Digit' Turner74d7ace2011-02-02 13:21:03 +01001305
1306 /* Setup SDL UI just before calling the code */
1307 init_sdl_ui(skinConfig, skinPath, opts);
1308
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +01001309 if (attach_ui_to_core(opts) < 0) {
1310 derror("Can't attach to core!");
1311 exit(1);
1312 }
1313
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001314 return qemu_main(n, args);
1315}