Automatically search for UBOOT location for NPCM8xx images.
diff --git a/npcm8xx/image.c b/npcm8xx/image.c
index f799774..3dade5c 100644
--- a/npcm8xx/image.c
+++ b/npcm8xx/image.c
@@ -1,7 +1,7 @@
 /*
  * Boot image parsing and loading.
  *
- * Copyright 2022 Google LLC
+ * Copyright 2020 Google LLC
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,10 +21,18 @@
 #define SPI0CS0 0x80000000
 #define CLK 0xf0801000
 #define FIU0 0xfb000000
+
 #define CLK_CLKSEL  0x04
 #define CLK_CLKSEL_DEFAULT 0x1f18fc9
+
 #define FIU_DRD_CFG 0x00
 
+#define UBOOT_TAG       0x4c42544f4f42550aULL  /* .UBOOTBL */
+#define UBOOT_MAGIC     0x1400000a
+#define UBOOT_SIZE      0xae680
+#define UBOOT_INVALID   0xffffffff
+#define UBOOT_DEST      0x7e00
+
 /*
  * This structure must reside at offset 0x100 in SRAM.
  *
@@ -70,17 +78,26 @@
     }
 }
 
+static void search_and_load_uboot(uintptr_t end)
+{
+    uintptr_t addr;
+    uintptr_t src_addr, dest_addr = UBOOT_DEST;
+
+    for (addr = 0; addr < end; addr += 0x100) {
+        src_addr = SPI0CS0 + addr;
+        if ((*(uint64_t *)src_addr == UBOOT_TAG) &&
+            (*(uint32_t *)(src_addr + 0x200) == UBOOT_MAGIC)) {
+            copy_boot_image(dest_addr, src_addr, UBOOT_SIZE);
+            return;
+        }
+    }
+}
+
 uintptr_t load_boot_image(void)
 {
-    uintptr_t dest_addr = 0x8000;
-
     /* Set CLKSEL to similar values as NPCM7XX */
     reg_write(CLK, CLK_CLKSEL, CLK_CLKSEL_DEFAULT);
+    search_and_load_uboot(0x200000);
 
-    /* Load the U-BOOT image to DRAM */
-    copy_boot_image(dest_addr, SPI0CS0 + 0x20200, 0xa6e80);
-    /* Set FIU to use 4 byte mode, similar to what TIP does in reality. */
-    reg_write(FIU0, FIU_DRD_CFG, 0x0301100b);
-
-    return dest_addr;
+    return UBOOT_DEST + 0x200;
 }