diff options
author | David 'Digit' Turner <digit@android.com> | 2011-03-01 14:04:00 +0100 |
---|---|---|
committer | David 'Digit' Turner <digit@android.com> | 2011-03-01 15:31:11 +0100 |
commit | 40841b2d221273a08abfe20824e7631211ade31d (patch) | |
tree | ea4ae5d5dd91b9473a4fd34c46e50f7af246f2a0 /android/main.c | |
parent | 5f64b873605baa5519211b0d47a53c93df9d4868 (diff) | |
download | external_qemu-40841b2d221273a08abfe20824e7631211ade31d.zip external_qemu-40841b2d221273a08abfe20824e7631211ade31d.tar.gz external_qemu-40841b2d221273a08abfe20824e7631211ade31d.tar.bz2 |
Move system image initialization to core.
Change-Id: Ic8da3ccaed9bab7dbb44c0bb341b0dba20b90980
Diffstat (limited to 'android/main.c')
-rw-r--r-- | android/main.c | 160 |
1 files changed, 151 insertions, 9 deletions
diff --git a/android/main.c b/android/main.c index 240574a..33a96ea 100644 --- a/android/main.c +++ b/android/main.c @@ -108,6 +108,52 @@ void emulator_help( void ) exit(1); } +/* TODO: Put in shared source file */ +static char* +_getFullFilePath( const char* rootPath, const char* fileName ) +{ + if (path_is_absolute(fileName)) { + return ASTRDUP(fileName); + } else { + char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp); + + p = bufprint(temp, end, "%s/%s", rootPath, fileName); + if (p >= end) { + return NULL; + } + return ASTRDUP(temp); + } +} + +static uint64_t +_adjustPartitionSize( const char* description, + uint64_t imageBytes, + uint64_t defaultBytes, + int inAndroidBuild ) +{ + char temp[64]; + unsigned imageMB; + unsigned defaultMB; + + if (imageBytes <= defaultBytes) + return defaultBytes; + + imageMB = convertBytesToMB(imageBytes); + defaultMB = convertBytesToMB(defaultBytes); + + if (imageMB > defaultMB) { + snprintf(temp, sizeof temp, "(%d MB > %d MB)", imageMB, defaultMB); + } else { + snprintf(temp, sizeof temp, "(%lld bytes > %lld bytes)", imageBytes, defaultBytes); + } + + if (inAndroidBuild) { + dwarning("%s partition size adjusted to match image file %s\n", description, temp); + } + + return convertMBToBytes(imageMB); +} + int main(int argc, char **argv) { char tmp[MAX_PATH]; @@ -126,6 +172,7 @@ int main(int argc, char **argv) AConfig* skinConfig; char* skinPath; int inAndroidBuild; + uint64_t defaultPartitionSize = convertMBToBytes(66); AndroidOptions opts[1]; /* net.shared_net_ip boot property value. */ @@ -426,21 +473,116 @@ int main(int argc, char **argv) hw->disk_ramdisk_path = avdInfo_getRamdiskPath(avd); D("autoconfig: -ramdisk %s", hw->disk_ramdisk_path); + /* -partition-size is used to specify the max size of both the system + * and data partition sizes. + */ + if (opts->partition_size) { + char* end; + long sizeMB = strtol(opts->partition_size, &end, 0); + long minSizeMB = 10; + long maxSizeMB = LONG_MAX / ONE_MB; + + if (sizeMB < 0 || *end != 0) { + derror( "-partition-size must be followed by a positive integer" ); + exit(1); + } + if (sizeMB < minSizeMB || sizeMB > maxSizeMB) { + derror( "partition-size (%d) must be between %dMB and %dMB", + sizeMB, minSizeMB, maxSizeMB ); + exit(1); + } + defaultPartitionSize = (uint64_t) sizeMB * ONE_MB; + } + + + /** SYSTEM PARTITION **/ + + if (opts->sysdir == NULL) { + if (avdInfo_inAndroidBuild(avd)) { + opts->sysdir = ASTRDUP(avdInfo_getContentPath(avd)); + D("autoconfig: -sysdir %s", opts->sysdir); + } + } + + if (opts->sysdir != NULL) { + if (!path_exists(opts->sysdir)) { + derror("Directory does not exist: %s", opts->sysdir); + exit(1); + } + } + { - const char* filetype = "file"; + char* rwImage = NULL; + char* initImage = NULL; + + do { + if (opts->system == NULL) { + /* If -system is not used, try to find a runtime system image + * (i.e. system-qemu.img) in the content directory. + */ + rwImage = avdInfo_getSystemImagePath(avd); + if (rwImage != NULL) { + break; + } + /* Otherwise, try to find the initial system image */ + initImage = avdInfo_getSystemInitImagePath(avd); + if (initImage == NULL) { + derror("No initial system image for this configuration!"); + exit(1); + } + break; + } - // TODO: This should go to core - if (avdInfo_isImageReadOnly(avd, AVD_IMAGE_INITSYSTEM)) - filetype = "initfile"; + /* If -system <name> is used, use it to find the initial image */ + if (opts->sysdir != NULL) { + initImage = _getFullFilePath(opts->sysdir, opts->system); + } else { + initImage = ASTRDUP(opts->system); + } + if (!path_exists(initImage)) { + derror("System image file doesn't exist: %s", initImage); + exit(1); + } - bufprint(tmp, tmpend, - "system,size=0x%x,%s=%s", (uint32_t)hw->disk_systemPartition_size, - filetype, avdInfo_getImageFile(avd, AVD_IMAGE_INITSYSTEM)); + } while (0); + + if (rwImage != NULL) { + /* Use the read/write image file directly */ + hw->disk_systemPartition_path = rwImage; + hw->disk_systemPartition_initPath = NULL; + D("Using direct system image: %s", rwImage); + } else if (initImage != NULL) { + hw->disk_systemPartition_path = NULL; + hw->disk_systemPartition_initPath = initImage; + D("Using initial system image: %s", initImage); + } - args[n++] = "-nand"; - args[n++] = strdup(tmp); + /* Check the size of the system partition image. + * If we have an AVD, it must be smaller than + * the disk.systemPartition.size hardware property. + * + * Otherwise, we need to adjust the systemPartitionSize + * automatically, and print a warning. + * + */ + const char* systemImage = hw->disk_systemPartition_path; + uint64_t systemBytes; + + if (systemImage == NULL) + systemImage = hw->disk_systemPartition_initPath; + + if (path_get_size(systemImage, &systemBytes) < 0) { + derror("Missing system image: %s", systemImage); + exit(1); + } + + hw->disk_systemPartition_size = + _adjustPartitionSize("system", systemBytes, defaultPartitionSize, + avdInfo_inAndroidBuild(avd)); } + /** DATA PARTITION **/ + bufprint(tmp, tmpend, "userdata,size=0x%x,file=%s", (uint32_t)hw->disk_dataPartition_size, |