Merge "look for the pc-bios files in the SDK tools/lib/pc-bios directory"
diff --git a/vl-android.c b/vl-android.c
index cb32eb2..b93ce9c 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -3547,9 +3547,11 @@
 
 /* Find a likely location for support files using the location of the binary.
    For installed binaries this will be "$bindir/../share/qemu".  When
-   running from the build tree this will be "$bindir/../pc-bios".  */
+   running from the build tree this will be "$bindir/../pc-bios".
+   The emulator running from the SDK will find the support files in $bindir/lib/pc-bios. */
 #define SHARE_SUFFIX "/share/qemu"
 #define BUILD_SUFFIX "/pc-bios"
+#define SDK_SUFFIX "/lib/pc-bios"
 static char *find_datadir(const char *argv0)
 {
     char *dir;
@@ -3590,19 +3592,25 @@
             return NULL;
         }
     }
-    dir = dirname(p);
-    dir = dirname(dir);
 
-    max_len = strlen(dir) +
-        MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
+#define STRLEN_CONST(str) (sizeof(str)-1)
+    dir = dirname(p);
+    max_len = strlen(dir) + 1 +
+        MAX(STRLEN_CONST(SDK_SUFFIX), MAX(STRLEN_CONST(SHARE_SUFFIX), STRLEN_CONST(BUILD_SUFFIX)));
     res = qemu_mallocz(max_len);
-    snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
+
+    snprintf(res, max_len, "%s%s", dir, SDK_SUFFIX);
     if (access(res, R_OK)) {
-        snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
-        if (access(res, R_OK)) {
-            qemu_free(res);
-            res = NULL;
-        }
+      dir = dirname(dir);
+
+      snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
+      if (access(res, R_OK)) {
+          snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
+          if (access(res, R_OK)) {
+              qemu_free(res);
+              res = NULL;
+          }
+      }
     }
 #ifndef PATH_MAX
     free(p);