scripts: fwgdb: Minor improvements to make reboot output less ugly

With the Python 3 update we decided to use byte strings for all the data
coming through the UART, which seems appropriate since this is a raw
byte channel. However, when printing raw byte strings with
logging.debug() in Python, they look pretty ugly (e.g. escaping newline
characters). This patch re-encodes them to text strings when logging to
avoid that, and additionally avoids logging empty lines (which there
tend to be a lot of since the UART output seems to come through in
bursts).

Also, since we just spam Ctrl+G once we reach depthcharge to trigger GDB
entry, and we can spam pretty fast in a tight loop, the firmware output
tends to get pushed away from screens full of "[Ctrl+G]". It's probably
still a good idea to print that we're pressing it, but we don't actually
need to press it quite this often to be effective -- add a little delay
between presses to mitigate this issue.

BUG=none
TEST=Connected to GDB on CoachZ

Change-Id: I082a71b72bbf2b5b897ba1a25e56d10f411f8033
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3721849
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Shelley Chen <shchen@chromium.org>
Commit-Queue: Julius Werner <jwerner@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Julius Werner <jwerner@chromium.org>
Tested-by: Julius Werner <jwerner@chromium.org>
diff --git a/scripts/fwgdb.py b/scripts/fwgdb.py
index 48e08a9..351233e 100644
--- a/scripts/fwgdb.py
+++ b/scripts/fwgdb.py
@@ -134,7 +134,8 @@
     if e.errno != errno.EAGAIN:
       raise
   data = b''.join(data)
-  logging.debug(data)
+  if data:
+    logging.debug(data.decode('ascii', errors='replace'))
   return data
 
 
@@ -203,6 +204,9 @@
              'and that you have GBB_FLAG_FORCE_DEV_SWITCH_ON (0x8) set.)')
       with timeout_util.Timeout(5, msg):
         while not re.search(_PTRN_GDB, data):
+          # Some delay to avoid spamming the console too hard while not being
+          # long enough to cause a user-visible slowdown.
+          time.sleep(0.5)
           # Send a CTRL+G to tell depthcharge to trap into GDB.
           logging.debug('[Ctrl+G]')
           os.write(fd, b'\x07')