fwgdb: Add support for unified builds

Unified builds have a model subdirectory. Make fwgdb look in the model
directory for fw.

BUG=none
TEST=Tested on grunt using: fwgdb --cgdb

Change-Id: Ib1bee497b5c4692d8942004f4ab30bc40e6334d5
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1064813
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/scripts/fwgdb.py b/scripts/fwgdb.py
index 7d78078..f8d772d 100644
--- a/scripts/fwgdb.py
+++ b/scripts/fwgdb.py
@@ -8,6 +8,7 @@
 from __future__ import print_function
 
 import errno
+import glob
 import os
 import re
 import socket
@@ -96,11 +97,26 @@
 
 def FindSymbols(firmware_dir, board):
   """Find the symbolized depthcharge ELF (may be supplied by -s flag)."""
+
+  # Allow overriding the file directly just in case our detection screws up.
+  if firmware_dir and firmware_dir.endswith('.elf'):
+    return firmware_dir
+
+  if not firmware_dir:
+    # Unified builds have the format
+    # /build/<board|family>/firmware/<build_target|model>/. The board in
+    # depthcharge corresponds to the build_target in unified builds. For this
+    # reason we need to glob all boards to find the correct build_target.
+    unified_build_dirs = glob.glob('/build/*/firmware/%s' % board)
+    if len(unified_build_dirs) == 1:
+      firmware_dir = unified_build_dirs[0]
+    elif len(unified_build_dirs) > 1:
+      raise ValueError(
+          'Multiple boards were found (%s). Use -s to specify manually' %
+          (', '.join(unified_build_dirs)))
+
   if not firmware_dir:
     firmware_dir = os.path.join(cros_build_lib.GetSysroot(board), 'firmware')
-  # Allow overriding the file directly just in case our detection screws up
-  if firmware_dir.endswith('.elf'):
-    return firmware_dir
 
   # Very old firmware you might still find on GoldenEye had dev.ro.elf.
   basenames = ['dev.elf', 'dev.ro.elf']