STOUT-FIRMWARE: Cache GBB images to speed up display

Rather than read the images from slow flash every time we need them, cache
them the first time and use that cache thereafter.

BUG=none
BRANCH=stout
TEST=manual, test basic firmware functions.

Change-Id: Ic0ad0bef7a958feb3ac044e41774be5c87f67e22
Original-Change-Id: Ieb39c44bddeb6315da8983669f19f550888659bd
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/35919
Reviewed-by: Shawn Nematbakhsh <shawnn@google.com>
Tested-by: Shawn Nematbakhsh <shawnn@google.com>
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index 16b1ea1..b15b518 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -161,7 +161,7 @@
 VbError_t VbDisplayScreenFromGBB(VbCommonParams* cparams, uint32_t screen,
                                  VbNvContext *vncptr) {
   GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)cparams->gbb_data;
-  uint8_t* bmpfv = NULL;
+  static uint8_t* bmpfv;
   void* fullimage = NULL;
   BmpBlockHeader* hdr;
   ScreenLayout* layout;
@@ -187,8 +187,10 @@
   }
 
   /* Copy bitmap data from GBB into RAM for speed */
-  bmpfv = (uint8_t*)VbExMalloc(gbb->bmpfv_size);
-  Memcpy(bmpfv, ((uint8_t*)gbb) + gbb->bmpfv_offset, gbb->bmpfv_size);
+  if (!bmpfv) {
+    bmpfv = (uint8_t*)VbExMalloc(gbb->bmpfv_size);
+    Memcpy(bmpfv, ((uint8_t*)gbb) + gbb->bmpfv_offset, gbb->bmpfv_size);
+  }
 
   /* Sanity-check the bitmap block header */
   hdr = (BmpBlockHeader *)bmpfv;
@@ -341,8 +343,6 @@
 VbDisplayScreenFromGBB_exit:
 
   VBDEBUG(("leaving VbDisplayScreenFromGBB() with %d\n",retval));
-  /* Free the bitmap data copy */
-  VbExFree(bmpfv);
   return retval;
 }